[asterisk-commits] dlee: branch dlee/ASTERISK-21969 r396464 - in /team/dlee/ASTERISK-21969/res: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 8 16:17:11 CDT 2013


Author: dlee
Date: Thu Aug  8 16:17:09 2013
New Revision: 396464

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396464
Log:
Cleanup

Modified:
    team/dlee/ASTERISK-21969/res/res_stasis.c
    team/dlee/ASTERISK-21969/res/stasis/app.c

Modified: team/dlee/ASTERISK-21969/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21969/res/res_stasis.c?view=diff&rev=396464&r1=396463&r2=396464
==============================================================================
--- team/dlee/ASTERISK-21969/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-21969/res/res_stasis.c Thu Aug  8 16:17:09 2013
@@ -435,6 +435,7 @@
 		}
 	}
 
+	app_unsubscribe_bridge(app, stasis_app_get_bridge(control));
 	app_unsubscribe_channel(app, chan);
 
 	res = send_end_msg(app, chan);

Modified: team/dlee/ASTERISK-21969/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21969/res/stasis/app.c?view=diff&rev=396464&r1=396463&r2=396464
==============================================================================
--- team/dlee/ASTERISK-21969/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-21969/res/stasis/app.c Thu Aug  8 16:17:09 2013
@@ -52,6 +52,7 @@
 	char name[];
 };
 
+/*! Subscription info for a particular channel/bridge. */
 struct app_forwards {
 	/*! Count of number of times this channel/bridge has been subscribed */
 	int interested;
@@ -101,6 +102,7 @@
 	return forwards;
 }
 
+/*! Forward a channel's topics to an app */
 static struct app_forwards *forwards_create_channel(struct app *app,
 	struct ast_channel *chan)
 {
@@ -134,6 +136,7 @@
 	return forwards;
 }
 
+/*! Forward a bridge's topics to an app */
 static struct app_forwards *forwards_create_bridge(struct app *app,
 	struct ast_bridge *bridge)
 {
@@ -214,6 +217,7 @@
 	struct app *app = data;
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 
+	/* By default, send any message that has a JSON representation */
 	json = stasis_message_to_json(message);
 	if (!json) {
 		return;
@@ -271,7 +275,8 @@
 	struct ast_channel_snapshot *new_snapshot,
 	const struct timeval *tv)
 {
-	struct ast_channel_snapshot *snapshot = new_snapshot ? new_snapshot : old_snapshot;
+	struct ast_channel_snapshot *snapshot = new_snapshot ?
+		new_snapshot : old_snapshot;
 
 	if (!old_snapshot) {
 		return channel_created_event(snapshot, tv);
@@ -291,8 +296,8 @@
 {
 	RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 
-	/* No Newexten event on cache clear */
-	if (!new_snapshot) {
+	/* No Newexten event on cache clear or first event */
+	if (!old_snapshot || !new_snapshot) {
 		return NULL;
 	}
 
@@ -301,7 +306,7 @@
 		return NULL;
 	}
 
-	if (old_snapshot && ast_channel_snapshot_cep_equal(old_snapshot, new_snapshot)) {
+	if (ast_channel_snapshot_cep_equal(old_snapshot, new_snapshot)) {
 		return NULL;
 	}
 
@@ -350,15 +355,26 @@
                 struct stasis_message *message)
 {
 	struct app *app = data;
-        struct stasis_cache_update *update = stasis_message_data(message);
-        struct ast_channel_snapshot *new_snapshot = stasis_message_data(update->new_snapshot);
-        struct ast_channel_snapshot *old_snapshot = stasis_message_data(update->old_snapshot);
+        struct stasis_cache_update *update;
+        struct ast_channel_snapshot *new_snapshot;
+        struct ast_channel_snapshot *old_snapshot;
+        const struct timeval *tv;
+        int i;
+
+	ast_assert(stasis_message_type(message) == stasis_cache_update_type());
+
+        update = stasis_message_data(message);
+
+	ast_assert(update->type == ast_bridge_snapshot_type());
+
+        new_snapshot = stasis_message_data(update->new_snapshot);
+        old_snapshot = stasis_message_data(update->old_snapshot);
+
         /* Pull timestamp from the new snapshot, or from the update message
          * when there isn't one. */
-        const struct timeval *tv = update->new_snapshot ?
+        tv = update->new_snapshot ?
 		stasis_message_timestamp(update->new_snapshot) :
 		stasis_message_timestamp(message);
-        int i;
 
         for (i = 0; i < ARRAY_LEN(channel_monitors); ++i) {
                 RAII_VAR(struct ast_json *, msg, NULL, ast_json_unref);
@@ -386,12 +402,12 @@
                 struct stasis_topic *topic,
                 struct stasis_message *message)
 {
+        RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 	struct app *app = data;
         struct stasis_cache_update *update;
         struct ast_bridge_snapshot *new_snapshot;
         struct ast_bridge_snapshot *old_snapshot;
         const struct timeval *tv;
-        RAII_VAR(struct ast_json *, json, NULL, ast_json_unref);
 
 	ast_assert(stasis_message_type(message) == stasis_cache_update_type());
 
@@ -404,7 +420,6 @@
 	tv = update->new_snapshot ?
 		stasis_message_timestamp(update->new_snapshot) :
 		stasis_message_timestamp(message);
-
 
         if (!new_snapshot) {
                 json = simple_bridge_event("BridgeDestroyed", old_snapshot, tv);
@@ -498,7 +513,6 @@
 	if (res != 0) {
 		return NULL;
 	}
-
 
 	strncpy(app->name, name, size - sizeof(*app));
 	app->handler = handler;
@@ -580,7 +594,6 @@
 		ast_verb(1, "Activating Stasis app '%s'\n", app->name);
 	}
 
-
 	app->handler = handler;
 	ao2_cleanup(app->data);
 	if (data) {
@@ -596,6 +609,8 @@
 
 int app_subscribe_channel(struct app *app, struct ast_channel *chan)
 {
+	int res;
+
 	if (!app || !chan) {
 		return -1;
 	} else {
@@ -610,7 +625,12 @@
 			if (!forwards) {
 				return -1;
 			}
-			ao2_link_flags(app->forwards, forwards, OBJ_NOLOCK);
+
+			res = ao2_link_flags(app->forwards, forwards,
+				OBJ_NOLOCK);
+			if (res != 0) {
+				return -1;
+			}
 		}
 
 		++forwards->interested;




More information about the asterisk-commits mailing list