fi.hu.cs.titokone
Class AssariUI

java.lang.Object
  extended byHttpServlet
      extended byfi.hu.cs.titokone.AssariUI

public class AssariUI
extends HttpServlet

This class is a servlet providing a HTML interface to the TTK91 simulator's core functions. It provides a method for compiling a program (the output is printed out, but not stored as such), for compiling and running a program either in whole or for a fixed number of commands (the program's output to screen and STDOUT is printed out, as is the memory up to the stack pointer and the registers' values and computer state). The TTK91 simulatee computer is recreated for each request.

See Also:
Serialized Form

Field Summary
static int EXECUTE_ALL
          This field defines the value to input in the command counter to execute commands until the program stops.
static int MAX_CYCLES
          This field contains the maximum number of TTK91 cpu cycles the given TTK91 code is allowed to execute until it is assumed to be in an infinite loop and is stopped.
private  Settings settings
           
 
Constructor Summary
AssariUI()
          This method sets up a new AssariUI servlet.
 
Method Summary
 void doGet(HttpServletRequest request, HttpServletResponse response)
          This method responds to a GET command.
 void doPost(HttpServletRequest request, HttpServletResponse response)
          This method respons to a POST command.
private  java.lang.String getPrintOut(TTK91Core computer)
          This method gathers a printout of the computer's state after running an application and returns it.
private  java.lang.String makeForm(java.lang.String code, java.lang.String kbdInput, java.lang.String fileInput, java.lang.String printout, int commandCounter)
          This method produces a string containing an HTML form that contains the input fields.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

settings

private Settings settings

EXECUTE_ALL

public static final int EXECUTE_ALL
This field defines the value to input in the command counter to execute commands until the program stops. In practice, the value is replaced by MAX_CYCLES. See also MAX_CYCLES.

See Also:
Constant Field Values

MAX_CYCLES

public static final int MAX_CYCLES
This field contains the maximum number of TTK91 cpu cycles the given TTK91 code is allowed to execute until it is assumed to be in an infinite loop and is stopped.

See Also:
Constant Field Values
Constructor Detail

AssariUI

public AssariUI()
This method sets up a new AssariUI servlet. It initializes a new TTK91Core for its use, and sets up the necessary settings for it.

Method Detail

doGet

public void doGet(HttpServletRequest request,
                  HttpServletResponse response)
           throws ServletException,
                  java.io.IOException
This method responds to a GET command. It produces a new HTML page containing a form gotten from makeForm() according to the user input, possibly after creating a computer and running a posted program on it. Any exceptions from the TTK91Core are caught and error messages are written to the user. The parameters and exceptions thrown are defined in HttpServlet's corresponding method.

Throws:
ServletException
java.io.IOException

doPost

public void doPost(HttpServletRequest request,
                   HttpServletResponse response)
            throws ServletException,
                   java.io.IOException
This method respons to a POST command. It calls doGet with its parameters and throws what it would throw. See doGet.

Throws:
ServletException
java.io.IOException

makeForm

private java.lang.String makeForm(java.lang.String code,
                                  java.lang.String kbdInput,
                                  java.lang.String fileInput,
                                  java.lang.String printout,
                                  int commandCounter)
This method produces a string containing an HTML form that contains the input fields.

Parameters:
code - The code string to insert in the TTK91 code text field.
kbdInput - The input string to insert in the KBD input text field.
fileInput - The input string to insert in the STDIN input text field.
printout - The output string to insert in the Program Output text field.
commandCounter - The number to insert in the counter for how many commands should be executed, or 0 if the field has either not been changed or has been changed to an invalid value (nonnumeric).
Returns:
A string containing the form.

getPrintOut

private java.lang.String getPrintOut(TTK91Core computer)
This method gathers a printout of the computer's state after running an application and returns it.

Parameters:
computer - A TTK91Core to draw the state information from.
Returns:
A string describing the computer's state, including things it printed out.