Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
openlcb::CallbackNetworkInitializedBit Class Reference

Speciallization of NetworkInitializedBit that adds callback support when the state changes. More...

#include <EventHandlerTemplates.hxx>

Inheritance diagram for openlcb::CallbackNetworkInitializedBit:
openlcb::NetworkInitializedBit openlcb::BitEventInterface

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.
 
Nodenode () 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
Nodenode_
 
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.
 

Detailed Description

Speciallization of NetworkInitializedBit that adds callback support when the state changes.

Definition at line 389 of file EventHandlerTemplates.hxx.

Constructor & Destructor Documentation

◆ CallbackNetworkInitializedBit()

openlcb::CallbackNetworkInitializedBit::CallbackNetworkInitializedBit ( openlcb::Node node,
uint64_t  event_on,
uint64_t  event_off,
bool  default_local_state 
)
inline

Constructor.

Parameters
nodethe virtual node who exposes this bit.
event_onevent ID to set the state to true
event_offevent ID to set the state to false
default_local_stateUntil 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.

Member Function Documentation

◆ reset()

void openlcb::CallbackNetworkInitializedBit::reset ( )
inline

Call this function in order to reset the network state to unknown.

Definition at line 430 of file EventHandlerTemplates.hxx.

◆ set_change_callback()

void openlcb::CallbackNetworkInitializedBit::set_change_callback ( std::function< void()>  cb)
inline

Specifies the change notifier.

Parameters
cbwill 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.

◆ set_state()

void openlcb::CallbackNetworkInitializedBit::set_state ( bool  new_value)
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.

Parameters
newstate value

Implements openlcb::BitEventInterface.

Definition at line 420 of file EventHandlerTemplates.hxx.

Member Data Documentation

◆ callback_

std::function<void()> openlcb::CallbackNetworkInitializedBit::callback_
private

This function is invoked when the state of the bit changes.

Definition at line 437 of file EventHandlerTemplates.hxx.


The documentation for this class was generated from the following file: