Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
DirectHub.hxx
Go to the documentation of this file.
1
37#ifndef _UTILS_DIRECTHUB_HXX_
38#define _UTILS_DIRECTHUB_HXX_
39
40#include "executor/Executor.hxx"
41#include "utils/DataBuffer.hxx"
42
43class Service;
44
48{ };
49
52{
54 void clear()
55 {
56 if (done_)
57 {
58 done_->notify();
59 done_ = nullptr;
60 }
61 source_ = dst_ = nullptr;
62 isFlush_ = false;
63 }
64
69 {
70 if (done_)
71 {
72 done_->notify();
73 done_ = nullptr;
74 }
75 done_ = done;
76 }
77
82 HubSource *source_ = nullptr;
85 HubSource *dst_ = nullptr;
87 bool isFlush_ = false;
88};
89
92template <class T> struct MessageAccessor : public MessageMetadata
93{
94public:
95 void clear()
96 {
97 payload_.reset();
99 }
100
103};
104
107template <> struct MessageAccessor<uint8_t[]> : public MessageMetadata
108{
109 void clear()
110 {
111 // Walks the buffer links and unrefs everything we own.
112 buf_.reset();
114 }
119};
120
127{
128public:
146 virtual ssize_t segment_message(const void *data, size_t size) = 0;
147
150 virtual void clear() = 0;
151};
152
154template <class T> class DirectHubPort : public HubSource
155{
156public:
161 virtual void send(MessageAccessor<T> *msg) = 0;
162};
163
165template <class T> class DirectHubInterface : public Destructable
166{
167public:
169 virtual Service *get_service() = 0;
170
174 virtual void register_port(DirectHubPort<T> *port) = 0;
178 virtual void unregister_port(DirectHubPort<T> *port) = 0;
183 virtual void unregister_port(DirectHubPort<T> *port, Notifiable *done) = 0;
184
190 virtual void enqueue_send(Executable *caller) = 0;
191
197
200 virtual void do_send() = 0;
201};
202
204
207
218 std::unique_ptr<MessageSegmenter> segmenter,
219 Notifiable *on_error = nullptr);
220
227
232
236
237// Forward declarations to avoid needing to include Hub.hxx here.
238template <class T> class GenericHubFlow;
239template <class T> class HubContainer;
240struct CanFrameContainer;
243
250 DirectHubInterface<uint8_t[]> *gc_hub, CanHubFlow *can_hub);
251
252#endif // _UTILS_DIRECTHUB_HXX_
AutoReleaseBuffer< T > BufferPtr
Smart pointer for buffers.
Definition Buffer.hxx:259
void create_port_for_fd(ByteDirectHubInterface *hub, int fd, std::unique_ptr< MessageSegmenter > segmenter, Notifiable *on_error=nullptr)
Creates a hub port of byte stream type reading/writing a given fd.
void create_direct_gc_tcp_hub(ByteDirectHubInterface *hub, int port)
Creates a new GridConnect listener on a given TCP port.
ByteDirectHubInterface * create_hub(ExecutorBase *e)
Creates a new byte stream typed hub.
MessageSegmenter * create_gc_message_segmenter()
Creates a message segmenter for gridconnect data.
Destructable * create_gc_to_legacy_can_bridge(DirectHubInterface< uint8_t[]> *gc_hub, CanHubFlow *can_hub)
Creates a bridge between a gridconnect-based DirectHub and an old style CAN hub flow.
MessageSegmenter * create_trivial_message_segmenter()
Creates a message segmenter for arbitrary data.
HubContainer< CanFrameContainer > CanHubData
This class can be sent via a Buffer to a CAN hub.
Definition Hub.hxx:134
GenericHubFlow< CanHubData > CanHubFlow
A hub that proxies packets of CAN frames.
Definition Hub.hxx:184
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
Base class of everything with a virtual destructor.
Interface for a the central part of a hub.
virtual MessageAccessor< T > * mutable_message()=0
Accessor to fill in the message payload.
virtual void unregister_port(DirectHubPort< T > *port, Notifiable *done)=0
Asynchronously removes a port from this hub.
virtual void register_port(DirectHubPort< T > *port)=0
Adds a port to this hub.
virtual void enqueue_send(Executable *caller)=0
Signals that the caller wants to send a message to the hub.
virtual void unregister_port(DirectHubPort< T > *port)=0
Synchronously removes a port from this hub.
virtual Service * get_service()=0
virtual void do_send()=0
Sends a message to the hub.
Interface for a downstream port of a hub (aka a target to send data to).
virtual void send(MessageAccessor< T > *msg)=0
Send some data out on this port.
An object that can be scheduled on an executor to run.
This class implements an execution of tasks pulled off an input queue.
Definition Executor.hxx:64
Templated implementation of the HubFlow.
Definition Hub.hxx:150
Data type wrapper for sending data through a Hub.
Definition Hub.hxx:101
Empty class that can be used as a pointer for identifying where a piece of data came from.
Definition DirectHub.hxx:48
A class that keeps ownership of a chain of linked DataBuffer references.
Abstract base class for segmenting a byte stream typed input into meaningful packet sized chunks.
virtual ssize_t segment_message(const void *data, size_t size)=0
Makes a segmenting decision given more input data.
virtual void clear()=0
Resets internal state machine.
An object that can schedule itself on an executor to run.
Collection of related state machines that pend on incoming messages.
Container for (binary) CAN frames going through Hubs.
Definition Hub.hxx:72
LinkedDataBufferPtr buf_
Owns a sequence of linked DataBuffers, holds the offset where to start reading in the first one,...
Typed message class.
Definition DirectHub.hxx:93
BufferPtr< T > payload_
Contains a reference of the actual data.
Metadata that is the same about every message (independent of data type).
Definition DirectHub.hxx:52
void set_done(BarrierNotifiable *done)
Sets the done notifiable to a barrier.
Definition DirectHub.hxx:68
void clear()
Clears the message metadata, including notifying the barrier, if set.
Definition DirectHub.hxx:54
HubSource * dst_
Represents the output port where the message will leave.
Definition DirectHub.hxx:85
bool isFlush_
If true, this message should flush the output buffer.
Definition DirectHub.hxx:87
BarrierNotifiable * done_
This must be notified when the processing of the message is complete.
Definition DirectHub.hxx:80
HubSource * source_
Represents the input port where the message came in.
Definition DirectHub.hxx:82