SVM pre-defines a number of macros. Pre-defined macros can be used in every model without being explicitly defined.
EVENT(ev, p=[]) = eventhandler.event([ev], [p])
.
This macro is used to raise an event. The event name is given by parameter ev. Parameter p can be used as a parameter or a list of parameters for the event. By default it is an empty Python list.
eventhandler is an internal object of the SVM simulation environment. For each simulation, there is exactly one instance of eventhandler. Its event method appends an event to the end of its global event list.
EXTEVENT(ev, p, rec=None) = eventhandler.external_event([ev], [p], [rec])
This macro is used to send an external event (or in another word, send a message to a remote component). ev is the event name, p is the parameter, and rec is a set of specific components that receive the message.
The event name contains the name of a port and the message, separated by a dot. For example, to send a massage m via port p, the value of ev is equal to ``p.m''. If the user wants to restrict the receivers to the components named model0 and model1, the value of rec should be equal to ["model0", "model1"].
When rec is not given or rec is equal to None, all the components in the group identified by the port name will receive the (possibly duplicated) message. In that case, macro EXTEVENT is the same as EVENT, except that EXTEVENT sends the message immediately in an asynchronous way, while EVENT queues the message in the global event list, and sends it asynchronously later when the simulator/executor is free.
DUMP(msg) = dump_message([msg])
This macro dumps a message to the output device. If SVM is run in the text mode, the message is printed on the console. If SVM is run with the default graphical interface, the message is displayed in the output box of the main window.
INSTATE(state, check_substate=0) = eventhandler.is_in_state([state],
[check_substate])
This macro checks whether the model is currently in a specific state. The state parameter is the name of the state. check_substate is default to 0, which means the simulator does not check the substate of the given state. Hence, if the given state is not a leaf state and check_substate is equal to 0, the result is always 0. If the model is in the given state or its substates, and check_substate is equal to 1, the result is 1. eventhandler.is_in_state is a method of the simulator that handles this inquiry.
This macro should only be used in the guards of transitions, as the DCharts formalism requires that the actions of a model cannot reflect upon the current state of the model itself.
PARAMS = eventhandler.get_event_params()
This macro can only be used in the guards or output of transitions. It returns the parameter of the event that triggers a transition. If the parameter is a list, [PARAMS][i] can be used to access individual elements in the list, where i is an integer between and (inclusively).
SENDER = eventhandler.get_event_sender()
This macro can only be used in the guards or output of transitions, and the transitions must be triggered by messages from remote components. It returns the sender (a model name) of the message.
SYNCALL(event, params, listento) = eventhandler.synchronous_call([event],
[params], [listento])
This macro provides the synchronous call facility for the action language. A model uses this macro to send a message to a remote component, and waits for a reply via a port. event is the event name, as is discussed for macro EXTEVENT. params is a parameter or a list of parameters. listento is the name of the event to be waited for. It also follows the convention of event names discussed in EXTEVENT. For example, if a model sends message m1 via port p1 without parameter, and waits for a reply m2 from port p2, the call is written as [SYNCALL("p1.m1", [], "p2.m2")]. The return of this call is the parameter(s) received with the reply.
This call does not return until the reply is received. If it is not the last action in the output, the actions after this are executed only after the call is finished.