2.2.1 : Register Variables
Registering a variable before using it can avoid a lot of mistakes during development.
Variables are defined by the PComposeVar class.It can be created by hand by specifying type and name manually :
1 2 3 |
PComposeVar var; var.setName("age"); var.setType(phoenix_getComposeType<int>()); |
And converted to std::string with ts_pcomposeVarToStr;
Or fully automatically with :
1 |
PComposeVar var = phoenix_getComposeVar<int>("age"); |
Then, the variable can be registered with the manager :
1 2 3 4 5 6 7 8 9 10 |
#include "phoenix_control.h" typedef PAbstractControlManager<std::string, PMockControlBackend, PMockControlBackend> ConnectorManager; //Inside a function ConnectorManager manager; manager.addClientConnector("Alice", "localhost", phoenix_mockControlParam(false, "mock_push", PLog::DEBUG)); //Register the variable manager.registerVar("Alice", phoenix_getComposeVar<int>("age")); |
At this point, it is possible to push and pull this variable from or to the client/server Alice.