|
Elma
An event loop manager for embedded systems
|
A finite state machine class. More...
#include <state_machine.h>
Inheritance diagram for elma::StateMachine:
Collaboration diagram for elma::StateMachine:Public Member Functions | |
| StateMachine (std::string name) | |
| Construct a new StateMachine with the given name. | |
| StateMachine () | |
| Construct an unnamed StateMachine. | |
| StateMachine & | set_initial (State &s) |
| StateMachine & | add_transition (std::string event_name, State &from, State &to) |
| StateMachine & | set_propagate (bool val) |
| vector< Transition > | transitions () |
| Get the list of transitions. | |
| State & | current () |
| void | init () |
| void | start () |
| void | update () |
| void | stop () |
Public Member Functions inherited from elma::Process | |
| Process (int n=0) | |
| Default constructor. Names process "no name". | |
| Process (std::string name, int n=0) | |
| Constructor that takes a name for the process. More... | |
| string | name () |
| void | set_name (std::string str) |
| status_type | status () |
| high_resolution_clock::duration | period () |
| int | num_updates () |
| time_point< high_resolution_clock > | start_time () |
| high_resolution_clock::duration | last_update () |
| high_resolution_clock::duration | previous_update () |
| Channel & | channel (string name) |
| Access a channel with the given name. More... | |
| double | milli_time () |
| The time since the last update in millisconds, as a double. More... | |
| double | delta () |
| The most recent amount of time between updates. More... | |
| void | watch (string event_name, std::function< void(Event &)> handler) |
| void | emit (const Event &event) |
| void | http_get (std::string url, std::function< void(json &)> handler) |
| void | halt () |
| void | set_manager (Manager *m_ptr) |
Protected Attributes | |
| vector< Transition > | _transitions |
| State * | _initial |
| State * | _current |
| bool | _propagate |
Protected Attributes inherited from elma::Process | |
| Manager * | _manager_ptr |
Additional Inherited Members | |
Public Types inherited from elma::Process | |
| enum | status_type { UNINITIALIZED, STOPPED, RUNNING } |
A finite state machine class.
Together with the State and Transition classes, this class is used to make a finite state machine process. For example, here is a toggle switch machine
Definition at line 13 of file state_machine.h.
| StateMachine & elma::StateMachine::add_transition | ( | std::string | event_name, |
| State & | from, | ||
| State & | to | ||
| ) |
Add a transition to the state machine
| event_name | Events with this name will trigger the transition |
| from | The state the machine must be in to take the transition |
| to | The state the machine will go to upon taking the transition |
Definition at line 12 of file state_machine.cc.
|
inline |
Definition at line 44 of file state_machine.h.
|
virtual |
If you override init() in your state machine class, you should call StateMachine::init() at the end of you init method.
Implements elma::Process.
Definition at line 19 of file state_machine.cc.
| StateMachine & elma::StateMachine::set_initial | ( | State & | s | ) |
Set the initial state of the state machine
| s | An instantiation of a class derived from State |
Definition at line 7 of file state_machine.cc.
|
inline |
Set whether the state machine should propagate transitions (default = false)
| val | True or false |
Definition at line 38 of file state_machine.h.
|
virtual |
If you override start() in your state machine class, you should call StateMachine::start() at the end of you start method.
Implements elma::Process.
Definition at line 34 of file state_machine.cc.
|
virtual |
If you override stop() in your state machine class, you should call StateMachine::stop() at the end of you stop method.
Implements elma::Process.
Definition at line 49 of file state_machine.cc.
|
virtual |
If you override update() in your state machine class, you should call StateMachine::update() at the end of you update method.
Implements elma::Process.
Definition at line 42 of file state_machine.cc.