|
Open Model Railroad Network (OpenMRN)
|
Speciallization of NetworkInitializedBit that adds callback support when the state changes. More...
#include <EventHandlerTemplates.hxx>
Public Member Functions | |
| CallbackNetworkInitializedBit (openlcb::Node *node, uint64_t event_on, uint64_t event_off, bool default_local_state) | |
| Constructor. | |
| void | set_change_callback (std::function< void()> cb) |
| Specifies the change notifier. | |
| 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 | reset () |
| Call this function in order to reset the network state to unknown. | |
Public Member Functions inherited from openlcb::NetworkInitializedBit | |
| NetworkInitializedBit (Node *node, uint64_t event_on, uint64_t event_off, bool default_local_state) | |
| Constructs a NetworkInitializedBit. | |
| Node * | node () override |
| Get a reference to the owning Node. | |
| EventState | get_current_state () override |
| Accessor from the network stack to return the current state. | |
| bool | get_local_state () |
| bool | is_network_state_known () |
| 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 | toggle_state () |
| Invert the current state. | |
Public Member Functions inherited from openlcb::BitEventInterface | |
| BitEventInterface (uint64_t event_on, uint64_t event_off) | |
| virtual EventState | get_requested_state () |
| Get the requested state. | |
| uint64_t | event_on () |
| returns the event ID for representing the state transition OFF->ON. | |
| uint64_t | event_off () |
| returns the event ID for representing the state transition ON->OFF. | |
Private Attributes | |
| std::function< void()> | callback_ |
| This function is invoked when the state of the bit changes. | |
Additional Inherited Members | |
Protected Attributes inherited from openlcb::NetworkInitializedBit | |
| Node * | node_ |
| uint8_t | isKnown_: 1 |
| true when we knowthe network state | |
| uint8_t | localState_: 1 |
| local state; either matches the network state or is the constructor-default local state. | |
Speciallization of NetworkInitializedBit that adds callback support when the state changes.
Definition at line 389 of file EventHandlerTemplates.hxx.
|
inline |
Constructor.
| node | the virtual node who exposes this bit. |
| event_on | event ID to set the state to true |
| event_off | event ID to set the state to false |
| default_local_state | Until there is a definite network state we return this state for a local query. Also determines what state a first local toggle() call will set to. |
Definition at line 400 of file EventHandlerTemplates.hxx.
|
inline |
Call this function in order to reset the network state to unknown.
Definition at line 430 of file EventHandlerTemplates.hxx.
|
inline |
Specifies the change notifier.
| cb | will be invoked every time the state is changed (both from local calls as well as from the network stack). |
Definition at line 409 of file EventHandlerTemplates.hxx.
|
inlineoverridevirtual |
Call from the network stack (or the client before notifying the network stack) to set the state.
Always sets the state to definite. NOTE: this does not send any messages. The caller must use the EventHandler object after this function to send out an event.
| new | state value |
Implements openlcb::BitEventInterface.
Definition at line 420 of file EventHandlerTemplates.hxx.
|
private |
This function is invoked when the state of the bit changes.
Definition at line 437 of file EventHandlerTemplates.hxx.