2008-06-12 14:21:32 +00:00
|
|
|
/*
|
|
|
|
* Asterisk -- An open source telephony toolkit.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008, Digium, Inc.
|
|
|
|
*
|
|
|
|
* Kevin P. Fleming <kpfleming@digium.com>
|
|
|
|
*
|
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*!
|
|
|
|
\file timing.h
|
|
|
|
\brief Timing source management
|
|
|
|
\author Kevin P. Fleming <kpfleming@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:
|
|
|
|
|
2008-06-12 17:30:55 +00:00
|
|
|
1) Periodic triggers, with a configurable interval (specified as
|
|
|
|
number of triggers per second).
|
2008-06-12 14:21:32 +00:00
|
|
|
|
|
|
|
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.
|
2008-10-30 20:46:17 +00:00
|
|
|
|
|
|
|
\todo Create an implementation of this API for Linux based on the
|
|
|
|
following API: http://www.kernel.org/doc/man-pages/online/pages/man2/timerfd_create.2.html
|
2008-06-12 14:21:32 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _ASTERISK_TIMING_H
|
|
|
|
#define _ASTERISK_TIMING_H
|
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
enum ast_timing_event {
|
|
|
|
AST_TIMING_EVENT_EXPIRED = 1,
|
|
|
|
AST_TIMING_EVENT_CONTINUOUS = 2,
|
|
|
|
};
|
|
|
|
|
2008-06-12 20:38:52 +00:00
|
|
|
/*!
|
|
|
|
* \brief Timing module interface
|
|
|
|
*
|
|
|
|
* The public API calls for the timing API directly map to this interface.
|
|
|
|
* So, the behavior of these calls should match the documentation of the
|
|
|
|
* public API calls.
|
|
|
|
*/
|
2008-06-12 14:21:32 +00:00
|
|
|
struct ast_timing_functions {
|
2008-06-13 12:45:50 +00:00
|
|
|
int (*timer_open)(void);
|
2008-06-12 14:21:32 +00:00
|
|
|
void (*timer_close)(int handle);
|
2008-06-13 12:45:50 +00:00
|
|
|
int (*timer_set_rate)(int handle, unsigned int rate);
|
2008-06-12 14:21:32 +00:00
|
|
|
void (*timer_ack)(int handle, unsigned int quantity);
|
|
|
|
int (*timer_enable_continuous)(int handle);
|
|
|
|
int (*timer_disable_continuous)(int handle);
|
|
|
|
enum ast_timing_event (*timer_get_event)(int handle);
|
2008-06-26 15:37:01 +00:00
|
|
|
unsigned int (*timer_get_max_rate)(int handle);
|
2008-06-12 14:21:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*!
|
2008-06-12 20:38:52 +00:00
|
|
|
* \brief Install a set of timing functions.
|
|
|
|
*
|
|
|
|
* \param funcs An instance of the \c ast_timing_functions structure with pointers
|
|
|
|
* to the functions provided by the timing implementation.
|
|
|
|
*
|
|
|
|
* \retval NULL failure
|
|
|
|
* \retval non-Null handle to be passed to ast_uninstall_timing_functions() on success
|
2008-06-12 14:21:32 +00:00
|
|
|
*/
|
|
|
|
void *ast_install_timing_functions(struct ast_timing_functions *funcs);
|
|
|
|
|
|
|
|
/*!
|
2008-06-12 20:38:52 +00:00
|
|
|
* \brief Uninstall a previously-installed set of timing functions.
|
|
|
|
*
|
|
|
|
* \param handle The handle returned from a prior successful call to
|
|
|
|
* ast_install_timing_functions().
|
|
|
|
*
|
|
|
|
* \return nothing
|
2008-06-12 14:21:32 +00:00
|
|
|
*/
|
|
|
|
void ast_uninstall_timing_functions(void *handle);
|
|
|
|
|
|
|
|
/*!
|
2008-06-12 20:38:52 +00:00
|
|
|
* \brief Open a timing fd
|
|
|
|
*
|
|
|
|
* \retval -1 error, with errno set
|
|
|
|
* \retval >=0 success
|
2008-06-12 14:21:32 +00:00
|
|
|
*/
|
2008-06-13 12:45:50 +00:00
|
|
|
int ast_timer_open(void);
|
2008-06-12 14:21:32 +00:00
|
|
|
|
|
|
|
/*!
|
2008-06-12 20:38:52 +00:00
|
|
|
* \brief Close an opened timing handle
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned from timer_open()
|
2008-06-12 20:38:52 +00:00
|
|
|
*
|
|
|
|
* \return nothing
|
2008-06-12 14:21:32 +00:00
|
|
|
*/
|
|
|
|
void ast_timer_close(int handle);
|
|
|
|
|
2008-06-13 12:45:50 +00:00
|
|
|
/*!
|
|
|
|
* \brief Set the timing tick rate
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned from timer_open()
|
|
|
|
* \param rate ticks per second, 0 turns the ticks off if needed
|
2008-06-13 12:45:50 +00:00
|
|
|
*
|
|
|
|
* Use this function if you want the timing fd to show input at a certain
|
|
|
|
* rate. The other alternative use of a timing fd, is using the continuous
|
|
|
|
* mode.
|
|
|
|
*
|
|
|
|
* \retval -1 error, with errno set
|
|
|
|
* \retval 0 success
|
|
|
|
*/
|
|
|
|
int ast_timer_set_rate(int handle, unsigned int rate);
|
|
|
|
|
2008-06-12 20:38:52 +00:00
|
|
|
/*!
|
|
|
|
* \brief Acknowledge a timer event
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned from timer_open()
|
|
|
|
* \param quantity number of timer events to acknowledge
|
2008-06-12 20:38:52 +00:00
|
|
|
*
|
|
|
|
* \note This function should only be called if timer_get_event()
|
|
|
|
* returned AST_TIMING_EVENT_EXPIRED.
|
|
|
|
*
|
|
|
|
* \return nothing
|
|
|
|
*/
|
2008-06-12 14:21:32 +00:00
|
|
|
void ast_timer_ack(int handle, unsigned int quantity);
|
|
|
|
|
2008-06-12 20:38:52 +00:00
|
|
|
/*!
|
|
|
|
* \brief Enable continuous mode
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned from timer_open()
|
2008-06-12 20:38:52 +00:00
|
|
|
*
|
|
|
|
* Continuous mode causes poll() on the timing fd to immediately return
|
|
|
|
* always until continuous mode is disabled.
|
|
|
|
*
|
|
|
|
* \retval -1 failure, with errno set
|
|
|
|
* \retval 0 success
|
|
|
|
*/
|
2008-06-12 14:21:32 +00:00
|
|
|
int ast_timer_enable_continuous(int handle);
|
|
|
|
|
2008-06-12 20:38:52 +00:00
|
|
|
/*!
|
|
|
|
* \brief Disable continuous mode
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned from timer_close()
|
2008-06-12 20:38:52 +00:00
|
|
|
*
|
|
|
|
* \retval -1 failure, with errno set
|
|
|
|
* \retval 0 success
|
|
|
|
*/
|
2008-06-16 12:48:11 +00:00
|
|
|
int ast_timer_disable_continuous(int handle);
|
2008-06-12 14:21:32 +00:00
|
|
|
|
2008-06-12 20:38:52 +00:00
|
|
|
/*!
|
|
|
|
* \brief Determine timing event
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned by timer_open()
|
2008-06-12 20:38:52 +00:00
|
|
|
*
|
|
|
|
* After poll() indicates that there is input on the timing fd, this will
|
|
|
|
* be called to find out what triggered it.
|
|
|
|
*
|
|
|
|
* \return which event triggered the timing fd
|
|
|
|
*/
|
2008-06-12 14:21:32 +00:00
|
|
|
enum ast_timing_event ast_timer_get_event(int handle);
|
|
|
|
|
2008-06-26 15:37:01 +00:00
|
|
|
/*!
|
|
|
|
* \brief Get maximum rate supported for a timing handle
|
|
|
|
*
|
2008-07-02 14:50:45 +00:00
|
|
|
* \param handle timing fd returned by timer_open()
|
2008-06-26 15:37:01 +00:00
|
|
|
*
|
|
|
|
* \return maximum rate supported for timing handle
|
|
|
|
*/
|
|
|
|
unsigned int ast_timer_get_max_rate(int handle);
|
|
|
|
|
2008-06-12 14:21:32 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _ASTERISK_TIMING_H */
|