[svn-commits] russell: branch group/chan_unistim r88325 - /team/group/chan_unistim/channels/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Nov 2 14:56:00 CDT 2007


Author: russell
Date: Fri Nov  2 14:55:59 2007
New Revision: 88325

URL: http://svn.digium.com/view/asterisk?view=rev&rev=88325
Log:
Change MWI handling to be able to grab the cached current state of the mailbox
instead of always polling the mailbox directly

Modified:
    team/group/chan_unistim/channels/chan_unistim.c

Modified: team/group/chan_unistim/channels/chan_unistim.c
URL: http://svn.digium.com/view/asterisk/team/group/chan_unistim/channels/chan_unistim.c?view=diff&rev=88325&r1=88324&r2=88325
==============================================================================
--- team/group/chan_unistim/channels/chan_unistim.c (original)
+++ team/group/chan_unistim/channels/chan_unistim.c Fri Nov  2 14:55:59 2007
@@ -81,6 +81,7 @@
 #include "asterisk/devicestate.h"
 #include "asterisk/stringfields.h"
 #include "asterisk/abstract_jb.h"
+#include "asterisk/event.h"
 
 /*! IP_PKTINFO is not portable. It's used to retrieve our IP.
    Comment the next line if your running *BSD */
@@ -4412,19 +4413,38 @@
 /*--- unistim_send_mwi_to_peer: Send message waiting indication ---*/
 static int unistim_send_mwi_to_peer(struct unistimsession *s, unsigned int tick)
 {
-	int newmsgs, oldmsgs;
+	struct ast_event *event;
+	int new, old;
+	char *mailbox, *context;
 	struct unistim_line *peer = s->device->lines;
 
-	/* Check for messages */
-	ast_app_inboxcount(peer->mailbox, &newmsgs, &oldmsgs);
+	context = mailbox = ast_strdupa(peer->mailbox);
+	strsep(&context, "@");
+	if (ast_strlen_zero(context))
+		context = "default";
+
+	event = ast_event_get_cached(AST_EVENT_MWI,
+		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
+		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
+		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+		AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
+		AST_EVENT_IE_END);
+
+	if (event) {
+		new = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+		old = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS);
+		ast_event_destroy(event);
+	} else /* Fall back on checking the mailbox directly */
+		ast_app_inboxcount(peer->mailbox, &new, &old);
+
 	peer->nextmsgcheck = tick + TIMER_MWI;
 
 	/* Return now if it's the same thing we told them last time */
-	if (((newmsgs << 8) | (oldmsgs)) == peer->lastmsgssent)
+	if (((new << 8) | (old)) == peer->lastmsgssent)
 		return 0;
 
-	peer->lastmsgssent = ((newmsgs << 8) | (oldmsgs));
-	if (newmsgs == 0)
+	peer->lastmsgssent = ((new << 8) | (old));
+	if (new == 0)
 		send_led_update(s, 0);
 	else
 		send_led_update(s, 1);
@@ -5505,7 +5525,9 @@
 	if (!unistim_reloading)
 		unistim_reloading = 1;
 	ast_mutex_unlock(&unistim_reload_lock);
+
 	restart_monitor();
+
 	return 0;
 }
 




More information about the svn-commits mailing list