[asterisk-commits] dlee: branch dlee/json_main r383261 - in /team/dlee/json_main: include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 15 15:38:06 CDT 2013


Author: dlee
Date: Fri Mar 15 15:38:03 2013
New Revision: 383261

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383261
Log:
Changes manager channel state subscription to use the message router.

Modified:
    team/dlee/json_main/include/asterisk/manager.h
    team/dlee/json_main/main/manager.c
    team/dlee/json_main/main/manager_channels.c

Modified: team/dlee/json_main/include/asterisk/manager.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/include/asterisk/manager.h?view=diff&rev=383261&r1=383260&r2=383261
==============================================================================
--- team/dlee/json_main/include/asterisk/manager.h (original)
+++ team/dlee/json_main/include/asterisk/manager.h Fri Mar 15 15:38:03 2013
@@ -318,7 +318,10 @@
 
 /*!
  * \brief Initialize support for AMI channel events.
- */
-void manager_channels_init(void);
+ * \return 0 on success.
+ * \return non-zero on error.
+ * \since 12
+ */
+int manager_channels_init(void);
 
 #endif /* _ASTERISK_MANAGER_H */

Modified: team/dlee/json_main/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/main/manager.c?view=diff&rev=383261&r1=383260&r2=383261
==============================================================================
--- team/dlee/json_main/main/manager.c (original)
+++ team/dlee/json_main/main/manager.c Fri Mar 15 15:38:03 2013
@@ -7491,7 +7491,9 @@
 
 	manager_enabled = 0;
 
-	manager_channels_init();
+	if (manager_channels_init()) {
+		return -1;
+	}
 
 	if (!registered) {
 		/* Register default actions */

Modified: team/dlee/json_main/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/main/manager_channels.c?view=diff&rev=383261&r1=383260&r2=383261
==============================================================================
--- team/dlee/json_main/main/manager_channels.c (original)
+++ team/dlee/json_main/main/manager_channels.c Fri Mar 15 15:38:03 2013
@@ -32,9 +32,10 @@
 
 #include "asterisk/channel.h"
 #include "asterisk/manager.h"
+#include "asterisk/stasis_message_router.h"
 #include "asterisk/pbx.h"
 
-static struct stasis_subscription *channel_state_sub;
+static struct stasis_message_router *channel_state_router;
 
 /*** DOCUMENTATION
 	<managerEvent language="en_US" name="Newchannel">
@@ -195,14 +196,22 @@
 		      snapshot->uniqueid);
 }
 
-static void channel_snapshot_update(struct stasis_cache_update *update)
-{
-	struct ast_channel_snapshot *old_snapshot =
-		stasis_message_data(update->old_snapshot);
-	struct ast_channel_snapshot *new_snapshot =
-		stasis_message_data(update->new_snapshot);
+static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
+				    struct stasis_topic *topic,
+				    struct stasis_message *message)
+{
+	struct stasis_cache_update *update = stasis_message_data(message);
+	struct ast_channel_snapshot *old_snapshot;
+	struct ast_channel_snapshot *new_snapshot;
 	int is_hungup, was_hungup;
 	char *manager_event = NULL;
+
+	if (ast_channel_snapshot() != update->type) {
+		return;
+	}
+
+	old_snapshot = stasis_message_data(update->old_snapshot);
+	new_snapshot = stasis_message_data(update->new_snapshot);
 
 	if (!new_snapshot) {
 		/* Ignore cache clearing events; we'll see the hangup first */
@@ -308,40 +317,60 @@
 /*!
  * \brief Callback processing messages on the channel topic.
  */
-static void channel_message_cb(void *data, struct stasis_subscription *sub,
-			       struct stasis_topic *topic,
-			       struct stasis_message *message)
-{
-	if (stasis_message_type(message) == stasis_cache_update()) {
-		struct stasis_cache_update *update =
-			stasis_message_data(message);
-		if (ast_channel_snapshot() == update->type) {
-			channel_snapshot_update(update);
-		}
-	} else if (stasis_message_type(message) == ast_channel_blob()) {
-		struct ast_channel_blob *obj = stasis_message_data(message);
-
-		if (strcmp("varset", ast_channel_blob_type(obj)) == 0) {
-			channel_varset(obj);
-		} else if (strcmp("userevent", ast_channel_blob_type(obj)) == 0) {
-			channel_userevent(obj);
-		}
+static void channel_blob_cb(void *data, struct stasis_subscription *sub,
+			    struct stasis_topic *topic,
+			    struct stasis_message *message)
+{
+	struct ast_channel_blob *obj = stasis_message_data(message);
+
+	if (strcmp("varset", ast_channel_blob_type(obj)) == 0) {
+		channel_varset(obj);
+	} else if (strcmp("userevent", ast_channel_blob_type(obj)) == 0) {
+		channel_userevent(obj);
 	}
 }
 
 static void manager_channels_shutdown(void)
 {
-	stasis_unsubscribe(channel_state_sub);
-	channel_state_sub = NULL;
-}
-
-void manager_channels_init(void)
-{
+	stasis_message_router_unsubscribe(channel_state_router);
+	channel_state_router = NULL;
+}
+
+int manager_channels_init(void)
+{
+	int ret = 0;
+
+	if (channel_state_router) {
+		/* Already initialized */
+		return 0;
+	}
+
 	ast_register_atexit(manager_channels_shutdown);
 
-	if (!channel_state_sub) {
-		channel_state_sub = stasis_subscribe(
-			stasis_caching_get_topic(ast_channel_topic_all_cached()),
-			channel_message_cb, NULL);
-	}
-}
+	channel_state_router = stasis_message_router_create(
+		stasis_caching_get_topic(ast_channel_topic_all_cached()));
+
+	if (!channel_state_router) {
+		return -1;
+	}
+
+	ret |= stasis_message_router_add(channel_state_router,
+					 stasis_cache_update(),
+					 channel_snapshot_update,
+					 NULL);
+
+	ret |= stasis_message_router_add(channel_state_router,
+					 ast_channel_blob(),
+					 channel_blob_cb,
+					 NULL);
+
+	/* If somehow we failed to add any routes, just shut down the whole
+	 * things and fail it.
+	 */
+	if (ret) {
+		manager_channels_shutdown();
+		return -1;
+	}
+
+	return 0;
+}




More information about the asterisk-commits mailing list