Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb/NetworkState.hxx
1
27#ifndef _OPENLCB_OLCBNETWORKSTATE_HXX_
28#define _OPENLCB_OLCBNETWORKSTATE_HXX_
29
31
32namespace openlcb
33{
34
37{
38public:
44 NetworkState(Node *node, WriteHelper *write_helper,
45 uint64_t event_on, uint64_t event_off)
46 : writeHelper_(write_helper)
47 , bit_(node, event_on, event_off, true)
48 , bitPC_(&bit_)
49 {
50 }
51
52private:
56 void set_callback(std::function<void()> cb) override
57 {
59 }
60
64 void toggle(Notifiable *done) override
65 {
68 }
69
74 void set_state(bool state, Notifiable *done) override
75 {
76 bit_.set_state(state);
78 }
79
82 State get_state() override
83 {
84 switch (bit_.get_current_state())
85 {
86 case EventState::VALID:
87 return State::VALID;
88 case EventState::INVALID:
89 return State::INVALID;
90 default:
91 return State::UNKNOWN;
92 }
93 }
94
97 bool is_state_known() override
98 {
100 }
101
106 {
108 }
109
111 void reset() override
112 {
113 bit_.reset();
114 }
115
118
121
124};
125
126} // namespace openlcb
127
128#endif // _OPENLCB_OLCBNETWORKSTATE_HXX_
129
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
"Abstract" interface for a binary network state.
@ INVALID
state is "invalid"
@ UNKNOWN
state is "unknown"
@ VALID
state is "valid"
An object that can schedule itself on an executor to run.
void SendEventReport(WriteHelper *writer, Notifiable *done)
Requests the event associated with the current value of the bit to be produced (unconditionally): sen...
Producer-Consumer event handler for a single bit represented by two event IDs.
void SendQueryConsumer(WriteHelper *writer, BarrierNotifiable *done)
Queries consumer and acquires the current state of the bit.
Speciallization of NetworkInitializedBit that adds callback support when the state changes.
void reset()
Call this function in order to reset the network state to unknown.
void set_state(bool new_value) override
Call from the network stack (or the client before notifying the network stack) to set the state.
void set_change_callback(std::function< void()> cb)
Specifies the change notifier.
EventState get_current_state() override
Accessor from the network stack to return the current state.
void toggle_state()
Invert the current state.
OpenLCB implementation of a binary network state.
NetworkState(Node *node, WriteHelper *write_helper, uint64_t event_on, uint64_t event_off)
Constructor.
State get_state() override
Get the current state.
bool is_state_known() override
Get an indication as to if the state is known.
void initiate_query(BarrierNotifiable *done) override
Queries and acquires the current state of the bit.
WriteHelper * writeHelper_
helper for generating events
CallbackNetworkInitializedBit bit_
bit (dual event) container
BitEventPC bitPC_
bit event producer/consumer
void reset() override
Reset the network state to unknown.
void toggle(Notifiable *done) override
Toggle the state.
void set_callback(std::function< void()> cb) override
Set the change notification callback.
void set_state(bool state, Notifiable *done) override
Set the state.
Base class for NMRAnet nodes conforming to the asynchronous interface.
Definition Node.hxx:52
A statically allocated buffer for sending one message to the OpenLCB bus.