Class TimedEvent#

Inheritance Relationships#

Base Type#

Class Documentation#

class TimedEvent : public Karana::Core::Base#

This class is used to execute events at a given time. The initial time and function to execute are constructor arguments. The callback function itself can be get/set afterwards as well using the f member variable. The period and reschedule_fn are member variables that are used for re-curring callbacks. If the period is non-zero, then the TimedEvent will be rescheduled using that period. If the period is 0, and the reschedule_fn is set, then the result of the reschedule_fn will be used to determine the next reschedule time. If the period is 0 and the reschedule_fn is not set, then the callback will not be rescheduled.

Public Functions

TimedEvent(std::string_view name, const km::Ktime &t, f fn, bool before_hop)#

Constructor for TimedEvent.

Parameters:
  • name – The event’s name.

  • t – The time to execute the TimedEvent at.

  • fn – The function to execute.

  • before_hop – This determines whether the timed event runs before or after the hop.

TimedEvent(const TimedEvent&)#

Copy constructor.

TimedEvent(TimedEvent&&) noexcept#

Move constructor.

virtual std::string dumpString(const std::string &prefix = "", const dumpOptions *options = nullptr) const override#

Dump the TimedEvent information to a string.

Returns:

A string with the dump info for this TimedEvent.

void dump(const std::string &prefix = "", const dumpOptions *options = nullptr) const#

Print the TimedEvent info to stdout.

bool reschedule()#

Reschedules the callback if appropriate. This will update the internal time with the new time if it should be rescheduled.

Returns:

true if the TimedEvent is rescheduled and false otherwise.

bool operator>(const TimedEvent &other) const#

Comparison operator. Used mainly to order TimedEvents on a heap.

First time is used to compare. If this is the same, then priority is used. If this is also the same, then the id is used.

Parameters:

other – - The TimedEvent to compare this one against.

Returns:

comparison status

bool isBeforeHop() const#

Returns whether the TimedEvent is a before hop timed event or not.

Returns:

true if the TimedEvent is a before hop timed event. false otherwise.

const km::Ktime &nextEventTime() const#

Get the next time this TimedEvent will execute its event function at.

Returns:

The next time this TimedEvent will execute its event function at.

Public Members

f fn#

The callback function that runs when this timed event is called.

int priority = 0#

The priority for this callback. This differentiates callbacks that are running at the same time. Lower is a higher priority.

km::Ktime period = {0}#

The period to reschedule this callback at. If 0, then the reschedule_fn will be used.

std::function<std::optional<km::Ktime>(const km::Ktime&)> reschedule_fn#

The reschedule_fn is used if and only if the period is 0. If the period is 0 and the reschedule_fn is not defined, then this timed event will not be rescheduled. If the reschedule_fn returns std::nullopt, then this will not be rescheduled.

Public Static Functions

static kc::ks_ptr<TimedEvent> create(std::string_view name, const km::Ktime &t, f fn, bool before_hop)#

Constructor for TimedEvent.

Parameters:
  • name – The event’s name.

  • t – The time to execute the TimedEvent at.

  • fn – The function to execute.

  • before_hop – This determines whether the timed event runs before or after the hop.

Returns:

the TimedEvent instance