|
Open Model Railroad Network (OpenMRN)
|
Implementation of the ConfigUpdateService: state flow issuing all the calls to the registered ConfigUpdateListener descendants. More...
#include <ConfigUpdateFlow.hxx>
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. | |
| Service * | service () |
| 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< ConfigUpdateListener > | queue_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 ConfigUpdateService * | instance () |
| 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 | |
| QMember * | next |
| pointer to the next member in the queue | |
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.
|
private |
Definition at line 202 of file ConfigUpdateFlow.hxx.
|
inline |
Definition at line 65 of file ConfigUpdateFlow.hxx.
|
inlineprivate |
TODO(balazs.racz) apply the changes reported.
Definition at line 185 of file ConfigUpdateFlow.hxx.
|
inlineprivate |
Definition at line 138 of file ConfigUpdateFlow.hxx.
|
inlineprivate |
Definition at line 123 of file ConfigUpdateFlow.hxx.
|
inlineprivate |
Definition at line 167 of file ConfigUpdateFlow.hxx.
| void openlcb::ConfigUpdateFlow::factory_reset | ( | ) |
Synchronously invokes all update listeners to factory reset.
Definition at line 57 of file ConfigUpdateFlow.cxx.
|
inline |
Definition at line 84 of file ConfigUpdateFlow.hxx.
| void openlcb::ConfigUpdateFlow::init_flow | ( | ) |
Asynchronously invokes all update listeners with the config FD.
Definition at line 52 of file ConfigUpdateFlow.cxx.
| 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.
|
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.
| listener | pointer to the implementation that needs to listen to config updates. |
Implements ConfigUpdateService.
Definition at line 69 of file ConfigUpdateFlow.cxx.
|
inlineoverridevirtual |
Executes an update in response to the configuration having changed.
Implements ConfigUpdateService.
Definition at line 108 of file ConfigUpdateFlow.hxx.
|
overridevirtual |
Removes a config update listener.
Requires: the listener has been inserted before using register_update_listener.
| listener | pointer to the implementation that needs to be removed. |
Implements ConfigUpdateService.
Definition at line 79 of file ConfigUpdateFlow.cxx.
|
private |
Definition at line 214 of file ConfigUpdateFlow.hxx.
|
private |
All registered update listeners. Protected by Atomic *this.
Definition at line 204 of file ConfigUpdateFlow.hxx.
|
private |
Definition at line 215 of file ConfigUpdateFlow.hxx.
|
private |
did anybody request a reboot to happen?
Definition at line 211 of file ConfigUpdateFlow.hxx.
|
private |
did anybody request a node reinit to happen?
Definition at line 213 of file ConfigUpdateFlow.hxx.
|
private |
Where are we in the refresh cycle.
Definition at line 209 of file ConfigUpdateFlow.hxx.
|
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.