Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
LatencyTestConsumer.hxx
Go to the documentation of this file.
1
35#ifndef _OPENLCB_LATENCYTESTCONSUMER_HXX_
36#define _OPENLCB_LATENCYTESTCONSUMER_HXX_
37
39
40namespace openlcb
41{
42
62{
63public:
65 using HookFn = std::function<void(Notifiable *)>;
66
67 LatencyTestConsumer(Node *node, HookFn hook = nullptr)
68 : node_(node)
69 , hook_(hook)
70 {
71 EventRegistry::instance()->register_handler(
73 }
74
75 void handle_identify_global(const EventRegistryEntry &registry_entry,
76 EventReport *event, BarrierNotifiable *done) override
77 {
78 AutoNotify an(done);
79 if (event->dst_node && event->dst_node != node_)
80 {
81 return;
82 }
83 event->event_write_helper<1>()->WriteAsync(node_,
84 Defs::MTI_CONSUMER_IDENTIFIED_RANGE, WriteHelper::global(),
86 done->new_child());
87 }
88
90 EventReport *event, BarrierNotifiable *done) override
91 {
92 event_ = event;
93 done_ = done;
94 if (hook_)
95 {
96 hook_(new TempNotifiable([this]() { reply(); }));
97 }
98 else
99 {
100 reply();
101 }
102 }
103
104private:
105 void reply()
106 {
107 AutoNotify an(done_);
108 event_->event_write_helper<1>()->WriteAsync(node_,
109 Defs::MTI_CONSUMER_IDENTIFIED_UNKNOWN, WriteHelper::global(),
111 }
112
115 static constexpr EventId EVENT_BASE = 0x0900013900000000;
116
119
123
126
129};
130
131} // namespace openlcb
132
133#endif // _OPENLCB_LATENCYTESTCONSUMER_HXX_
This class sends a notification in its destructor.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
BarrierNotifiable * new_child()
Call this for each child task.
An object that can schedule itself on an executor to run.
static EventRegistry * instance()
Definition Singleton.hxx:77
A notifiable class that calls a particular function object once when it is invoked,...
Structure used in registering event handlers.
This event consumer works together with the hub_test application in order to detect the response late...
void handle_identify_consumer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Called on another node sending IdentifyConsumer.
EventReport * event_
Incoming event report we are working on.
void handle_identify_global(const EventRegistryEntry &registry_entry, EventReport *event, BarrierNotifiable *done) override
Called on the need of sending out identification messages.
Node * node_
Which node should be sending responses.
HookFn hook_
The owner's hook will be invoked and run (asynchronous) before replying.
std::function< void(Notifiable *)> HookFn
To complete the hook, call the notifiable.
static constexpr EventId EVENT_BASE
This is within NMRA ID 1, which is not assigned.
BarrierNotifiable * done_
Will notify this after sending the reply.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
SimpleEventHandler ignores all non-essential callbacks.
uint64_t EncodeRange(uint64_t begin, unsigned size)
Creates a single encoded event range from the beginning of the range and the number fo events to cove...
Payload eventid_to_buffer(uint64_t eventid)
Converts an Event ID to a Payload suitable to be sent as an event report.
Definition If.cxx:72
@ MTI_CONSUMER_IDENTIFIED_UNKNOWN
consumer broadcast, validity unknown
@ MTI_CONSUMER_IDENTIFIED_RANGE
consumer broadcast about a range of consumers
Shared notification structure that is assembled for each incoming event-related message,...
EventId event
The event ID from the incoming message.
Node * dst_node
nullptr for global messages; points to the specific virtual node for addressed events identify messag...
WriteHelper * event_write_helper()
These allow event handlers to produce up to four messages per invocation.