Class TimedEvent#
Defined in File TimedEvent.h
Inheritance Relationships#
Base Type#
public Karana::Core::Base(Class Base)
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
fmember variable. Theperiodandreschedule_fnare member variables that are used for recurring callbacks. If theperiodis non-zero, then theTimedEventwill be rescheduled using that period. If the period is 0, and thereschedule_fnis set, then the result of thereschedule_fnwill be used to determine the next reschedule time. If theperiodis 0 and thereschedule_fnis not set, then the callback will not be rescheduled.Public Functions
-
TimedEvent(std::string_view name, const km::Ktime &t, f fn, bool pre_hop)#
TimedEvent constructor. The constructor is not meant to be called directly. Please use the create(…) method instead to create an instance.
- Parameters:
name – The event’s name.
t – The time to execute the TimedEvent at.
fn – The function to execute.
pre_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(std::string_view prefix = "", const DumpOptions *options = nullptr) const override#
Dump the TimedEvent information to a string.
- Returns:
A string with the dump info for this TimedEvent.
-
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
TimedEventis 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 isPreHop() const#
Returns whether the TimedEvent is a pre-hop timed event or not.
- Returns:
trueif the TimedEvent is a pre-hop timed event.falseotherwise.
-
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
-
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 pre_hop)#
Constructor for TimedEvent.
- Parameters:
name – The event’s name.
t – The time to execute the TimedEvent at.
fn – The function to execute.
pre_hop – This determines whether the timed event runs before or after the hop.
- Returns:
the TimedEvent instance
-
TimedEvent(std::string_view name, const km::Ktime &t, f fn, bool pre_hop)#