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

Basic alarm type that all other alarms are based off of. More...

#include <BroadcastTimeAlarm.hxx>

Inheritance diagram for openlcb::BroadcastTimeAlarm:
StateFlowBase Atomic Executable Notifiable QMember Destructable openlcb::BroadcastTimeAlarmDate openlcb::BroadcastTimeAlarmMinute openlcb::BroadcastTimeServerAlarm

Classes

class  Wakeup
 

Public Member Functions

 BroadcastTimeAlarm (Node *node, BroadcastTime *clock, std::function< void(BarrierNotifiable *)> callback)
 Constructor.
 
 ~BroadcastTimeAlarm ()
 Destructor.
 
void set_period (time_t period)
 Start the alarm to expire at the given period from now.
 
void set (time_t time)
 Start the alarm to expire at the given fast time.
 
void clear ()
 Inactivate the alarm.
 
- 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.
 

Protected Member Functions

virtual Action entry ()
 Entry point to state flow.
 
virtual void update_notify ()
 Called by the clock when time, rate, or running state has changed.
 
- 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 Member Functions inherited from Atomic
void lock ()
 
void unlock ()
 

Protected Attributes

BroadcastTimeclock_
 clock that our alarm is based off of
 
- Protected Attributes inherited from QMember
QMembernext
 pointer to the next member in the queue
 

Private Member Functions

Action setup ()
 Setup, or wait to setup alarm.
 
Action timeout ()
 Wait for timeout or early trigger.
 
Action expired ()
 Handle action on timer expiration.
 
void wakeup ()
 Wakeup the state machine. Must be called from this service's executor.
 
 DISALLOW_COPY_AND_ASSIGN (BroadcastTimeAlarm)
 

Private Attributes

Wakeup wakeup_
 wakeup helper for scheduling alarms
 
std::function< void(BarrierNotifiable *)> callback_
 callback for when alarm expires
 
StateFlowTimer timer_
 timer helper
 
BarrierNotifiable bn_
 notifiable for callback callee
 
BarrierNotifiablebnPtr_
 not null we have an outstanding notification
 
time_t expires_
 time at which the alarm expires
 
uint8_t running_: 1
 true if running (alarm armed), else false
 
uint8_t set_: 1
 true if a start request is pending
 
BroadcastTime::UpdateSubscribeHandle updateSubscribeHandle_
 handle to the update subscrition used for unsubcribing in the destructor
 

Friends

class BroadcastTimeAlarm::Wakeup
 make our wakeup agent a friend
 

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.
 
- Protected Types inherited from StateFlowBase
typedef Action(StateFlowBase::* Callback) ()
 State Flow callback prototype.
 

Detailed Description

Basic alarm type that all other alarms are based off of.

Definition at line 44 of file BroadcastTimeAlarm.hxx.

Constructor & Destructor Documentation

◆ BroadcastTimeAlarm()

openlcb::BroadcastTimeAlarm::BroadcastTimeAlarm ( Node node,
BroadcastTime clock,
std::function< void(BarrierNotifiable *)>  callback 
)
inline

Constructor.

Parameters
nodethe virtual node that our StateFlowBase service will be derived from
clockclock that our alarm is based off of
callbackcallback for when alarm expires

Definition at line 52 of file BroadcastTimeAlarm.hxx.

◆ ~BroadcastTimeAlarm()

openlcb::BroadcastTimeAlarm::~BroadcastTimeAlarm ( )
inline

Destructor.

Definition at line 78 of file BroadcastTimeAlarm.hxx.

Member Function Documentation

◆ clear()

void openlcb::BroadcastTimeAlarm::clear ( )
inline

Inactivate the alarm.

Definition at line 115 of file BroadcastTimeAlarm.hxx.

◆ entry()

virtual Action openlcb::BroadcastTimeAlarm::entry ( )
inlineprotectedvirtual

Entry point to state flow.

Returns
next state setup()

Reimplemented in openlcb::BroadcastTimeAlarmDate, openlcb::BroadcastTimeAlarmMinute, and openlcb::BroadcastTimeServerAlarm.

Definition at line 141 of file BroadcastTimeAlarm.hxx.

◆ expired()

Action openlcb::BroadcastTimeAlarm::expired ( )
inlineprivate

Handle action on timer expiration.

Returns
setup()

