[asterisk-commits] rmudgett: branch rmudgett/bridge_phase r390740 - in /team/rmudgett/bridge_pha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 6 16:08:05 CDT 2013


Author: rmudgett
Date: Thu Jun  6 16:08:03 2013
New Revision: 390740

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390740
Log:
Resolve conflict.  Restart automerge.

Modified:
    team/rmudgett/bridge_phase/   (props changed)
    team/rmudgett/bridge_phase/CHANGES
    team/rmudgett/bridge_phase/apps/app_bridgewait.c
    team/rmudgett/bridge_phase/include/asterisk/stasis_message_router.h
    team/rmudgett/bridge_phase/main/bridging.c
    team/rmudgett/bridge_phase/main/features.c
    team/rmudgett/bridge_phase/main/stasis_message_router.c
    team/rmudgett/bridge_phase/res/parking/parking_manager.c
    team/rmudgett/bridge_phase/res/res_agi.c

Propchange: team/rmudgett/bridge_phase/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/rmudgett/bridge_phase/
------------------------------------------------------------------------------
--- bridge_phase-integrated (original)
+++ bridge_phase-integrated Thu Jun  6 16:08:03 2013
@@ -1,1 +1,1 @@
-/trunk:1-390692
+/trunk:1-390739

Modified: team/rmudgett/bridge_phase/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/CHANGES?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/CHANGES (original)
+++ team/rmudgett/bridge_phase/CHANGES Thu Jun  6 16:08:03 2013
@@ -105,6 +105,13 @@
  * The AMI 'Hold' event has been moved out of individual channel drivers, into
    core, and is now two events: Hold and Unhold.  The status field has been
    removed.
+
+AGI (Asterisk Gateway Interface)
+------------------
+ * The manager event AGIExec has been split into AGIExecStart and AGIExecEnd.
+
+ * The manager event AsyncAGI has been split into AsyncAGIStart, AsyncAGIExec,
+   and AsyncAGIEnd.
 
 Channel Drivers
 ------------------

Modified: team/rmudgett/bridge_phase/apps/app_bridgewait.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/apps/app_bridgewait.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/apps/app_bridgewait.c (original)
+++ team/rmudgett/bridge_phase/apps/app_bridgewait.c Thu Jun  6 16:08:03 2013
@@ -141,7 +141,7 @@
 
 	/* Limits struct holds time as milliseconds, so muliply 1000x */
 	hold_limits.duration *= 1000;
-	ast_bridge_features_set_limits(features, &hold_limits, 1 /* remove_on_pull */);
+	ast_bridge_features_set_limits(features, &hold_limits, AST_BRIDGE_HOOK_REMOVE_ON_PULL);
 	ast_bridge_features_limits_destroy(&hold_limits);
 
 	return 0;

