2.3.1 : Local Variables
Local variables have to be registered :
1 2 3 4 5 6 7 8 9 10 |
#include "phoenix_control.h" typedef PAbstractControlManager<std::string, PMockControlBackend, PMockControlBackend> ConnectorManager; void simpleLocalVariable(){ ConnectorManager manager; //Default value of the local variable size_t defaultState(0lu); manager.registerLocalVar("currentState", defaultState); } |
Then, it can be modified with setLocalVar and read with getLocalVar. However, in mock mode, getLocalVar method will need to find its corresponding mock file to work without complaining.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
//from string_utils : just to check if everything goes well #include "phoenix_assert.h" #include "phoenix_control.h" typedef PAbstractControlManager<std::string, PMockControlBackend, PMockControlBackend> ConnectorManager; void simpleLocalVariable(){ //First, let's create the mock file PMockConnectorVar mock; mock.setType(phoenix_getComposeType<size_t>()); //Set the type of data inside the mock file phoenix_mockCreate(mock, phoenix_getControlMockFileVar("mock_connector", "MockManager", "getLocalVar", "currentState")); for(size_t i(0lu); i < 10lu; ++i){ //Let's push 10 values //In order : event Id, mock structure, value phoenix_mockVarAppendData(i, mock, i); } phoenix_mockSave(mock); //Finally, save the mock file //Then, we can create the manager and simulate a client or server ConnectorManager manager; //Default value of the local variable size_t defaultState(0lu); manager.registerLocalVar("currentState", defaultState); //Then, the variable can be used inside a client or a server for(size_t i(0lu); i < 10lu; ++i){ //Let's push 10 values //Set the local var phoenix_assert(manager.setLocalVar("currentState", i)); //Get its value size_t value(0lu); phoenix_assert(manager.getLocalVar("currentState", value)); //Check the value is OK phoenix_assert(value == i); } } |