Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
Datagram.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_DATAGRAM_HXX_
36#define _OPENLCB_DATAGRAM_HXX_
37
39#include "utils/Queue.hxx"
40#include "openlcb/If.hxx"
41
42namespace openlcb
43{
44
45struct IncomingDatagram;
46
48extern long long DATAGRAM_RESPONSE_TIMEOUT_NSEC;
49
52
64
67
76
78class DatagramClient : public QMember
79{
80public:
81 virtual ~DatagramClient()
82 {
83 }
84
98 unsigned priority = UINT_MAX) = 0;
99
102 virtual void cancel() = 0;
103
105 uint32_t result()
106 {
107 return result_;
108 }
109
114 {
115 PERMANENT_ERROR = 0x1000,
116 RESEND_OK = 0x2000,
117 // Resend OK errors
118 TRANSPORT_ERROR = 0x4000,
119 BUFFER_UNAVAILABLE = 0x0020,
120 OUT_OF_ORDER = 0x0040,
121 // Permanent error error bits
122 SOURCE_NOT_PERMITTED = 0x0020,
123 DATAGRAMS_NOT_ACCEPTED = 0x0040,
124
125 // Internal error codes generated by the send flow
126 OPERATION_SUCCESS = 0x10000, //< set when the Datagram OK arrives
127 OPERATION_PENDING = 0x20000, //< cleared when done is called.
128 DST_NOT_FOUND = Defs::ERROR_DST_NOT_FOUND, //< on CAN. Permanent error code.
129 TIMEOUT = Defs::OPENMRN_TIMEOUT, //< Timeout waiting for ack/nack.
130 DST_REBOOT = Defs::ERROR_DST_REBOOT, //< Target node has rebooted.
131
132 // The top byte of result_ is the response flags from Datagram_OK
133 // response.
134 RESPONSE_FLAGS_SHIFT = 24,
135 RESPONSE_CODE_MASK = (1<<RESPONSE_FLAGS_SHIFT) - 1,
136 OK_REPLY_PENDING = (1 << 31),
137 };
138
139 // These values are okay in the respond_ok flags byte.
140 enum ResponseFlag
141 {
142 REPLY_PENDING = 0x80,
143 REPLY_TIMEOUT_SEC = 0x1,
144 REPLY_TIMEOUT_MASK = 0xf,
145 };
146
147protected:
148 uint32_t result_;
149};
150
161{
162public:
164
171 DatagramService(If *iface, size_t num_registry_entries);
173
176 {
177 return dispatcher_.registry();
178 }
179
190
191 If *iface()
192 {
193 return iface_;
194 }
195
196private:
206 {
207 public:
208 DatagramDispatcher(If *iface, size_t num_registry_entries)
210 , registry_(num_registry_entries)
211 {
212 }
213
215 {
216 }
217
220 {
221 return &registry_;
222 }
223
224 private:
225 Action entry() override;
226
228 Action respond_rejection();
229
230 Buffer<IncomingDatagram> *d_; //< Datagram to send to handler.
231 uint16_t resultCode_; //< Rejection reason
232
235
236 // TypedAllocator<IncomingMessageHandler> lock_;
237 };
238
241
244
247};
248
249} // namespace openlcb
250
251#endif // _OPENLCB_DATAGRAM_HXX_
Base class for all QMember types that hold data in an expandable format.
Definition Buffer.hxx:195
Abstract class for message recipients.
Pool of previously allocated, but currently unused, items.
Definition Buffer.hxx:278
A list of queues.
Definition Queue.hxx:466
Essentially a "next" pointer container.
Definition QMember.hxx:42
Collection of related state machines that pend on incoming messages.
State flow with a given typed input queue.
A type-safe map that allows registration and lookup or per-node handler of a particular message ID.
Strongly typed queue class with asynchronous access.
Definition Queue.hxx:406
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
Use this class to send datagrams.
Definition Datagram.hxx:79
virtual void cancel()=0
Requests cancelling the datagram send operation.
uint32_t result()
Returns a bitmask of ResultCodes for the transmission operation.
Definition Datagram.hxx:105
ResultCodes
Known result codes from the DatagramClient.
Definition Datagram.hxx:114
virtual void write_datagram(Buffer< GenMessage > *b, unsigned priority=UINT_MAX)=0
Triggers sending a datagram.
Class for routing incoming datagram messages to the datagram handlers.
Definition Datagram.hxx:206
Action entry() override
Entry into the StateFlow activity.
Definition Datagram.cxx:58
Registry registry_
Maintains the registered datagram handlers.
Definition Datagram.hxx:234
Transport-agnostic dispatcher of datagrams.
Definition Datagram.hxx:161
TypedQAsync< DatagramClient > * client_allocator()
Datagram clients.
Definition Datagram.hxx:186
TypedQAsync< DatagramClient > clients_
Datagram clients.
Definition Datagram.hxx:243
If * iface_
Interface on which we are registered.
Definition Datagram.hxx:240
DatagramDispatcher dispatcher_
Datagram dispatch handler.
Definition Datagram.hxx:246
Abstract class representing an OpenLCB Interface.
Definition If.hxx:185
Base class for incoming message handler flows.
Definition If.hxx:400
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
long long DATAGRAM_RESPONSE_TIMEOUT_NSEC
Defines how long the datagram client flow should wait for the datagram ack/nack response message.
Definition Datagram.cxx:42
FlowInterface< Buffer< IncomingDatagram > > DatagramHandler
Base class for datagram handlers.
Definition Datagram.hxx:73
string Payload
Container that carries the data bytes in an NMRAnet message.
StateFlow< Buffer< IncomingDatagram >, QList< 1 > > DatagramHandlerFlow
Derive datagram handlers that are stateflows from this base class.
Definition Datagram.hxx:75
Pool *const g_incoming_datagram_allocator
Allocator to be used for Buffer<IncomingDatagram> objects.
Payload DatagramPayload
Contents of a Datagram message.
Definition Datagram.hxx:51
Message structure for incoming datagram handlers.
Definition Datagram.hxx:55
DatagramPayload payload
Owned by the current IncomingDatagram object.
Definition Datagram.hxx:62
Node * dst
Virtual node that the datagram was addressed to.
Definition Datagram.hxx:59
NodeHandle src
Originator of the incoming datagram.
Definition Datagram.hxx:57
Container of both a NodeID and NodeAlias.