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

Implementation of the ConfigUpdateService: state flow issuing all the calls to the registered ConfigUpdateListener descendants. More...

#include <ConfigUpdateFlow.hxx>

Inheritance diagram for openlcb::ConfigUpdateFlow:
StateFlowBase ConfigUpdateService Atomic Executable Singleton< ConfigUpdateService > Notifiable QMember Destructable

Public Member Functions

 ConfigUpdateFlow (If *iface)
 
int open_file (const char *path)
 Must be called once (only) before calling anything else.
 
void init_flow ()
 Asynchronously invokes all update listeners with the config FD.
 
void factory_reset ()
 Synchronously invokes all update listeners to factory reset.
 
int get_fd ()
 
void trigger_update () override
 Executes an update in response to the configuration having changed.
 
void register_update_listener (ConfigUpdateListener *listener) override
 Adds a config update listener to be called upon configuration updates.
 
void unregister_update_listener (ConfigUpdateListener *listener) override
 Removes a config update listener.
 
- Public Member Functions inherited from StateFlowBase
void run () override
 Callback from the executor.
 
void notify () override
 Wakeup call arrived.
 
Serviceservice ()
 Return a pointer to the service I am bound to.
 
- Public Member Functions inherited from Executable
void test_deletion ()
 
- Public Member Functions inherited from QMember
void init ()
 Initiailize a QMember, in place of a public placement construction.
 

Private Types

typedef TypedQueue< ConfigUpdateListenerqueue_type
 

Private Member Functions

Action call_next_listener ()
 
Action call_listener (ConfigUpdateListener *l, bool is_initial)
 
Action do_initial_load ()
 
Action apply_action ()
 
- Private Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Private Attributes

queue_type listeners_
 All registered update listeners. Protected by Atomic *this.
 
queue_type pendingListeners_
 All listeners that have not yet been added to listeners_ and their initial load needs to be called.
 
queue_type::iterator nextRefresh_
 Where are we in the refresh cycle.
 
unsigned needsReboot_: 1
 did anybody request a reboot to happen?
 
unsigned needsReInit_: 1
 did anybody request a node reinit to happen?
 
int fd_
 
BarrierNotifiable n_
 

Additional Inherited Members

- Static Public Member Functions inherited from StateFlowBase
template<class T , typename... Args>
static void invoke_subflow_and_ignore_result (FlowInterface< Buffer< T > > *target_flow, Args &&... args)
 Calls a helper flow to perform some actions.
 
- Static Public Member Functions inherited from Singleton< ConfigUpdateService >
static ConfigUpdateServiceinstance ()
 
static bool exists ()
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 
- Protected Member Functions inherited from StateFlowBase
 StateFlowBase (Service *service)
 Constructor.
 
 ~StateFlowBase ()
 Destructor.
 
void reset_flow (Callback c)
 Resets the flow to the specified state.
 
bool is_state (Callback c)
 
bool is_terminated ()
 
void start_flow (Callback c)
 Resets the flow to the specified state and starts it.
 
Action again ()
 Call the current state again via call_immediately.
 
Action exit ()
 Terminate current StateFlow activity.
 
Action delete_this ()
 Terminates the flow and deletes *this.
 
Action set_terminated ()
 Sets the flow to terminated state.
 
Action call_immediately (Callback c)
 Imediately call the next state upon return.
 
Action wait ()
 Wait for an asynchronous call.
 
Action wait_and_call (Callback c)
 Wait for resource to become available before proceeding to next state.
 
template<class T >
Action allocate_and_call (FlowInterface< Buffer< T > > *target_flow, Callback c, Pool *pool=nullptr)
 Allocates a buffer from a pool and proceed to the next state when allocation is successful.
 
Action allocate_and_call (Callback c, QAsync *queue)
 Allocates an entry from an asynchronous queue, and transitions to a state once the allocation is complete.
 
template<class T >
Buffer< T > * full_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
T * full_allocation_result (TypedQAsync< T > *queue)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
void cast_allocation_result (T **member)
 Takes the result of the asynchronous allocation without resetting the object.
 
template<class T >
Buffer< T > * get_allocation_result (FlowInterface< Buffer< T > > *target_flow)
 Takes the result of the asynchronous allocation.
 
Action yield_and_call (Callback c)
 Place the current flow to the back of the executor, and transition to a new state after we get the CPU again.
 
Action yield ()
 Place the current flow to the back of the executor, and re-try the current state after we get the CPU again.
 
Action sleep_and_call (::Timer *timer, long long timeout_nsec, Callback c)
 Suspends execution of this control flow for a specified time.
 
template<class T , typename... Args>
Action invoke_subflow_and_wait (FlowInterface< Buffer< T > > *target_flow, Callback c, Args &&... args)
 Calls a helper flow to perform some actions.
 
