4 - Behavior
First of all a process has an implicit message queue to receive the messages listed in the channels.
A process description is based on an extended finite state machine. A process state determines which behavior the process will have when receiving a specific stimulation. A transition is the code between two states. The process can be hanging on its message queue or a semaphore or running e.g. executing code.
SDL-RT processes run concurrently; depending on the underlying RTOS and sometimes on the target hardware the behavior might be slightly different. But messages and semaphores are there to handle process synchronization so the final behavior should be independent of the RTOS and of the hardware. Since SDL-RT is open to any C code it is up to the designer to make sure this statement stays true !
Note that in a state diagram the previous statement is always connected to the symbol upper frame and the next statement is connected to the lower frame or on the side.
4.1 - Start
The start symbol represent the starting point for the execution of the process:
The transition between the Start symbol and the first state of the process is called the start transition. This transition is the first thing the process will do when started. During this initialization phase the process can not receive messages. All other symbols are allowed.
4.2 - State
The name of the process state is written in the state symbol:
The state symbol means the process is waiting for some input to go on, the allowed symbols to follow a state symbol are:
the message could be coming from an external channel, or it could be a timer message started by the process itself.
when reaching a state with continuous signals, the expressions in the continuous signals are evaluated following the defined priorities. All continuous signal expressions are evaluated before the message input !
the incoming message can not be treated in the current process state. It is saved until the process state changes. When the process state has changed the saved messages are treated first (before any other messages in the queue but after continuous signals).
Some transitions can be valid for several states, the different state names are then listed separated by a comma. A star ('*') means all states.
Examples:
A process in a specific state can receive several types of messages or treat several continuous signals. To represent such a situation it is possible to have several message inputs connected to the state or to split the state in several symbols with the same name.
Examples:
4.3 - Stop
A process can terminate itself with the stop symbol.
Note a process can not kill another process, it can only kill itself.
There is no syntax for that symbol.
4.4 - Message input
The message input symbol represent the type of message that is expected in an SDL-RT state. It always follows an SDL-RT state symbol and if received the symbols following the input are executed.
An input has a name and can come with parameters. To receive the parameters it is necessary to declare the variables that will be assigned to the parameters values in accordance with the message definition.
The syntax in the message input symbol is the following:
<Message name> [(<parameter name> {, <parameter name>}*)]
<parameter name> is a variable that needs to be declared.
If the parameter type is undeclared it is still possible to transmit unstructured data with the parameter length and a pointer on the data.
If the parameter length is unknown, because the parameters are unstructured data, it is also possible to get the parameter length assigned to a pre-declared variable.
Message with undeclared parameters
The syntax in the message input symbol is the following:
<Message name> [(<data length>, <pointer on data>)]
<data length> is a variable that needs to be declared as a long.
<pointer on data> is a variable that needs to be declared as an unsigned char *.
Examples:
4.5 - Message output
A message output is used to exchange information. It puts data in the receiver's message queue in an asynchronous way.
When a message has parameters, user defined local variables are used to assign the parameters. General syntax in the output symbol is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_XXX...
If the parameter is undefined the length of data and a pointer on the data can be provided. In that case, the symbol syntax is:
<message name>[(<data length>, <pointer on data>)] TO_XXX...
The syntax in the message output symbol can be written in several ways depending if the queue Id or the name of the receiver is known or not. A message can be sent to a queue Id or to a process name or via a channel or a gate. When communicating with the environment, a special syntax is provided.
4.5.1 To a queue Id
Message output to a queue id
The symbol syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_ID <receiver queue id>
It can take the value given by the SDL-RT keywords:
PARENT The queue id of the parent process.
SELF The queue id of the current process.
OFFSPRING The queue id of the last created process if any or NULL if none.
SENDER The queue id of the sender of the last received message.
Examples:
4.5.2 To a process name
Message output to a process name
The syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_NAME <receiver name>
<receiver name> is the name of a process if unique or it can be ENV when simulating and the message is sent out of the SDL system.
Examples:
Note:
If several instances have the same process name (several instances of the same process for example), the 'TO_NAME' will send the message to the first created process with the corresponding name. Therefore this method should no be used when the process name is not unique within the system.
4.5.3 To the environment
Message output to environment
The symbol syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_ENV [<C macro name>]
<C macro name> is the name of the macro that will be called when this SDL output symbol is hit. The macro will take 3 parameters:
- name of message,
- length of a C struct that contains all parameters,
- pointer on the C struct containing all parameters.
The fields of the implicit C struct will have the same type as the types defined for the message.
If no macro is declared the message will be sent to the environment.
Example:
Note:
The implicit C struct memory space is implictly allocated and it is the C macro responsability to ensure it will be freed at some point.
4.5.4 Via a channel or a gate
A message can be sent via a channel in the case of a process or via a gate in the case of a process class.
Message output via a channel or a gate
The symbol syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] VIA <channel or gate name>
<channel or gate name> is the name of the channel or gate the message will go through.
This concept is especially usefull when using object orientation since classes are not supposed to know their environment; so messages are sent via the gates that will be connected to the surrouding environment when instanciated.
Examples:
With the architecture defined above, both outputs are equivalent.
4.5.5 As a broadcast
A message can be sent to all possible receivers at once with the broadcast. There are two typical situations: either there are several instances of the same process that can receive the message, or there are several processes connected via a channel that can carry the message. In the first case the TO_ALL keyword is used:
Message broadcast to all instances of a process
The symbol syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_ALL <process name>
<process name> is the name of the receiver process that may have several instances.
This concept is especially useful when some messages are to be received by all instances of the same process. It avoids having to store all active pids and to loop on the message output.
Examples:
The broadcast can also be based on the channel connexion.
Message broadcast to all possible receivers at the end of the channel path
The symbol syntax is:
<message name>[(<parameter value> {,<parameter value>}*)] TO_ALL VIA <channel or gate name>
<channel or gate name> is the name of the channel or of the gate that carries the messsage.
All possible receivers at the end of the channel path will receive a copy of the message.
Examples:
4.6 - Message save
A process may have intermediate states that can not deal with new request until the on-going job is done. These new requests should not be lost but kept until the process reaches a stable state. Save concept has been made for that matter, it basically holds the message until it can be treated.
The Save symbol is followed by no symbol. When the process changes to a new state the saved messages will be the first to be treated (after continuous signals if any).
The symbol syntax is:
<message name>
Even if the message has parameters.
Example:
4.7 - Continuous signal
A continuous signal is an expression that is evaluated right after a process reaches a new state. It is evaluated before any message input or saved messages.
The continuous signal expression to evaluate can contain any standard C expression that returns a C true/false expression. Since an SDL state can contain several continuous signal a priority level needs to be defined with the PRIO keyword. Lower values correspond to higher priorities. A continuous signal symbol can be followed by any other symbol except another continuous signal or a message input. The syntax is:
<C condition expression