Definition at line 270 of file BroadcastTimeAlarm.hxx.

◆ set()

void openlcb::BroadcastTimeAlarm::set ( time_t  time)
inline

Start the alarm to expire at the given fast time.

Parameters
timein seconds since epoch to expire

Definition at line 95 of file BroadcastTimeAlarm.hxx.

◆ set_period()

void openlcb::BroadcastTimeAlarm::set_period ( time_t  period)
inline

Start the alarm to expire at the given period from now.

Parameters
periodin fast seconds from now to expire. period is a a signed value. If the fast time rate is negative, the period passed in should also be negative for an expiration in the future.

Definition at line 88 of file BroadcastTimeAlarm.hxx.

◆ setup()

Action openlcb::BroadcastTimeAlarm::setup ( )
inlineprivate

Setup, or wait to setup alarm.

Returns
expired() if alarm is set and already expired, timeout() if alarm will expire in the future, setup() if clock and/or alarm is not currently active

Definition at line 214 of file BroadcastTimeAlarm.hxx.

◆ timeout()

Action openlcb::BroadcastTimeAlarm::timeout ( )
inlineprivate

Wait for timeout or early trigger.

Returns
setup() if the timer is triggered prematurely, else expired() if the timer has expired

Definition at line 254 of file BroadcastTimeAlarm.hxx.

◆ update_notify()

virtual void openlcb::BroadcastTimeAlarm::update_notify ( )
inlineprotectedvirtual

Called by the clock when time, rate, or running state has changed.

Reimplemented in openlcb::BroadcastTimeAlarmDate, openlcb::BroadcastTimeAlarmMinute, and openlcb::BroadcastTimeServerAlarm.

Definition at line 147 of file BroadcastTimeAlarm.hxx.

◆ wakeup()

void openlcb::BroadcastTimeAlarm::wakeup ( )
inlineprivate

Wakeup the state machine. Must be called from this service's executor.

Definition at line 283 of file BroadcastTimeAlarm.hxx.

Friends And Related Symbol Documentation

◆ BroadcastTimeAlarm::Wakeup

friend class BroadcastTimeAlarm::Wakeup
friend

make our wakeup agent a friend

Definition at line 309 of file BroadcastTimeAlarm.hxx.

Member Data Documentation

◆ bn_

BarrierNotifiable openlcb::BroadcastTimeAlarm::bn_
private

notifiable for callback callee

Definition at line 297 of file BroadcastTimeAlarm.hxx.

◆ bnPtr_

BarrierNotifiable* openlcb::BroadcastTimeAlarm::bnPtr_
private

not null we have an outstanding notification

Definition at line 298 of file BroadcastTimeAlarm.hxx.

◆ callback_

std::function<void(BarrierNotifiable *)> openlcb::BroadcastTimeAlarm::callback_
private

callback for when alarm expires

Definition at line 295 of file BroadcastTimeAlarm.hxx.

◆ clock_

BroadcastTime* openlcb::BroadcastTimeAlarm::clock_
protected

clock that our alarm is based off of

Definition at line 164 of file BroadcastTimeAlarm.hxx.

◆ expires_

time_t openlcb::BroadcastTimeAlarm::expires_
private

time at which the alarm expires

Definition at line 299 of file BroadcastTimeAlarm.hxx.

◆ running_

uint8_t openlcb::BroadcastTimeAlarm::running_
private

true if running (alarm armed), else false

Definition at line 300 of file BroadcastTimeAlarm.hxx.

◆ set_

uint8_t openlcb::BroadcastTimeAlarm::set_
private

true if a start request is pending

Definition at line 301 of file BroadcastTimeAlarm.hxx.

◆ timer_

StateFlowTimer openlcb::BroadcastTimeAlarm::timer_
private

timer helper

Definition at line 296 of file BroadcastTimeAlarm.hxx.

◆ updateSubscribeHandle_

BroadcastTime::UpdateSubscribeHandle openlcb::BroadcastTimeAlarm::updateSubscribeHandle_
private

handle to the update subscrition used for unsubcribing in the destructor

Definition at line 306 of file BroadcastTimeAlarm.hxx.

◆ wakeup_

Wakeup openlcb::BroadcastTimeAlarm::wakeup_
private

wakeup helper for scheduling alarms

Definition at line 293 of file BroadcastTimeAlarm.hxx.


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