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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Mar 11 12:03:06 CDT 2013


Author: dlee
Date: Mon Mar 11 12:03:02 2013
New Revision: 382802

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382802
Log:
Move Newexten events to Stasis

Modified:
    team/dlee/json_main/include/asterisk/pbx.h
    team/dlee/json_main/main/manager.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=382802&r1=382801&r2=382802
==============================================================================
--- team/dlee/json_main/include/asterisk/pbx.h (original)
+++ team/dlee/json_main/include/asterisk/pbx.h Mon Mar 11 12:03:02 2013
@@ -1422,6 +1422,14 @@
  */
 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.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/json_main/main/manager.c?view=diff&rev=382802&r1=382801&r2=382802
==============================================================================
--- team/dlee/json_main/main/manager.c (original)
+++ team/dlee/json_main/main/manager.c Mon Mar 11 12:03:02 2013
@@ -7591,8 +7591,37 @@
 		      eventname, uniqueid, body);
 }
 
-static void channel_event_cb(void *data, struct stasis_subscription *sub,
-			     struct stasis_topic *topic, struct stasis_message *message)
+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.
+ */
+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);
@@ -7607,6 +7636,9 @@
 		} 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);
 	}
 }
 
@@ -7730,7 +7762,7 @@
 	if (!channel_state_sub) {
 		channel_state_sub = stasis_subscribe(
 			stasis_caching_get_topic(ast_channel_topic_all_cached()),
-			channel_event_cb, NULL);
+			channel_message_cb, NULL);
 	}
 
 	if (!registered) {

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=382802&r1=382801&r2=382802
==============================================================================
--- team/dlee/json_main/main/pbx.c (original)
+++ team/dlee/json_main/main/pbx.c Mon Mar 11 12:03:02 2013
@@ -1199,6 +1199,14 @@
 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.
@@ -4655,8 +4663,9 @@
 	int res;
 	struct pbx_find_info q = { .stacklen = 0 }; /* the rest is reset in pbx_find_extension */
 	char passdata[EXT_DATA_SIZE];
-
 	int matching_action = (action == E_MATCH || action == E_CANMATCH || action == E_MATCHMORE);
+	RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 	ast_rdlock_contexts();
 	if (found)
@@ -4700,28 +4709,18 @@
 					COLORIZE(COLOR_BRMAGENTA, 0, passdata),
 					"in new stack");
 			}
-			/*** 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",
-					ast_channel_name(c), ast_channel_context(c), ast_channel_exten(c), ast_channel_priority(c), app->name, passdata, ast_channel_uniqueid(c));
+			snapshot = ast_channel_snapshot_create(c);
+			if (snapshot) {
+				/* pbx_exec sets application name and data, but we don't want to log
+				 * every exec. Just update the snapshot here instead.
+				 */
+				ast_string_field_set(snapshot, appl, app->name);
+				ast_string_field_set(snapshot, data, passdata);
+				msg = stasis_message_create(ast_pbx_newexten(), snapshot);
+				if (msg) {
+					stasis_publish(ast_channel_topic(c), msg);
+				}
+			}
 			return pbx_exec(c, app, passdata);	/* 0 on success, -1 on failure */
 		}
 	} else if (q.swo) {	/* not found here, but in another switch */
@@ -12229,6 +12228,8 @@
  */
 static void pbx_shutdown(void)
 {
+	ao2_cleanup(__newexten);
+	__newexten = NULL;
 	if (hints) {
 		ao2_ref(hints, -1);
 		hints = NULL;
@@ -12245,6 +12246,7 @@
 
 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=382802&r1=382801&r2=382802
==============================================================================
--- team/dlee/json_main/pbx/pbx_realtime.c (original)
+++ team/dlee/json_main/pbx/pbx_realtime.c Mon Mar 11 12:03:02 2013
@@ -345,6 +345,8 @@
 				char tmp1[80];
 				char tmp2[80];
 				char tmp3[EXT_DATA_SIZE];
+				RAII_VAR(struct ast_channel_snapshot *, snapshot, NULL, ao2_cleanup);
+				RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
 				appdata[0] = 0; /* just in case the substitute var func isn't called */
 				if(!ast_strlen_zero(tmp))
@@ -354,16 +356,18 @@
 						 term_color(tmp1, app, COLOR_BRCYAN, 0, sizeof(tmp1)),
 						 term_color(tmp2, ast_channel_name(chan), COLOR_BRMAGENTA, 0, sizeof(tmp2)),
 						 term_color(tmp3, S_OR(appdata, ""), COLOR_BRMAGENTA, 0, sizeof(tmp3)));
-				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",
-							  ast_channel_name(chan), ast_channel_context(chan), ast_channel_exten(chan), ast_channel_priority(chan), app, !ast_strlen_zero(appdata) ? appdata : "(NULL)", ast_channel_uniqueid(chan));
-				
+				snapshot = ast_channel_snapshot_create(chan);
+				if (snapshot) {
+					/* pbx_exec sets application name and data, but we don't want to log
+					 * every exec. Just update the snapshot here instead.
+					 */
+					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);
+					if (msg) {
+						stasis_publish(ast_channel_topic(chan), msg);
+					}
+				}
 				res = pbx_exec(chan, a, appdata);
 			} else
 				ast_log(LOG_NOTICE, "No such application '%s' for extension '%s' in context '%s'\n", app, exten, context);




More information about the asterisk-commits mailing list