Scanframe Modular Application 0.1.0
Loading...
Searching...
No Matches
Variable Event Example

Example 1: Linking an instance to another class.

Class declaration

++
class ClientOrServer
{
public:
virtual ClientOrServer(bool client);
private:
Variable _variable;
TVariableHandler<ClientOrServer> _eventHandler;
void eventHandler
(
Variable::EEvent event,
const Variable& caller,
Variable& link,
bool sameinst
);
};

Class implementation.

++
ClientOrServer::ClientOrServer()
:_eventHandler(this, &ClientOrServer::eventHandler)
{
// Link handler to the variable instance.
Fvariable->setHandler(&_eventHandler);
if (client)
{
// Setup instance as a client which triggers events.
_variable.setup(0x98001);
}
else
{
// Setup instance as a server which triggers events.
_variable.setup
(
"0x98001,Calibrate|Blue Pos,%,ASP,"
"Blue position for calibrating the C-scan plot.,"
"FLOAT,,"
"0.1,50,0,100"
);
}
}
void ClientOrServer::eventHandler
(
Variable::EEvent event,
const Variable& caller,
Variable& link,
bool sameinst
)
{
switch (event)
{
case Variable::veFlagsChange:
// Handle something
break;
case Variable::veValueChange:
// Handle something
break;
case Variable::veConverted:
// Handle something
break;
case Tvariable::veIdChanged:
// Handle something
break;
}
}