MIRA
|
Previous: Tutorial: Using Parameters and Properties | Next: Tutorials for Developers |
---|
This tutorial extends the "FloatProducer" unit from Tutorial: Creating a Unit that Publishes Data.
Beside Channels, Remote Procedure Calls (RPC) are the second mechanism that can be used to communicate with other modules outside of your Unit. Remote Procedure Calls are suitable for "request - reply" interactions since they allow to call a procedure or method.
So we like to provide a service method that computes the mean on a vector of float values. First we need to add a method that does exactly that:
Nothing special here. Please note that we throw an exception if the vector is emtpy. Throwing exceptions within RPC methods is not a problem. They are transported to the caller side and are rethrown there, if necessary.
Now lets expose this method as a service function that can be called by other modules using RPC. For this purpose, we need to extend our reflect method and add an include that provides the reflect mechanism for std::vectors, since such a vector is used as parameter of the method and needs to be serialized.
Finally we need to publish our unit as a service:
And we are done. Now other modules can call our "calculateMean" method via RPC and will be presented with a nice and clean mean - or an exception if they pass an empty vector.
TODO...
For more information on how to use RPC, please refer to Services and Remote Procedure Calls.
Next: Tutorials for Developers |
---|