[asterisk-commits] russell: branch russell/res_monkeys r81265 - in /team/russell/res_monkeys: fu...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 28 14:19:25 CDT 2007
Author: russell
Date: Tue Aug 28 14:19:24 2007
New Revision: 81265
URL: http://svn.digium.com/view/asterisk?view=rev&rev=81265
Log:
Add the beginning of support for periodic announcements. It doesn't do the
hard part yet...
Added:
team/russell/res_monkeys/funcs/func_announce.c (with props)
Modified:
team/russell/res_monkeys/include/asterisk/audiohook.h
Added: team/russell/res_monkeys/funcs/func_announce.c
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/funcs/func_announce.c?view=auto&rev=81265
==============================================================================
--- team/russell/res_monkeys/funcs/func_announce.c (added)
+++ team/russell/res_monkeys/funcs/func_announce.c Tue Aug 28 14:19:24 2007
@@ -1,0 +1,158 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Russell Bryant <russell at 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
+ *
+ * \brief Application independent periodic announcements
+ *
+ * \author Russell Bryant <russell at digium.com>
+ *
+ * \ingroup functions
+ */
+
+#include "asterisk.h"
+
+ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+
+#include <stdlib.h>
+
+#include "asterisk/module.h"
+#include "asterisk/channel.h"
+#include "asterisk/pbx.h"
+#include "asterisk/utils.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/audiohook.h"
+
+static int unique_id;
+
+struct announce_data {
+ struct timeval begin;
+ int id;
+};
+
+static void announce_ds_destroy(void *arg)
+{
+ struct announce_data *announce = arg;
+
+ ast_free(announce);
+}
+
+static const struct ast_datastore_info announce_datastore = {
+ .type = "func_announce",
+ .destroy = announce_ds_destroy,
+};
+
+static int start_announce_read(struct ast_channel *chan, const char *cmd,
+ char *data, char *buf, size_t len)
+{
+ struct ast_datastore *datastore;
+ struct announce_data *announce;
+
+ if (!(announce = ast_calloc(1, sizeof(*announce))))
+ return -1;
+
+ announce->id = ast_atomic_fetchadd_int(&unique_id, +1);
+ announce->begin = ast_tvnow();
+
+ snprintf(buf, len, "%d", announce->id);
+
+ if (!(datastore = ast_channel_datastore_alloc(&announce_datastore, buf))) {
+ ast_free(announce);
+ buf[0] = '\0';
+ return -1;
+ }
+
+ ast_channel_lock(chan);
+ ast_channel_datastore_add(chan, datastore);
+ ast_channel_unlock(chan);
+
+ return 0;
+}
+
+static int stop_announce_read(struct ast_channel *chan, const char *cmd,
+ char *data, char *buf, size_t len)
+{
+ struct ast_datastore *datastore;
+ struct announce_data *announce;
+
+ if (!(datastore = ast_channel_datastore_find(chan, &announce_datastore, data))) {
+ ast_log(LOG_WARNING, "Periodic Announcement with ID '%s' not found for channel '%s'\n",
+ data, chan->name);
+ return -1;
+ }
+
+ ast_channel_lock(chan);
+ ast_channel_datastore_remove(chan, datastore);
+ ast_channel_unlock(chan);
+
+ announce = datastore->data;
+
+ snprintf(buf, len, "%d", ast_tvdiff_ms(ast_tvnow(), announce->begin));
+
+ ast_channel_datastore_free(datastore);
+
+ return 0;
+}
+
+static struct ast_custom_function start_announce_function = {
+ .name = "START_ANNOUNCE",
+ .synopsis = "Start a periodic announcement",
+ .syntax = "START_ANNOUNCE(<file>,<begin_time>[,<repeat_interval>])",
+ .desc =
+ "Start playing a periodic announcement to the channel. The function\n"
+ "will return a unique identifier which can later be used to stop the\n"
+ "announcement. All intervals should be specified in seconds\n"
+ "\n",
+ .read = start_announce_read,
+};
+
+static struct ast_custom_function stop_announce_function = {
+ .name = "STOP_ANNOUNCE",
+ .synopsis = "Stop a periodic announcement",
+ .syntax = "STOP_ANNOUNCE(id)",
+ .desc =
+ "This function is used to stop a periodic announcement that was\n"
+ "previously started using the START_ANNOUNCE function. The\n"
+ "argument provided here should be the ID that was returned by the\n"
+ "START function. This function will return the number of seconds\n"
+ "since START_ANNOUNCE was invoked.\n"
+ "\n",
+ .read = stop_announce_read,
+};
+
+static int unload_module(void)
+{
+ int res;
+
+ res = ast_custom_function_unregister(&start_announce_function);
+ res |= ast_custom_function_unregister(&stop_announce_function);
+
+ return res;
+}
+
+static int load_module(void)
+{
+ int res;
+
+ res = ast_custom_function_register(&start_announce_function);
+ res |= ast_custom_function_register(&stop_announce_function);
+
+ return res;
+}
+
+AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Application independent periodic announcements");
Propchange: team/russell/res_monkeys/funcs/func_announce.c
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: team/russell/res_monkeys/funcs/func_announce.c
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision
Propchange: team/russell/res_monkeys/funcs/func_announce.c
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: team/russell/res_monkeys/include/asterisk/audiohook.h
URL: http://svn.digium.com/view/asterisk/team/russell/res_monkeys/include/asterisk/audiohook.h?view=diff&rev=81265&r1=81264&r2=81265
==============================================================================
--- team/russell/res_monkeys/include/asterisk/audiohook.h (original)
+++ team/russell/res_monkeys/include/asterisk/audiohook.h Tue Aug 28 14:19:24 2007
@@ -165,18 +165,12 @@
/*! \brief Lock an audiohook
* \param audiohook Audiohook structure
*/
-static inline int ast_audiohook_lock(struct ast_audiohook *audiohook)
-{
- return ast_mutex_lock(&audiohook->lock);
-}
+#define ast_audiohook_lock(ah) ast_mutex_lock(&(ah)->lock)
/*! \brief Unlock an audiohook
* \param audiohook Audiohook structure
*/
-static inline int ast_audiohook_unlock(struct ast_audiohook *audiohook)
-{
- return ast_mutex_unlock(&audiohook->lock);
-}
+#define ast_audiohook_unlock(ah) ast_mutex_unlock(&(ah)->lock)
#if defined(__cplusplus) || defined(c_plusplus)
}
More information about the asterisk-commits
mailing list