This chapter is a reference to the communication mechanism in the Telelogic Tau tools, the PostMaster. The functionality of the PostMaster makes it possible to integrate applications by using a well-defined means of communication.
The PostMaster is the mechanism used for communication between the different tools in Telelogic Tau. A C program generated by the Telelogic Tau tools can also take advantage of this communication mechanism. It can communicate with any application connected to the PostMaster that send messages according to a defined format. This makes it possible for an SDT simulator to communicate with, for instance, a user interface process for the Simulator.
The PostMaster also provides the basic means for the Open Telelogic Tau concept, see The Telelogic Tau Public Interface.
The PostMaster provides the following functionality:
The PostMaster is a message passing service based on a selective broadcasting mechanism. It will distribute a copy of each message it receives to the tools subscribing to that type of message. By this, the PostMaster provides an integration mechanism between tools without the hard coupling between them that follows from conventional two part communication mechanisms.
Figure 172 illustrates some of the PostMaster concepts. The PostMaster maintains a list of which messages each tool subscribes to. Each tool has a PostMaster part for sending and receiving messages. In the figure, tool F broadcasts a message, i.e. the message is sent to the PostMaster. The subscription lists of tool A and C (but not the lists of B and F) contains the message type. Accordingly the PostMaster broadcasts the message to tool A and C.
Figure 172 : Example of a PostMaster broadcast
|
The PostMaster configuration is a file that informs the PostMaster about what tools and messages exist in the current context, i.e. it contains the message subscription lists. To include new tools or add new messages, the configuration must be edited.
For detailed information on the configuration, see The PostMaster Configuration.
This section describes the external interface to the PostMaster, including messages to send and their format, contents of the configuration, and functions to call.
Note: In order to promote a high throughput, it is strongly recommended that the PostMaster messages are consumed as soon as they are available. |
The PostMaster configuration defines a large number of messages that can be utilized in a Telelogic Tau system. A broad range of these messages are public, that is, they can be used externally. A description of these are found in The Telelogic Tau Public Interface.
All messages contain information about the identity of the sender, the time it was sent, the message type, and the size of an optional data part.
The optional data part can be seen as parameters to the message and is not interpreted by the PostMaster.
Note: It is the responsibility of the tools using the PostMaster to define the format of the data part and to interpret it correctly. |
The PostMaster can be configured either statically at start up or dynamically during runtime. When a dynamic configuration is performed, the services Add Tool or Add Tool Subscription is used. The PostMaster is configured statically using the PostMaster configuration file(s)
The PostMaster configuration file(s) informs the PostMaster about what tools and messages exist in the current context. These files are often referred to as simply the configuration.
At start-up the PostMaster reads an environment variable POSTPATH
which is a list of directories separated by colons (on UNIX) or semicolons (in Windows). In these directories, the PostMaster searches for configuration files.
Such files should be named post.cfd
and are read by the PostMaster whenever it is invoked, for instance when SDT, ORCA1 or ITEX is started.
It is not possible to use C preprocessor statements or symbols in the configuration file.
It is possible to have local configurations which extends the standard PostMaster configuration set up by the Telelogic Tau tools, by simply defining the POSTPATH
variable with a directory holding the extended configuration.
The configuration is a list of tool identities. Each tool identity is bound to an executable, a subscription list of messages and optionally a limit of instances of that tool. Each tool in the file is described in the following way:
Tool <tool number>:<executable>:<instance limit> <message number>; <message number>; ...
Description<tool number>
SET_
symbols in the file sdt.h
, and by IET_
symbols in the file itex.h
. The number 27000 (SET_SDLENV
) is used for tools acting as an SDL environment.<executable>
"/home/sdt/demo/demotool"
(on UNIX) or "c:\sdt\demo\demotool"
(in Windows)).<instance limit>
SPMAXNOOFINSTANCES
).
<message number>
SE
in sdt.h
. It is normally specified as <tool number> + <nr>
. Symbols which are used in ITEX have the prefix IE
and are defined in itex.h
.To include new tools or add new messages, the configuration file must be edited. However, the tools and subscription lists existing in the original configuration must not be changed.
To include a new tool, follow the steps below. Note that it is not required to include a new tool in the configuration if it only serves as an SDL/TTCN environment that does not need to be started from other tools by using the Start service.
SET_
(IET_
)symbol in the file sdt.h
(itex.h
) so that the tool number can be easily accessed in the code.#define SET_MYTOOL 110000
To add a new message, follow these steps:
SE
(IE
) symbol in the file sdt.h
(itex.h
)as the tool symbol plus an ordinal number, not conflicting with any other message symbol.#define SEMYMESSAGE SP_MESSAGE(SET_MYTOOL+1)
110000+1;
The PostMaster recognizes a number of environment variables setting the context in which the PostMaster is to operate. They are read when the PostMaster starts.
The following environment variables are recognized by the PostMaster:
POSTSERVERPORT
POSTPATH
post.cfd.
POSTDEBUG
'-e'
the log is put on stdout
. The second parameter tells the log level. Normally only public messages are logged. But if set to a value > 2 all messages will be logged. post.mpr
STARTTIMEOUT
The following environment variables are recognized by the PostMaster application library. These environment variables are read in the SPInit function.
POSTHOST
POSTPORT
POSTPID
Communication with the PostMaster is based on a small set of fundamental functions:
SPInit |
initialization |
SPExit |
termination |
SPBroadcast |
output message, broadcast |
SPSendToTool |
output message, sent to a certain tool |
SPSendToPid |
output message, sent to a certain PId |
SPRead |
input message |
SPFree |
frees memory allocated by SPRead or SPFindActivePostMasters |
SPConvert |
translate a symbolic message to an id |
SPErrorString |
Error string conversion |
SPRegisterPMCallback |
Message notification (Windows only) |
SPQuoteString |
Quoting strings |
SPUnquoteString |
Unquoting strings |
SPFindActivePostMasters |
find all PostMasters |
Every function returns a value denoting success or failure of the associated operation.
The PostMaster functions should be called in the following ways from the external tool:
,
SPSendToPidor SPBroadcast.SESTOPNOTIFY
by calling SPBroadcast. Then it should disconnect from the PostMaster by calling SPExit.The following variables are defined.
extern INT16 sperrno; extern INT16 spPortNO; (on UNIX) extern int spPortNO; (in Windows)
sperrno
contains an error code when a call to a PostMaster function failed. The error codes are defined in sdt.h
and should be self-explanatory.
On UNIX, spPortNO
contains a descriptor to the port where incoming messages from the PostMaster are found. In Windows, spPortNO
contains a process identifier associated with the current process. The state of the variable prior to the call of SPInitis undefined.
These variables are found in the file post.h
.
When a function returns SPERROR
which indicates an error or an not expected result of the function. In this case sperrno
is set to one of the following values.
Error Code | Explanation |
---|---|
SPNOSESSION |
The function SPInit has not been called successfully |
SPALREADYCONNECTED |
When calling SPInit more than once without disconnecting |
SPNOPOSTMASTER |
No PostMaster could be found when trying to connect |
SPNOCHANNEL |
The contact with the PostMaster is lost. |
SPNOMESSAGE |
No message available when trying to read by polling or after a timeout. |
SPTIMEDOUT |
The connection to the PostMaster timed out. |
SPNOSUCHPID |
Sending to a PId with a non positive value (<=0) |
SPNOMEMORY |
Cannot allocate anymore dynamic memory (rare) |
SPTOOLNOTFOUND |
When sending to a tool, this tool is not found in PostMaster configuration list |
SPINVALIDMESSAGE |
Sending a message with a NULL parameter but specifying the length greater than 0. |
SPBADMESSAGE |
A not supported message was to be sent. |
SPMANYPOSTMASTERS |
Many PostMasters running. Could not decide which one to connect to. (Windows only) |
SPOLDPOSTMASTER |
Old PostMaster running. (Windows only) |
The available PostMaster functions are described on the following pages. The descriptions use the following format.
First, the function declaration is shown, including data types of parameters, followed by a short explanation of what the function does.
After that, in- and out parameters are described, together with possible return values and error codes.
int SPInit(int toolType, char * argv0, *SPMList list);
SPInit
initiates a session and establishes a connection with the PostMaster. See Multiple PostMaster Instances for information on how to connect to a specific instance of the PostMaster.
toolType
SET_SDLENV
. See Run-Time Considerations for more information.argv0
list
sdt.h
(itex.h
) is used. This list is later used by the function SPConvert, which translates between a textual string and the corresponding identifier. >0
SPERROR
SPInit
failed, sperrno
is set.SPNOPOSTMASTER SPTIMEDOUT SPALREADYCONNECTED SPNOMEMORY SPMANYPOSTMASTERS SPOLDPOSTMASTER
int SPExit(void);
SPExit
exits a session and disconnects the connection with the PostMaster. Subsequent calls to PostMaster functions will return the error code
SPNOSESSION
until a new SPInitis performed.
SPOK
SPERROR
SPExit
failed, sperrno
is set.SPNOCHANNEL SPNOSESSION
int SPSendToTool(int tool, int event, void * data, int size);
SPSendToTool
sends a message to the process of kind type.
tool
event
data
size
SPOK
SPERROR
SPSendToTool
failed, sperrno
is set.SPNOCHANNEL SPNOSESSION SPNOMEMORY SPBADMESSAGE SPINVALIDMESSAGE SPTOOLNOTFOUND SPBADMESSAGE SPNOSUCHPID
int SPSendToPid(int pid, int event, void * data, int size);
SPSendToPid
sends a message to the process which has process id toPid
.
pid
SEOPFAILED
message or a service reply is sent by the PostMaster.event
data
size
SPOK
SPERROR
SPSendToPid
failed, sperrno
is set.SPNOCHANNEL SPNOSESSION SPNOMEMORY SPBADMESSAGE SPINVALIDMESSAGE SPTOOLNOTFOUND SPNOSUCHPID
int SPBroadcast(int event, void * data, int size);
SPBroadcast
sends a message to all processes that subscribes on the message type.
event
data
size
SPOK
SPERROR
SPBroadcast
failed, sperrno
is set.SPNOCHANNEL SPNOSESSION SPNOMEMORY SPBADMESSAGE SPINVALIDMESSAGE
int SPRead(int timeOut, int * pid, int * message, void ** data, int * len);
SPRead
reads a message from the queue of unread messages that the PostMaster has sent. When the message is read, it is also consumed, i.e. removed from the queue. The function allocates the necessary amount of memory needed for the data
component in the message. The application using this function is responsible for freeing the allocated memory with
SPFree when it is no longer needed.
timeOut
timeOut
expires, the function returns with return value SPERROR
and sperrno
is set to
SPNOMESSAGE
. If a message arrives, the function reads the message and returns immediately. If the desired behavior is to wait until a message arrives, which could mean forever, timeOut
should be set to SPWAITFOREVER
.pid
message
data
malloc
len
data[len-1]
is `\0'.SPOK
SPERROR
SPRead
failed, sperrno
is set.SPNOCHANNEL SPNOMESSAGE SPNOSESSION SPNOMEMORY
void SPFree (void * ptr)
SPFree
should be used to free the memory allocated by SPRead
. This is necessary when different compilers with different memory management are used.
ptr
N/A.
char * SPErrorString(int code);
Converts an error code into a textual string description of a tool or a message from the corresponding integer value.
code
sperrno
.An descriptive error string corresponding to the error code.
int SPConvert(char * str);
Converts a textual description of a tool or a message to the corresponding integer value as provided by the parameter list
in SPInit.
str
An integer value for the tool or message. If no mapping is found, SPERROR
is returned.
typedef void (* SP_PM_MessageCallback) (void); void SPRegisterPMCallback (SP_PM_MessageCallback cb);
Windows only: Registers a callback function that gets called every time a new PostMaster message arrives. Registering this callback enables (32-bit) Windows applications to function correctly. Console applications need not use this function.
cb
cb
is NULL
the current callback is removed; otherwise the callback is replaced.N/A.
int SPQuoteString(char *stringToQuote, char *buffer, int bufferLength, int append)
SPQuoteString
quotes a string. The following operations are performed:
The quoted string can later be unquoted with a call to SPUnquoteString.
stringToQuote
bufferLength
append
buffer
is supposed to already contain a null-terminated string. The result of the quoting operation will be appended to this string at the end.
buffer
1
0
int SPUnquoteString(char *quotedString, int inputLength, char *buffer, int bufferLength, int position)
SPUnquoteString
unquotes a string previously quoted with SPQuoteString, ignoring leading white-space characters. The following operations are performed:
Several concatenated quoted strings can be extracted with subsequent calls to this function by using the value returned in the position out parameter, see below.
quotedString
inputLength
below should have a meaningful value.
inputLength
quotedString
that will be scanned. If quotedString
is known to be null-terminated, a very large number should be supplied here.
bufferLength
buffer
buffer
can also be null, in which case no unquoting will be performed. The value of position can still be interesting, though.
position
1
0
position
are undefined.int SPFindActivePostMaster (int *bufferPid, char** bufferText, int maxBufferlength);
Finds all PostMasters available for the application on the computer. Information retrieved is process id and a description in plain text.
maxBufferlength
bufferPid
and bufferText
.Number of PostMasters found.
When Telelogic Tau is started in Windows, an instance of the PostMaster is automatically started. No additional commands are needed for the PostMaster. There might however be situations when it is necessary to start the PostMaster stand-alone. This is described in the following sections. The examples only handle how SDT is started from the "DOS" command prompt, but in many cases a shortcut with the analogous parameters can be created.
There are several possible ways to start the PostMaster itself and the tools that wish to communicate via the PostMaster. In principle, there are two main alternatives:
We will exemplify the start-up methods by using the DemonGame simulator and a User Interface to the DemonGame simulator.
Note: The PostMaster must be started first, but the communicating tools may be started in any order. An SDT simulator must also execute the commands Start-SDT-Env and Go before communication with another tool can start. |
When SDT is started from the "DOS" or UNIX prompt, an instance of the PostMaster is automatically started. No additional commands are needed for the PostMaster in this case.
The DemonGame simulator is preferably started from SDT, thus giving access to all simulation features. It can also be started directly from the "DOS" or UNIX prompt.
Use the following command from the "DOS" prompt:
DemonGame.exe -post
Note: In Windows, the simulator is a Windows GUI application and not a Console application. It is therefore not possible to run the simulator stand-alone, i.e. without |
Use the following command from the UNIX prompt:
DemonGame.sct -post
(Without the parameter, the simulator runs stand-alone, which is not desired in this case.) Starting the simulator this way restricts the possibilities of the simulation since there is no connection to the SDT tools. For instance, graphical trace is disabled.
The UI is preferably started directly from the UNIX prompt. It can also be started from the DemonGame simulator with the command Start-ITEX-Com, but this requires that the executable is named sdtenv
. This is the name specified in the configuration for tool number 27000.
When SDT is not running, the PostMaster must be started directly from the "DOS" or UNIX prompt with the command:
$telelogic/bin/sdtpm <arg> & (on UNIX) <SDT Installation Directory>\sdt <arg> (in Windows)
(using one of the start-up arguments, see below).
The DemonGame simulator must also be started directly from the "DOS" or UNIX prompt, as described above.
Note: On UNIX: If activating the PostMaster this way, the environment variable |
The UI can be started in the same way as when SDT is running (see above). It can also be started indirectly when starting the PostMaster by using the "DOS" or UNIX command:
$telelogic/bin/sdtpm -clients 27000 & (on UNIX) <SDT Installation Directory>\sdt -clients 27000 (in Windows)
This requires that the executable is named sdtenv
, the name specified in the configuration for tool number 27000.
Note: A tool communicating through the PostMaster can also be started from another tool by using the SESTART message. This requires that the tool to be started is specified in the configuration. |
The PostMaster recognizes the following arguments at start-up. Normally they are not needed, but could be used for special purposes
-clients <toolid>
Used if the PostMaster should invoke a certain tool at start-up. <toolid>
is set to the logical tool number of a tool to start as defined in post.cfd
.-noclients
Used if only the PostMaster is to be invoked without starting any clients. In this case the PostMaster enters an idle state where it waits for a client to connectAll other arguments are passed to the tool started.
Applications or tools linked with an SDT 2.X PostMaster application library will not be compatible with SDT 3.X PostMaster. Trying to connect such an old application to an SDT 3.X PostMaster will result in an error message:
Postmaster cannot connect SDT2 tool:<tool> with pid: <pid>
on standard output, if externally started, or as a service reply, if started via the start service, and the connection is aborted.
If an old PostMaster (version 3.4 or older) is used the SPInit function will fail. The error code is SPOLDPOSTMASTER.
Applications or tools linked with an SDT 3.4 PostMaster application library will not be compatible with the SDT 3.5 PostMaster. Trying to connect such an old application to an SDT 3.5 PostMaster with the SPInit function will fail. The error code is SPNOPOSTMASTER.
It is possible to have multiple instances of the PostMaster running, for instance when more than one Telelogic Tau tool has been started. In this case it should be made sure that the communicating tools are connected to the correct instance of the PostMaster.
On UNIX, the function SPInitby default looks for the PostMaster instance with the highest process id (PId) number and connects to it.
On Windows, the function SPInitby default fails if more than one PostMaster is found.
To connect to another PostMaster instance, you can set the environment variable
POSTPID
to the PId number of the desired PostMaster. If this variable is set, SPInitconnects to the PostMaster instance with that PId number.
The PostMaster configuration is read whenever a PostMaster instance is invoked. The environment variable
POSTPATH defines a list of directories where the PostMaster looks for a configuration file named
post.cfd.
The user can extend the normal configuration by defining the
POSTPATH variable to a directory containing an extended configuration. When a Telelogic Tau tool is started normally, the directories containing the binaries are put as the first directories in the
POSTPATH variable.
The same search order is applied when the start service is used. The supplied tool number is matched against the name of an executable in the configuration, which is then searched for as above.