Hiva::CreateSteadyTimer
Description
Creates a SteadyTimer.
Prototype
Hiva::SteadyTimer Hiva::CreateSteadyTimer(const Hiva::WallDuration &steadyPeriod, const SteadyTimerCallback &steadyCallback, const std::string &steadyGroupName, const bool oneshot = false, const bool autostart = true)
Parameters
Parameter |
Input/Output |
Description |
||
|---|---|---|---|---|
steadyPeriod |
Input |
Period for triggering the callback function. The value is of the standard Duration type for the framework. |
||
steadyCallback |
Input |
Callback function after the timer expires. The parameter type is SteadyTimerCallback. WallTimerEvent is as follows: using SteadyTimerCallback = std::function<void (const SteadyTimerEvent &)>;
|
||
steadyGroupName |
Input |
Thread group created when OpenHiva::Init is invoked. For a deterministic group, the deterministic scheduling framework is used. For other groups, the OS scheduling framework is used. |
||
oneshot |
Input |
Mode flag.
|
||
autostart |
Input |
Start flag.
|
Returns
The handle of Hiva::SteadyTimer is returned. The start and stop operations can be performed based on this handle.
Usage
A process invokes this interface to create and run a timer.
- When creating a SteadyTimer, an application subscribes to a timer event. The timer name is generated in the format of application name + timer + sequence number to ensure uniqueness.
- The application sends the timer name and related information to the timer server through the topic communication mode of the server/client. After the time expires, the timer server publishes the topic, notifies the original application, and executes the user callback function.
Precautions
None