index previous next 

file name: cont_sw.hpp, cont_sw.cpp
classification: pure simulation
contents: class CSoftwareController
derived from: class ACController
use: the controller class used for pure simulation (Linux with C++SIM)
 

global items used:

 
local items defined in the implementation file:

int dummy_announce (renvx *, bufx *, INT16, int): dummy function for ci_init(). Should never be called. It the function is called, an assert fails.

int dummy_error_announce (tenvx *, bufx *, INT16, int, int): dummy error function for ci_init(). Should never be called. It the function is called, an assert fails.
 

member variables:

SINT32 networkID_: Contains the first free network ID. Whenever a new network is created, this value is used for its ID.
default and reset value: 1
 

member functions:

CSoftwareController (char qname[4], ACSocketAddress *addr): The constructor sets all members to their default values.

~CSoftwareController(): calls DeleteAllSimulationObjects().
Note: This function is also called in the base class, but since the derived object is already destructed, the class would only call its own function, not that of the derived class. Furthermore, since ACController::DeleteAllSimulationObjects() would call the pure virtual function ACController::StopApplication(), an error would occur.

EBool CreateNewNetwork (SNetworkCreateCommand& command): The function obtains the creation function for a network of type command.networkType from the network manager and creates a new network of that type. ci_init() is called to initialize the network, and ReplyToMessage() is called with the networkID (cast to double) to send the ID to the evaluation. Then, networkID is incremented and True is returned. If the network type is not installed, the function returns False. If ci_init() returns an error code, an assert fails.

virtual void DeleteAllSimulationObjects (): Removes all objects from the listOfClocks and listOfLances. Then calls DeleteAllSimulationObjects() of the base class to delete the supervisors. At last, all networks stored in the listOfNetworks are deleted.

EBool DeleteANetwork (SNetworkCommand& command): If the network with the command.networkID is stored in the listOfNetworks, it is deleted and True is returned. If no network with the given ID was found, the function returns False.

virtual EBool ExecuteCommand (const SCommand& command): If param.module = Network, ExecuteNetworkCommand() is called and its value is returned.

All other commands to the Controller are passed to the ExecuteCommand() function of the base class and its value is returned.

EBool ExecuteNetworkCommand (SNetworkCommand& command): Searches for the command.networkID in the listOfNetworks. If a network was found, its ExecuteCommand() function is called with command and the return value of that function is returned. Otherwise, the function returns False.

virtual EBool GetParameter (SParameter& param) const: If param.module == Network, the controller searches for the network with the specified ID (param is cast to type SNetworkParameter) and returns the value of its GetParameter() function.
All parameters to the Controller are passed to the GetParameter() function of the base class and its value is returned.

virtual void Reset(): Sets the networkID to its reset value and calls the Reset() function of the base class.

virtual EBool ResetTheSimulation(): Goes through the listOfNetworks and calls the Reset() functions of the networks. Then the function calls ResetTheSimulation() of the base class to reset the supervisors. If ACController::ResetTheSimulation() returns True, or if at least one network was stored in the list, the function returns True. Otherwise, there was nothing to reset and the function returns False.

virtual EBool SetParameter (const SParameter& param): If param.module == Network, the controller searches for the network with the specified ID (param is cast to type SNetworkParameter) and returns the value of its SetParameter() function.
All parameters to the Controller are passed to the SetParameter() function of the base class and its value is returned.

virtual EBool StartApplication (SINT32 nodeID, int area): Searches for the supervisor of the application in the listOfSupervisors. If it was found, its clock and lance objects are inserted into the listOfClocks and listOfLances. Then, the supervisor process is referenced (if resource control is turned on) and scheduled to become active at once. The function always returns True. If no supervisor was found, an assert fails.

virtual EBool StopApplication (SINT32 nodeID, int area): Searches for the supervisor in the listOfSupervisors. If it was found, it is suspended through calling its SuspendOperation() function, then it is reset. That should kill all C++SIM processes associated with it (the clock interrupts). Then, functions Cancel() and terminate() of the supervisor are called to stop the supervisor process itself. The clock and lance objects are removed from their lists, and if NO_RESOURCE is not defined, ClearISRs() is called to remove all ISRs of this CSA.
Note that the supervisor process is not unreferenced. It is assumed that the listOfSupervisors does that when the supervisor is deleted. If no supervisor was found, an assert fails.

virtual void StopExecution(): The function sets global variable g_finished to true and calls Cancel() to deactivate the controller process. Since it is executed in the context of this process, the function does not return.


last modified: Fri Feb 5 18:56:08 1999