[asterisk-commits] dhubbard: branch dhubbard/named_processors r110334 - in /team/dhubbard/named_...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Mar 20 16:21:58 CDT 2008
Author: dhubbard
Date: Thu Mar 20 16:21:58 2008
New Revision: 110334
URL: http://svn.digium.com/view/asterisk?view=rev&rev=110334
Log:
app_voicemail mwi subscriptions use app_voicemail taskprocessor
Modified:
team/dhubbard/named_processors/apps/app_queue.c
team/dhubbard/named_processors/apps/app_voicemail.c
team/dhubbard/named_processors/main/pbx.c
team/dhubbard/named_processors/main/taskprocessor.c
Modified: team/dhubbard/named_processors/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/apps/app_queue.c?view=diff&rev=110334&r1=110333&r2=110334
==============================================================================
--- team/dhubbard/named_processors/apps/app_queue.c (original)
+++ team/dhubbard/named_processors/apps/app_queue.c Thu Mar 20 16:21:58 2008
@@ -132,8 +132,8 @@
{ QUEUE_STRATEGY_WRANDOM, "wrandom"},
};
-struct taskproducer *tpsp;
-struct taskprocessor_singleton_info *tpsi;
+static struct taskproducer *taskproducer;
+static struct taskprocessor_singleton_info *taskprocessor;
#define DEFAULT_RETRY 5
#define DEFAULT_TIMEOUT 15
@@ -802,7 +802,7 @@
sc->state = state;
strcpy(sc->dev, device);
t = ast_task_alloc(handle_statechange, sc, "app_queue-device_state_cb");
- if (tpsp->queue_task(tpsp, t) < 0) {
+ if (taskproducer->queue_task(taskproducer, t) < 0) {
ast_log(LOG_WARNING, "queue_task failed!!\n");
ast_task_free(t);
}
@@ -6164,8 +6164,8 @@
clear_and_free_interfaces();
ao2_ref(queues, -1);
- ao2_ref(tpsp, -1);
- ao2_ref(tpsi, -1);
+ ao2_ref(taskproducer, -1);
+ ao2_ref(taskprocessor, -1);
return res;
}
@@ -6211,8 +6211,8 @@
res |= ast_custom_function_register(&queuewaitingcount_function);
res |= ast_custom_function_register(&queuememberpenalty_function);
- tpsi = ast_taskprocessor_reference("app_queue", 0);
- tpsp = ast_taskproducer_alloc(tpsi);
+ taskprocessor = ast_taskprocessor_reference("app_queue", 0);
+ taskproducer = ast_taskproducer_alloc(taskprocessor);
if (!(device_state_sub = ast_event_subscribe(AST_EVENT_DEVICE_STATE, device_state_cb, NULL, AST_EVENT_IE_END)))
res = -1;
Modified: team/dhubbard/named_processors/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/apps/app_voicemail.c?view=diff&rev=110334&r1=110333&r2=110334
==============================================================================
--- team/dhubbard/named_processors/apps/app_voicemail.c (original)
+++ team/dhubbard/named_processors/apps/app_voicemail.c Thu Mar 20 16:21:58 2008
@@ -110,6 +110,8 @@
#include "asterisk/stringfields.h"
#include "asterisk/smdi.h"
#include "asterisk/event.h"
+#include "asterisk/taskprocessor.h"
+#include "asterisk/astobj2.h"
#ifdef ODBC_STORAGE
#include "asterisk/res_odbc.h"
@@ -611,6 +613,15 @@
uint32_t uniqueid;
char mailbox[1];
};
+
+struct mwi_sub_task {
+ const char *mailbox;
+ const char *context;
+ uint32_t uniqueid;
+};
+
+static struct taskprocessor_singleton_info *taskprocessor;
+static struct taskproducer *taskproducer;
static AST_RWLIST_HEAD_STATIC(mwi_subs, mwi_sub);
@@ -7983,22 +7994,14 @@
ast_free(mwi_sub);
}
-static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
-{
- uint32_t uniqueid;
+static int handle_unsubscribe(struct a_task *task)
+{
struct mwi_sub *mwi_sub;
-
- if (ast_event_get_type(event) != AST_EVENT_UNSUB)
- return;
-
- if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
- return;
-
- uniqueid = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
-
+ uint32_t *uniqueid = (uint32_t *)task->_datap;
+
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_TRAVERSE_SAFE_BEGIN(&mwi_subs, mwi_sub, entry) {
- if (mwi_sub->uniqueid == uniqueid) {
+ if (mwi_sub->uniqueid == *uniqueid) {
AST_LIST_REMOVE_CURRENT(entry);
break;
}
@@ -8008,48 +8011,93 @@
if (mwi_sub)
mwi_sub_destroy(mwi_sub);
-}
-
-static void mwi_sub_event_cb(const struct ast_event *event, void *userdata)
-{
- const char *mailbox;
- const char *context;
- uint32_t uniqueid;
+
+ ast_free(uniqueid);
+ task->_datap = NULL;
+ ast_log(LOG_DEBUG, "unsubscribe handled\n");
+ return 0;
+}
+
+static int handle_subscribe(struct a_task *task)
+{
unsigned int len;
struct mwi_sub *mwi_sub;
-
- if (ast_event_get_type(event) != AST_EVENT_SUB)
- return;
-
- if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
- return;
-
- mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
- context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
- uniqueid = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
+ struct mwi_sub_task *p = task->_datap;
len = sizeof(*mwi_sub);
- if (!ast_strlen_zero(mailbox))
- len += strlen(mailbox);
-
- if (!ast_strlen_zero(context))
- len += strlen(context) + 1; /* Allow for seperator */
+ if (!ast_strlen_zero(p->mailbox))
+ len += strlen(p->mailbox);
+
+ if (!ast_strlen_zero(p->context))
+ len += strlen(p->context) + 1; /* Allow for seperator */
if (!(mwi_sub = ast_calloc(1, len)))
- return;
-
- mwi_sub->uniqueid = uniqueid;
- if (!ast_strlen_zero(mailbox))
- strcpy(mwi_sub->mailbox, mailbox);
-
- if (!ast_strlen_zero(context)) {
+ return -1;
+
+ mwi_sub->uniqueid = p->uniqueid;
+ if (!ast_strlen_zero(p->mailbox))
+ strcpy(mwi_sub->mailbox, p->mailbox);
+
+ if (!ast_strlen_zero(p->context)) {
strcat(mwi_sub->mailbox, "@");
- strcat(mwi_sub->mailbox, context);
+ strcat(mwi_sub->mailbox, p->context);
}
AST_RWLIST_WRLOCK(&mwi_subs);
AST_RWLIST_INSERT_TAIL(&mwi_subs, mwi_sub, entry);
AST_RWLIST_UNLOCK(&mwi_subs);
+ ast_free(p);
+ task->_datap = NULL;
+ ast_log(LOG_DEBUG, "subscribe handled\n");
+ return 0;
+}
+
+static void mwi_unsub_event_cb(const struct ast_event *event, void *userdata)
+{
+ struct a_task *t;
+ uint32_t u, *uniqueid = ast_calloc(1, sizeof(*uniqueid));
+ if (ast_event_get_type(event) != AST_EVENT_UNSUB)
+ return;
+
+ if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
+ return;
+
+ if (!taskproducer) {
+ ast_log(LOG_WARNING, "taskproducer is still NULL\n");
+ }
+ u = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
+ *uniqueid = u;
+ t = ast_task_alloc(handle_unsubscribe, uniqueid, "app_voicemail, mwi_unsub_event_cb");
+ if (taskproducer->queue_task(taskproducer, t) < 0) {
+ ast_log(LOG_ERROR, "failed to queue task\n");
+ ast_task_free(t);
+ }
+}
+
+static void mwi_sub_event_cb(const struct ast_event *event, void *userdata)
+{
+ struct mwi_sub_task *mwist;
+ struct a_task *t;
+ if (ast_event_get_type(event) != AST_EVENT_SUB)
+ return;
+
+ if (ast_event_get_ie_uint(event, AST_EVENT_IE_EVENTTYPE) != AST_EVENT_MWI)
+ return;
+
+ if ((mwist = ast_calloc(1, (sizeof(*mwist)))) == NULL) {
+ ast_log(LOG_ERROR, "could not allocate a mwi_sub_task\n");
+ return;
+ }
+ mwist->mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
+ mwist->context = ast_event_get_ie_str(event, AST_EVENT_IE_CONTEXT);
+ mwist->uniqueid = ast_event_get_ie_uint(event, AST_EVENT_IE_UNIQUEID);
+
+ t = ast_task_alloc(handle_subscribe, mwist, "app_voicemail, mwi_sub_event_cb");
+ if (taskproducer->queue_task(taskproducer, t) < 0) {
+ ast_log(LOG_ERROR, "failed to queue task\n");
+ ast_task_free(t);
+ }
+
}
static void start_poll_thread(void)
@@ -8853,6 +8901,9 @@
if (poll_thread != AST_PTHREADT_NULL)
stop_poll_thread();
+ ao2_ref(taskproducer, -1);
+ ao2_ref(taskprocessor, -1);
+
return res;
}
@@ -8864,6 +8915,10 @@
/* compute the location of the voicemail spool directory */
snprintf(VM_SPOOL_DIR, sizeof(VM_SPOOL_DIR), "%s/voicemail/", ast_config_AST_SPOOL_DIR);
+
+ /* this should probably go into load_config() */
+ taskprocessor = ast_taskprocessor_reference("app_voicemail", 0);
+ taskproducer = ast_taskproducer_alloc(taskprocessor);
if ((res = load_config(0)))
return res;
Modified: team/dhubbard/named_processors/main/pbx.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/main/pbx.c?view=diff&rev=110334&r1=110333&r2=110334
==============================================================================
--- team/dhubbard/named_processors/main/pbx.c (original)
+++ team/dhubbard/named_processors/main/pbx.c Thu Mar 20 16:21:58 2008
@@ -124,8 +124,8 @@
struct ast_context;
struct ast_app;
-struct taskprocessor_singleton_info *taskprocessor;
-struct taskproducer *taskproducer;
+static struct taskprocessor_singleton_info *taskprocessor;
+static struct taskproducer *taskproducer;
AST_THREADSTORAGE(switch_data);
Modified: team/dhubbard/named_processors/main/taskprocessor.c
URL: http://svn.digium.com/view/asterisk/team/dhubbard/named_processors/main/taskprocessor.c?view=diff&rev=110334&r1=110333&r2=110334
==============================================================================
--- team/dhubbard/named_processors/main/taskprocessor.c (original)
+++ team/dhubbard/named_processors/main/taskprocessor.c Thu Mar 20 16:21:58 2008
@@ -569,19 +569,19 @@
*/
static int tps_default_queue_task(struct taskproducer* producer, struct a_task* task)
{
- if ((!producer) || (!task)) {
- ast_log(LOG_ERROR, "a taskproducer: 0x%ld and a task: 0x%ld are required for this operation.\n", (unsigned long)producer, (unsigned long)task);
+ if (!((producer)&&(producer->_taskprocessor)) || !task) {
+ ast_log(LOG_ERROR, "this function requires a \'%s\' structure too.\n", (task)?"producer":"task");
return -1;
}
+ ast_log(LOG_DEBUG, "task from \'%s\' queued to taskprocessor \'%s\'\n", task->_source, producer->_taskprocessor->_name);
if (ast_taskprocessor_push(producer->_taskprocessor, task) < 0) {
- ast_log(LOG_ERROR, "we failed to push task to taskprocessor \'%s\'.\n", (producer->_taskprocessor)?producer->_taskprocessor->_name:"<null>");
+ ast_log(LOG_ERROR, "we failed to push task to taskprocessor \'%s\'.\n", producer->_taskprocessor->_name);
return -1;
}
producer->_tasks_produced++;
ast_mutex_lock(&producer->_taskprocessor->_taskprocessor_lock);
ast_cond_signal(&producer->_taskprocessor->_poll_cond);
ast_mutex_unlock(&producer->_taskprocessor->_taskprocessor_lock);
- ast_log(LOG_DEBUG, "task queued to taskprocessor\n");
return 0;
}
More information about the asterisk-commits
mailing list