#include#include #include #include #include namespace sc = boost::statechart; struct DeviceState : sc::state { DeviceState(DeviceStateMachine& machine) : sc::state (machine) {} void on_entry() { /* set the state of the device */ } }; struct DeviceStateMachine : sc::state_machine { DeviceStateMachine() {} }; int main() { DeviceStateMachine machine; machine.initiate(); return 0; }
#includeThis example uses the device_state_entry to check the state of a device during a state operation. The code creates a state machine with a single state (DeviceState) and a function (some_operation) that checks the device state before performing an action. If the device is in the correct state, the action is performed. Otherwise, a different action is taken. Package Library: Boost C++ Libraries (boost).#include #include #include #include namespace sc = boost::statechart; struct DeviceState : sc::state { DeviceState(DeviceStateMachine& machine) : sc::state (machine) {} void some_operation() { /* check the state of the device */ if (/* device is in correct state */) { /* perform some action */ } else { /* perform a different action */ } } }; struct DeviceStateMachine : sc::state_machine { DeviceStateMachine() {} }; int main() { DeviceStateMachine machine; machine.initiate(); return 0; }