Action read_repeated (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read and then invokes the next state.
 
Action read_single (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size_t bytes, and blocks the caller until at least one byte is read.
 
Action read_nonblocking (StateFlowSelectHelper *helper, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Attempts to read at most size bytes, and then invokes the next state, even if only zero bytes are available right now.
 
Action read_repeated_with_timeout (StateFlowTimedSelectHelper *helper, long long timeout_nsec, int fd, void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Blocks until size bytes are read, or a timeout expires.
 
Action internal_try_read ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on reading.
 
Action write_repeated (StateFlowSelectHelper *helper, int fd, const void *buf, size_t size, Callback c, unsigned priority=Selectable::MAX_PRIO)
 Writes some data into a file descriptor, repeating the operation as necessary until all bytes are written.
 
Action internal_try_write ()
 Implementation state that gets repeatedly called upon every wakeup and tries to make progress on writing.
 
- Protected Member Functions inherited from QMember
 QMember ()
 Constructor.
 
 ~QMember ()
 Destructor.
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Detailed Description

Implementation of the ConfigUpdateService: state flow issuing all the calls to the registered ConfigUpdateListener descendants.

This flow also handles any necessary action such as reboot or factory reset. This flow keeps the file descriptor for the config file that's currently open.

Definition at line 60 of file ConfigUpdateFlow.hxx.

Member Typedef Documentation

◆ queue_type

Constructor & Destructor Documentation

◆ ConfigUpdateFlow()

openlcb::ConfigUpdateFlow::ConfigUpdateFlow ( If iface)
inline

Definition at line 65 of file ConfigUpdateFlow.hxx.

Member Function Documentation

◆ apply_action()

Action openlcb::ConfigUpdateFlow::apply_action ( )
inlineprivate

TODO(balazs.racz) apply the changes reported.

Definition at line 185 of file ConfigUpdateFlow.hxx.

◆ call_listener()

Action openlcb::ConfigUpdateFlow::call_listener ( ConfigUpdateListener l,
bool  is_initial 
)
inlineprivate

Definition at line 138 of file ConfigUpdateFlow.hxx.

◆ call_next_listener()

Action openlcb::ConfigUpdateFlow::call_next_listener ( )
inlineprivate

Definition at line 123 of file ConfigUpdateFlow.hxx.

◆ do_initial_load()

Action openlcb::ConfigUpdateFlow::do_initial_load ( )
inlineprivate

Definition at line 167 of file ConfigUpdateFlow.hxx.

◆ factory_reset()

void openlcb::ConfigUpdateFlow::factory_reset ( )

Synchronously invokes all update listeners to factory reset.

Definition at line 57 of file ConfigUpdateFlow.cxx.

◆ get_fd()

int openlcb::ConfigUpdateFlow::get_fd ( )
inline
Returns
the file descriptor of the configuration file, or -1 if the configuration file has not yet been opened.

Definition at line 84 of file ConfigUpdateFlow.hxx.

◆ init_flow()

void openlcb::ConfigUpdateFlow::init_flow ( )

Asynchronously invokes all update listeners with the config FD.

Definition at line 52 of file ConfigUpdateFlow.cxx.

◆ open_file()

int openlcb::ConfigUpdateFlow::open_file ( const char *  path)

Must be called once (only) before calling anything else.

Returns the file descriptor.

Definition at line 43 of file ConfigUpdateFlow.cxx.

◆ register_update_listener()

void openlcb::ConfigUpdateFlow::register_update_listener ( ConfigUpdateListener listener)
overridevirtual

Adds a config update listener to be called upon configuration updates.

Should be called before the startup of the stack in order to ensure that the initial load will be successful.

Parameters
listenerpointer to the implementation that needs to listen to config updates.

Implements ConfigUpdateService.

Definition at line 69 of file ConfigUpdateFlow.cxx.

◆ trigger_update()

void openlcb::ConfigUpdateFlow::trigger_update ( )
inlineoverridevirtual

Executes an update in response to the configuration having changed.

Implements ConfigUpdateService.

Definition at line 108 of file ConfigUpdateFlow.hxx.

◆ unregister_update_listener()

void openlcb::ConfigUpdateFlow::unregister_update_listener ( ConfigUpdateListener listener)
overridevirtual

Removes a config update listener.

Requires: the listener has been inserted before using register_update_listener.

Parameters
listenerpointer to the implementation that needs to be removed.

Implements ConfigUpdateService.

Definition at line 79 of file ConfigUpdateFlow.cxx.

Member Data Documentation

◆ fd_

int openlcb::ConfigUpdateFlow::fd_
private

Definition at line 214 of file ConfigUpdateFlow.hxx.

◆ listeners_

queue_type openlcb::ConfigUpdateFlow::listeners_
private

All registered update listeners. Protected by Atomic *this.

Definition at line 204 of file ConfigUpdateFlow.hxx.

◆ n_

BarrierNotifiable openlcb::ConfigUpdateFlow::n_
private

Definition at line 215 of file ConfigUpdateFlow.hxx.

◆ needsReboot_

unsigned openlcb::ConfigUpdateFlow::needsReboot_
private

did anybody request a reboot to happen?

Definition at line 211 of file ConfigUpdateFlow.hxx.

◆ needsReInit_

unsigned openlcb::ConfigUpdateFlow::needsReInit_
private

did anybody request a node reinit to happen?

Definition at line 213 of file ConfigUpdateFlow.hxx.

◆ nextRefresh_

queue_type::iterator openlcb::ConfigUpdateFlow::nextRefresh_
private

Where are we in the refresh cycle.

Definition at line 209 of file ConfigUpdateFlow.hxx.

◆ pendingListeners_

queue_type openlcb::ConfigUpdateFlow::pendingListeners_
private

All listeners that have not yet been added to listeners_ and their initial load needs to be called.

Definition at line 207 of file ConfigUpdateFlow.hxx.


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