[asterisk-commits] dlee: branch dlee/json_main r383509 - /team/dlee/json_main/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 21 09:05:02 CDT 2013


Author: dlee
Date: Thu Mar 21 09:04:58 2013
New Revision: 383509

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383509
Log:
Avoid duplicating the channel snapshot string on the same event.

Modified:
    team/dlee/json_main/main/manager_channels.c

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=383509&r1=383508&r2=383509
==============================================================================
--- team/dlee/json_main/main/manager_channels.c (original)
+++ team/dlee/json_main/main/manager_channels.c Thu Mar 21 09:04:58 2013
@@ -162,110 +162,112 @@
 	return out;
 }
 
-static void channel_newexten(struct ast_channel_snapshot *snapshot)
+static inline int cep_has_changed(
+	const struct ast_channel_snapshot *old_snapshot,
+	const struct ast_channel_snapshot *new_snapshot)
+{
+	ast_assert(old_snapshot != NULL);
+	ast_assert(new_snapshot != NULL);
+	return old_snapshot->priority != new_snapshot->priority ||
+		strcmp(old_snapshot->context, new_snapshot->context) != 0 ||
+		strcmp(old_snapshot->exten, new_snapshot->exten) != 0;
+}
+
+static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
+				    struct stasis_topic *topic,
+				    struct stasis_message *message)
 {
 	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-
-	if (ast_strlen_zero(snapshot->appl)) {
-		/* Channel's not in a valid state for a Newexten event yet */
+	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;
+	int new_exten;
+
+	if (ast_channel_snapshot() != update->type) {
 		return;
 	}
 
-	channel_event_string = manager_build_channel_state_string(snapshot);
+	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 */
+		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) {
+		manager_event = "Newchannel";
+	}
+
+	if (old_snapshot && old_snapshot->state != new_snapshot->state) {
+		manager_event = "Newstate";
+	}
+
+	if (!was_hungup && is_hungup) {
+		manager_event = "Hangup";
+	}
+
+	/* Detect Newexten transitions
+	 *  - if new snapshot has an application set AND
+	 *    - first snapshot OR
+	 *    - if the old snapshot has no application (first Newexten) OR
+	 *    - if the context/priority/exten changes
+	 */
+	new_exten = !ast_strlen_zero(new_snapshot->appl) && (
+		!old_snapshot ||
+		ast_strlen_zero(old_snapshot->appl) ||
+		cep_has_changed(old_snapshot, new_snapshot));
+
+	if (manager_event || new_exten) {
+		channel_event_string =
+			manager_build_channel_state_string(new_snapshot);
+	}
 
 	if (!channel_event_string) {
 		return;
 	}
 
-	/* DEPRECATED: Extension field deprecated in 12; remove in 14 */
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-				<parameter name="Extension">
-					<para>Deprecated in 12, but kept for
-					backward compatability. Please use
-					'Exten' instead.</para>
-				</parameter>
-				<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>
-	***/
+	/* Channel state change events */
+	if (manager_event) {
+		manager_event(EVENT_FLAG_CALL, manager_event, "%s",
+			      ast_str_buffer(channel_event_string));
+	}
+
+	if (new_exten) {
+		/* DEPRECATED: Extension field deprecated in 12; remove in 14 */
+		/*** DOCUMENTATION
+			<managerEventInstance>
+				<synopsis>Raised when a channel enters a new context, extension, priority.</synopsis>
+				<syntax>
+					<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+					<parameter name="Extension">
+						<para>Deprecated in 12, but kept for
+						backward compatability. Please use
+						'Exten' instead.</para>
+					</parameter>
+					<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",
 		      "%s"
 		      "Extension: %s\r\n"
 		      "Application: %s\r\n"
 		      "AppData: %s\r\n",
 		      ast_str_buffer(channel_event_string),
-		      snapshot->exten, snapshot->appl, snapshot->data);
-}
-
-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 */
-		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) {
-		manager_event = "Newchannel";
-	}
-
-	if (old_snapshot && old_snapshot->state != new_snapshot->state) {
-		manager_event = "Newstate";
-	}
-
-	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);
-
-		channel_event_string =
-			manager_build_channel_state_string(new_snapshot);
-
-		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);
+		      new_snapshot->exten,
+		      new_snapshot->appl,
+		      new_snapshot->data);
 	}
 }
 




More information about the asterisk-commits mailing list