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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 11 21:38:40 CDT 2013


Author: dlee
Date: Mon Mar 11 21:38:36 2013
New Revision: 382826

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382826
Log:
Replaced the newexten message type with a snapshot.

In working with stasis-http, I figured out that we need to update the
snapshots on these newexten events. I've updated this patch to disptach
channel snapshots when exec'ing dialplan, and the handler in manager
to detect newexten changes.

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

Modified: team/dlee/json_main/include/asterisk/pbx.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/include/asterisk/pbx.h?view=diff&rev=382826&r1=382825&r2=382826
==============================================================================
--- team/dlee/json_main/include/asterisk/pbx.h (original)
+++ team/dlee/json_main/include/asterisk/pbx.h Mon Mar 11 21:38:36 2013
@@ -1422,14 +1422,6 @@
  */
 char *ast_complete_applications(const char *line, const char *word, int state);
 
-/*!
- * \brief Message type for \c Newexten messages.
- *
- * These messages are actually just \ref ast_channel_snapshot, since the
- * snapshot contains all the necessary information.
- */
-struct stasis_message_type *ast_pbx_newexten(void);
-
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

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=382826&r1=382825&r2=382826
==============================================================================
--- team/dlee/json_main/main/manager_channels.c (original)
+++ team/dlee/json_main/main/manager_channels.c Mon Mar 11 21:38:36 2013
@@ -92,11 +92,41 @@
 	return out;
 }
 
+static void channel_newexten(struct ast_channel_snapshot *snapshot)
+{
+	/*** DOCUMENTATION
+		<managerEventInstance>
+			<synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
+			<syntax>
+				<parameter name="Application">
+					<para>The application about to be executed.</para>
+				</parameter>
+				<parameter name="AppData">
+					<para>The data to be passed to the application.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	***/
+	if (ast_strlen_zero(snapshot->appl)) {
+		/* Channel's not in a valid state for a Newexten event yet */
+		return;
+	}
+	manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
+		      "Channel: %s\r\n"
+		      "Context: %s\r\n"
+		      "Extension: %s\r\n"
+		      "Priority: %d\r\n"
+		      "Application: %s\r\n"
+		      "AppData: %s\r\n"
+		      "Uniqueid: %s\r\n",
+		      snapshot->name, snapshot->context, snapshot->exten, snapshot->priority, snapshot->appl, snapshot->data, 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);
-	int is_hungup;
+	int is_hungup, was_hungup;
 	char *manager_event = NULL;
 
 	if (!new_snapshot) {
@@ -104,6 +134,7 @@
 		return;
 	}
 
+	was_hungup = (old_snapshot && ast_test_flag(&old_snapshot->flags, AST_FLAG_ZOMBIE)) ? 1 : 0;
 	is_hungup = ast_test_flag(&new_snapshot->flags, AST_FLAG_ZOMBIE) ? 1 : 0;
 
 	if (!old_snapshot) {
@@ -114,10 +145,11 @@
 		manager_event = "Newstate";
 	}
 
-	if (old_snapshot && is_hungup) {
+	if (!was_hungup && is_hungup) {
 		manager_event = "Hangup";
 	}
 
+	/* Channel state change events */
 	if (manager_event) {
 		RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 
@@ -125,6 +157,18 @@
 		if (channel_event_string) {
 			manager_event(EVENT_FLAG_CALL, manager_event, "%s", ast_str_buffer(channel_event_string));
 		}
+	}
+
+	/* Detect Newexten transitions
+	 *  - if the old snapshot has no application (first Newexten)
+	 *  - or if the context/priority/exten changes
+	 */
+	if (!old_snapshot || ast_strlen_zero(old_snapshot->appl) || (
+		    new_snapshot && (
+			    old_snapshot->priority != new_snapshot->priority ||
+			    strcmp(old_snapshot->context, new_snapshot->context) != 0 ||
+			    strcmp(old_snapshot->exten, new_snapshot->exten) != 0))) {
+		channel_newexten(new_snapshot);
 	}
 }
 
