[asterisk-commits] kmoore: branch kmoore/stasis-cel_refactoring r388950 - /team/kmoore/stasis-ce...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri May 17 08:26:05 CDT 2013


Author: kmoore
Date: Fri May 17 08:26:03 2013
New Revision: 388950

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=388950
Log:
Reduce code by using S_OR and refactor channel router to be more extensible

Modified:
    team/kmoore/stasis-cel_refactoring/main/cel.c

Modified: team/kmoore/stasis-cel_refactoring/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-cel_refactoring/main/cel.c?view=diff&rev=388950&r1=388949&r2=388950
==============================================================================
--- team/kmoore/stasis-cel_refactoring/main/cel.c (original)
+++ team/kmoore/stasis-cel_refactoring/main/cel.c Fri May 17 08:26:03 2013
@@ -58,8 +58,14 @@
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/stasis_channels.h"
 
-/*! Message router for channel state */
-static struct stasis_message_router *cel_channel_state_router;
+/*! Message router for state that CEL needs to know about */
+static struct stasis_message_router *cel_state_router;
+
+/*! Aggregation topic for all topics CEL needs to know about */
+static struct stasis_topic *cel_state_topic;
+
+/*! Subscription for forwarding the channel caching topic */
+static struct stasis_subscription *cel_channel_forwarder;
 
 /*! Is the CEL subsystem enabled ? */
 static unsigned char cel_enabled;
@@ -385,6 +391,10 @@
 	struct ast_event *ev;
 	char *linkedid = ast_strdupa(snapshot->linkedid);
 
+	if (!cel_enabled) {
+		return 0;
+	}
+
 	/* Make sure a reload is not occurring while we're checking to see if this
 	 * is an event that we care about.  We could lose an important event in this
 	 * process otherwise. */
@@ -392,14 +402,14 @@
 
 	/* Record the linkedid of new channels if we are tracking LINKEDID_END even if we aren't
 	 * reporting on CHANNEL_START so we can track when to send LINKEDID_END */
-	if (cel_enabled && ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
+	if (ast_cel_track_event(AST_CEL_LINKEDID_END) && event_type == AST_CEL_CHANNEL_START && linkedid) {
 		if (ast_cel_linkedid_ref(linkedid)) {
 			ast_mutex_unlock(&reload_lock);
 			return -1;
 		}
 	}
 
-	if (!cel_enabled || !ast_cel_track_event(event_type)) {
+	if (!ast_cel_track_event(event_type)) {
 		ast_mutex_unlock(&reload_lock);
 		return 0;
 	}
@@ -415,21 +425,13 @@
 
 	ast_mutex_unlock(&reload_lock);
 
-	if (!userdefevname) {
-		userdefevname = "";
-	}
-
-	if (!extra) {
-		extra = "";
-	}
-
 	eventtime = ast_tvnow();
 
 	ev = ast_event_new(AST_EVENT_CEL,
 		AST_EVENT_IE_CEL_EVENT_TYPE, AST_EVENT_IE_PLTYPE_UINT, event_type,
 		AST_EVENT_IE_CEL_EVENT_TIME, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_sec,
 		AST_EVENT_IE_CEL_EVENT_TIME_USEC, AST_EVENT_IE_PLTYPE_UINT, eventtime.tv_usec,
-		AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, userdefevname,
+		AST_EVENT_IE_CEL_USEREVENT_NAME, AST_EVENT_IE_PLTYPE_STR, S_OR(userdefevname, ""),
 		AST_EVENT_IE_CEL_CIDNAME, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_name,
 		AST_EVENT_IE_CEL_CIDNUM, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_number,
 		AST_EVENT_IE_CEL_CIDANI, AST_EVENT_IE_PLTYPE_STR, snapshot->caller_ani,
@@ -446,7 +448,7 @@
 		AST_EVENT_IE_CEL_UNIQUEID, AST_EVENT_IE_PLTYPE_STR, snapshot->uniqueid,
 		AST_EVENT_IE_CEL_LINKEDID, AST_EVENT_IE_PLTYPE_STR, snapshot->linkedid,
 		AST_EVENT_IE_CEL_USERFIELD, AST_EVENT_IE_PLTYPE_STR, snapshot->userfield,
-		AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, extra,
+		AST_EVENT_IE_CEL_EXTRA, AST_EVENT_IE_PLTYPE_STR, S_OR(extra, ""),
 		AST_EVENT_IE_CEL_PEER, AST_EVENT_IE_PLTYPE_STR, snapshot->bridged_name,
 		AST_EVENT_IE_END);
 
@@ -907,8 +909,11 @@
 
 static void ast_cel_engine_term(void)
 {
-	stasis_message_router_unsubscribe(cel_channel_state_router);
-	cel_channel_state_router = NULL;
+	stasis_message_router_unsubscribe(cel_state_router);
+	cel_state_router = NULL;
+	ao2_cleanup(cel_state_topic);
+	cel_state_topic = NULL;
+	cel_channel_forwarder = stasis_unsubscribe(cel_channel_forwarder);
 	if (appset) {
 		ao2_ref(appset, -1);
 		appset = NULL;
@@ -939,14 +944,22 @@
 		return -1;
 	}
 
-	cel_channel_state_router = stasis_message_router_create(
-		stasis_caching_get_topic(ast_channel_topic_all_cached()));
-
-	if (!cel_channel_state_router) {
-		return -1;
-	}
-
-	ret |= stasis_message_router_add(cel_channel_state_router,
+	cel_state_topic = stasis_topic_create("cel_state_topic");
+	if (!cel_state_topic) {
+		return -1;
+	}
+
+	cel_channel_forwarder = stasis_forward_all(stasis_caching_get_topic(ast_channel_topic_all_cached()), cel_state_topic);
+	if (!cel_channel_forwarder) {
+		return -1;
+	}
+
+	cel_state_router = stasis_message_router_create(cel_state_topic);
+	if (!cel_state_router) {
+		return -1;
+	}
+
+	ret |= stasis_message_router_add(cel_state_router,
 		stasis_cache_update_type(),
 		cel_channel_snapshot_update_cb,
 		NULL);




More information about the asterisk-commits mailing list