[svn-commits] russell: branch russell/events r59294 - in /team/russell/events: channels/ in...

svn-commits at lists.digium.com svn-commits at lists.digium.com
Wed Mar 28 13:59:28 MST 2007


Author: russell
Date: Wed Mar 28 15:59:27 2007
New Revision: 59294

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59294
Log:
Allow subscribers to provide data to be passed back to the event callback.  Now
chan_sip immediately knows which peer to send MWI to, instead of having to
traverse the peer list on each MWI event.

Modified:
    team/russell/events/channels/chan_iax2.c
    team/russell/events/channels/chan_mgcp.c
    team/russell/events/channels/chan_sip.c
    team/russell/events/channels/chan_zap.c
    team/russell/events/include/asterisk/event.h
    team/russell/events/main/event.c
    team/russell/events/res/res_eventtest.c

Modified: team/russell/events/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_iax2.c?view=diff&rev=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/channels/chan_iax2.c (original)
+++ team/russell/events/channels/chan_iax2.c Wed Mar 28 15:59:27 2007
@@ -884,7 +884,7 @@
 	.fixup = iax2_fixup,
 };
 
-static void mwi_event_cb(const struct ast_event *event)
+static void mwi_event_cb(const struct ast_event *event, void *userdata)
 {
 	/* The MWI subscriptions exist just so the core knows we care about those
 	 * mailboxes.  However, we just grab the events out of the cache when it
@@ -8741,7 +8741,7 @@
 		ast_free_ha(oldha);
 
 	if (!ast_strlen_zero(peer->mailbox)) {
-		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
 			AST_EVENT_IE_END);
 	}

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=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/channels/chan_mgcp.c (original)
+++ team/russell/events/channels/chan_mgcp.c Wed Mar 28 15:59:27 2007
@@ -452,7 +452,7 @@
 	.bridge = ast_rtp_bridge,
 };
 
-static void mwi_event_cb(const struct ast_event *event)
+static void mwi_event_cb(const struct ast_event *event, void *userdata)
 {
 	/* 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
@@ -3765,7 +3765,7 @@
 					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,
+						e->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
 							AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, e->mailbox,
 							AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 							AST_EVENT_IE_END);

Modified: team/russell/events/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/channels/chan_sip.c?view=diff&rev=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/channels/chan_sip.c (original)
+++ team/russell/events/channels/chan_sip.c Wed Mar 28 15:59:27 2007
@@ -1376,7 +1376,7 @@
 static int sip_poke_peer(struct sip_peer *peer);
 static void sip_poke_all_peers(void);
 static void sip_peer_hold(struct sip_pvt *p, int hold);
-static void mwi_event_cb(const struct ast_event *);
+static void mwi_event_cb(const struct ast_event *, void *);
 
 /*--- Applications, functions, CLI and manager command helpers */
 static const char *sip_nat_mode(const struct sip_pvt *p);
@@ -8717,20 +8717,13 @@
 }
 
 /*! \brief Receive MWI events that we have subscribed to */
