Thu Apr 28 2011 16:57:19

Asterisk developer's documentation


timing.h File Reference

Timing source management. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  ast_timing_interface
 Timing module interface. More...

Defines

#define ast_register_timing_interface(i)   _ast_register_timing_interface(i, ast_module_info->self)
 Register a set of timing functions.

Enumerations

enum  ast_timer_event { AST_TIMING_EVENT_EXPIRED = 1, AST_TIMING_EVENT_CONTINUOUS = 2 }

Functions

void * _ast_register_timing_interface (struct ast_timing_interface *funcs, struct ast_module *mod)
void ast_timer_ack (const struct ast_timer *handle, unsigned int quantity)
 Acknowledge a timer event.
void ast_timer_close (struct ast_timer *handle)
 Close an opened timing handle.
int ast_timer_disable_continuous (const struct ast_timer *handle)
 Disable continuous mode.
int ast_timer_enable_continuous (const struct ast_timer *handle)
 Enable continuous mode.
int ast_timer_fd (const struct ast_timer *handle)
 Get a poll()-able file descriptor for a timer.
enum ast_timer_event ast_timer_get_event (const struct ast_timer *handle)
 Retrieve timing event.
unsigned int ast_timer_get_max_rate (const struct ast_timer *handle)
 Get maximum rate supported for a timer.
const char * ast_timer_get_name (const struct ast_timer *handle)
 Get name of timer in use.
struct ast_timerast_timer_open (void)
 Open a timer.
int ast_timer_set_rate (const struct ast_timer *handle, unsigned int rate)
 Set the timing tick rate.
int ast_unregister_timing_interface (void *handle)
 Unregister a previously registered timing interface.

Detailed Description

Timing source management.

Author:
Kevin P. Fleming <kpfleming@digium.com>
Russell Bryant <russell@digium.com>

Portions of Asterisk require a timing source, a periodic trigger for media handling activities. The functions in this file allow a loadable module to provide a timing source for Asterisk and its modules, so that those modules can request a 'timing handle' when they require one. These handles are file descriptors, which can be used with select() or poll().

The timing source used by Asterisk must provide the following features:

1) Periodic triggers, with a configurable interval (specified as number of triggers per second).

2) Multiple outstanding triggers, each of which must be 'acked' to clear it. Triggers must also be 'ackable' in quantity.

3) Continuous trigger mode, which when enabled causes every call to poll() on the timer handle to immediately return.

4) Multiple 'event types', so that the code using the timer can know whether the wakeup it received was due to a periodic trigger or a continuous trigger.

Definition in file timing.h.


Define Documentation

#define ast_register_timing_interface (   i)    _ast_register_timing_interface(i, ast_module_info->self)

Register a set of timing functions.

Parameters:
funcsAn instance of the ast_timing_interfaces structure with pointers to the functions provided by the timing implementation.
Return values:
NULLfailure
non-Nullhandle to be passed to ast_unregister_timing_interface() on success
Since:
1.6.1

Definition at line 94 of file timing.h.

Referenced by load_module().


Enumeration Type Documentation

Enumerator:
AST_TIMING_EVENT_EXPIRED 
AST_TIMING_EVENT_CONTINUOUS 

Definition at line 57 of file timing.h.


Function Documentation

void ast_timer_ack ( const struct ast_timer handle,
unsigned int  quantity 
)

Acknowledge a timer event.

Parameters:
handletimer handle returned from timer_open()
quantitynumber of timer events to acknowledge
Note:
This function should only be called if timer_get_event() returned AST_TIMING_EVENT_EXPIRED.
Returns:
nothing
Since:
1.6.1

Definition at line 167 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_ack.

Referenced by __ast_read(), softmix_bridge_thread(), timing_read(), and timing_test().

{
   handle->holder->iface->timer_ack(handle->fd, quantity);
}
void ast_timer_close ( struct ast_timer handle)

Close an opened timing handle.

Parameters:
handletimer handle returned from timer_open()
Returns:
nothing
Since:
1.6.1

Definition at line 146 of file timing.c.

References ast_free, ast_module_unref(), ast_timer::fd, ast_timer::holder, timing_holder::iface, timing_holder::mod, and ast_timing_interface::timer_close.

Referenced by __ast_channel_alloc_ap(), __unload_module(), ast_channel_free(), load_module(), softmix_bridge_destroy(), and timing_test().

{
   handle->holder->iface->timer_close(handle->fd);
   ast_module_unref(handle->holder->mod);
   ast_free(handle);
}
int ast_timer_disable_continuous ( const struct ast_timer handle)

Disable continuous mode.

Parameters:
handletimer handle returned from timer_close()
Return values:
-1failure, with errno set
0success
Since:
1.6.1

Definition at line 181 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_disable_continuous.

Referenced by __ast_read().

{
   int res = -1;

   res = handle->holder->iface->timer_disable_continuous(handle->fd);

   return res;
}
int ast_timer_enable_continuous ( const struct ast_timer handle)

