Description

  • The netconfd-pro process supports timer callbacks.
  • The minimum interval is 1 second.
  • The interval units are seconds.
  • One-time-only and periodic timers are supported
  • The definitions for timer callbacks are in agt/agt_timer.h
  • Timer APIs are
    • agt_timer_create
    • agt_timer_restart
    • agt_timer_delete

Callback template

 

/* timer callback function
 *
 * Process the timer expired event
 *
 * INPUTS:
 *    timer_id == timer identifier 
 *    cookie == context pointer, such as a session control block,
 *            passed to agt_timer_set function (may be NULL)
 *
 * RETURNS:
 *     0 == normal exit
 *    -1 == error exit, delete timer upon return
 */
typedef int (*agt_timer_fn_t) (uint32  timer_id,
			       void *cookie);

 

Callback example

     

#include "procdefs.h"
#include "agt_timer.h"

static uint32 my_timer_id = 0;


static int my_timer (uint32 timer_id, void *cookie)
{
   (void)timer_id;  // used if callback supports multiple timers
    my_struct_t *my_struct = (my_struct_t * )cookie;

    check_stuff(my_struct);
    return 0;
} 


static status_t some_init_fn (void)
{

     status_t res =
       agt_timer_create(10,  // seconds (interval)
           true,   // is_periodic
          my_timer,   // callback fn
          my_context_struct,  // example cookie
         &my_timer_id);  // save timer ID for cleanup
     return res;
}




static void some_cleanup_fn (void)
{
     agt_timer_delete(my_timer_id);
}

 

     

API Definitions

 

/********************************************************************
* FUNCTION agt_timer_create
*
* Malloc and start a new timer control block
*
* INPUTS:
*   seconds == number of seconds to wait between polls
*   is_periodic == TRUE if periodic timer
*                  FALSE if a 1-event timer
*   timer_fn == address of callback function to invoke when
*               the timer poll event occurs
*   cookie == address of user cookie to pass to the timer_fn
*   ret_timer_id == address of return timer ID
*
* OUTPUTS:
*  *ret_timer_id == timer ID for the allocated timer, 
*    if the return value is NO_ERR
*
* RETURNS:
*   NO_ERR if all okay, the minimum spare requests will be malloced
*********************************************************************/
extern status_t
    agt_timer_create (uint32   seconds,
                      boolean is_periodic,
                      agt_timer_fn_t  timer_fn,
                      void *cookie,
                      uint32 *ret_timer_id);


/********************************************************************
* FUNCTION agt_timer_restart
*
* Restart a timer with a new timeout value.
* If this is a periodic timer, then the interval
* will be changed to the new value.  Otherwise
* a 1-shot timer will just be reset to the new value
*
* INPUTS:
*   timer_id == timer ID to reset
*   seconds == new timeout value
*
* RETURNS:
*   status, NO_ERR if all okay,
*********************************************************************/
extern status_t
    agt_timer_restart (uint32 timer_id,
                       uint32 seconds);


/********************************************************************
* FUNCTION agt_timer_delete
*
* Remove and delete a timer control block
* periodic timers need to be deleted to be stopped
* 1-shot timers will be deleted automatically after
* they expire and the callback is invoked
*
* INPUTS:
*   timer_id == timer ID to destroy
*
*********************************************************************/
extern void
    agt_timer_delete (uint32  timer_id);