Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
EventServiceImpl.hxx
Go to the documentation of this file.
1
37#ifndef _OPENLCB_EVENTSERVICEIMPL_HXX_
38#define _OPENLCB_EVENTSERVICEIMPL_HXX_
39
40#include <memory>
41#include <vector>
42
45
46namespace openlcb
47{
48
49class IncomingEventFlow;
50class GlobalIdentifyFlow;
51class EventHandler;
52
57{
58 const EventRegistryEntry *registry_entry;
59 EventReport *rep;
60 EventHandlerFunction fn;
61 unsigned epoch;
62 void reset(const EventRegistryEntry *entry, unsigned epoch,
63 EventReport *rep, EventHandlerFunction fn)
64 {
65 this->registry_entry = entry;
66 this->rep = rep;
67 this->fn = fn;
68 this->epoch = epoch;
69 }
70};
71
77class EventCallerFlow : public StateFlow<Buffer<EventHandlerCall>, QList<5>>
78{
79public:
80 EventCallerFlow(Service *service)
82
83private:
84 virtual Action entry() OVERRIDE;
85 Action call_done();
86
88};
89
94{
95public:
96 Impl(EventService *service);
97 ~Impl();
98
100 std::unique_ptr<EventRegistry> registry;
101
104 std::vector<std::unique_ptr<StateFlowWithQueue>> ownedFlows_;
105
109
110 enum
111 {
112 // These address/mask should match all the messages carrying an event
113 // id.
114 MTI_VALUE_EVENT = Defs::MTI_EVENT_MASK,
115 MTI_MASK_EVENT = Defs::MTI_EVENT_MASK,
116 MTI_VALUE_GLOBAL = Defs::MTI_EVENTS_IDENTIFY_GLOBAL,
117 MTI_MASK_GLOBAL = 0xffff,
118 MTI_VALUE_ADDRESSED_ALL = Defs::MTI_EVENTS_IDENTIFY_ADDRESSED,
119 MTI_MASK_ADDRESSED_ALL = 0xffff,
120 };
121};
122
128{
129public:
130 EventIteratorFlow(If *iface, EventService *event_service,
131 unsigned mti_value, unsigned mti_mask);
133
134protected:
136 Action iterate_next();
137
138private:
139 virtual Action dispatch_event(const EventRegistryEntry *entry);
140
141protected:
142 EventService *eventService_;
143
147
157
159 EventHandlerFunction fn_;
160
161#ifdef DEBUG_EVENT_PERFORMANCE
162 static const int REPORT_COUNT = 100;
164 uint8_t countEvents_{0};
165 uint16_t mtiValue_;
167 long long numProcessNsec_{0};
170#endif
171};
172
178{
179public:
180 InlineEventIteratorFlow(If *iface, EventService *event_service,
181 unsigned mti_value, unsigned mti_mask)
182 : EventIteratorFlow(iface, event_service, mti_value, mti_mask)
183 {
184 }
185
186private:
187 Action dispatch_event(const EventRegistryEntry *entry) OVERRIDE;
188
191};
192
193} // namespace openlcb
194
195#endif // _OPENLCB_EVENTSERVICEIMPL_HXX_
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
An object that can schedule itself on an executor to run.
A list of queues.
Definition Queue.hxx:466
Collection of related state machines that pend on incoming messages.
State flow with a given typed input queue.
Base::Action Action
Allows using Action without having StateFlowBase:: prefix in front of it.
Control flow that calls individual event handlers one at a time and waits until the done callback is ...
virtual Action entry() OVERRIDE
Entry into the StateFlow activity.
Flow to receive incoming messages of event protocol, and dispatch them to the registered event handle...
unsigned eventRegistryEpoch_
The epoch of the event registry at the start of the iteration.
uint8_t countEvents_
How many events' cost are accumulated so far.
long long numProcessNsec_
Accumulator of how many msec processingthe events took.
EventIterator * iterator_
Iterator for generating the event handlers from the registry.
Action entry() OVERRIDE
Entry into the StateFlow activity.
long long currentProcessStart_
When the processing of the current event started.
Notifiable * incomingDone_
This done notifiable holds a reference to the incoming message buffer.
EventReport eventReport_
Statically allocated structure for calling the event handlers from the main event queue.
Abstract class for representing iteration through a container for event handlers.
Structure used in registering event handlers.
PImpl class for the EventService.
std::unique_ptr< EventRegistry > registry
The implementation of the event registry.
std::vector< std::unique_ptr< StateFlowWithQueue > > ownedFlows_
Flows that we own.
EventCallerFlow callerFlow_
This flow will serialize calls to NMRAnetEventHandler objects.
Global Event Service.
Abstract class representing an OpenLCB Interface.
Definition If.hxx:185
Base class for incoming message handler flows.
Definition If.hxx:400
Flow to receive incoming messages of event protocol, and dispatch them to the registered event handle...
const EventRegistryEntry * currentEntry_
The handler we need to call.
#define OVERRIDE
Function attribute for virtual functions declaring that this funciton is overriding a funciton that s...
Definition macros.h:180
@ MTI_EVENT_MASK
event number present mask
@ MTI_EVENTS_IDENTIFY_GLOBAL
request identify all of every node's events
@ MTI_EVENTS_IDENTIFY_ADDRESSED
request identify all of a node's events
Arguments structure for the EventCallerFlow.
Shared notification structure that is assembled for each incoming event-related message,...