[asterisk-commits] russell: branch russell/events r59271 -
/team/russell/events/channels/
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Mar 27 12:41:59 MST 2007
Author: russell
Date: Tue Mar 27 14:41:58 2007
New Revision: 59271
URL: http://svn.digium.com/view/asterisk?view=rev&rev=59271
Log:
Convert chan_mgcp over to getting MWI information from the event cache instead
of polling the mailbox directly
Modified:
team/russell/events/channels/chan_mgcp.c
team/russell/events/channels/chan_zap.c
Modified: team/russell/events/channels/chan_mgcp.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_mgcp.c?view=diff&rev=59271&r1=59270&r2=59271
==============================================================================
--- team/russell/events/channels/chan_mgcp.c (original)
+++ team/russell/events/channels/chan_mgcp.c Tue Mar 27 14:41:58 2007
@@ -76,6 +76,7 @@
#include "asterisk/devicestate.h"
#include "asterisk/stringfields.h"
#include "asterisk/abstract_jb.h"
+#include "asterisk/event.h"
#ifndef IPTOS_MINCOST
#define IPTOS_MINCOST 0x02
@@ -320,9 +321,10 @@
char cid_name[AST_MAX_EXTENSION]; /*!< Caller*ID name */
char lastcallerid[AST_MAX_EXTENSION]; /*!< Last Caller*ID */
char call_forward[AST_MAX_EXTENSION]; /*!< Last Caller*ID */
- char mailbox[AST_MAX_EXTENSION];
char musicclass[MAX_MUSICCLASS];
char curtone[80]; /*!< Current tone */
+ char mailbox[AST_MAX_EXTENSION];
+ struct ast_event_sub *mwi_event_sub;
ast_group_t callgroup;
ast_group_t pickupgroup;
int callwaiting;
@@ -450,9 +452,31 @@
.bridge = ast_rtp_bridge,
};
+static void mwi_event_cb(const struct ast_event *event)
+{
+ /* This module does not handle MWI in an event-based manner. However, it
+ * subscribes to MWI for each mailbox that is configured so that the core
+ * knows that we care about it. Then, chan_mgcp will get the MWI from the
+ * event cache instead of checking the mailbox directly. */
+}
+
static int has_voicemail(struct mgcp_endpoint *p)
{
- return ast_app_has_voicemail(p->mailbox, NULL);
+ int new_msgs;
+ struct ast_event *event;
+
+ event = ast_event_get_cached(AST_EVENT_MWI,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, p->mailbox,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+
+ if (event) {
+ new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+ ast_event_destroy(event);
+ } else
+ new_msgs = ast_app_has_voicemail(p->mailbox, NULL);
+
+ return new_msgs;
}
static int unalloc_sub(struct mgcp_subchannel *sub)
@@ -3740,6 +3764,12 @@
ast_copy_string(e->language, language, sizeof(e->language));
ast_copy_string(e->musicclass, musicclass, sizeof(e->musicclass));
ast_copy_string(e->mailbox, mailbox, sizeof(e->mailbox));
+ if (!ast_strlen_zero(e->mailbox)) {
+ e->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, e->mailbox,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+ }
snprintf(e->rqnt_ident, sizeof(e->rqnt_ident), "%08lx", ast_random());
e->msgstate = -1;
e->amaflags = amaflags;
@@ -4014,6 +4044,10 @@
ast_mutex_destroy(&s->cx_queue_lock);
free(s);
}
+
+ if (e->mwi_event_sub)
+ ast_event_unsubscribe(e->mwi_event_sub);
+
ast_mutex_destroy(&e->lock);
ast_mutex_destroy(&e->rqnt_queue_lock);
ast_mutex_destroy(&e->cmd_queue_lock);
Modified: team/russell/events/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_zap.c?view=diff&rev=59271&r1=59270&r2=59271
==============================================================================
--- team/russell/events/channels/chan_zap.c (original)
+++ team/russell/events/channels/chan_zap.c Tue Mar 27 14:41:58 2007
@@ -7885,10 +7885,12 @@
tmp->cid_ton = 0;
ast_copy_string(tmp->cid_name, conf.chan.cid_name, sizeof(tmp->cid_name));
ast_copy_string(tmp->mailbox, conf.chan.mailbox, sizeof(tmp->mailbox));
- tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
- AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, tmp->mailbox,
- AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
- AST_EVENT_IE_END);
+ if (!ast_strlen_zero(tmp->mailbox)) {
+ tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+ AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, tmp->mailbox,
+ AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+ AST_EVENT_IE_END);
+ }
tmp->msgstate = -1;
tmp->group = conf.chan.group;
tmp->callgroup = conf.chan.callgroup;
More information about the asterisk-commits
mailing list