State machine framework. More...
#include <stateMachine.hpp>
Classes | |
class | ConnectionPool |
class | FunIface |
Main interface for the needs of a state function. More... | |
struct | State |
Represents one connection. More... | |
Public Types | |
using | stateFun = std::function< void(State &, Packet *, FunIface &)> |
This is the signature any state function needs to expose. More... | |
using | timeoutFun = std::function< void(State &, FunIface &)> |
This is the signature any timeout function needs to expose. More... | |
Public Member Functions | |
StateMachine () | |
~StateMachine () | |
size_t | getStateTableSize () |
Get the number of tracked connections This is probably only for statistics. More... | |
void | registerFunction (StateID id, stateFun function) |
Register a function for a given state. More... | |
void | registerEndStateID (StateID endStateID) |
This registers an end state If a connections reaches this id, it will be destroyed. More... | |
void | registerStartStateID (StateID startStateID, std::function< void *(ConnectionID)> startStateFun) |
This method describes, how to proceed with incoming connections. More... | |
void | registerGetPktCB (std::function< Packet *()> fun) |
Register a callback in order to get new buffer. More... | |
void | setConnectionPool (ConnectionPool *cp) |
void | removeState (ConnectionID id) |
Remove a connection. More... | |
void | addState (ConnectionID id, State st, BufArray< Packet > &pktsIn) |
Open an outgoing connection. More... | |
void | runPktBatch (BufArray< Packet > &pktsIn) |
Run a batch of packets. More... | |
Static Public Attributes | |
static constexpr auto | StateIDInvalid = std::numeric_limits<StateID>::max() |
Represents an invalid StateID. More... | |
Detailed Description
template<class Identifier, class Packet>
class StateMachine< Identifier, Packet >
State machine framework.
This class is a comprehensive framework, on top of which a developer can build high-performance state machines.
It can be specialized to work with different underlying packet packet sources and packet identifiers.
The Identifier needs to have the following form:
The Packet needs to have the following form:
- Template Parameters
-
Identifier This class is used to uniquely identify incoming packets (see above) Packet This class wraps around any kind of packet buffer (see above)
Definition at line 66 of file stateMachine.hpp.
Member Typedef Documentation
◆ stateFun
using StateMachine< Identifier, Packet >::stateFun = std::function<void(State &, Packet *, FunIface &)> |
This is the signature any state function needs to expose.
Definition at line 83 of file stateMachine.hpp.
◆ timeoutFun
using StateMachine< Identifier, Packet >::timeoutFun = std::function<void(State &, FunIface &)> |
This is the signature any timeout function needs to expose.
Definition at line 86 of file stateMachine.hpp.
Constructor & Destructor Documentation
◆ StateMachine()
|
inline |
Definition at line 571 of file stateMachine.hpp.
◆ ~StateMachine()
|
inline |
Definition at line 575 of file stateMachine.hpp.
Member Function Documentation
◆ addState()
|
inline |
Open an outgoing connection.
This is the function you want to call, if you want to connect to a server.
- Parameters
-
id The connection id this connection will use st The state data pktsIn Packet buffer for the state to work with (only one packet)
Definition at line 652 of file stateMachine.hpp.
◆ getStateTableSize()
|
inline |
Get the number of tracked connections This is probably only for statistics.
- Returns
- Number of connections
Definition at line 587 of file stateMachine.hpp.
◆ registerEndStateID()
|
inline |
This registers an end state If a connections reaches this id, it will be destroyed.
- Parameters
-
endStateID the state in question
Definition at line 610 of file stateMachine.hpp.
◆ registerFunction()
|
inline |
Register a function for a given state.
This function should be called once for each state you wish to use
- Parameters
-
id ID of the state for which to set a function function This function will be called, when a connection is in state id, and gets a packet
Definition at line 597 of file stateMachine.hpp.
◆ registerGetPktCB()
|
inline |
Register a callback in order to get new buffer.
- Parameters
-
fun Function to call, if new buffers are needed
Definition at line 632 of file stateMachine.hpp.
◆ registerStartStateID()
|
inline |
This method describes, how to proceed with incoming connections.
If you call this function, you allow for incoming connections. They will start using the parameters.
- Parameters
-
startStateID All new connections will start in this state startStateFun This function is called to populate the void* for the state (may be nullptr)
Definition at line 621 of file stateMachine.hpp.
◆ removeState()
|
inline |
Remove a connection.
Using this function you can delete a connection.
- Parameters
-
id The connection id of the connection to remove
Definition at line 642 of file stateMachine.hpp.
◆ runPktBatch()
|
inline |
Run a batch of packets.
This method is the function you want to call, in order to pump new packets into the state machine. Timeouts get handled, as soon as this function is called.
- Parameters
-
pktsIn Incoming packets
Definition at line 692 of file stateMachine.hpp.
◆ setConnectionPool()
|
inline |
Definition at line 634 of file stateMachine.hpp.
Member Data Documentation
◆ StateIDInvalid
|
static |
Represents an invalid StateID.
Definition at line 89 of file stateMachine.hpp.
The documentation for this class was generated from the following file:
- /home/dominik/uni/MoonState/include/stateMachine.hpp