36#ifndef _OPENLCB_IFIMPL_HXX_
37#define _OPENLCB_IFIMPL_HXX_
73 return release_and_exit();
79 return static_cast<If *
>(service());
110 virtual void WriteGlobalMessage(Defs::MTI mti, NodeID src, Buffer* data,
113 HASSERT(IsNotStarted());
121 StartFlowAt(STATE(send_to_local_nodes));
178 return release_and_exit();
180#ifndef SIMPLE_NODE_ONLY
187#ifdef SIMPLE_NODE_ONLY
189 If::VNodeMap::Iterator it = iface()->
localNodes_.begin();
190 if (it == iface()->localNodes_.end())
193 return release_and_exit();
195 srcNode_ = it->second;
197 HASSERT(it == iface()->localNodes_.end());
201 if (it_ == iface()->localNodes_.end())
204 return release_and_exit();
206 srcNode_ = it_->second;
213 return allocate_and_call(iface()->global_message_write_flow(),
217 return release_and_exit();
220#ifdef SIMPLE_NODE_ONLY
224 get_allocation_result(iface()->global_message_write_flow());
226 NodeID id = srcNode_->node_id();
235 get_allocation_result(iface()->global_message_write_flow());
239 NodeID id = srcNode_->node_id();
240 LOG(
VERBOSE,
"Sending verified reply from node %012" PRIx64,
id);
248 if (it_ != iface()->localNodes_.end())
250 srcNode_ = it_->second;
252 return allocate_and_call(iface()->global_message_write_flow(),
265#ifndef SIMPLE_NODE_ONLY
266 If::VNodeMap::Iterator it_;
291 if (!
message()->data()->dstNode)
294 return release_and_exit();
296 auto mti =
message()->data()->mti;
302 return release_and_exit();
304 return allocate_and_call(
314 get_allocation_result(iface()->addressed_message_write_flow()));
321 return release_and_exit();
BufferPtr< T > get_buffer_deleter(Buffer< T > *b)
Helper function to create a BufferPtr of an appropriate type without having to explicitly specify the...
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void register_fallback_handler(HandlerType *handler)
Sets one handler to receive all messages that no other handler has matched.
void unregister_handler(HandlerType *handler, ID id, ID mask)
Removes a specific instance of a handler from this dispatcher.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
State flow with a given typed input queue.
void release() OVERRIDE
Unrefs the current buffer.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
Abstract class representing an OpenLCB Interface.
VNodeMap localNodes_
Local virtual nodes registered on this interface.
MessageHandler * global_message_write_flow()
MessageDispatchFlow * dispatcher()
Node * lookup_local_node(NodeID id)
Looks up a node ID in the local nodes' registry.
MessageHandler * addressed_message_write_flow()
Base class for incoming message handler flows.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Message handler that is registered as a fallback handler in the interface's message dispatcher.
Action fill_oir()
Called after the message buffer allocation is complete.
Action entry() override
Handler callback for incoming messages.
This handler handles VerifyNodeId messages (both addressed and global) on the interface level.
Action entry() override
Handler callback for incoming messages.
Implementation of the hardware-independent parts of the write flows.
virtual Action send_to_local_node()
This state is called when an addressed message's destination is a node that is local to this interfac...
Action global_entry()
Global write flows should return to this state AFTER sending the message to the hardware.
virtual Action send_finished()
Virtual method called after the send is completed, i.e., all the frames are generated and sent to the...
GenMessage * nmsg()
Implementations shall call this function when they are done with sending the packet.
Action addressed_entry()
Addressed write flows should call this state BEFORE sending to the hardware.
virtual Action send_to_hardware()=0
This function will be called (on the main executor) to initiate sending this message to the hardware.
#define LOG(level, message...)
Conditionally write a message to the logging output.
static const int VERBOSE
Loglevel that is usually not printed, reporting debugging information.
static const int WARNING
Loglevel that is always printed, reporting a warning or a retryable error.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
string node_id_to_buffer(NodeID id)
Convenience function to render a 48-bit NMRAnet node ID into a new buffer.
uint64_t NodeID
48-bit NMRAnet Node ID type
NodeID buffer_to_node_id(const string &buf)
Converts a 6-byte-long buffer to a node ID.
Payload error_payload(uint16_t error_code, Defs::MTI incoming_mti)
Generates the payload for an OIR or TDE message.
@ MTI_VERIFY_NODE_ID_ADDRESSED
verify a Node ID
@ MTI_VERIFY_NODE_ID_GLOBAL
verify a Node ID globally
@ MTI_VERIFIED_NODE_ID_NUMBER
respond to a verify Node ID request
@ MTI_OPTIONAL_INTERACTION_REJECTED
rejected request
@ MTI_TERMINATE_DUE_TO_ERROR
terminate due to some error
This class is used in the dispatching of incoming or outgoing NMRAnet messages to the message handler...
NodeHandle dst
Destination node.
Node * dstNode
If the destination node is local, this value is non-NULL.
NodeHandle src
Source node.
Defs::MTI mti
OpenLCB MTI of the incoming message.
string payload
Data content in the message body.
NodeID id
48-bit NMRAnet Node ID