Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::If Class Referenceabstract

Abstract class representing an OpenLCB Interface. More...

#include <If.hxx>

Inheritance diagram for openlcb::If:
Service openlcb::IfCan openlcb::IfTcp openlcb::LocalIf

Public Types

typedef DispatchFlow< Buffer< GenMessage >, 4 > MessageDispatchFlow
 Type of the dispatcher of incoming NMRAnet messages.
 

Public Member Functions

 If (ExecutorBase *executor, int local_nodes_count)
 Constructs an NMRAnet interface.
 
virtual ~If ()
 Destructor.
 
MessageHandlerglobal_message_write_flow ()
 
MessageHandleraddressed_message_write_flow ()
 
MessageDispatchFlowdispatcher ()
 
virtual void add_owned_flow (Executable *e)=0
 Transfers ownership of a module to the interface.
 
void add_local_node (Node *node)
 Registers a new local node on this interface.
 
virtual void delete_local_node (Node *node)=0
 Removes a local node from this interface.
 
Nodelookup_local_node (NodeID id)
 Looks up a node ID in the local nodes' registry.
 
virtual Nodelookup_local_node_handle (NodeHandle handle)
 Looks up a node ID in the local nodes' registry.
 
Nodefirst_local_node ()
 
Nodenext_local_node (NodeID previous)
 Iterator helper on the local nodes map.
 
virtual bool matching_node (NodeHandle expected, NodeHandle actual)=0
 
virtual void canonicalize_handle (NodeHandle *h)
 Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.
 
virtual NodeID get_default_node_id ()=0
 
void set_tx_hook (std::function< void()> hook)
 Sets a transmit hook.
 
StreamTransportstream_transport ()
 
void set_stream_transport (StreamTransport *s)
 Adds the necessary object for this interface to support stream transport.
 
- Public Member Functions inherited from Service
 Service (ExecutorBase *e)
 Constructor.
 
 ~Service ()
 Destructor.
 
ExecutorBaseexecutor ()
 

Protected Member Functions

void remove_local_node_from_map (Node *node)
 

Protected Attributes

MessageHandlerglobalWriteFlow_
 Allocator containing the global write flows.
 
MessageHandleraddressedWriteFlow_
 Allocator containing the addressed write flows.
 

Private Types

typedef Map< NodeID, Node * > VNodeMap
 

Private Member Functions

 DISALLOW_COPY_AND_ASSIGN (If)
 

Private Attributes

MessageDispatchFlow dispatcher_
 Flow responsible for routing incoming messages to handlers.
 
std::function< void()> txHook_
 This function is pinged every time a message is transmitted.
 
VNodeMap localNodes_
 Local virtual nodes registered on this interface.
 
StreamTransportstreamTransport_ {nullptr}
 Accessor for the objects and variables for supporting stream transport.
 

Friends

class VerifyNodeIdHandler
 

Detailed Description

Abstract class representing an OpenLCB Interface.

All interaction between the local software stack and the physical bus has to go through this class. The API that's not specific to the wire protocol appears here. The implementations of this class would be specific to the wire protocol (e.g. IfCan for CAN, and a not-yet-implemented class for TCP).

Definition at line 184 of file If.hxx.

Member Typedef Documentation

◆ MessageDispatchFlow

Type of the dispatcher of incoming NMRAnet messages.

Definition at line 221 of file If.hxx.

◆ VNodeMap

typedef Map<NodeID, Node *> openlcb::If::VNodeMap
private

Definition at line 380 of file If.hxx.

Constructor & Destructor Documentation

◆ If()

openlcb::If::If ( ExecutorBase executor,
int  local_nodes_count 
)

Constructs an NMRAnet interface.

@TODO(balazs.racz): make the map size parametrizable.

Parameters
executoris the thread that will be used for all processing on this interface.
local_nodes_countis the maximum number of virtual nodes that this interface will support.

Definition at line 174 of file If.cxx.

◆ ~If()

virtual openlcb::If::~If ( )
inlinevirtual

Destructor.

Definition at line 195 of file If.hxx.

Member Function Documentation

◆ add_local_node()

void openlcb::If::add_local_node ( Node node)
inline

Registers a new local node on this interface.

This function must be called from the interface's executor.

Parameters
nodeis the node to register.

Definition at line 242 of file If.hxx.

◆ add_owned_flow()

virtual void openlcb::If::add_owned_flow ( Executable e)
pure virtual

Transfers ownership of a module to the interface.

It will be brought down in the destructor. The destruction order is guaranteed such that all supporting structures are still available when the flow is destryed, but incoming messages can not come in anymore.

Todo:
(balazs.racz) revise whether this needs to be virtual.

Implemented in openlcb::IfCan, openlcb::IfTcp, and openlcb::LocalIf.

◆ addressed_message_write_flow()

MessageHandler * openlcb::If::addressed_message_write_flow ( )
inline
Returns
Flow to send addressed messages to the NMRAnet bus.

Definition at line 210 of file If.hxx.

◆ canonicalize_handle()

virtual void openlcb::If::canonicalize_handle ( NodeHandle h)
inlinevirtual

Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.

Noop for TCP interface. Must be called on the interface executor.

Reimplemented in openlcb::IfCan.

