45 size_t num_registry_entries)
46 :
Service(iface->executor()), iface_(iface), dispatcher_(iface_, num_registry_entries)
52DatagramService::~DatagramService()
62 return release_and_exit();
71 get_allocation_result<IncomingDatagram>(
nullptr);
74 d->
dst = nmsg()->dstNode;
78 d->
payload.swap(nmsg()->payload);
85 unsigned datagram_id = -1;
89 "Invalid arguments: incoming datagram from node %012" PRIx64
90 " alias %x has no payload.",
92 resultCode_ = DatagramClient::PERMANENT_ERROR;
93 return allocate_and_call(iface()->addressed_message_write_flow(),
94 STATE(respond_rejection));
96 datagram_id = *
reinterpret_cast<const uint8_t*
>(d->
payload.data());
103 LOG(
VERBOSE,
"No datagram handler found for node %p id %x", d->
dst,
105 resultCode_ = DatagramClient::PERMANENT_ERROR;
106 return allocate_and_call(iface()->addressed_message_write_flow(),
107 STATE(respond_rejection));
116DatagramService::DatagramDispatcher::respond_rejection()
118 auto* f = get_allocation_result(iface()->addressed_message_write_flow());
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
Base class for all QMember types that hold data in an expandable format.
T * data()
get a pointer to the start of the data.
void register_handler(HandlerType *handler, ID id, ID mask)
Adds a new handler to this dispatcher.
void unregister_handler(HandlerType *handler, ID id, ID mask)
Removes a specific instance of a handler from this dispatcher.
Abstract class for message recipients.
virtual void send(MessageType *message, unsigned priority=UINT_MAX)=0
Entry point to the flow.
Collection of related state machines that pend on incoming messages.
Return type for a state flow callback.
Action entry() override
Entry into the StateFlow activity.
Action incoming_datagram_allocated()
DatagramService(If *iface, size_t num_registry_entries)
Creates a datagram dispatcher.
If * iface_
Interface on which we are registered.
DatagramDispatcher dispatcher_
Datagram dispatch handler.
Abstract class representing an OpenLCB Interface.
MessageDispatchFlow * dispatcher()
MessageHandler * addressed_message_write_flow()
GenMessage * nmsg()
Returns the NMRAnet message we received.
#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.
long long DATAGRAM_RESPONSE_TIMEOUT_NSEC
Defines how long the datagram client flow should wait for the datagram ack/nack response message.
Pool *const g_incoming_datagram_allocator
Allocator to be used for Buffer<IncomingDatagram> objects.
string error_to_buffer(uint16_t error_code, uint16_t mti)
Formats a payload for response of error response messages such as OPtioanl Interaction Rejected or Te...
#define SEC_TO_NSEC(_sec)
Convert a second value to a nanosecond value.
@ MTI_DATAGRAM_REJECTED
datagram rejected by receiver
Message structure for incoming datagram handlers.
DatagramPayload payload
Owned by the current IncomingDatagram object.
Node * dst
Virtual node that the datagram was addressed to.
NodeHandle src
Originator of the incoming datagram.
NodeID id
48-bit NMRAnet Node ID
NodeAlias alias
alias to NMRAnet Node ID