Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
withrottle::ThrottleFlow Class Reference

State flow for handling a throttle instance. More...

#include <Server.hxx>

Inheritance diagram for withrottle::ThrottleFlow:
StateFlowBase Executable Notifiable QMember Destructable

Public Member Functions

 ThrottleFlow (Server *server, int fd, openlcb::Node *node)
 Constructor.
 
 ~ThrottleFlow ()
 Destructor.
 
void start ()
 Start the service.
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Types

typedef DispatchFlow< Buffer< ThrottleCommand >, 1 > CommandDispatchFlow
 dispatch flow that will handle messages incoming from the cab
 

Private Member Functions

bool parse ()
 Parse the incoming data.
 
void parse_command ()
 Parse the incoming data.
 
void parse_multi_type ()
 Parse the incoming data.
 
void parse_train ()
 Parse the incoming data.
 
bool parse_subcommand ()
 Parse the incoming data.
 
void parse_multi ()
 Parse the incoming data.
 
StateFlowBase::Action entry ()
 Beginning of state flow.
 
StateFlowBase::Action data_sent ()
 Data sent successfully.
 
StateFlowBase::Action data_received ()
 Process read data.
 

Private Attributes

openlcb::TractionThrottle olcbThrottle
 
Serverserver
 reference to parent server
 
string name
 name of throttle
 
string id
 id of throttle
 
LocoAddress address
 primary locomitve addres
 
LocoAddress secondaryAddress
 secondary locomotive address
 
int fd
 socket descriptor of throttle connection
 
char readRaw [128]
 read data buffer
 
string data
 agrigate pre-processed stream data
 
size_t dataIndex
 data index for parsing
 
ServerState state
 Current state of parsing the data.
 
StateFlowSelectHelper selectHelper
 Helper for waiting on data from a file descriptor.
 
CommandDispatchFlow dispatcher
 flow responsible for routing incoming messages to handlers.
 
Buffer< ThrottleCommand > * command
 throttle command
 
ServerCommandLoco serverCommandLoco
 handler for locomotive commands
 

Friends

class ServerCommandBase
 allow access to private members from class ServerCommandBase
 
class ServerCommandLoco
 allow access to private members from class ServerCommandLoco
 

Additional Inherited Members

- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
Action allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
 Allocates a buffer from a pool and proceed to the next state when allocation is successful.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
Action read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

State flow for handling a throttle instance.

Definition at line 103 of file Server.hxx.

Member Typedef Documentation

◆ CommandDispatchFlow

dispatch flow that will handle messages incoming from the cab

Definition at line 196 of file Server.hxx.

Constructor & Destructor Documentation

◆ ThrottleFlow()

withrottle::ThrottleFlow::ThrottleFlow ( Server server,
int  fd,
openlcb::Node node 
)

Constructor.

Parameters
serviceservice this flow belongs to
fdsocket descriptor of throttle connection.
nodeOpenLCB node that proxies our throttles

Definition at line 38 of file Server.cxx.

◆ ~ThrottleFlow()

withrottle::ThrottleFlow::~ThrottleFlow ( )
inline

Destructor.

Definition at line 115 of file Server.hxx.

Member Function Documentation

◆ data_received()

StateFlowBase::Action withrottle::ThrottleFlow::data_received ( )
private

Process read data.

Returns
next state is data_received() OpenLCB throttle instance

Definition at line 76 of file Server.cxx.

◆ data_sent()

StateFlowBase::Action withrottle::ThrottleFlow::data_sent ( )
private

Data sent successfully.

Returns
next state is data_received()

Definition at line 67 of file Server.cxx.

◆ entry()

StateFlowBase::Action withrottle::ThrottleFlow::entry ( )
private

Beginning of state flow.

Returns
next state is data_sent()

Definition at line 56 of file Server.cxx.

◆ parse()

bool withrottle::ThrottleFlow::parse ( )
private

Parse the incoming data.

Returns
true if a fully parsed command has been found, else false

Definition at line 110 of file Server.cxx.

◆ parse_command()

void withrottle::ThrottleFlow::parse_command ( )
private

Parse the incoming data.

Definition at line 158 of file Server.cxx.

◆ parse_multi_type()

void withrottle::ThrottleFlow::parse_multi_type ( )
private

Parse the incoming data.

Definition at line 193 of file Server.cxx.

◆ parse_subcommand()

bool withrottle::ThrottleFlow::parse_subcommand ( )
private

Parse the incoming data.

Returns
true if a fully parsed command has been found, else false

Definition at line 240 of file Server.cxx.

◆ parse_train()

void withrottle::ThrottleFlow::parse_train ( )
private

Parse the incoming data.

Definition at line 214 of file Server.cxx.

◆ start()

void withrottle::ThrottleFlow::start ( )
inline

Start the service.

Definition at line 123 of file Server.hxx.

Friends And Related Symbol Documentation

◆ ServerCommandBase

friend class ServerCommandBase
friend

allow access to private members from class ServerCommandBase

Definition at line 208 of file Server.hxx.

◆ ServerCommandLoco

friend class ServerCommandLoco
friend

allow access to private members from class ServerCommandLoco

Definition at line 211 of file Server.hxx.

Member Data Documentation

◆ address

LocoAddress withrottle::ThrottleFlow::address
private

primary locomitve addres

Definition at line 174 of file Server.hxx.

◆ command

Buffer<ThrottleCommand>* withrottle::ThrottleFlow::command
private

throttle command

Definition at line 202 of file Server.hxx.

◆ data

string withrottle::ThrottleFlow::data
private

agrigate pre-processed stream data

Definition at line 184 of file Server.hxx.

◆ dataIndex

size_t withrottle::ThrottleFlow::dataIndex
private

data index for parsing

Definition at line 187 of file Server.hxx.

◆ dispatcher

CommandDispatchFlow withrottle::ThrottleFlow::dispatcher
private

flow responsible for routing incoming messages to handlers.

Definition at line 199 of file Server.hxx.

◆ fd

int withrottle::ThrottleFlow::fd
private

socket descriptor of throttle connection

Definition at line 178 of file Server.hxx.

◆ id

string withrottle::ThrottleFlow::id
private

id of throttle

Definition at line 173 of file Server.hxx.

◆ name

string withrottle::ThrottleFlow::name
private

name of throttle

Definition at line 172 of file Server.hxx.

◆ olcbThrottle

openlcb::TractionThrottle withrottle::ThrottleFlow::olcbThrottle
private

Definition at line 167 of file Server.hxx.

◆ readRaw

char withrottle::ThrottleFlow::readRaw[128]
private

read data buffer

Definition at line 181 of file Server.hxx.

◆ secondaryAddress

LocoAddress withrottle::ThrottleFlow::secondaryAddress
private

secondary locomotive address

Definition at line 175 of file Server.hxx.

◆ selectHelper

StateFlowSelectHelper withrottle::ThrottleFlow::selectHelper
private

Helper for waiting on data from a file descriptor.

Definition at line 193 of file Server.hxx.

◆ server

Server* withrottle::ThrottleFlow::server
private

reference to parent server

Definition at line 170 of file Server.hxx.

◆ serverCommandLoco

ServerCommandLoco withrottle::ThrottleFlow::serverCommandLoco
private

handler for locomotive commands

Definition at line 205 of file Server.hxx.

◆ state

ServerState withrottle::ThrottleFlow::state
private

Current state of parsing the data.

Definition at line 190 of file Server.hxx.


The documentation for this class was generated from the following files: