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

Schedule callbacks to be called in the future. More...

Collaboration diagram for Timer:

Data Structures

struct  discord_timer
 struct used for modifying, and getting info about a timer More...
 

Typedefs

typedef void(* discord_ev_timer) (struct discord *client, struct discord_timer *ev)
 callback to be used with struct discord_timer More...
 

Enumerations

enum  discord_timer_flags {
  DISCORD_TIMER_MILLISECONDS = 0 , DISCORD_TIMER_MICROSECONDS = 1 << 0 , DISCORD_TIMER_DELETE = 1 << 1 , DISCORD_TIMER_DELETE_AUTO = 1 << 2 ,
  DISCORD_TIMER_CANCELED = 1 << 3 , DISCORD_TIMER_TICK = 1 << 4 , DISCORD_TIMER_GET = 1 << 5 , DISCORD_TIMER_INTERVAL_FIXED = 1 << 6
}
 flags used to change behaviour of timer More...
 

Functions

unsigned discord_timer_ctl (struct discord *client, struct discord_timer *timer)
 modifies or creates a timer More...
 
unsigned discord_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...
 
unsigned discord_timer_interval (struct discord *client, discord_ev_timer on_tick_cb, discord_ev_timer on_status_changed_cb, void *data, int64_t delay, int64_t interval, int64_t repeat)
 creates a repeating timer that automatically deletes itself upon completion More...
 
bool discord_timer_get (struct discord *client, unsigned id, struct discord_timer *timer)
 get the data associated with the timer More...
 
bool discord_timer_start (struct discord *client, unsigned id)
 starts a timer More...
 
bool discord_timer_stop (struct discord *client, unsigned id)
 stops a timer More...
 
bool discord_timer_cancel (struct discord *client, unsigned id)
 cancels a timer, this will delete the timer if DISCORD_TIMER_DELETE_AUTO is enabled More...
 
bool discord_timer_delete (struct discord *client, unsigned id)
 deletes a timer More...
 
bool discord_timer_cancel_and_delete (struct discord *client, unsigned id)
 cancels, and deletes a timer More...
 

Detailed Description

Schedule callbacks to be called in the future.

Typedef Documentation

◆ discord_ev_timer

typedef void(* discord_ev_timer) (struct discord *client, struct discord_timer *ev)

callback to be used with struct discord_timer

Enumeration Type Documentation

◆ discord_timer_flags

flags used to change behaviour of timer

Enumerator
DISCORD_TIMER_MILLISECONDS 

use milliseconds for interval and start_time

DISCORD_TIMER_MICROSECONDS 

use microseconds for interval and start_time

DISCORD_TIMER_DELETE 

whether or not timer is marked for deletion

DISCORD_TIMER_DELETE_AUTO 

automatically delete a timer once its repeat counter runs out

DISCORD_TIMER_CANCELED 

timer has been canceled. user should cleanup only

DISCORD_TIMER_TICK 

flag is set when on_tick callback has been called

DISCORD_TIMER_GET 

used in discord_timer_ctl to get the timer's data

DISCORD_TIMER_INTERVAL_FIXED 

timer should run using a fixed interval based on start time

Function Documentation

◆ discord_timer_ctl()

unsigned discord_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_timer()

unsigned discord_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
Examples
timers.c.

◆ discord_timer_interval()

unsigned discord_timer_interval ( struct discord client,
discord_ev_timer  on_tick_cb,
discord_ev_timer  on_status_changed_cb,
void *  data,
int64_t  delay,
int64_t  interval,
int64_t  repeat 
)

creates a repeating 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
intervalinterval between runs. (-1 == disable repeat)
repeatrepetitions (-1 == infinity)
Returns
the id of the timer
Examples
timers.c.

◆ discord_timer_get()

bool discord_timer_get ( struct discord client,
unsigned  id,
struct discord_timer timer 
)

get the data associated with the timer

Parameters
clientthe client created with discord_init()
idid of the timer
timerwhere to copy the timer data to
Returns
true on success

◆ discord_timer_start()

bool discord_timer_start ( struct discord client,
unsigned  id 
)

starts a timer

Parameters
clientthe client created with discord_init()
idid of the timer
Returns
true on success

◆ discord_timer_stop()

bool discord_timer_stop ( struct discord client,
unsigned  id 
)

stops a timer

Parameters
clientthe client created with discord_init()
idid of the timer
Returns
true on success

◆ discord_timer_cancel()

bool discord_timer_cancel ( struct discord client,
unsigned  id 
)

cancels a timer, this will delete the timer if DISCORD_TIMER_DELETE_AUTO is enabled

Parameters
clientthe client created with discord_init()
idid of the timer
Returns
true on success
Examples
timers.c.

◆ discord_timer_delete()

bool discord_timer_delete ( struct discord client,
unsigned  id 
)

deletes a timer

Parameters
clientthe client created with discord_init()
idid of the timer
Returns
true on success

◆ discord_timer_cancel_and_delete()

bool discord_timer_cancel_and_delete ( struct discord client,
unsigned  id 
)

cancels, and deletes a timer

Parameters
clientthe client created with discord_init()
idid of the timer
Returns
true on success