Modified: team/rmudgett/bridge_phase/include/asterisk/stasis_message_router.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/include/asterisk/stasis_message_router.h?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/include/asterisk/stasis_message_router.h (original)
+++ team/rmudgett/bridge_phase/include/asterisk/stasis_message_router.h Thu Jun  6 16:08:03 2013
@@ -47,9 +47,12 @@
 
 /*!
  * \brief Create a new message router object.
+ *
  * \param topic Topic to subscribe route to.
+ *
  * \return New \ref stasis_message_router.
  * \return \c NULL on error.
+ *
  * \since 12
  */
 struct stasis_message_router *stasis_message_router_create(
@@ -59,6 +62,7 @@
  * \brief Unsubscribe the router from the upstream topic.
  *
  * \param router Router to unsubscribe.
+ *
  * \since 12
  */
 void stasis_message_router_unsubscribe(struct stasis_message_router *router);
@@ -71,6 +75,7 @@
  * vs. stasis_message_router_unsubscribe().
  *
  * \param router Router to unsubscribe.
+ *
  * \since 12
  */
 void stasis_message_router_unsubscribe_and_join(
@@ -80,6 +85,7 @@
  * \brief Returns whether \a router has received its final message.
  *
  * \param router Router.
+ *
  * \return True (non-zero) if stasis_subscription_final_message() has been
  *         received.
  * \return False (zero) if waiting for the end.
@@ -88,10 +94,15 @@
 
 /*!
  * \brief Add a route to a message router.
+ *
  * \param router Router to add the route to.
  * \param message_type Type of message to route.
  * \param callback Callback to forard messages of \a message_type to.
  * \param data Data pointer to pass to \a callback.
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
  * \since 12
  */
 int stasis_message_router_add(struct stasis_message_router *router,
@@ -100,10 +111,26 @@
 			      void *data);
 
 /*!
+ * \brief Remove a route from a message router.
+ *
+ * \param router Router to remove the route from.
+ * \param message_type Type of message to route.
+ *
+ * \since 12
+ */
+void stasis_message_router_remove(struct stasis_message_router *router,
+			      struct stasis_message_type *message_type);
+
+/*!
  * \brief Sets the default route of a router.
+ *
  * \param router Router to set the default route of.
  * \param callback Callback to forard messages which otherwise have no home.
  * \param data Data pointer to pass to \a callback.
+ *
+ * \retval 0 on success
+ * \retval -1 on failure
+ *
  * \since 12
  */
 int stasis_message_router_set_default(struct stasis_message_router *router,

Modified: team/rmudgett/bridge_phase/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridging.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/main/bridging.c (original)
+++ team/rmudgett/bridge_phase/main/bridging.c Thu Jun  6 16:08:03 2013
@@ -75,7 +75,7 @@
 
 static void cleanup_video_mode(struct ast_bridge *bridge);
 static int bridge_make_compatible(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel);
-static void bridge_features_remove(struct ast_bridge_features *features, enum ast_bridge_hook_remove_flags flags);
+static void bridge_features_remove(struct ast_bridge_features *features, enum ast_bridge_hook_remove_flags remove_flags);
 
 /*! Default DTMF keys for built in features */
 static char builtin_features_dtmf[AST_BRIDGE_BUILTIN_END][MAXIMUM_DTMF_FEATURE_STRING];
@@ -4951,17 +4951,17 @@
  *
  * \param obj Feature hook object.
  * \param arg Removal flags
- * \param unused Not used
+ * \param flags Not used
  *
  * \retval CMP_MATCH if hook's remove_flags match the removal flags set.
  * \retval 0 if not match.
  */
-static int hook_remove_match(void *obj, void *arg, int unused)
+static int hook_remove_match(void *obj, void *arg, int flags)
 {
 	struct ast_bridge_hook *hook = obj;
-	enum ast_bridge_hook_remove_flags *flags = arg;
-
-	if (ast_test_flag(&hook->remove_flags, *flags)) {
+	enum ast_bridge_hook_remove_flags *remove_flags = arg;
+
+	if (ast_test_flag(&hook->remove_flags, *remove_flags)) {
 		return CMP_MATCH;
 	} else {
 		return 0;
@@ -4974,14 +4974,14 @@
  * \since 12.0.0
  *
  * \param hooks Hooks container to work on.
- * \param flags Determinator for whether hook is removed
+ * \param remove_flags Determinator for whether hook is removed
  *
  * \return Nothing
  */
-static void hooks_remove_container(struct ao2_container *hooks, enum ast_bridge_hook_remove_flags flags)
+static void hooks_remove_container(struct ao2_container *hooks, enum ast_bridge_hook_remove_flags remove_flags)
 {
 	ao2_callback(hooks, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE,
-		hook_remove_match, &flags);
+		hook_remove_match, &remove_flags);
 }
 
 /*!
@@ -4990,11 +4990,11 @@
  * \since 12.0.0
  *
  * \param hooks Hooks heap to work on.
- * \param flags Determinator for whether hook is removed
+ * \param remove_flags Determinator for whether hook is removed
  *
  * \return Nothing
  */
-static void hooks_remove_heap(struct ast_heap *hooks, enum ast_bridge_hook_remove_flags flags)
+static void hooks_remove_heap(struct ast_heap *hooks, enum ast_bridge_hook_remove_flags remove_flags)
 {
 	struct ast_bridge_hook *hook;
 	int changed;
@@ -5006,7 +5006,7 @@
 		changed = 0;
 		for (idx = ast_heap_size(hooks); idx; --idx) {
 			hook = ast_heap_peek(hooks, idx);
-			if (ast_test_flag(&hook->remove_flags, flags)) {
+			if (ast_test_flag(&hook->remove_flags, remove_flags)) {
 				ast_heap_remove(hooks, hook);
 				ao2_ref(hook, -1);
 				changed = 1;
@@ -5022,17 +5022,17 @@
  * \since 12.0.0
  *
  * \param features Bridge features structure
- * \param flags Determinator for whether hook is removed.
+ * \param remove_flags Determinator for whether hook is removed.
  *
  * \return Nothing
  */
-static void bridge_features_remove(struct ast_bridge_features *features, enum ast_bridge_hook_remove_flags flags)
-{
-	hooks_remove_container(features->dtmf_hooks, flags);
-	hooks_remove_container(features->hangup_hooks, flags);
-	hooks_remove_container(features->join_hooks, flags);
-	hooks_remove_container(features->leave_hooks, flags);
-	hooks_remove_heap(features->interval_hooks, flags);
+static void bridge_features_remove(struct ast_bridge_features *features, enum ast_bridge_hook_remove_flags remove_flags)
+{
+	hooks_remove_container(features->dtmf_hooks, remove_flags);
+	hooks_remove_container(features->hangup_hooks, remove_flags);
+	hooks_remove_container(features->join_hooks, remove_flags);
+	hooks_remove_container(features->leave_hooks, remove_flags);
+	hooks_remove_heap(features->interval_hooks, remove_flags);
 }
 
 static int interval_hook_time_cmp(void *a, void *b)

Modified: team/rmudgett/bridge_phase/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/features.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/main/features.c (original)
+++ team/rmudgett/bridge_phase/main/features.c Thu Jun  6 16:08:03 2013
@@ -4207,7 +4207,7 @@
 	strcpy(&hook_data->app_name[hook_data->feature_offset], feature_name);/* Safe */
 
 	return ast_bridge_dtmf_hook(features, dtmf, dynamic_dtmf_hook_trip, hook_data,
-		ast_free_ptr, 1);
+		ast_free_ptr, AST_BRIDGE_HOOK_REMOVE_ON_PULL);
 }
 
 /*!

Modified: team/rmudgett/bridge_phase/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/stasis_message_router.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/main/stasis_message_router.c (original)
+++ team/rmudgett/bridge_phase/main/stasis_message_router.c Thu Jun  6 16:08:03 2013
@@ -33,8 +33,6 @@
 
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis_message_router.h"
-
-#define INITIAL_ROUTES_MAX 8
 
 /*! \internal */
 struct stasis_message_route {
@@ -54,36 +52,51 @@
 	route->message_type = NULL;
 }
 
+static int route_hash(const void *obj, const int flags)
+{
+	const struct stasis_message_route *route = obj;
+	const struct stasis_message_type *message_type = (flags & OBJ_KEY) ? obj : route->message_type;
+
+	return ast_str_hash(stasis_message_type_name(message_type));
+}
+
+static int route_cmp(void *obj, void *arg, int flags)
+{
+	const struct stasis_message_route *left = obj;
+	const struct stasis_message_route *right = arg;
+	const struct stasis_message_type *message_type = (flags & OBJ_KEY) ? arg : right->message_type;
+
+	return (left->message_type == message_type) ? CMP_MATCH | CMP_STOP : 0;
+}
+
 /*! \internal */
 struct stasis_message_router {
 	/*! Subscription to the upstream topic */
 	struct stasis_subscription *subscription;
-	/*! Variable length array of the routes */
-	struct stasis_message_route **routes;
+	/*! Subscribed routes */
+	struct ao2_container *routes;
 	/*! Route of last resort */
 	struct stasis_message_route *default_route;
-	/*! Allocated length of the routes array */
-	size_t num_routes_max;
-	/*! Current size of the routes array */
-	size_t num_routes_current;
 };
 
 static void router_dtor(void *obj)
 {
 	struct stasis_message_router *router = obj;
-	size_t i;
 
 	ast_assert(!stasis_subscription_is_subscribed(router->subscription));
 	ast_assert(stasis_subscription_is_done(router->subscription));
 	router->subscription = NULL;
-	for (i = 0; i < router->num_routes_current; ++i) {
-		ao2_cleanup(router->routes[i]);
-		router->routes[i] = NULL;
-	}
-	ast_free(router->routes);
+
+	ao2_cleanup(router->routes);
 	router->routes = NULL;
+
 	ao2_cleanup(router->default_route);
 	router->default_route = NULL;
+}
+
+static struct stasis_message_route *find_route(struct stasis_message_router *router, struct stasis_message_type *message_type)
+{
+	return ao2_find(router->routes, message_type, OBJ_KEY);
 }
 
 static void router_dispatch(void *data,
@@ -95,28 +108,14 @@
 	RAII_VAR(struct stasis_message_router *, router_needs_cleanup, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message_route *, route, NULL, ao2_cleanup);
 	struct stasis_message_type *type = stasis_message_type(message);
-	size_t i;
 
 	{
 		SCOPED_AO2LOCK(lock, router);
 
-		/* We don't expect many message types, so a simple loop should
-		 * be adequate, even if the complexity is O(n). Sorting the list
-		 * would be an easy way to bring that down to O(log(n)). Using a
-		 * hashtable/ao2_container could be even better. Just be sure to
-		 * profile before you optimize!
-		 */
-		route = router->default_route;
-		for (i = 0; i < router->num_routes_current; ++i) {
-			if (router->routes[i]->message_type == type) {
-				route = router->routes[i];
-				break;
+		if (!(route = find_route(router, type))) {
+			if ((route = router->default_route)) {
+				ao2_ref(route, +1);
 			}
-		}
-
-		/* Ref the route before leaving the scoped lock */
-		if (route) {
-			ao2_ref(route, +1);
 		}
 	}
 
@@ -141,10 +140,7 @@
 		return NULL;
 	}
 
-	router->num_routes_max = INITIAL_ROUTES_MAX;
-	router->routes = ast_calloc(router->num_routes_max,
-				    sizeof(*router->routes));
-	if (!router->routes) {
+	if (!(router->routes = ao2_container_alloc(7, route_hash, route_cmp))) {
 		return NULL;
 	}
 
@@ -212,31 +208,14 @@
 static int add_route(struct stasis_message_router *router,
 		     struct stasis_message_route *route)
 {
-	struct stasis_message_route **routes;
-	size_t i;
+	RAII_VAR(struct stasis_message_route *, existing_route, NULL, ao2_cleanup);
 	SCOPED_AO2LOCK(lock, router);
 
-	/* Check for route conflicts */
-	for (i = 0; i < router->num_routes_current; ++i) {
-		if (router->routes[i]->message_type == route->message_type) {
-			return -1;
-		}
-	}
-
-	/* Increase list size, if needed */
-	if (router->num_routes_current + 1 > router->num_routes_max) {
-		routes = realloc(router->routes,
-				 2 * router->num_routes_max * sizeof(*routes));
-		if (!routes) {
-			return -1;
-		}
-		router->routes = routes;
-		router->num_routes_max *= 2;
-	}
-
-
-	ao2_ref(route, +1);
-	router->routes[router->num_routes_current++] = route;
+	if ((existing_route = find_route(router, route->message_type))) {
+		return -1;
+	}
+
+	ao2_link(router->routes, route);
 	return 0;
 }
 
@@ -255,6 +234,14 @@
 	return add_route(router, route);
 }
 
+void stasis_message_router_remove(struct stasis_message_router *router,
+			      struct stasis_message_type *message_type)
+{
+	SCOPED_AO2LOCK(lock, router);
+
+	ao2_find(router->routes, message_type, OBJ_UNLINK | OBJ_NODATA | OBJ_KEY);
+}
+
 int stasis_message_router_set_default(struct stasis_message_router *router,
 				      stasis_subscription_cb callback,
 				      void *data)

Modified: team/rmudgett/bridge_phase/res/parking/parking_manager.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/parking/parking_manager.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/res/parking/parking_manager.c (original)
+++ team/rmudgett/bridge_phase/res/parking/parking_manager.c Thu Jun  6 16:08:03 2013
@@ -68,12 +68,12 @@
 		<managerEventInstance class="EVENT_FLAG_CALL">
 			<synopsis>Raised when a channel is parked.</synopsis>
 			<syntax>
-				<parameter name="ChannelParkee">
-				</parameter>
-				<parameter name="ChannelStateParkee">
+				<parameter name="ParkeeChannel">
+				</parameter>
+				<parameter name="ParkeeChannelState">
 					<para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
 				</parameter>
-				<parameter name="ChannelStateDescParkee">
+				<parameter name="ParkeeChannelStateDesc">
 					<enumlist>
 						<enum name="Down"/>
 						<enum name="Rsrvd"/>
@@ -88,30 +88,30 @@
 						<enum name="Unknown"/>
 					</enumlist>
 				</parameter>
-				<parameter name="CallerIDNumParkee">
-				</parameter>
-				<parameter name="CallerIDNameParkee">
-				</parameter>
-				<parameter name="ConnectedLineNumParkee">
-				</parameter>
-				<parameter name="ConnectedLineNameParkee">
-				</parameter>
-				<parameter name="AccountCodeParkee">
-				</parameter>
-				<parameter name="ContextParkee">
-				</parameter>
-				<parameter name="ExtenParkee">
-				</parameter>
-				<parameter name="PriorityParkee">
-				</parameter>
-				<parameter name="UniqueidParkee">
-				</parameter>
-				<parameter name="ChannelParker">
-				</parameter>
-				<parameter name="ChannelStateParker">
+				<parameter name="ParkeeCallerIDNum">
+				</parameter>
+				<parameter name="ParkeeCallerIDName">
+				</parameter>
+				<parameter name="ParkeeConnectedLineNum">
+				</parameter>
+				<parameter name="ParkeeConnectedLineName">
+				</parameter>
+				<parameter name="ParkeeAccountCode">
+				</parameter>
+				<parameter name="ParkeeContext">
+				</parameter>
+				<parameter name="ParkeeExten">
+				</parameter>
+				<parameter name="ParkeePriority">
+				</parameter>
+				<parameter name="ParkeeUniqueid">
+				</parameter>
+				<parameter name="ParkerChannel">
+				</parameter>
+				<parameter name="ParkerChannelState">
 				<para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
 				</parameter>
-				<parameter name="ChannelStateDescParker">
+				<parameter name="ParkerChannelStateDesc">
 					<enumlist>
 						<enum name="Down"/>
 						<enum name="Rsrvd"/>
@@ -126,23 +126,23 @@
 						<enum name="Unknown"/>
 					</enumlist>
 				</parameter>
-				<parameter name="CallerIDNumParker">
-				</parameter>
-				<parameter name="CallerIDNameParker">
-				</parameter>
-				<parameter name="ConnectedLineNumParker">
-				</parameter>
-				<parameter name="ConnectedLineNameParker">
-				</parameter>
-				<parameter name="AccountCodeParker">
-				</parameter>
-				<parameter name="ContextParker">
-				</parameter>
-				<parameter name="ExtenParker">
-				</parameter>
-				<parameter name="PriorityParker">
-				</parameter>
-				<parameter name="UniqueidParker">
+				<parameter name="ParkerCallerIDNum">
+				</parameter>
+				<parameter name="ParkerCallerIDName">
+				</parameter>
+				<parameter name="ParkerConnectedLineNum">
+				</parameter>
+				<parameter name="ParkerConnectedLineName">
+				</parameter>
+				<parameter name="ParkerAccountCode">
+				</parameter>
+				<parameter name="ParkerContext">
+				</parameter>
+				<parameter name="ParkerExten">
+				</parameter>
+				<parameter name="ParkerPriority">
+				</parameter>
+				<parameter name="ParkerUniqueid">
 				</parameter>
 				<parameter name="Parkinglot">
 					<para>Name of the parking lot that the parkee is parked in</para>
@@ -180,12 +180,12 @@
 			<synopsis>Raised when a channel leaves a parking lot because it was retrieved from the parking lot and reconnected.</synopsis>
 			<syntax>
 				<xi:include xpointer="xpointer(/docs/managerEvent[@name='ParkedCall']/managerEventInstance/syntax/parameter)" />
-				<parameter name="ChannelRetriever">
-				</parameter>
-				<parameter name="ChannelStateRetriever">
+				<parameter name="RetrieverChannel">
+				</parameter>
+				<parameter name="RetrieverChannelState">
 					<para>A numeric code for the channel's current state, related to ChannelStateDesc</para>
 				</parameter>
-				<parameter name="ChannelStateDescRetriever">
+				<parameter name="RetrieverChannelStateDesc">
 					<enumlist>
 						<enum name="Down"/>
 						<enum name="Rsrvd"/>
@@ -200,23 +200,23 @@
 						<enum name="Unknown"/>
 					</enumlist>
 				</parameter>
-				<parameter name="CallerIDNumRetriever">
-				</parameter>
-				<parameter name="CallerIDNameRetriever">
-				</parameter>
-				<parameter name="ConnectedLineNumRetriever">
-				</parameter>
-				<parameter name="ConnectedLineNameRetriever">
-				</parameter>
-				<parameter name="AccountCodeRetriever">
-				</parameter>
-				<parameter name="ContextRetriever">
-				</parameter>
-				<parameter name="ExtenRetriever">
-				</parameter>
-				<parameter name="PriorityRetriever">
-				</parameter>
-				<parameter name="UniqueidRetriever">
+				<parameter name="RetrieverCallerIDNum">
+				</parameter>
+				<parameter name="RetrieverCallerIDName">
+				</parameter>
+				<parameter name="RetrieverConnectedLineNum">
+				</parameter>
+				<parameter name="RetrieverConnectedLineName">
+				</parameter>
+				<parameter name="RetrieverAccountCode">
+				</parameter>
+				<parameter name="RetrieverContext">
+				</parameter>
+				<parameter name="RetrieverExten">
+				</parameter>
+				<parameter name="RetrieverPriority">
+				</parameter>
+				<parameter name="RetrieverUniqueid">
 				</parameter>
 			</syntax>
 		</managerEventInstance>

Modified: team/rmudgett/bridge_phase/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/res_agi.c?view=diff&rev=390740&r1=390739&r2=390740
==============================================================================
--- team/rmudgett/bridge_phase/res/res_agi.c (original)
+++ team/rmudgett/bridge_phase/res/res_agi.c Thu Jun  6 16:08:03 2013
@@ -66,6 +66,8 @@
 #include "asterisk/srv.h"
 #include "asterisk/test.h"
 #include "asterisk/netsock2.h"
+#include "asterisk/stasis_channels.h"
+#include "asterisk/stasis_message_router.h"
 
 #define AST_API_MODULE
 #include "asterisk/agi.h"
@@ -928,6 +930,68 @@
 			<para>Add an AGI command to the execute queue of the channel in Async AGI.</para>
 		</description>
 	</manager>
+	<managerEvent language="en_US" name="AsyncAGIStart">
+		<managerEventInstance class="EVENT_FLAG_AGI">
+			<synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Env">
+					<para>URL encoded string read from the AsyncAGI server.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AsyncAGIEnd">
+		<managerEventInstance class="EVENT_FLAG_AGI">
+			<synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AsyncAGIExec">
+		<managerEventInstance class="EVENT_FLAG_AGI">
+			<synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="CommandID" required="false">
+					<para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
+				</parameter>
+				<parameter name="Result">
+					<para>URL encoded result string from the executed AGI command.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AGIExecStart">
+		<managerEventInstance class="EVENT_FLAG_AGI">
+			<synopsis>Raised when a received AGI command starts processing.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Command">
+					<para>The AGI command as received from the external source.</para>
+				</parameter>
+				<parameter name="CommandId">
+					<para>Random identification number assigned to the execution of this command.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="AGIExecEnd">
+		<managerEventInstance class="EVENT_FLAG_AGI">
+			<synopsis>Raised when a received AGI command completes processing.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='AGIExecStart']/managerEventInstance/syntax/parameter)" />
+				<parameter name="ResultCode">
+					<para>The numeric result code from AGI</para>
+				</parameter>
+				<parameter name="Result">
+					<para>The text result reason from AGI</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
  ***/
 
 #define MAX_ARGS 128
@@ -962,6 +1026,44 @@
 	AGI_RESULT_NOTFOUND,
 	AGI_RESULT_HANGUP,
 };
+
+struct stasis_message_type *agi_exec_start_type(void);
+struct stasis_message_type *agi_exec_end_type(void);
+struct stasis_message_type *agi_async_start_type(void);
+struct stasis_message_type *agi_async_exec_type(void);
+struct stasis_message_type *agi_async_end_type(void);
+
+STASIS_MESSAGE_TYPE_DEFN(agi_exec_start_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_exec_end_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_start_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_exec_type);
+STASIS_MESSAGE_TYPE_DEFN(agi_async_end_type);
+
+static void agi_channel_manager_event(void *data,
+	struct stasis_subscription *sub, struct stasis_topic *topic,
+	struct stasis_message *message)
+{
+	const char *type = data;
+	struct ast_channel_blob *obj = stasis_message_data(message);
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	RAII_VAR(struct ast_str *, event_string, NULL, ast_free);
+
+	channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
+	if (!channel_event_string) {
+		return;
+	}
+
+	event_string = ast_manager_str_from_json_object(obj->blob, NULL);
+	if (!event_string) {
+		return;
+	}
+
+	manager_event(EVENT_FLAG_AGI, type,
+		"%s"
+		"%s",
+		ast_str_buffer(channel_event_string),
+		ast_str_buffer(event_string));
+}
 
 static agi_command *find_command(const char * const cmds[], int exact);
 
@@ -1300,6 +1402,7 @@
 	char ami_buffer[AMI_BUF_SIZE];
 	enum agi_result returnstatus = AGI_RESULT_SUCCESS;
 	AGI async_agi;
+	RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
 
 	if (efd) {
 		ast_log(LOG_WARNING, "Async AGI does not support Enhanced AGI yet\n");
@@ -1349,32 +1452,9 @@
 	   care of AGI commands on this channel can decide which AGI commands
 	   to execute based on the setup info */
 	ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel starts AsyncAGI command processing.</synopsis>
-			<syntax>
-				<parameter name="SubEvent">
-					<para>A sub event type, specifying the channel AsyncAGI processing status.</para>
-					<enumlist>
-						<enum name="Start"/>
-						<enum name="Exec"/>
-						<enum name="End"/>
-					</enumlist>
-				</parameter>
-				<parameter name="Env">
-					<para>URL encoded string read from the AsyncAGI server.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_AGI, "AsyncAGI",
-		"SubEvent: Start\r\n"
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"Env: %s\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan),
-		ami_buffer);
+	startblob = ast_json_pack("{s: s}", "Env", ami_buffer);
+	ast_channel_publish_blob(chan, agi_async_start_type(), startblob);
+
 	hungup = ast_check_hangup(chan);
 	for (;;) {
 		/*
@@ -1382,6 +1462,7 @@
 		 * the manager or the cli threads.
 		 */
 		while (!hungup) {
+			RAII_VAR(struct ast_json *, execblob, NULL, ast_json_unref);
 			res = get_agi_cmd(chan, &cmd);
 
 			if (res) {
@@ -1413,40 +1494,13 @@
 			 */
 			agi_buffer[res] = '\0';
 			ast_uri_encode(agi_buffer, ami_buffer, AMI_BUF_SIZE, ast_uri_http);
-			if (ast_strlen_zero(cmd->cmd_id)) {
-				manager_event(EVENT_FLAG_AGI, "AsyncAGI",
-					"SubEvent: Exec\r\n"
-					"Channel: %s\r\n"
-					"Uniqueid: %s\r\n"
-					"Result: %s\r\n",
-					ast_channel_name(chan),
-					ast_channel_uniqueid(chan),
-					ami_buffer);
-			} else {
-				/*** DOCUMENTATION
-					<managerEventInstance>
-						<synopsis>Raised when AsyncAGI completes an AGI command.</synopsis>
-						<syntax>
-							<parameter name="CommandID" required="false">
-								<para>Optional command ID sent by the AsyncAGI server to identify the command.</para>
-							</parameter>
-							<parameter name="Result">
-								<para>URL encoded result string from the executed AGI command.</para>
-							</parameter>
-						</syntax>
-					</managerEventInstance>
-				***/
-				manager_event(EVENT_FLAG_AGI, "AsyncAGI",
-					"SubEvent: Exec\r\n"
-					"Channel: %s\r\n"
-					"Uniqueid: %s\r\n"
-					"CommandID: %s\r\n"
-					"Result: %s\r\n",
-					ast_channel_name(chan),
-					ast_channel_uniqueid(chan),
-					cmd->cmd_id,
-					ami_buffer);
+
+			execblob = ast_json_pack("{s: s}", "Result", ami_buffer);
+			if (execblob && !ast_strlen_zero(cmd->cmd_id)) {
+				ast_json_object_set(execblob, "CommandId", ast_json_string_create(cmd->cmd_id));
 			}
+			ast_channel_publish_blob(chan, agi_async_exec_type(), execblob);
+
 			free_agi_cmd(cmd);
 
 			/*
@@ -1505,17 +1559,7 @@
 		ast_speech_destroy(async_agi.speech);
 	}
 	/* notify manager users this channel cannot be controlled anymore by Async AGI */
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a channel stops AsyncAGI command processing.</synopsis>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_AGI, "AsyncAGI",
-		"SubEvent: End\r\n"
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan));
+	ast_channel_publish_blob(chan, agi_async_end_type(), NULL);
 
 async_agi_abort:
 	/* close the pipe */
@@ -3546,47 +3590,34 @@
 	return 0;
 }
 
+static void publish_async_exec_end(struct ast_channel *chan, int command_id, const char *command, int result_code, const char *result)
+{
+	RAII_VAR(struct ast_json *, blob, NULL, ast_json_unref);
+	blob = ast_json_pack("{s: i, s: s, s: i, s: s}",
+			     "CommandId", command_id,
+			     "Command", command,
+			     "ResultCode", result_code,
+			     "Result", result);
+	ast_channel_publish_blob(chan, agi_exec_end_type(), blob);
+}
+
 static enum agi_result agi_handle_command(struct ast_channel *chan, AGI *agi, char *buf, int dead)
 {
 	const char *argv[MAX_ARGS];
 	int argc = MAX_ARGS;
 	int res;
 	agi_command *c;
+	char *ami_cmd = ast_strdupa(buf);
 	const char *ami_res;
-	char *ami_cmd = ast_strdupa(buf);
 	int command_id = ast_random();
-	int resultcode;
-
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a received AGI command starts processing.</synopsis>
-			<syntax>
-				<parameter name="SubEvent">
-					<para>A sub event type, specifying whether the AGI command has begun or ended.</para>
-					<enumlist>
-						<enum name="Start"/>
-						<enum name="End"/>
-					</enumlist>
-				</parameter>
-				<parameter name="CommandId">
-					<para>Random identification number assigned to the execution of this command.</para>
-				</parameter>
-				<parameter name="Command">
-					<para>The AGI command as received from the external source.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_AGI, "AGIExec",
-		"SubEvent: Start\r\n"
-		"Channel: %s\r\n"
-		"Uniqueid: %s\r\n"
-		"CommandId: %d\r\n"
-		"Command: %s\r\n",
-		ast_channel_name(chan),
-		ast_channel_uniqueid(chan),
-		command_id,
-		ami_cmd);
+	int resultcode = 0;
+	RAII_VAR(struct ast_json *, startblob, NULL, ast_json_unref);
+
+	startblob = ast_json_pack("{s: i, s: s}",
+			     "CommandId", command_id,
+			     "Command", ami_cmd);
+	ast_channel_publish_blob(chan, agi_exec_start_type(), startblob);
+
 	parse_args(buf, &argc, argv);
 	c = find_command(argv, 0);
 	if (c && (!dead || (dead && c->dead))) {
@@ -3606,42 +3637,9 @@
 		case RESULT_SHOWUSAGE:
 			ami_res = "Usage";
 			resultcode = 520;
-			break;
-		case RESULT_FAILURE:
-			ami_res = "Failure";
-			resultcode = -1;
-			break;
-		case ASYNC_AGI_BREAK:
-		case RESULT_SUCCESS:
-			ami_res = "Success";
-			resultcode = 200;
-			break;
-		default:
-			ami_res = "Unknown Result";
-			resultcode = 200;
-			break;
-		}
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when a received AGI command completes processing.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_AGI, "AGIExec",
-			"SubEvent: End\r\n"
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"CommandId: %d\r\n"
-			"Command: %s\r\n"
-			"ResultCode: %d\r\n"
-			"Result: %s\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			command_id,
-			ami_cmd,
-			resultcode,
-			ami_res);
-		switch (res) {
-		case RESULT_SHOWUSAGE:
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			if (ast_strlen_zero(c->usage)) {
 				ast_agi_send(agi->fd, chan, "520 Invalid command syntax.  Proper usage not available.\n");
 			} else {
@@ -3649,44 +3647,54 @@
 				ast_agi_send(agi->fd, chan, "%s", c->usage);
 				ast_agi_send(agi->fd, chan, "520 End of proper usage.\n");
 			}
+
 			break;
-		case ASYNC_AGI_BREAK:
-			return AGI_RESULT_SUCCESS_ASYNC;
 		case RESULT_FAILURE:
+			ami_res = "Failure";
+			resultcode = -1;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			/* The RESULT_FAILURE code is usually because the channel hungup. */
 			return AGI_RESULT_FAILURE;
+		case ASYNC_AGI_BREAK:
+			ami_res = "Success";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+			return AGI_RESULT_SUCCESS_ASYNC;
+		case RESULT_SUCCESS:
+			ami_res = "Success";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
+			break;
 		default:
+			ami_res = "Unknown Result";
+			resultcode = 200;
+
+			publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+
 			break;
 		}
 	} else if (c) {
-		ast_agi_send(agi->fd, chan, "511 Command Not Permitted on a dead channel\n");
-		manager_event(EVENT_FLAG_AGI, "AGIExec",
-			"SubEvent: End\r\n"
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"CommandId: %d\r\n"
-			"Command: %s\r\n"
-			"ResultCode: 511\r\n"
-			"Result: Command not permitted on a dead channel\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			command_id,
-			ami_cmd);
+		ami_res = "Command Not Permitted on a dead channel";
+		resultcode = 511;
+
+		ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+		publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
 	} else {
-		ast_agi_send(agi->fd, chan, "510 Invalid or unknown command\n");
-		manager_event(EVENT_FLAG_AGI, "AGIExec",
-			"SubEvent: End\r\n"
-			"Channel: %s\r\n"
-			"Uniqueid: %s\r\n"
-			"CommandId: %d\r\n"
-			"Command: %s\r\n"
-			"ResultCode: 510\r\n"
-			"Result: Invalid or unknown command\r\n",
-			ast_channel_name(chan),
-			ast_channel_uniqueid(chan),
-			command_id,
-			ami_cmd);
-	}
+		ami_res = "Invalid or unknown command";
+		resultcode = 510;
+
+		ast_agi_send(agi->fd, chan, "%d %s\n", resultcode, ami_res);
+
+		publish_async_exec_end(chan, command_id, ami_cmd, resultcode, ami_res);
+	}
+
 	return AGI_RESULT_SUCCESS;
 }
 static enum agi_result run_agi(struct ast_channel *chan, char *request, AGI *agi, int pid, int *status, int dead, int argc, char *argv[])
@@ -4228,6 +4236,23 @@
 
 static int unload_module(void)
 {
+	struct stasis_message_router *message_router;
+
+	message_router = ast_manager_get_message_router();
+	if (message_router) {
+		stasis_message_router_remove(message_router, agi_exec_start_type());
+		stasis_message_router_remove(message_router, agi_exec_end_type());
+		stasis_message_router_remove(message_router, agi_async_start_type());
+		stasis_message_router_remove(message_router, agi_async_exec_type());
+		stasis_message_router_remove(message_router, agi_async_end_type());
+	}
+
+	STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_start_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(agi_exec_end_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(agi_async_start_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(agi_async_exec_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(agi_async_end_type);
+
 	ast_cli_unregister_multiple(cli_agi, ARRAY_LEN(cli_agi));
 	/* we can safely ignore the result of ast_agi_unregister_multiple() here, since it cannot fail, as
 	   we know that these commands were registered by this module and are still registered
@@ -4242,6 +4267,44 @@
 
 static int load_module(void)
 {
+	struct stasis_message_router *message_router;
+
+	message_router = ast_manager_get_message_router();
+	if (!message_router) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	STASIS_MESSAGE_TYPE_INIT(agi_exec_start_type);
+	STASIS_MESSAGE_TYPE_INIT(agi_exec_end_type);
+	STASIS_MESSAGE_TYPE_INIT(agi_async_start_type);
+	STASIS_MESSAGE_TYPE_INIT(agi_async_exec_type);
+	STASIS_MESSAGE_TYPE_INIT(agi_async_end_type);
+
+	stasis_message_router_add(message_router,
+				  agi_exec_start_type(),
+				  agi_channel_manager_event,
+				  "AGIExecStart");
+
+	stasis_message_router_add(message_router,
+				  agi_exec_end_type(),
+				  agi_channel_manager_event,
+				  "AGIExecEnd");
+
+	stasis_message_router_add(message_router,
+				  agi_async_start_type(),
+				  agi_channel_manager_event,
+				  "AsyncAGIStart");
+
+	stasis_message_router_add(message_router,
+				  agi_async_exec_type(),
+				  agi_channel_manager_event,
+				  "AsyncAGIExec");
+
+	stasis_message_router_add(message_router,
+				  agi_async_end_type(),
+				  agi_channel_manager_event,
+				  "AsyncAGIEnd");
+
 	ast_cli_register_multiple(cli_agi, ARRAY_LEN(cli_agi));
 	/* we can safely ignore the result of ast_agi_register_multiple() here, since it cannot fail, as
 	   no other commands have been registered yet




More information about the asterisk-commits mailing list