Top Up Prev Next Bottom Contents Index Search

4.4 Class SimControl

The SimControl class controls execution of the simulation. It has some global status flags that indicate whether there has been an error in the execution or if a halt has been requested. It also has mechanisms for registering functions to be called before or after star executions, or in response to a particular star's execution, and responding to interrupts. This class interacts with the Error class (which sets error and halt bits) and the Star class (to permit execution of registered actions when stars are fired). Schedulers and Targets are expected to monitor the SimControl halt flag to halt execution when errors are signaled and halts are requested. Once exceptions are commonplace in C++ implementations, a cleaner implementation could be produced.

4.4.1 Access to SimControl status flags.

SimControl currently has four global status bits: the error bit, the halt bit, the interrupt bit, and the poll bit. These functions set, clear, or report on these bits.

static void requestHalt (); 
This function sets the halt bit. The effect is to cause schedulers and targets to cease execution. It is important to note that this function does not alter flow of control; it only sets a flag.

static void declareErrorHalt (); 
This is the same as requestHalt except that it also sets the error bit. It is called, for example, by Error::abortRun.

static int haltRequested (); 
This function returns true if the halt bit is set, false otherwise. If the poll or interrupt bits are set, it calls handlers for them (see the subsection describing these).

static void clearHalt (); 
This function clears the halt and error flags.

4.4.2 Pre-actions and Post-actions

SimControl can register a function that will be called before or after the execution of a particular star, or before or after the execution of all stars. A function that is called before a star is a preaction; on that is called after a star is a post-action. The functions that can be registered have take two arguments: a pointer to a Star (possibly null), and a const char* pointer that points to a string (possibly null). The type definition

typedef void (*SimActionFunction)(Star*,const char*); 
gives the name SimActionFunction to functions of this type; several SimControl functions take arguments of this form.

static SimAction* registerAction(SimActionFunction action, int pre,
const char* textArg = 0, Star* which = 0);
Register a pre-action or post-action. If pre is TRUE it is a preaction. If textArg is given, it is passed as an argument when the action function is called. If which is 0, the function will be called unconditionally by doPreActions (if it is a preaction) or doPostActions (if it is a post-action; otherwise it will only be called if the star being executed has the same address as which. The return value represents the registered action; class SimAction is treated as if it is opaque (I'm not telling you what is in it) which can be used for cancel calls.

static int doPreActions(Star * which); 
static int doPostActions(Star * which);
Execute all pre-actions, or post-actions, for a the particular Star which. The which pointer is passed to each action function, along with any text argument declared when the action was registered. Return TRUE if no halting condition arises, FALSE if we are to halt.

static int cancel(SimAction* action); 
Cancel action. Warning: argument is deleted. Future versions will provide more ways of cancelling actions.

4.4.3 SimControl interrupts and polling

Features in this section will be used in a new graphic interface; they are mostly untested at this point. The SimControl class can handle interrupts and can register a polling function that is called for every star execution. It only provides one handler.

static void catchInt(int signo = -1, int always = 0); 
This static member function installs a simple interrupt handler for the signal with Unix signal number signo. If always is true, the signal is always caught; otherwise the signal is not caught if the current status of the signal is that it is ignored (for example, processes running in the background ignore interrupt signals from the keyboard). This handler simply sets the SimControl interrupt bit; on the next call to haltRequested, the user-specified interrupt handler is called.

static SimHandlerFunction setInterrupt(SimHandlerFunction f); 
Set the user-specified interrupt handler to f, and return the old handler, if any. This function is called in response to any signals specified in catchInt.

static SimHandlerFunction setPoll(SimHandlerFunction f); 
Register a function to be called by haltRequested if the poll flag is set, and set the poll flag. Returns old handler if any.

Top Up Prev Next Bottom Contents Index Search

Copyright © 1990-1997, University of California. All rights reserved.