35#ifndef _OPENLCB_BROADCASTTIMEALARM_HXX_
36#define _OPENLCB_BROADCASTTIMEALARM_HXX_
97 bool need_wakeup =
false;
149 bool need_wakeup =
false;
230 (now <= expires_ && clock_->get_rate_quarters() < 0))
238 long long real_expires = 0;
303 uint8_t shutdown_ : 1;
327 this, std::placeholders::_1))
355 set(seconds + (60 - tm->tm_sec) +
356 (60 * (59 - tm->tm_min)) +
357 (60 * 60 * (23 - tm->tm_hour)));
361 set(seconds - ((tm->tm_sec + 1) +
362 (60 * (tm->tm_min)) +
363 (60 * 60 * tm->tm_hour)));
402 std::placeholders::_1))
441 set(seconds + (60 - tm->tm_sec));
445 set(seconds - (tm->tm_sec + 1));
int bind(int socket, const struct sockaddr *address, socklen_t address_len)
Bind a name to a socket.
#define STATE(_fn)
Turns a function name into an argument to be supplied to functions expecting a state.
See OSMutexLock in os/OS.hxx.
Lightweight locking class for protecting small critical sections.
A BarrierNotifiable allows to create a number of child Notifiable and wait for all of them to finish.
void notify() override
Implementation of the barrier semantics.
BarrierNotifiable * reset(Notifiable *done)
Resets the barrier. Returns &*this. Asserts that is_done().
BarrierNotifiable * new_child()
Call this for each child task.
An object that can be scheduled on an executor to run.
virtual void add(Executable *action, unsigned priority=UINT_MAX)=0
Send a message to this Executor's queue.
ExecutorBase * executor()
Return type for a state flow callback.
Use this timer class to deliver the timeout notification to a stateflow.
Base class for state machines.
Service * service()
Return a pointer to the service I am bound to.
Action exit()
Terminate current StateFlow activity.
void start_flow(Callback c)
Resets the flow to the specified state and starts it.
Action call_immediately(Callback c)
Imediately call the next state upon return.
Action wait_and_call(Callback c)
Wait for resource to become available before proceeding to next state.
Action sleep_and_call(::Timer *timer, long long timeout_nsec, Callback c)
Suspends execution of this control flow for a specified time.
int16_t get_rate_quarters()
Report the clock rate as a 12-bit fixed point number (-512.00 to 511.75).
bool is_running()
Test of the clock is running.
bool real_nsec_until_fast_time_abs(time_t fast_sec, long long *real_nsec)
Convert a fast time to absolute nsec until it will occur.
time_t time()
Get the time as a value of seconds relative to the system epoch.
void ensure_triggered()
Triggers the timer if it is not expired yet.
Specialization of BroadcastTimeAlarm meant to expire at each date rollover.
std::function< void(BarrierNotifiable *)> callbackUser_
callback for when alarm expires
void update_notify() override
Called when the clock time has changed.
~BroadcastTimeAlarmDate()
Destructor.
void reset_expired_time()
Reset the expired time based on what time it is now.
Action entry() override
Entry point of the state machine.
void expired_callback(BarrierNotifiable *done)
callback for when the alarm expires
BroadcastTimeAlarmDate(Node *node, BroadcastTime *clock, std::function< void(BarrierNotifiable *)> callback)
Constructor.
Specialization of BroadcastTimeAlarm meant to expire at each minute.
void update_notify() override
Called when the clock time has changed.
void expired_callback(BarrierNotifiable *done)
callback for when the alarm expires
~BroadcastTimeAlarmMinute()
Destructor.
BroadcastTimeAlarmMinute(Node *node, BroadcastTime *clock, std::function< void(BarrierNotifiable *)> callback)
Constructor.
Action entry() override
Entry point of the state machine.
void reset_expired_time(bool force_on_match=false)
Reset the expired time based on what time it is now.
std::function< void(BarrierNotifiable *)> callbackUser_
callback for when alarm expires
Wakeup(BroadcastTimeAlarm *alarm)
Constructor.
void run() override
Entry point.
BroadcastTimeAlarm * alarm_
our parent alarm we will wakeup
void trigger()
Trigger the wakeup to run.
Basic alarm type that all other alarms are based off of.
void set_period(time_t period)
Start the alarm to expire at the given period from now.
void clear()
Inactivate the alarm.
Wakeup wakeup_
wakeup helper for scheduling alarms
time_t expires_
time at which the alarm expires
~BroadcastTimeAlarm()
Destructor.
void wakeup()
Wakeup the state machine. Must be called from this service's executor.
void set(time_t time)
Start the alarm to expire at the given fast time.
std::function< void(BarrierNotifiable *)> callback_
callback for when alarm expires
BarrierNotifiable bn_
notifiable for callback callee
BroadcastTimeAlarm(Node *node, BroadcastTime *clock, std::function< void(BarrierNotifiable *)> callback)
Constructor.
BroadcastTime * clock_
clock that our alarm is based off of
Action setup()
Setup, or wait to setup alarm.
virtual Action entry()
Entry point to state flow.
uint8_t set_
true if a start request is pending
Action timeout()
Wait for timeout or early trigger.
BarrierNotifiable * bnPtr_
not null we have an outstanding notification
StateFlowTimer timer_
timer helper
virtual void update_notify()
Called by the clock when time, rate, or running state has changed.
BroadcastTime::UpdateSubscribeHandle updateSubscribeHandle_
handle to the update subscrition used for unsubcribing in the destructor
Action expired()
Handle action on timer expiration.
uint8_t running_
true if running (alarm armed), else false
Implementation of Broadcast Time Protocol.
void update_subscribe_remove(UpdateSubscribeHandle handle)
Unregister a callback for when the time synchronization is updated.
size_t UpdateSubscribeHandle
An opaque data element that is returned from update subscriber registration, and allows unregistering...
const struct tm * gmtime_recalculate()
Recalculate the struct tm representation of time.
Base class for NMRAnet nodes conforming to the asynchronous interface.
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Removes default copy-constructor and assignment added by C++.