-static void mwi_event_cb(const struct ast_event *event)
-{
-	const char *mailbox;
-
-	mailbox = ast_event_get_ie_str(event, AST_EVENT_IE_MAILBOX);
-
-	ASTOBJ_CONTAINER_RDLOCK(&peerl);
-	ASTOBJ_CONTAINER_TRAVERSE(&peerl, 1, do {
-		ASTOBJ_RDLOCK(iterator);
-		if (!strcmp(mailbox, iterator->mailbox))
-			sip_send_mwi_to_peer(iterator, event, 0);
-		ASTOBJ_UNLOCK(iterator);
-	} while (0) );
-	ASTOBJ_CONTAINER_UNLOCK(&peerl);
+static void mwi_event_cb(const struct ast_event *event, void *userdata)
+{
+	struct sip_peer *peer = userdata;
+
+	ASTOBJ_RDLOCK(peer);
+	sip_send_mwi_to_peer(peer, event, 0);
+	ASTOBJ_UNLOCK(peer);
 }
 
 /*! \brief Callback for the devicestate notification (SUBSCRIBE) support subsystem
@@ -15168,7 +15161,7 @@
 
 		p->subscribed = MWI_NOTIFICATION;
 		if (ast_test_flag(&authpeer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY)) {
-			authpeer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+			authpeer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, authpeer,
 				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, authpeer->mailbox,
 				AST_EVENT_IE_END);
 		}
@@ -16875,7 +16868,7 @@
 	 * subscribe to it now. */
 	if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && 
 		!ast_strlen_zero(peer->mailbox)) {
-		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+		peer->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, peer,
 			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, peer->mailbox,
 			AST_EVENT_IE_END);
 		/* Send MWI from the event cache only.  This is so we can send initial

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=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/channels/chan_zap.c (original)
+++ team/russell/events/channels/chan_zap.c Wed Mar 28 15:59:27 2007
@@ -263,7 +263,7 @@
 
 static int zt_sendtext(struct ast_channel *c, const char *text);
 
-static void mwi_event_cb(const struct ast_event *event)
+static void mwi_event_cb(const struct ast_event *event, void *userdata)
 {
 	/* 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
@@ -7886,7 +7886,7 @@
 		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));
 		if (!ast_strlen_zero(tmp->mailbox)) {
-			tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb,
+			tmp->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
 				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, tmp->mailbox,
 				AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
 				AST_EVENT_IE_END);

Modified: team/russell/events/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event.h?view=diff&rev=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/include/asterisk/event.h (original)
+++ team/russell/events/include/asterisk/event.h Wed Mar 28 15:59:27 2007
@@ -27,9 +27,9 @@
 
 #include "asterisk/event_defs.h"
 
-typedef void (*ast_event_cb_t)(const struct ast_event *);
+typedef void (*ast_event_cb_t)(const struct ast_event *, void *userdata);
 
-struct ast_event_sub *ast_event_subscribe(enum ast_event_type, ast_event_cb_t, ...);
+struct ast_event_sub *ast_event_subscribe(enum ast_event_type, ast_event_cb_t, void *userdata, ...);
 
 void ast_event_unsubscribe(struct ast_event_sub *);
 

Modified: team/russell/events/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/event.c?view=diff&rev=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/main/event.c (original)
+++ team/russell/events/main/event.c Wed Mar 28 15:59:27 2007
@@ -79,6 +79,7 @@
 struct ast_event_sub {
 	enum ast_event_type type;
 	ast_event_cb_t cb;
+	void *userdata;
 	AST_LIST_HEAD_NOLOCK(, ast_event_ie_val) ie_vals;
 	AST_RWLIST_ENTRY(ast_event_sub) entry;
 };
@@ -170,7 +171,8 @@
 	return res;
 }
 
-struct ast_event_sub *ast_event_subscribe(enum ast_event_type type, ast_event_cb_t cb, ...)
+struct ast_event_sub *ast_event_subscribe(enum ast_event_type type, ast_event_cb_t cb, 
+	void *userdata, ...)
 {
 	va_list ap;
 	enum ast_event_ie_type ie_type;
@@ -184,7 +186,7 @@
 	if (!(sub = ast_calloc(1, sizeof(*sub))))
 		return NULL;
 
-	va_start(ap, cb);
+	va_start(ap, userdata);
 	for (ie_type = va_arg(ap, enum ast_event_type);
 		ie_type != AST_EVENT_IE_END;
 		ie_type = va_arg(ap, enum ast_event_type))
@@ -208,6 +210,7 @@
 
 	sub->type = type;
 	sub->cb = cb;
+	sub->userdata = userdata;
 
 	AST_RWLIST_WRLOCK(&ast_event_subs[type]);
 	AST_RWLIST_INSERT_TAIL(&ast_event_subs[type], sub, entry);
@@ -589,14 +592,14 @@
 			}
 			if (ie_val)
 				continue;
-			sub->cb(event_ref->event);
+			sub->cb(event_ref->event, sub->userdata);
 		}
 		AST_RWLIST_UNLOCK(&ast_event_subs[host_event_type]);
 
 		/* Now to subscribers to all event types */
 		AST_RWLIST_RDLOCK(&ast_event_subs[AST_EVENT_ALL]);
 		AST_RWLIST_TRAVERSE(&ast_event_subs[AST_EVENT_ALL], sub, entry)
-			sub->cb(event_ref->event);
+			sub->cb(event_ref->event, sub->userdata);
 		AST_RWLIST_UNLOCK(&ast_event_subs[AST_EVENT_ALL]);
 
 		ast_event_ref_destroy(event_ref);

Modified: team/russell/events/res/res_eventtest.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/res/res_eventtest.c?view=diff&rev=59294&r1=59293&r2=59294
==============================================================================
--- team/russell/events/res/res_eventtest.c (original)
+++ team/russell/events/res/res_eventtest.c Wed Mar 28 15:59:27 2007
@@ -60,7 +60,7 @@
 		mailbox, new, old);
 }
 
-static void ast_event_process(const struct ast_event *event)
+static void ast_event_process(const struct ast_event *event, void *userdata)
 {
 	switch (ast_event_get_type(event)) {
 	case AST_EVENT_MWI:
@@ -93,8 +93,10 @@
 	if (a->argc != e->args)
 		return CLI_SHOWUSAGE;
 
-	if (!(event_sub = ast_event_subscribe(AST_EVENT_ALL, ast_event_process, AST_EVENT_IE_END)))
+	if (!(event_sub = ast_event_subscribe(AST_EVENT_ALL, ast_event_process, 
+		NULL, AST_EVENT_IE_END))) {
 		return CLI_FAILURE;
+	}
 
 	if (!(event = ast_event_new(AST_EVENT_MWI)))
 		return CLI_FAILURE;



More information about the svn-commits mailing list