[asterisk-commits] kpfleming: trunk r122062 - in /trunk: include/asterisk/ main/
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jun 12 09:21:33 CDT 2008
Author: kpfleming
Date: Thu Jun 12 09:21:32 2008
New Revision: 122062
URL: http://svn.digium.com/view/asterisk?view=rev&rev=122062
Log:
add infrastructure so that timing source can be a loadable module... next steps are to convert channel.c and chan_iax2.c to use this new API, and to move all the DAHDI-specific timing source code into a new res_timing_dahdi module
Added:
trunk/include/asterisk/timing.h
- copied, changed from r121991, trunk/include/asterisk/musiconhold.h
trunk/main/timing.c
- copied, changed from r121991, trunk/main/global_datastores.c
Modified:
trunk/main/Makefile
Copied: trunk/include/asterisk/timing.h (from r121991, trunk/include/asterisk/musiconhold.h)
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/timing.h?view=diff&rev=122062&p1=trunk/include/asterisk/musiconhold.h&r1=121991&p2=trunk/include/asterisk/timing.h&r2=122062
==============================================================================
--- trunk/include/asterisk/musiconhold.h (original)
+++ trunk/include/asterisk/timing.h Thu Jun 12 09:21:32 2008
@@ -1,9 +1,9 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 1999 - 2005, Digium, Inc.
+ * Copyright (C) 2008, Digium, Inc.
*
- * Mark Spencer <markster at digium.com>
+ * Kevin P. Fleming <kpfleming at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -16,44 +16,97 @@
* at the top of the source tree.
*/
-/*! \file
- * \brief Music on hold handling
+/*!
+ \file timing.h
+ \brief Timing source management
+ \author Kevin P. Fleming <kpfleming at 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 in
+ millisconds).
+
+ 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.
*/
-#ifndef _ASTERISK_MOH_H
-#define _ASTERISK_MOH_H
+#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,
+};
+
+struct ast_timing_functions {
+ int (*timer_open)(unsigned int rate);
+ void (*timer_close)(int handle);
+ 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);
+};
+
/*!
- * \brief Turn on music on hold on a given channel
- *
- * \param chan The channel structure that will get music on hold
- * \param mclass The class to use if the musicclass is not currently set on
- * the channel structure.
- * \param interpclass The class to use if the musicclass is not currently set on
- * the channel structure or in the mclass argument.
- *
- * \retval Zero on success
- * \retval non-zero on failure
+ \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 on failure, or a handle to be passed to
+ ast_uninstall_timing_functions() on success
*/
-int ast_moh_start(struct ast_channel *chan, const char *mclass, const char *interpclass);
+void *ast_install_timing_functions(struct ast_timing_functions *funcs);
-/*! Turn off music on hold on a given channel */
-void ast_moh_stop(struct ast_channel *chan);
+/*!
+ \brief Uninstall a previously-installed set of timing functions.
+ \param handle The handle returned from a prior successful call to
+ ast_install_timing_functions().
+ \retval none
+ */
+void ast_uninstall_timing_functions(void *handle);
-void ast_install_music_functions(int (*start_ptr)(struct ast_channel *, const char *, const char *),
- void (*stop_ptr)(struct ast_channel *),
- void (*cleanup_ptr)(struct ast_channel *));
+/*!
+ \brief Open a timer handle.
+ \param rate The rate at which the timer should trigger.
+ \retval -1 on failure, or a positive integer on success
+ */
+int ast_timer_open(unsigned int rate);
-void ast_uninstall_music_functions(void);
+/*!
+ \brief Close a previously-opened timer handle.
+ \param handle The timer handle to close.
+ \retval none
+ */
+void ast_timer_close(int handle);
-void ast_moh_cleanup(struct ast_channel *chan);
+void ast_timer_ack(int handle, unsigned int quantity);
+
+int ast_timer_enable_continuous(int handle);
+
+int ast_timer_disable_continous(int handle);
+
+enum ast_timing_event ast_timer_get_event(int handle);
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
-#endif /* _ASTERISK_MOH_H */
+#endif /* _ASTERISK_TIMING_H */
Modified: trunk/main/Makefile
URL: http://svn.digium.com/view/asterisk/trunk/main/Makefile?view=diff&rev=122062&r1=122061&r2=122062
==============================================================================
--- trunk/main/Makefile (original)
+++ trunk/main/Makefile Thu Jun 12 09:21:32 2008
@@ -30,7 +30,7 @@
cryptostub.o sha1.o http.o fixedjitterbuf.o abstract_jb.o \
strcompat.o threadstorage.o dial.o event.o adsistub.o audiohook.o \
astobj2.o hashtab.o global_datastores.o $(RESAMPLE_OBJS) version.o \
- features.o taskprocessor.o
+ features.o taskprocessor.o timing.o
# we need to link in the objects statically, not as a library, because
# otherwise modules will not have them available if none of the static
Copied: trunk/main/timing.c (from r121991, trunk/main/global_datastores.c)
URL: http://svn.digium.com/view/asterisk/trunk/main/timing.c?view=diff&rev=122062&p1=trunk/main/global_datastores.c&r1=121991&p2=trunk/main/timing.c&r2=122062
==============================================================================
--- trunk/main/global_datastores.c (original)
+++ trunk/main/timing.c Thu Jun 12 09:21:32 2008
@@ -1,9 +1,9 @@
/*
* Asterisk -- An open source telephony toolkit.
*
- * Copyright (C) 1999 - 2007, Digium, Inc.
+ * Copyright (C) 2008, Digium, Inc.
*
- * Mark Michelson <mmichelson at digium.com>
+ * Kevin P. Fleming <kpfleming at digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
@@ -18,96 +18,157 @@
/*! \file
*
- * \brief globally-accessible datastore information and callbacks
+ * \brief Timing source management
*
- * \author Mark Michelson <mmichelson at digium.com>
+ * \author Kevin P. Fleming <kpfleming at digium.com>
*/
#include "asterisk.h"
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
-#include "asterisk/global_datastores.h"
-#include "asterisk/linkedlists.h"
+#include "asterisk/timing.h"
+#include "asterisk/lock.h"
-static void dialed_interface_destroy(void *data)
+AST_MUTEX_DEFINE_STATIC(lock);
+
+static struct ast_timing_functions timer_funcs;
+
+void *ast_install_timing_functions(struct ast_timing_functions *funcs)
{
- struct ast_dialed_interface *di = NULL;
- AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;
+ if (!funcs->timer_open ||
+ !funcs->timer_close ||
+ !funcs->timer_ack ||
+ !funcs->timer_get_event ||
+ !funcs->timer_enable_continuous ||
+ !funcs->timer_disable_continuous) {
+ return NULL;
+ }
+
+ ast_mutex_lock(&lock);
+
+ if (timer_funcs.timer_open) {
+ ast_mutex_unlock(&lock);
+ return NULL;
+ }
- if (!dialed_interface_list) {
+ timer_funcs = *funcs;
+
+ ast_mutex_unlock(&lock);
+
+ return &timer_funcs;
+}
+
+void ast_uninstall_timing_functions(void *handle)
+{
+ ast_mutex_lock(&lock);
+
+ if (handle != &timer_funcs) {
+ ast_mutex_unlock(&lock);
return;
}
- AST_LIST_LOCK(dialed_interface_list);
- while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
- ast_free(di);
- AST_LIST_UNLOCK(dialed_interface_list);
+ memset(&timer_funcs, 0, sizeof(timer_funcs));
- AST_LIST_HEAD_DESTROY(dialed_interface_list);
- ast_free(dialed_interface_list);
+ ast_mutex_unlock(&lock);
}
-static void *dialed_interface_duplicate(void *data)
+int ast_timer_open(unsigned int rate)
{
- struct ast_dialed_interface *di = NULL;
- AST_LIST_HEAD(, ast_dialed_interface) *old_list;
- AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;
+ int timer;
- if(!(old_list = data)) {
- return NULL;
+ ast_mutex_lock(&lock);
+
+ if (!timer_funcs.timer_open) {
+ ast_mutex_unlock(&lock);
+ return -1;
}
- if(!(new_list = ast_calloc(1, sizeof(*new_list)))) {
- return NULL;
+ timer = timer_funcs.timer_open(rate);
+
+ ast_mutex_unlock(&lock);
+
+ return timer;
+}
+
+void ast_timer_close(int timer)
+{
+ ast_mutex_lock(&lock);
+
+ if (!timer_funcs.timer_close) {
+ ast_mutex_unlock(&lock);
+ return;
}
- AST_LIST_HEAD_INIT(new_list);
- AST_LIST_LOCK(old_list);
- AST_LIST_TRAVERSE(old_list, di, list) {
- struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) + strlen(di->interface));
- if(!di2) {
- AST_LIST_UNLOCK(old_list);
- dialed_interface_destroy(new_list);
- return NULL;
- }
- strcpy(di2->interface, di->interface);
- AST_LIST_INSERT_TAIL(new_list, di2, list);
- }
- AST_LIST_UNLOCK(old_list);
+ timer_funcs.timer_close(timer);
- return new_list;
+ ast_mutex_unlock(&lock);
}
+void ast_timer_ack(int handle, unsigned int quantity)
+{
+ ast_mutex_lock(&lock);
-static void *dial_features_duplicate(void *data)
-{
- struct ast_dial_features *df = data, *df_copy;
-
- if (!(df_copy = ast_calloc(1, sizeof(*df)))) {
- return NULL;
+ if (!timer_funcs.timer_ack) {
+ ast_mutex_unlock(&lock);
+ return;
}
- memcpy(df_copy, df, sizeof(*df));
+ timer_funcs.timer_ack(handle, quantity);
- return df_copy;
+ ast_mutex_unlock(&lock);
}
-static void dial_features_destroy(void *data) {
- struct ast_dial_features *df = data;
- if (df) {
- ast_free(df);
+int ast_timer_enable_continuous(int handle)
+{
+ int result;
+
+ ast_mutex_lock(&lock);
+
+ if (!timer_funcs.timer_enable_continuous) {
+ ast_mutex_unlock(&lock);
+ return -1;
}
+
+ result = timer_funcs.timer_enable_continuous(handle);
+
+ ast_mutex_unlock(&lock);
+
+ return result;
}
-const struct ast_datastore_info dialed_interface_info = {
- .type = "dialed-interface",
- .destroy = dialed_interface_destroy,
- .duplicate = dialed_interface_duplicate,
-};
+int ast_timer_disable_continous(int handle)
+{
+ int result;
-const struct ast_datastore_info dial_features_info = {
- .type = "dial-features",
- .destroy = dial_features_destroy,
- .duplicate = dial_features_duplicate,
-};
+ ast_mutex_lock(&lock);
+
+ if (!timer_funcs.timer_disable_continuous) {
+ ast_mutex_unlock(&lock);
+ return -1;
+ }
+
+ result = timer_funcs.timer_disable_continuous(handle);
+
+ ast_mutex_unlock(&lock);
+
+ return result;
+}
+
+enum ast_timing_event ast_timer_get_event(int handle)
+{
+ enum ast_timing_event result;
+
+ ast_mutex_lock(&lock);
+
+ if (!timer_funcs.timer_get_event) {
+ ast_mutex_unlock(&lock);
+ return -1;
+ }
+
+ result = timer_funcs.timer_get_event(handle);
+
+ ast_mutex_unlock(&lock);
+
+ return result;
+}
More information about the asterisk-commits
mailing list