2.2.2 : Register Methods
Registering a method before calling it can avoid a lot of mistakes during development. Methods are defined by the PFunctionPrototype class.It can be created by hand by specifying type and name manually :
1 2 3 4 |
PFunctionPrototype prototype; prototype.setName("pompe"); prototype.getVecReturnType().push_back(phoenix_getComposeType<bool>()); prototype.getVecParam().push_back(phoenix_getComposeType<int>()); |
And converted to std::string with ts_protoTypeToStr; Or fully automatically with :
1 2 3 4 5 6 7 8 9 10 |
///Some very interesting function to call /** @param val : some very important value * @return some very important result */ bool pompe(int val){ return val > 0; } //Inside a function PFunctionPrototype prototype = phoenix_getPrototype("pompe", pompe); |
Then, the call can be registered with the manager :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
#include "phoenix_control.h" typedef PAbstractControlManager<std::string, PMockControlBackend, PMockControlBackend> ConnectorManager; ///Some very interesting function to call /** @param val : some very important value * @return some very important result */ bool pompe(int val){ return val > 0; } //Inside a function ConnectorManager manager; manager.addClientConnector("Alice", "localhost", phoenix_mockControlParam(false, "mock_call", PLog::DEBUG)); //Register the call manager.registerCall("Alice", phoenix_getPrototype("pompe", pompe)); |
At this point, it is possible to call the method pompe on the client/server Alice.