Concord - C Discord API library
A Discord API wrapper library written in C

Callback scheduling API. More...

Collaboration diagram for Timer API:

Data Structures

struct  discord_timers
 

Functions

void discord_timers_init (struct discord_timers *timers, struct io_poller *io)
 Prepare timers for usage. More...
 
void discord_timers_cleanup (struct discord *client, struct discord_timers *timers)
 Cleanup timers and call cancel any running ones. More...
 
int64_t discord_timers_get_next_trigger (struct discord_timers *const timers[], size_t n, int64_t now, int64_t max_time)
 Get earliest trigger time from a group of timers. More...
 
void discord_timers_run (struct discord *client, struct discord_timers *timers)
 Run all timers that are due. More...
 
unsigned _discord_timer_ctl (struct discord *client, struct discord_timers *timers, struct discord_timer *timer)
 Modifies or creates a timer. More...
 
unsigned discord_internal_timer_ctl (struct discord *client, struct discord_timer *timer)
 Modifies or creates a timer. More...
 
unsigned discord_internal_timer (struct discord *client, discord_ev_timer on_tick_cb, discord_ev_timer on_status_changed_cb, void *data, int64_t delay)
 Creates a one shot timer that automatically deletes itself upon completion. More...
 

Detailed Description

Callback scheduling API.

Function Documentation

◆ discord_timers_init()

void discord_timers_init ( struct discord_timers timers,
struct io_poller *  io 
)

Prepare timers for usage.

Parameters
timersthe 'struct discord_timers' to init

◆ discord_timers_cleanup()

void discord_timers_cleanup ( struct discord client,
struct discord_timers timers 
)

Cleanup timers and call cancel any running ones.

Parameters
clientthe client created with discord_init()
timersthe 'struct discord_timers' to cleanup

◆ discord_timers_get_next_trigger()

int64_t discord_timers_get_next_trigger ( struct discord_timers *const  timers[],
size_t  n,
int64_t  now,
int64_t  max_time 
)

Get earliest trigger time from a group of timers.

Parameters
timersarray of timers
nnumber of timers in array
nowcurrent time
max_timemax time to allowed
Returns
time in microseconds until next timer, or max

◆ discord_timers_run()

void discord_timers_run ( struct discord client,
struct discord_timers timers 
)

Run all timers that are due.

Parameters
clientthe client created with discord_init()
timersthe timers to run

◆ _discord_timer_ctl()

unsigned _discord_timer_ctl ( struct discord client,
struct discord_timers timers,
struct discord_timer timer 
)

Modifies or creates a timer.

Parameters
clientthe client created with discord_init()
timersthe timer group to perform this operation on
timerthe timer that should be modified
Returns
the id of the timer

◆ discord_internal_timer_ctl()

unsigned discord_internal_timer_ctl ( struct discord client,
struct discord_timer timer 
)

Modifies or creates a timer.

Parameters
clientthe client created with discord_init()
timerthe timer that should be modified
Returns
the id of the timer

◆ discord_internal_timer()

unsigned discord_internal_timer ( struct discord client,
discord_ev_timer  on_tick_cb,
discord_ev_timer  on_status_changed_cb,
void *  data,
int64_t  delay 
)

Creates a one shot timer that automatically deletes itself upon completion.

Parameters
clientthe client created with discord_init()
on_tick_cb(nullable) the callback that should be called when timer triggers
on_status_changed_cb(nullable) the callback for status updates timer->flags will have: DISCORD_TIMER_CANCELED, and DISCORD_TIMER_DELETE
datauser data
delaydelay before timer should start in milliseconds
Returns
the id of the timer