When ACS generates a Class that owns a State Diagram through a State Machine, ACS generates state machine code to implement the State Diagram unless the «C++ Class» stereotype has been applied to the Class and the tagged value of the C++ Generate State Machine tag definition set to FALSE.
When you choose to generate code for State Diagrams, the ACS generates attributes, typedefs and operations in the code to implement the State Diagrams associated with the Classes that are being generated.
When ACS generates an attribute, typedef or operation in a code file, that attribute, typedef or operation is not associated with an Attribute, Typedef or Operation item in the model. To help you identify these code elements in the code files, ACS prefixes code elements generated for State Diagrams with 'Rts', except for the constructor and destructor operations. In addition, the code elements are conditional through RTS_SIMULATINON, so that they are not reversed into the Model as model items.
This topic uses an example to provide an overview of the Attributes, Typedefs and Operations that are generated from a simple State Diagram.
For entering the state machine
ACS generates a constructor operation to initialize the Class.
cBarCodeReader::cBarCodeReader() { RtsNotifySynchronous(CREATE,"4be68c7c-a4e7-4960-a1d7-448f7ffdeb6c",0, NULL); RtsCreateSemaphore(RtsBusy); RtsLock(RtsBusy); /* Initializing State Vectors to NotIn */ RtsCurrent_cBarCodeReader=RtscBarCodeReader_States_NotIn_cBarCodeReader; while(RtsRunToCompletion()); RtsUnlock(RtsBusy); }
For setting and reading the current state of the state machine:
ACS generates a current state attribute to store the current state of the Class.
RtssdBCReader_States RtsCurrent_sdBCReader;
The preceding attribute can be set to Idle, Reading or NotIn_sdBCReader. NotIn_sdBCReader indicates that the state machine is not active.
ACS generates an enter state operation to initialize each State (Idle and Reading) on entry.
void cBarCodeReader::RtsEnter_Idle() { /* Simulation support : Notification function call for entering state : Idle */ RtsNotify(ENTER,"682cee54-01d5-46e9-b5d1-7bf579f3cf5b",0,NULL); RtsCurrent_sdBCReader = RtssdBCReader_States_Idle; } void cBarCodeReader::RtsEnter_Reading() { /* Simulation support : Notification function call for entering state : Reading */ RtsNotify(ENTER,"380d33eb-71c5-4ee8-816e-d2895a5f35db",0,NULL); RtsCurrent_sdBCReader = RtssdBCReader_States_Reading; }}
For exiting from each state
ACS generates an exit state operation to execute code on exit from each State (Idle and Reading).
void cBarCodeReader::RtsExit_Idle() { if (RtsCurrent_sdBCReader == RtssdBCReader_States_Idle) { /* Simulation support : Notification function call for exiting state : Idle */ RtsNotify(EXIT,"682cee54-01d5-46e9-b5d1-7bf579f3cf5b",0,NULL);
} } void cBarCodeReader::RtsExit_Reading() { if (RtsCurrent_sdBCReader == RtssdBCReader_States_Reading) { /* Simulation support : Notification function call for exiting state : Reading */ RtsNotify(EXIT,"380d33eb-71c5-4ee8-816e-d2895a5f35db",0,NULL);
} }
For handling each event
ACS generates a signal event handler operation to handle the event.
For ensuring that calls are not executed when the state machine is busy
ACS generates a busy attribute to lock the state machine and each state when it is busy.RtsSemaphore RtsBusy;
For handling transitions that do not require further triggers
ACS generates a run to completion operation to handle all transitions that do not require further triggers.
bool cBarCodeReader::RtsRunToCompletion() { if (RtsCurrent_cBarCodeReader == RtscBarCodeReader_States_NotIn_cBarCodeReader) { /* Simulation support : Notification function calls for Entry and Exit of Initial state */ RtsNotify(ENTER,"dab2d3c6-e6f0-43b5-8acd-4147e5d08014",0,NULL); RtsNotify(EXIT,"dab2d3c6-e6f0-43b5-8acd-4147e5d08014",0,NULL);
/* Simulation support : Notification function calls for transition */ RtsNotify(TRANSITION,"0bf3e14a-e3a5-4be3-bb27-f815548530cc",0,NULL);