Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::IfTcp Class Reference

Network interface class for a character stream link that speaks the (point-to-point) TcpTransfer protocol. More...

#include <IfTcp.hxx>

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

Public Member Functions

 IfTcp (NodeID gateway_node_id, HubFlow *device, int local_nodes_count)
 Creates a TCP interface.
 
 ~IfTcp ()
 Destructor.
 
void add_owned_flow (Executable *e) override
 Transfers ownership of a module to the interface.
 
void add_owned_flow (Destructable *e)
 Transfers ownership of a module to the interface.
 
void delete_owned_flow (Destructable *d)
 Finds a given pointer in the owned flows list, deletes it and removes it from the list.
 
void delete_local_node (Node *node) override
 Removes a local node from this interface.
 
bool matching_node (NodeHandle expected, NodeHandle actual) override
 
void add_network_fd (int fd, Notifiable *on_error=nullptr)
 Adds a network client connection to the device.
 
NodeID get_default_node_id () override
 
- Public Member Functions inherited from openlcb::If
 If (ExecutorBase *executor, int local_nodes_count)
 Constructs an NMRAnet interface.
 
virtual ~If ()
 Destructor.
 
MessageHandlerglobal_message_write_flow ()
 
MessageHandleraddressed_message_write_flow ()
 
MessageDispatchFlowdispatcher ()
 
void add_local_node (Node *node)
 Registers a new local node on 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 void canonicalize_handle (NodeHandle *h)
 Canonicalizes the node handle: fills in id and/or alias from the maps the interface holds internally.
 
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 ()
 

Private Attributes

HubFlowdevice_
 Where to send traffic to.
 
std::vector< std::unique_ptr< Destructable > > ownedFlows_
 Various implementation control flows that this interface owns.
 
ClockBaseSequenceNumberGeneratorseq_
 Sequence number generator for outgoing TCP packets.
 
TcpSendFlowsendFlow_
 Flow used for converting GenMessage into the binary representation.
 
TcpRecvFlowrecvFlow_
 Flow for parsing incoming messages. Owned by ownedFlows_.
 

Additional Inherited Members

- Public Types inherited from openlcb::If
typedef DispatchFlow< Buffer< GenMessage >, 4 > MessageDispatchFlow
 Type of the dispatcher of incoming NMRAnet messages.
 
- Protected Member Functions inherited from openlcb::If
void remove_local_node_from_map (Node *node)
 
- Protected Attributes inherited from openlcb::If
MessageHandlerglobalWriteFlow_
 Allocator containing the global write flows.
 
MessageHandleraddressedWriteFlow_
 Allocator containing the addressed write flows.
 

Detailed Description

Network interface class for a character stream link that speaks the (point-to-point) TcpTransfer protocol.

This is the class that needs to be given to the virtual node (Node*) on the constructor. The If class provides the API and owns all of the implementation for sending and receiving messages to/from this network link.

Today the IfTcp class supports a dumb hub on the device end. This allows creating servers although without any advanced routing logic.

Definition at line 66 of file IfTcp.hxx.

Constructor & Destructor Documentation

◆ IfTcp()

openlcb::IfTcp::IfTcp ( NodeID  gateway_node_id,
HubFlow device,
int  local_nodes_count 
)

Creates a TCP interface.

Parameters
gateway_node_idwill be stamped on outgoing messages as the gateway's node ID.
deviceis a Hub to send the TCP packets to / receive input from. The interface will register itself into this hub. The executor of this device will be used for processing the packets in this interface.
local_nodes_countis the maximum number of virtual nodes that this interface will support.

Definition at line 186 of file IfTcp.cxx.

◆ ~IfTcp()

openlcb::IfTcp::~IfTcp ( )

Destructor.

Definition at line 205 of file IfTcp.cxx.

Member Function Documentation

◆ add_network_fd()

void openlcb::IfTcp::add_network_fd ( int  fd,
Notifiable on_error = nullptr 
)

Adds a network client connection to the device.

Parameters
fdis the socket going towards the client
on_errorwill be invoked when a socket error is encountered.

Definition at line 83 of file IfTcp.cxx.

◆ add_owned_flow() [1/2]

void openlcb::IfTcp::add_owned_flow ( Destructable e)
inline

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.

Definition at line 93 of file IfTcp.hxx.

◆ add_owned_flow() [2/2]

void openlcb::IfTcp::add_owned_flow ( Executable e)
overridevirtual

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.

Implements openlcb::If.

Definition at line 53 of file IfTcp.cxx.

◆ delete_local_node()

void openlcb::IfTcp::delete_local_node ( Node node)
overridevirtual

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.

Implements openlcb::If.

Definition at line 48 of file IfTcp.cxx.

◆ delete_owned_flow()

void openlcb::IfTcp::delete_owned_flow ( Destructable d)

Finds a given pointer in the owned flows list, deletes it and removes it from the list.

Definition at line 58 of file IfTcp.cxx.

◆ get_default_node_id()

NodeID openlcb::IfTcp::get_default_node_id ( )
overridevirtual
Returns
the gateway node ID.

Implements openlcb::If.

Definition at line 214 of file IfTcp.cxx.

◆ matching_node()

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

Implements openlcb::If.

Definition at line 71 of file IfTcp.cxx.

Member Data Documentation

◆ device_

HubFlow* openlcb::IfTcp::device_
private

Where to send traffic to.

Definition at line 121 of file IfTcp.hxx.

◆ ownedFlows_

std::vector<std::unique_ptr<Destructable> > openlcb::IfTcp::ownedFlows_
private

Various implementation control flows that this interface owns.

Definition at line 123 of file IfTcp.hxx.

◆ recvFlow_

TcpRecvFlow* openlcb::IfTcp::recvFlow_
private

Flow for parsing incoming messages. Owned by ownedFlows_.

Definition at line 130 of file IfTcp.hxx.

◆ sendFlow_

TcpSendFlow* openlcb::IfTcp::sendFlow_
private

Flow used for converting GenMessage into the binary representation.

Owned by ownedFlows_.

Definition at line 128 of file IfTcp.hxx.

◆ seq_

ClockBaseSequenceNumberGenerator* openlcb::IfTcp::seq_
private

Sequence number generator for outgoing TCP packets.

Definition at line 125 of file IfTcp.hxx.


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