[asterisk-commits] dlee: branch dlee/json_main r383262 - in /team/dlee/json_main: ./ main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Mar 15 18:34:26 CDT 2013


Author: dlee
Date: Fri Mar 15 18:34:21 2013
New Revision: 383262

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=383262
Log:
Put channel snapshot info in channel events.

Updated CHANGES file accordingly.

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

Modified: team/dlee/json_main/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/CHANGES?view=diff&rev=383262&r1=383261&r2=383262
==============================================================================
--- team/dlee/json_main/CHANGES (original)
+++ team/dlee/json_main/CHANGES Fri Mar 15 18:34:21 2013
@@ -40,6 +40,15 @@
    stopped, restarted, reversed, or skipped forward. When initiated by other
    mechanisms (such as the Playback application), the audio can be stopped,
    reversed, or skipped forward.
+
+ * Channel related events now contain a snapshot of channel state, adding new
+   fields to many of these events.
+
+ * The AMI event 'Newchannel' field 'Exten' is deprecated, and may be removed in
+   a future release. Please use the common 'Extension' field instead.
+
+ * The AMI event 'UserEvent' from app_userevent now contains the channel state
+   fields. The channel state fields will come before the body fields.
 
 Channel Drivers
 ------------------

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=383262&r1=383261&r2=383262
==============================================================================
--- team/dlee/json_main/main/manager_channels.c (original)
+++ team/dlee/json_main/main/manager_channels.c Fri Mar 15 18:34:21 2013
@@ -74,7 +74,12 @@
 				</parameter>
 				<parameter name="Context">
 				</parameter>
+				<parameter name="Extension">
+				</parameter>
 				<parameter name="Exten">
+					<para>Deprecated in 12, but kept for
+					backward compatability. Please use
+					'Extension' instead.</para>
 				</parameter>
 				<parameter name="Priority">
 				</parameter>
@@ -135,7 +140,7 @@
 		"ConnectedLineName: %s\r\n"
 		"AccountCode: %s\r\n"
 		"Context: %s\r\n"
-		"Exten: %s\r\n"
+		"Extension: %s\r\n"
 		"Priority: %d\r\n"
 		"Uniqueid: %s\r\n"
 		"Cause: %d\r\n"
@@ -164,6 +169,8 @@
 
 static void channel_newexten(struct ast_channel_snapshot *snapshot)
 {
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+
 	/*** DOCUMENTATION
 	<managerEvent language="en_US" name="Newchannel">
 		<managerEventInstance>
@@ -183,17 +190,20 @@
 		/* Channel's not in a valid state for a Newexten event yet */
 		return;
 	}
+
+	channel_event_string = manager_build_channel_state_string(snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
+
+	/* DEPRECATED: Extension field deprecated in 12 */
 	manager_event(EVENT_FLAG_DIALPLAN, "Newexten",
-		      "Channel: %s\r\n"
-		      "Context: %s\r\n"
-		      "Extension: %s\r\n"
-		      "Priority: %d\r\n"
+		      "%s"
 		      "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);
+		      "AppData: %s\r\n",
+		      ast_str_buffer(channel_event_string),
+		      snapshot->appl, snapshot->data);
 }
 
 static void channel_snapshot_update(void *data, struct stasis_subscription *sub,
@@ -204,6 +214,7 @@
 	struct ast_channel_snapshot *old_snapshot;
 	struct ast_channel_snapshot *new_snapshot;
 	int is_hungup, was_hungup;
+	int add_exten = 0;
 	char *manager_event = NULL;
 
 	if (ast_channel_snapshot() != update->type) {
@@ -223,6 +234,7 @@
 
 	if (!old_snapshot) {
 		manager_event = "Newchannel";
+		add_exten = 1;
 	}
 
 	if (old_snapshot && old_snapshot->state != new_snapshot->state) {
@@ -239,6 +251,12 @@
 
 		channel_event_string =
 			manager_build_channel_state_string(new_snapshot);
+
+		if (add_exten) {
+			ast_str_append(&channel_event_string, 0, "Exten: %s\r\n",
+				       new_snapshot->exten);
+		}
+
 		if (channel_event_string) {
 			manager_event(EVENT_FLAG_CALL, manager_event, "%s",
 				      ast_str_buffer(channel_event_string));
@@ -260,41 +278,49 @@
 
 static void channel_varset(struct ast_channel_blob *obj)
 {
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
 	const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
-	const char *name;
-	const char *uniqueid;
 
 	if (obj->snapshot) {
-		name = obj->snapshot->name;
-		uniqueid = obj->snapshot->uniqueid;
+		channel_event_string = manager_build_channel_state_string(obj->snapshot);
 	} else {
-		name = "none";
-		uniqueid = "none";
+		channel_event_string = ast_str_create(35);
+		ast_str_set(&channel_event_string, 0,
+			    "Channel: none\r\n"
+			    "Uniqueid: none\r\n");
+	}
+
+	if (!channel_event_string) {
+		return;
 	}
 
 	/*** DOCUMENTATION
 		<managerEventInstance>
 			<synopsis>Raised when a variable is set to a particular value.</synopsis>
 		</managerEventInstance>
-	***/
+o	***/
 	manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
-		      "Channel: %s\r\n"
+		      "%s"
 		      "Variable: %s\r\n"
-		      "Value: %s\r\n"
-		      "Uniqueid: %s\r\n",
-		      name, variable, value, uniqueid);
+		      "Value: %s\r\n",
+		      ast_str_buffer(channel_event_string),
+		      variable, value);
 }
 
 static void channel_userevent(struct ast_channel_blob *obj)
 {
-	const char *uniqueid;
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
 	const char *eventname;
 	const char *body;
 
-	uniqueid = obj->snapshot->uniqueid;
 	eventname = ast_json_string_get(ast_json_object_get(obj->blob, "eventname"));
 	body = ast_json_string_get(ast_json_object_get(obj->blob, "body"));
+	channel_event_string = manager_build_channel_state_string(obj->snapshot);
+
+	if (!channel_event_string) {
+		return;
+	}
 
 	/*** DOCUMENTATION
 		<managerEventInstance>
@@ -308,10 +334,10 @@
 		</managerEventInstance>
 	***/
 	manager_event(EVENT_FLAG_USER, "UserEvent",
+		      "%s"
 		      "UserEvent: %s\r\n"
-		      "Uniqueid: %s\r\n"
 		      "%s",
-		      eventname, uniqueid, body);
+		      ast_str_buffer(channel_event_string), eventname, body);
 }
 
 /*!




More information about the asterisk-commits mailing list