Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
NonAuthoritativeEventProducer.hxx
1
37#ifndef _OPENLCB_NONAUTHORITATIVEEVENTPRODUCER_HXX_
38#define _OPENLCB_NONAUTHORITATIVEEVENTPRODUCER_HXX_
39
41
42namespace openlcb
43{
44
47{
48public:
61 BitRangeNonAuthoritativeEventP(Node *node, uint64_t event_base,
62 uint32_t size,
63 std::function<void(unsigned, bool)> state_callback = nullptr)
64 : node_(node)
65 , eventBase_(event_base)
66 , eventBaseOff_(0)
67 , size_(size)
68 , stateCallback_(state_callback)
69 {
70 unsigned mask = EventRegistry::align_mask(&event_base, size * 2);
71 EventRegistry::instance()->register_handler(
72 EventRegistryEntry(this, event_base, EVENT_BASE), mask);
73 }
74
88 BitRangeNonAuthoritativeEventP(Node *node, uint64_t event_base_on,
89 uint64_t event_base_off, uint32_t size,
90 std::function<void(unsigned, bool)> state_callback = nullptr)
91 : node_(node)
92 , eventBaseOn_(event_base_on)
93 , eventBaseOff_(event_base_off)
94 , size_(size)
95 , stateCallback_(state_callback)
96 {
97 unsigned mask;
98
99 mask = EventRegistry::align_mask(&event_base_on, size);
100 EventRegistry::instance()->register_handler(
101 EventRegistryEntry(this, event_base_on, EVENT_BASE_ON), mask);
102
103 mask = EventRegistry::align_mask(&event_base_off, size);
104 EventRegistry::instance()->register_handler(
105 EventRegistryEntry(this, event_base_off, EVENT_BASE_OFF), mask);
106 }
107
110 {
111 EventRegistry::instance()->unregister_handler(this);
112 }
113
120 void send_query_consumer(unsigned bit, WriteHelper *writer,
121 BarrierNotifiable *done);
122
130 void set(unsigned bit, bool new_value, WriteHelper *writer,
131 BarrierNotifiable *done);
132
138 void handle_event_report(const EventRegistryEntry &entry,
139 EventReport *event,
140 BarrierNotifiable *done) override;
141
148 EventReport *event,
149 BarrierNotifiable *done) override;
150
157 EventReport *event,
158 BarrierNotifiable *done) override;
159
166 EventReport *event,
167 BarrierNotifiable *done) override;
168
169private:
171 enum EventBaseType : unsigned
172 {
173 // start counting at 1 as 0 is reserved or unused
174 EVENT_BASE = 1,
177 };
178
180 union
181 {
182 uint64_t eventBase_;
183 uint64_t eventBaseOn_;
184 };
185 uint64_t eventBaseOff_;
186 unsigned size_;
187
190 std::function<void(unsigned, bool)> stateCallback_;
191
193};
194
195} // namespace openlcb
196
197#endif // _OPENLCB_AUTHORITATIVEEVENTPRODUCER_HXX_
198
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
static EventRegistry * instance()
Definition Singleton.hxx:77
Event producer for range of bits (event pairs) that is non-autoritative.
BitRangeNonAuthoritativeEventP(Node *node, uint64_t event_base, uint32_t size, std::function< void(unsigned, bool)> state_callback=nullptr)
Constructor.
void set(unsigned bit, bool new_value, WriteHelper *writer, BarrierNotifiable *done)
Requests the event associated with the current value of the bit to be produced (unconditionally).
void handle_identify_global(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming identify global or addressed message.
uint64_t eventBaseOn_
base event ID for "on" range
void handle_event_report(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming event.
void handle_consumer_identified(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming consumer identified message.
uint64_t eventBaseOff_
base event ID for "off" range
void handle_identify_producer(const EventRegistryEntry &entry, EventReport *event, BarrierNotifiable *done) override
Handle an incoming identify producer message.
BitRangeNonAuthoritativeEventP(Node *node, uint64_t event_base_on, uint64_t event_base_off, uint32_t size, std::function< void(unsigned, bool)> state_callback=nullptr)
Constructor.
std::function< void(unsigned, bool)> stateCallback_
Callback method that will be invoked when a consumer identified message is received with a known stat...
uint64_t eventBase_
base event ID of the full range
Node * node_
Node ID that this producer is attached to.
void send_query_consumer(unsigned bit, WriteHelper *writer, BarrierNotifiable *done)
Queries consumer and acquires the current state of the bit.
EventBaseType
Identifiers for the types of event range registration.
@ EVENT_BASE_ON
one unified range starting at eventBase_
Structure used in registering event handlers.
static unsigned align_mask(EventId *event, unsigned size)
Computes the alignment mask for registering an event range.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
SimpleEventHandler ignores all non-essential callbacks.
A statically allocated buffer for sending one message to the OpenLCB bus.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.
Definition macros.h:171
Shared notification structure that is assembled for each incoming event-related message,...