Enable continuous mode.

Parameters:
handletimer handle returned from timer_open()

Continuous mode causes poll() on the timer's fd to immediately return always until continuous mode is disabled.

Return values:
-1failure, with errno set
0success
Since:
1.6.1

Definition at line 172 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_enable_continuous.

Referenced by __ast_queue_frame().

{
   int res = -1;

   res = handle->holder->iface->timer_enable_continuous(handle->fd);

   return res;
}
int ast_timer_fd ( const struct ast_timer handle)

Get a poll()-able file descriptor for a timer.

Parameters:
handletimer handle returned from timer_open()
Returns:
file descriptor which can be used with poll() to wait for events
Since:
1.6.1

Definition at line 153 of file timing.c.

References ast_timer::fd.

Referenced by __ast_channel_alloc_ap(), network_thread(), softmix_bridge_thread(), and timing_test().

{
   return handle->fd;
}
enum ast_timer_event ast_timer_get_event ( const struct ast_timer handle)

Retrieve timing event.

Parameters:
handletimer handle returned by timer_open()

After poll() indicates that there is input on the timer's fd, this will be called to find out what triggered it.

Returns:
which event triggered the timer
Since:
1.6.1

Definition at line 190 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_get_event.

Referenced by __ast_read().

{
   enum ast_timer_event res = -1;

   res = handle->holder->iface->timer_get_event(handle->fd);

   return res;
}
unsigned int ast_timer_get_max_rate ( const struct ast_timer handle)

Get maximum rate supported for a timer.

Parameters:
handletimer handle returned by timer_open()
Returns:
maximum rate supported by timer
Since:
1.6.1

Definition at line 199 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_get_max_rate.

Referenced by ast_settimeout().

{
   unsigned int res = 0;

   res = handle->holder->iface->timer_get_max_rate(handle->fd);

   return res;
}
const char* ast_timer_get_name ( const struct ast_timer handle)

Get name of timer in use.

Parameters:
handletimer handle returned by timer_open()
Returns:
name of timer
Since:
1.6.2

Definition at line 208 of file timing.c.

References ast_timer::holder, timing_holder::iface, and ast_timing_interface::name.

Referenced by __ast_channel_alloc_ap().

{
   return handle->holder->iface->name;
}
struct ast_timer* ast_timer_open ( void  ) [read]

Open a timer.

Return values:
NULLon error, with errno set
non-NULLtimer handle on success
Since:
1.6.1

Definition at line 119 of file timing.c.

References ast_calloc, ast_heap_peek(), ast_heap_rdlock(), ast_heap_unlock(), ast_module_ref(), ast_timer::fd, ast_timer::holder, timing_holder::iface, timing_holder::mod, ast_timing_interface::timer_close, and ast_timing_interface::timer_open.

Referenced by __ast_channel_alloc_ap(), load_module(), softmix_bridge_create(), and timing_test().

{
   int fd = -1;
   struct timing_holder *h;
   struct ast_timer *t = NULL;

   ast_heap_rdlock(timing_interfaces);

   if ((h = ast_heap_peek(timing_interfaces, 1))) {
      fd = h->iface->timer_open();
      ast_module_ref(h->mod);
   }

   if (fd != -1) {
      if (!(t = ast_calloc(1, sizeof(*t)))) {
         h->iface->timer_close(fd);
      } else {
         t->fd = fd;
         t->holder = h;
      }
   }

   ast_heap_unlock(timing_interfaces);

   return t;
}
int ast_timer_set_rate ( const struct ast_timer handle,
unsigned int  rate 
)

Set the timing tick rate.

Parameters:
handletimer handle returned from timer_open()
rateticks per second, 0 turns the ticks off if needed

Use this function if you want the timer to show input at a certain rate. The other alternative use of a timer is the continuous mode.

Return values:
-1error, with errno set
0success
Since:
1.6.1

Definition at line 158 of file timing.c.

References ast_timer::fd, ast_timer::holder, timing_holder::iface, and ast_timing_interface::timer_set_rate.

Referenced by __ast_read(), ast_settimeout(), load_module(), softmix_bridge_thread(), and timing_test().

{
   int res = -1;

   res = handle->holder->iface->timer_set_rate(handle->fd, rate);

   return res;
}
int ast_unregister_timing_interface ( void *  handle)

Unregister a previously registered timing interface.

Parameters:
handleThe handle returned from a prior successful call to ast_register_timing_interface().
Return values:
0success
non-zerofailure
Since:
1.6.1

Definition at line 101 of file timing.c.

References ast_free, ast_heap_remove(), ast_heap_unlock(), and ast_heap_wrlock().

Referenced by unload_module().

{
   struct timing_holder *h = handle;
   int res = -1;

   ast_heap_wrlock(timing_interfaces);
   h = ast_heap_remove(timing_interfaces, h);
   ast_heap_unlock(timing_interfaces);

   if (h) {
      ast_free(h);
      h = NULL;
      res = 0;
   }

   return res;
}