Hiva::CreateWallTimer

Description

Creates a WallTimer.

Prototype

Hiva::WallTimer Hiva::CreateWallTimer(const Hiva::WallDuration &wallPeriod, const WallTimerCallback &wallCallback, const std::string &wallGroupName, const bool oneshot = false, const bool autostart = true)

Parameters

Parameter

Input/Output

Description

wallPeriod

Input

Period for triggering the callback function. The value is of the standard Duration type for the framework.

wallCallback

Input

Callback function after the timer expires. The type is WallTimerCallback. WallTimerEvent is as follows:

using WallTimerCallback = std::function<void (const WallTimerEvent &)>;

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
struct WallTimerEvent
{
    Hiva::WallTime last_expected;    // Time when the last callback should occur
    Hiva::WallTime last_real;        // Actual time when the last callback occurs
    Hiva::WallTime last_expired;     // Time when the last timer expires on the timer server and a notification is sent to the application
    Hiva::WallTime current_expected; // Time when the current callback should occur
    Hiva::WallTime current_real;     // Actual time when the current callback occurs
    Hiva::WallTime current_expired;  // Time when the current timer expires on the timer server and a notification is sent to the application
    struct{
    Hiva::WallDuration last_duration; // Last callback execution duration
    } profile;
};

wallGroupName

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.

  • true indicates that the one-off oneshot mode is used and the timer is triggered only once.
  • false indicates that the periodic mode is used. The timer is triggered periodically until the process resources are cleared.

autostart

Input

Start flag.

  • true indicates that the timer is automatically started. When the interface returns a value, the timer is started.
  • false indicates that the timer is not automatically started. When the interface returns a value, the timer is not started and needs to be manually started through Hiva::WallTimer::Start.

Returns

The handle of Hiva::WallTimer 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 WallTimer, 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