GS Messenger Overview
This summarizes what we have (and what is to be implemented) for passing messages/commands from one module to another, possibly cross-language. The syntax should be as similar as possible for both C++ and Python.
There is a low-level interface, consisting on: (a) create a message object; (b) fill the message with named values; (c) search the receiving object by name and get a reference to it; (d) send the message calling the "write(msg)" interface method on the object. The write interface returns when the message was delivered. It is up to the receiver implementation to execute the command or not before return from the write. The syntax is this in C++:
gs::Msg msg;
msg["command"] = "foo";
msg["field1"] = 123;
msg["reply_to"] = reply_fifo; // declared in the module as "sc_fifo<gs::Msg> reply_fifo;"
gs::WriteIf& receiver = gs::findReceiver("other_module");
receiver.write(msg);
There will be also a high-level interface that does all the above steps in a single method call, with the syntax:
gs::sendMsg("other_module", "command", "foo", "field1", 123, "reply_to", reply_fifo);
The advantage of using the low-level interface instead of the easier high level one is that it can be faster when reusing the message and the receiver objects multiple times.
In the receiver side, the write method can be implemented in two ways: (1) it can be a sc_fifo's write method, so the message goes directly to the fifo; (2) the write can be implemented directly by the module or some helper class. The advantage of (1) is the simplicity to handle the messages from any module process, but it has a drawback that no message can be prioritized. When using (2) the module creator has the opportunity to read each message to prioritize it or not, executing immediately a "reset", for example, but queuing other types of commands.
- Printer-friendly version
- Login or register to post comments
Posted August 6th, 2008 by MarcusBartholomeu