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

A network-initialized bit is a tri-state bit implementation that starts up in the UNKNOWN state until either a local state set or a remote state set occurs. More...

#include <EventHandlerTemplates.hxx>

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

Public Member Functions

 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.
 

Protected Attributes

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

A network-initialized bit is a tri-state bit implementation that starts up in the UNKNOWN state until either a local state set or a remote state set occurs.

After that transient passes the state will always be definite. The network state set typically comes from query responses or other nodes setting the state. The owner of this bit will typically want to actively send out a query upon boot or network reconnect.

Definition at line 308 of file EventHandlerTemplates.hxx.

Constructor & Destructor Documentation

◆ NetworkInitializedBit()

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

Constructs a NetworkInitializedBit.

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 318 of file EventHandlerTemplates.hxx.

Member Function Documentation

◆ get_current_state()

EventState openlcb::NetworkInitializedBit::get_current_state ( )
inlineoverridevirtual

Accessor from the network stack to return the current state.

Returns
tri-stated value

Implements openlcb::BitEventInterface.

Definition at line 336 of file EventHandlerTemplates.hxx.

◆ get_local_state()

bool openlcb::NetworkInitializedBit::get_local_state ( )
inline
Returns
the local state, which defaults to default_local_state if the network state is unknown.

Definition at line 345 of file EventHandlerTemplates.hxx.

◆ is_network_state_known()

bool openlcb::NetworkInitializedBit::is_network_state_known ( )
inline
Returns
true if the network state is known; i.e. when we are sure that the network state matches the local state.

Definition at line 351 of file EventHandlerTemplates.hxx.

◆ node()

Node * openlcb::NetworkInitializedBit::node ( )
inlineoverridevirtual

Get a reference to the owning Node.

Returns
Node reference

Implements openlcb::BitEventInterface.

Definition at line 329 of file EventHandlerTemplates.hxx.

◆ set_state()

void openlcb::NetworkInitializedBit::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.

Parameters
newstate value

NOTE: this does not send any messages. The caller must use the EventHandler object after this function to send out an event.

Implements openlcb::BitEventInterface.

Definition at line 361 of file EventHandlerTemplates.hxx.

◆ toggle_state()

void openlcb::NetworkInitializedBit::toggle_state ( )
inline

Invert the current state.

This also works when the network state is not yet known: in that case it sets the state to the opposite of the default state.

NOTE: this does not send any messages. The caller must use the EventHandler object after this function to send out an event.

Definition at line 373 of file EventHandlerTemplates.hxx.

Member Data Documentation

◆ isKnown_

uint8_t openlcb::NetworkInitializedBit::isKnown_
protected

true when we knowthe network state

Definition at line 381 of file EventHandlerTemplates.hxx.

◆ localState_

uint8_t openlcb::NetworkInitializedBit::localState_
protected

local state; either matches the network state or is the constructor-default local state.

Definition at line 384 of file EventHandlerTemplates.hxx.

◆ node_

Node* openlcb::NetworkInitializedBit::node_
protected

Definition at line 379 of file EventHandlerTemplates.hxx.


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