Definition at line 327 of file If.hxx.

◆ delete_local_node()

virtual void openlcb::If::delete_local_node ( Node node)
pure virtual

Removes a local node from this interface.

This function must be called from the interface's executor.

Parameters
nodeis the node to delete. The node will not be freed, just removed from the data structures.

Implemented in openlcb::IfCan, openlcb::IfTcp, and openlcb::LocalIf.

◆ dispatcher()

MessageDispatchFlow * openlcb::If::dispatcher ( )
inline
Returns
Dispatcher of incoming NMRAnet messages.

Definition at line 224 of file If.hxx.

◆ first_local_node()

Node * openlcb::If::first_local_node ( )
inline
Returns
the first node (by nodeID order) that is registered in this interface as a local node, or nullptr if this interface has no local nodes.

Definition at line 289 of file If.hxx.

◆ get_default_node_id()

virtual NodeID openlcb::If::get_default_node_id ( )
pure virtual
Returns
the node ID of the default node on this interface. For TCP interfaces this is the gateway node ID, for CAN interfaces this is the node ID used for alias allocation on the CAN-bus.

Implemented in openlcb::IfCan, openlcb::IfTcp, and openlcb::LocalIf.

◆ global_message_write_flow()

MessageHandler * openlcb::If::global_message_write_flow ( )
inline
Returns
Flow to send global messages to the NMRAnet bus.

Definition at line 200 of file If.hxx.

◆ lookup_local_node()

Node * openlcb::If::lookup_local_node ( NodeID  id)
inline

Looks up a node ID in the local nodes' registry.

This function must be called from the interface's executor.

Parameters
idis the 48-bit NMRAnet node ID to look up.
Returns
the node pointer or NULL if the node is not registered.

Definition at line 263 of file If.hxx.

◆ lookup_local_node_handle()

virtual Node * openlcb::If::lookup_local_node_handle ( NodeHandle  handle)
inlinevirtual

Looks up a node ID in the local nodes' registry.

This function must be called from the interface's executor.

Parameters
handleis the NodeHandle representing a target node.
Returns
the node pointer or NULL if the node is not local registered.

Reimplemented in openlcb::IfCan.

Definition at line 279 of file If.hxx.

◆ matching_node()

virtual bool openlcb::If::matching_node ( NodeHandle  expected,
NodeHandle  actual 
)
pure virtual
Returns
true if the two node handles match as far as we can tell without doing any network traffic.

Implemented in openlcb::IfCan, openlcb::IfTcp, and openlcb::LocalIf.

◆ next_local_node()

Node * openlcb::If::next_local_node ( NodeID  previous)
inline

Iterator helper on the local nodes map.

Parameters
previousis the node ID of a valid local node.
Returns
the node pointer of the next local node (in node ID order) or null if this was the last node or an invalid argument (not the node ID of a local node).

Definition at line 304 of file If.hxx.

◆ remove_local_node_from_map()

void openlcb::If::remove_local_node_from_map ( Node node)
inlineprotected

Definition at line 361 of file If.hxx.

◆ set_stream_transport()

void openlcb::If::set_stream_transport ( StreamTransport s)
inline

Adds the necessary object for this interface to support stream transport.

May be called only once per interface.

Parameters
sthe stream transport object. Ownership is not transferred. (If needed, see add_owned_flow.)

Definition at line 354 of file If.hxx.

◆ set_tx_hook()

void openlcb::If::set_tx_hook ( std::function< void()>  hook)
inline

Sets a transmit hook.

This function will be called once for every OpenLCB message transmitted. Used for implementing activity LEDs.

Parameters
hookfunction to call for each transmit message.

Definition at line 337 of file If.hxx.

◆ stream_transport()

StreamTransport * openlcb::If::stream_transport ( )
inline
Returns
the object supporting stream transport in OpenLCB. May be null if stream transport was not initialized for this interface. This is typical when a small node is low on flash space for code.

Definition at line 345 of file If.hxx.

Friends And Related Symbol Documentation

◆ VerifyNodeIdHandler

friend class VerifyNodeIdHandler
friend

Definition at line 388 of file If.hxx.

Member Data Documentation

◆ addressedWriteFlow_

MessageHandler* openlcb::If::addressedWriteFlow_
protected

Allocator containing the addressed write flows.

Definition at line 371 of file If.hxx.

◆ dispatcher_

MessageDispatchFlow openlcb::If::dispatcher_
private

Flow responsible for routing incoming messages to handlers.

Definition at line 375 of file If.hxx.

◆ globalWriteFlow_

MessageHandler* openlcb::If::globalWriteFlow_
protected

Allocator containing the global write flows.

Definition at line 369 of file If.hxx.

◆ localNodes_

VNodeMap openlcb::If::localNodes_
private

Local virtual nodes registered on this interface.

Definition at line 383 of file If.hxx.

◆ streamTransport_

StreamTransport* openlcb::If::streamTransport_ {nullptr}
private

Accessor for the objects and variables for supporting stream transport.

Definition at line 386 of file If.hxx.

◆ txHook_

std::function<void()> openlcb::If::txHook_
private

This function is pinged every time a message is transmitted.

Definition at line 378 of file If.hxx.


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