@@ -184,32 +228,6 @@
 		      eventname, uniqueid, body);
 }
 
-static void channel_newexten(struct ast_channel_snapshot *snapshot)
-{
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
-			<syntax>
-				<parameter name="Application">
-					<para>The application about to be executed.</para>
-				</parameter>
-				<parameter name="AppData">
-					<para>The data to be passed to the application.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
-		      "Channel: %s\r\n"
-		      "Context: %s\r\n"
-		      "Extension: %s\r\n"
-		      "Priority: %d\r\n"
-		      "Application: %s\r\n"
-		      "AppData: %s\r\n"
-		      "Uniqueid: %s\r\n",
-		      snapshot->name, snapshot->context, snapshot->exten, snapshot->priority, snapshot->appl, snapshot->data, snapshot->uniqueid);
-}
-
 /*!
  * \brief Callback processing messages on the channel topic.
  */
@@ -229,9 +247,6 @@
 		} else if (strcmp("userevent", ast_channel_blob_type(obj)) == 0) {
 			channel_userevent(obj);
 		}
-	} else if (stasis_message_type(message) == ast_pbx_newexten()) {
-		struct ast_channel_snapshot *snapshot = stasis_message_data(message);
-		channel_newexten(snapshot);
 	}
 }
 

Modified: team/dlee/json_main/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/main/pbx.c?view=diff&rev=382826&r1=382825&r2=382826
==============================================================================
--- team/dlee/json_main/main/pbx.c (original)
+++ team/dlee/json_main/main/pbx.c Mon Mar 11 21:38:36 2013
@@ -1199,14 +1199,6 @@
 static struct ast_context *find_context(const char *context);
 static void get_device_state_causing_channels(struct ao2_container *c);
 
-static struct stasis_message_type *__newexten;
-
-struct stasis_message_type *ast_pbx_newexten(void)
-{
-	return __newexten;
-}
-
-
 /*!
  * \internal
  * \brief Character array comparison function for qsort.
@@ -4716,7 +4708,7 @@
 				 */
 				ast_string_field_set(snapshot, appl, app->name);
 				ast_string_field_set(snapshot, data, passdata);
-				msg = stasis_message_create(ast_pbx_newexten(), snapshot);
+				msg = stasis_message_create(ast_channel_snapshot(), snapshot);
 				if (msg) {
 					stasis_publish(ast_channel_topic(c), msg);
 				}
@@ -12228,8 +12220,6 @@
  */
 static void pbx_shutdown(void)
 {
-	ao2_cleanup(__newexten);
-	__newexten = NULL;
 	if (hints) {
 		ao2_ref(hints, -1);
 		hints = NULL;
@@ -12246,7 +12236,6 @@
 
 int ast_pbx_init(void)
 {
-	__newexten = stasis_message_type_create("ast_newexten");
 	hints = ao2_container_alloc(HASH_EXTENHINT_SIZE, hint_hash, hint_cmp);
 	hintdevices = ao2_container_alloc(HASH_EXTENHINT_SIZE, hintdevice_hash_cb, hintdevice_cmp_multiple);
 	statecbs = ao2_container_alloc(1, NULL, statecbs_cmp);

Modified: team/dlee/json_main/pbx/pbx_realtime.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/pbx/pbx_realtime.c?view=diff&rev=382826&r1=382825&r2=382826
==============================================================================
--- team/dlee/json_main/pbx/pbx_realtime.c (original)
+++ team/dlee/json_main/pbx/pbx_realtime.c Mon Mar 11 21:38:36 2013
@@ -363,7 +363,7 @@
 					 */
 					ast_string_field_set(snapshot, appl, app);
 					ast_string_field_set(snapshot, data, !ast_strlen_zero(appdata) ? appdata : "(NULL)");
-					msg = stasis_message_create(ast_pbx_newexten(), snapshot);
+					msg = stasis_message_create(ast_channel_snapshot(), snapshot);
 					if (msg) {
 						stasis_publish(ast_channel_topic(chan), msg);
 					}




More information about the asterisk-commits mailing list