Timer


Typedefs

typedef ix_timer_s ix_timer_t
 the timer class
typedef itimerval ix_timer_val_t
 timer value

Enumerations

enum  ix_timer_type_e { IX_TIMER_ABSOLUTE = 0x20, IX_TIMER_PERIODIC = 0x40, IX_TIMER_ONESHOT = 0x80, IX_TIMER_NORMAL = 0x100 }

Functions

int ix_timer_val_init (ix_timer_val_t *ptv, int v_sec, int v_usec, int i_sec, int i_usec)
void ix_get_timenow (struct timeval *ptv)
timeval ix_timer_add (struct timeval *pt1, struct timeval *pt2)
ix_timer_tix_timer_new (ix_event_t *pev, ix_timer_type_e type, unsigned long userid, void(*cb)(void *parg), void *parg, ix_timer_val_t *pitv)
int ix_timer_free (ix_timer_t *pt)
int ix_timer_cancel (ix_timer_t *pt)
int ix_timer_restart (ix_timer_t *pt, ix_event_t *pev, ix_timer_type_e type, ix_timer_val_t *pitv)
int ix_timer_id_free (unsigned long id)

Detailed Description

This module describes the methods to deal with timers.

Timers are implemented by the timeout mechanism of the central select() call. During creation you can relate an event to a timer, which is fired when the timer elapse. You can choose between absolute timer, periodic timer, normal timer and one-shot timer, see ix_timer_new(), ix_timer_restart(), ... and ix_timer_val_init()


Enumeration Type Documentation

enum ix_timer_type_e

Enumerator:
IX_TIMER_ABSOLUTE  timer expires at given absolute time
IX_TIMER_PERIODIC  timer fires periodically after starttime has ellapsed
IX_TIMER_ONESHOT  timer fires only once and frees itself afterwards
IX_TIMER_NORMAL  timer fires after given time elapsed


Function Documentation

void ix_get_timenow ( struct timeval *  ptv  ) 

Get actual time

Parameters:
ptv,: pointer to store actual time

struct timeval ix_timer_add ( struct timeval *  pt1,
struct timeval *  pt2 
)

Adds two timeval structures

Parameters:
pt1 1st summand
pt2 2nd summand
Returns:
sum of times as struct timeval

int ix_timer_cancel ( ix_timer_t pt  ) 

cancel timer (not free), i.e. event will not be trigger. The timer can be used again with ix_timer_restart().

Parameters:
pt handle of timer
Returns:
  • 0: OK
  • <0: Error

int ix_timer_free ( ix_timer_t pt  ) 

cancel and frees timer

Parameters:
pt handle of timer object
Returns:
  • 0: OK
  • <0: Error

int ix_timer_id_free ( unsigned long  id  ) 

cancel and frees all timer with userid id if id == 0 all timers are cancelled and freed

Parameters:
it timer id
Returns:
  • 0: OK
  • <0: Error

ix_timer_t* ix_timer_new ( ix_event_t pev,
ix_timer_type_e  type,
unsigned long  userid,
void(*)(void *parg)  cb,
void *  parg,
ix_timer_val_t pitv 
)

constructor, creates new timer

Parameters:
pev handle of event which is triggered when timer fires
type type of timer s.above
userid some id which is used in ix_timer_id_free() to cancel and free timer
cb if supplied the callback is called when timer expires
parg argument for the callback
pitv time structure to supply sec and micro-sec for time to ellapse as absolute, delta, or startdelta and period time (minimal value is 1000 usec i.e. 1 milli sec)
Returns:
  • handle for timer
  • NULL: Error

int ix_timer_restart ( ix_timer_t pt,
ix_event_t pev,
ix_timer_type_e  type,
ix_timer_val_t pitv 
)

restart timer after or before it fired with new features

Parameters:
pt handle of timer
pev handle of event to trigger
type type of timer
pitv the time values
Returns:
  • 0: OK
  • <0: Error

int ix_timer_val_init ( ix_timer_val_t ptv,
int  v_sec,
int  v_usec,
int  i_sec,
int  i_usec 
)

utility function to initialize timer value

Parameters:
v_sec,: second of absolute or normal timer, or start sec of periodic timer
v_usec,: micro-second of absolute or normal timer, or start msec of periodic timer
i_sec,: second of periodic timer
i_usec,: micro-second of periodic timer
Returns:
  • 0: OK
  • !0: error


Generated on 4 Mar 2014 for ixtools by  doxygen 1.4.7