libkeepalive
Loading...
Searching...
No Matches
keepalive-heartbeat.h File Reference

Provides wrapper API for libiphb wakeups. More...

#include <stdbool.h>

Go to the source code of this file.

Typedefs

typedef struct heartbeat_t heartbeat_t
 
typedef void(* heartbeat_wakeup_fn) (void *aptr)
 
typedef void(* heartbeat_free_fn) (void *aptr)
 

Functions

heartbeat_theartbeat_new (void)
 
heartbeat_theartbeat_ref (heartbeat_t *self)
 
void heartbeat_unref (heartbeat_t *self)
 
void heartbeat_set_delay (heartbeat_t *self, int delay_lo, int delay_hi)
 
void heartbeat_set_notify (heartbeat_t *self, heartbeat_wakeup_fn notify_cb, void *user_data, heartbeat_free_fn user_free_cb)
 
void heartbeat_start (heartbeat_t *self)
 
void heartbeat_stop (heartbeat_t *self)
 

Detailed Description

Provides wrapper API for libiphb wakeups.

Typedef Documentation

◆ heartbeat_t

typedef struct heartbeat_t heartbeat_t

Opaque heartbeat wakeup object

Allocate via heartbeat_new() and release via heartbeat_unref().

◆ heartbeat_wakeup_fn

typedef void(* heartbeat_wakeup_fn) (void *aptr)

Hearbeat wakeup function type

Parameters
aptruser_data set via heartbeat_set_notify()

◆ heartbeat_free_fn

typedef void(* heartbeat_free_fn) (void *aptr)

User data free function type

Called when heartbeat object is deleted after the final reference is dropped via heartbeat_unref(), or when heartbeat_set_notify() is called while user_data is already set.

Parameters
user_dataset via heartbeat_set_notify()

Function Documentation

◆ heartbeat_new()

heartbeat_t * heartbeat_new ( void )

Create heartbeat wakeup object

Initially has reference count of 1.

Use heartbeat_ref() to increment reference count and heartbeat_unref() to decrement reference count.

Will be automatically released after reference count drops to zero.

Returns
pointer to heartbeat wakeup object, or NULL

◆ heartbeat_ref()

heartbeat_t * heartbeat_ref ( heartbeat_t * self)

Increment reference count of heartbeat wakeup object

Passing NULL object is explicitly allowed and does nothing.

Parameters
selfheartbeat wakeup object pointer
Returns
pointer to heartbeat wakeup object, or NULL in case of errors

◆ heartbeat_unref()

void heartbeat_unref ( heartbeat_t * self)

Decrement reference count of heartbeat wakeup object

Passing NULL object is explicitly allowed and does nothing.

The object will be released if reference count reaches zero.

Parameters
selfheartbeat wakeup object pointer

◆ heartbeat_set_delay()

void heartbeat_set_delay ( heartbeat_t * self,
int delay_lo,
int delay_hi )

Set wakeup delay range

If delay_lo == delay_hi, the value specifies global wakeup slot rather seconds from current time.

If delay_hi < delay_lo, then the upper bound is adjusted so that it is delay_lo + heartbeat interval (=12 seconds, but may vary from one device to another).

Parameters
selfheartbeat wakeup object pointer
delay_lominimum seconds to wakeup
delay_himaximum seconds to wakeup

◆ heartbeat_set_notify()

void heartbeat_set_notify ( heartbeat_t * self,
heartbeat_wakeup_fn notify_cb,
void * user_data,
heartbeat_free_fn user_free_cb )

Set notification callback function to use on hearbeat wakeup

If non-null user_free_cb is given, it is assumed that heartbeat wakeup object owns user_data and it will be released when heartbeat object is deleted or when heartbeat_set_notify() is called again.

Parameters
selfheartbeat wakeup object pointer
notify_cbcallback function pointer, or NULL
user_datadata to pass to callback function
user_free_cbcallback function for releasing user_data

◆ heartbeat_start()

void heartbeat_start ( heartbeat_t * self)

Start waiting for heartbeat wakeup

Parameters
selfheartbeat wakeup object pointer

◆ heartbeat_stop()

void heartbeat_stop ( heartbeat_t * self)

Cancel already scheduled heartbeat wakeup

Parameters
selfheartbeat wakeup object pointer