[asterisk-commits] mmichelson: branch mmichelson/atxfer_features r390755 - in /team/mmichelson/a...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jun 6 17:02:50 CDT 2013


Author: mmichelson
Date: Thu Jun  6 17:02:48 2013
New Revision: 390755

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390755
Log:
Resolve conflicts and reset automerge.


Added:
    team/mmichelson/atxfer_features/include/asterisk/features_config.h
      - copied unchanged from r390751, trunk/include/asterisk/features_config.h
    team/mmichelson/atxfer_features/main/features_config.c
      - copied unchanged from r390751, trunk/main/features_config.c
Modified:
    team/mmichelson/atxfer_features/   (props changed)
    team/mmichelson/atxfer_features/CHANGES
    team/mmichelson/atxfer_features/apps/app_bridgewait.c
    team/mmichelson/atxfer_features/channels/chan_sip.c
    team/mmichelson/atxfer_features/include/asterisk/stasis_message_router.h
    team/mmichelson/atxfer_features/main/bridging.c
    team/mmichelson/atxfer_features/main/features.c
    team/mmichelson/atxfer_features/main/manager.c
    team/mmichelson/atxfer_features/main/stasis_message_router.c
    team/mmichelson/atxfer_features/res/parking/parking_manager.c
    team/mmichelson/atxfer_features/res/res_agi.c

Propchange: team/mmichelson/atxfer_features/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/mmichelson/atxfer_features/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Jun  6 17:02:48 2013
@@ -1,1 +1,1 @@
-/trunk:1-390682
+/trunk:1-390753

Modified: team/mmichelson/atxfer_features/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/CHANGES?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/CHANGES (original)
+++ team/mmichelson/atxfer_features/CHANGES Thu Jun  6 17:02:48 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/mmichelson/atxfer_features/apps/app_bridgewait.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/apps/app_bridgewait.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/apps/app_bridgewait.c (original)
+++ team/mmichelson/atxfer_features/apps/app_bridgewait.c Thu Jun  6 17:02:48 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/mmichelson/atxfer_features/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/channels/chan_sip.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/channels/chan_sip.c (original)
+++ team/mmichelson/atxfer_features/channels/chan_sip.c Thu Jun  6 17:02:48 2013
@@ -25661,7 +25661,7 @@
 		enum ast_channel_state c_state = ast_channel_state(c);
 		RAII_VAR(struct ast_features_pickup_config *, pickup_cfg, ast_get_chan_features_pickup_config(c), ao2_cleanup);
 		const char *pickupexten;
-		
+
 		if (!pickup_cfg) {
 			ast_log(LOG_ERROR, "Unable to retrieve pickup configuration options. Unable to detect call pickup extension\n");
 			pickupexten = "";

Modified: team/mmichelson/atxfer_features/include/asterisk/stasis_message_router.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/include/asterisk/stasis_message_router.h?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/include/asterisk/stasis_message_router.h (original)
+++ team/mmichelson/atxfer_features/include/asterisk/stasis_message_router.h Thu Jun  6 17:02:48 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/mmichelson/atxfer_features/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/main/bridging.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/main/bridging.c (original)
+++ team/mmichelson/atxfer_features/main/bridging.c Thu Jun  6 17:02:48 2013
@@ -1921,6 +1921,7 @@
 	gen_cfg = ast_get_chan_features_general_config(bridge_channel->chan);
 	if (!gen_cfg) {
 		ast_log(LOG_ERROR, "Unable to retrieve features configuration.\n");
+		ast_channel_unlock(bridge_channel->chan);
 		return;
 	}
 	digit_timeout = gen_cfg->featuredigittimeout;
@@ -4637,17 +4638,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;
@@ -4660,14 +4661,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);
 }
 
 /*!
@@ -4676,11 +4677,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;
@@ -4692,7 +4693,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;
@@ -4702,13 +4703,13 @@
 	ast_heap_unlock(hooks);
 }
 
-void ast_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);
+void ast_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/mmichelson/atxfer_features/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/main/features.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/main/features.c (original)
+++ team/mmichelson/atxfer_features/main/features.c Thu Jun  6 17:02:48 2013
@@ -76,6 +76,7 @@
 #include "asterisk/bridging_basic.h"
 #include "asterisk/features_config.h"
 
+/* BUGBUG TEST_FRAMEWORK is disabled because parking tests no longer work. */
 #undef TEST_FRAMEWORK
 
 /*
@@ -3242,9 +3243,9 @@
 
 	res = 0;
 	if (ast_test_flag(flags, AST_FEATURE_REDIRECT)) {
+		/* Add atxfer and blind transfer. */
 		if (!builtin_feature_get_exten(chan, "blindxfer", dtmf, sizeof(dtmf))
 				&& !ast_strlen_zero(dtmf)) {
-		/* Add atxfer and blind transfer. */
 /* BUGBUG need to supply a blind transfer structure and destructor to use other than defaults */
 			res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_BLINDTRANSFER, dtmf,
 					NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
@@ -3259,26 +3260,26 @@
 	if (ast_test_flag(flags, AST_FEATURE_DISCONNECT) &&
 			!builtin_feature_get_exten(chan, "disconnect", dtmf, sizeof(dtmf)) &&
 			!ast_strlen_zero(dtmf)) {
-		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_HANGUP, dtmf, NULL, NULL,
-				AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
+		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_HANGUP, dtmf,
+				NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
 	}
 	if (ast_test_flag(flags, AST_FEATURE_PARKCALL) &&
 			!builtin_feature_get_exten(chan, "parkcall", dtmf, sizeof(dtmf)) &&
 			!ast_strlen_zero(dtmf)) {
-		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_PARKCALL, dtmf, NULL, NULL,
-				AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
+		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_PARKCALL, dtmf,
+				NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
 	}
 	if (ast_test_flag(flags, AST_FEATURE_AUTOMON) &&
 			!builtin_feature_get_exten(chan, "automon", dtmf, sizeof(dtmf)) &&
 			!ast_strlen_zero(dtmf)) {
-		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_AUTOMON, dtmf, NULL, NULL,
-				AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
+		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_AUTOMON, dtmf,
+				NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
 	}
 	if (ast_test_flag(flags, AST_FEATURE_AUTOMIXMON) &&
 			!builtin_feature_get_exten(chan, "automixmon", dtmf, sizeof(dtmf)) &&
 			!ast_strlen_zero(dtmf)) {
-		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_AUTOMIXMON, dtmf, NULL, NULL,
-				AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
+		res |= ast_bridge_features_enable(features, AST_BRIDGE_BUILTIN_AUTOMIXMON, dtmf,
+				NULL, NULL, AST_BRIDGE_HOOK_REMOVE_ON_PULL | AST_BRIDGE_HOOK_REMOVE_ON_PERSONALITY_CHANGE);
 	}
 
 #if 0	/* BUGBUG don't report errors untill all of the builtin features are supported. */
@@ -3375,7 +3376,7 @@
 	}
 
 	return ast_bridge_dtmf_hook(features, dtmf, app_dtmf_feature_hook,
-		app_data, ast_free_ptr, 1);
+		app_data, ast_free_ptr, AST_BRIDGE_HOOK_REMOVE_ON_PULL);
 }
 
 static int setup_dynamic_feature(void *obj, void *arg, void *data, int flags)
@@ -4389,10 +4390,16 @@
 	RAII_VAR(struct ast_bridge *, chan_bridge, NULL, ao2_cleanup);
 	RAII_VAR(struct ast_features_xfer_config *, xfer_cfg, NULL, ao2_cleanup);
 	struct ast_channel *bridge_chan = NULL;
+	const char *tone = NULL;
 
 	ast_channel_lock(chan);
 	chan_bridge = ast_channel_get_bridge(chan);
 	xfer_cfg = ast_get_chan_features_xfer_config(chan);
+	if (!xfer_cfg) {
+		ast_log(LOG_ERROR, "Unable to determine what tone to play to channel.\n");
+	} else {
+		tone = ast_strdupa(xfer_cfg->xfersound);
+	}
 	ast_channel_unlock(chan);
 
 	if (chan_bridge) {
@@ -4417,7 +4424,7 @@
 		}
 	}
 
-	if (play_tone && !ast_strlen_zero(xfer_cfg->xfersound)) {
+	if (play_tone && !ast_strlen_zero(tone)) {
 		struct ast_channel *play_chan = bridge_chan ?: chan;
 		RAII_VAR(struct ast_bridge_channel *, play_bridge_channel, NULL, ao2_cleanup);
 
@@ -4429,7 +4436,7 @@
 			ast_log(LOG_WARNING, "Unable to play tone for channel %s. Unable to get bridge channel\n",
 					ast_channel_name(play_chan));
 		} else {
-			ast_bridge_channel_queue_playfile(play_bridge_channel, NULL, xfer_cfg->xfersound, NULL);
+			ast_bridge_channel_queue_playfile(play_bridge_channel, NULL, tone, NULL);
 		}
 	}
 	return 0;
@@ -4818,8 +4825,12 @@
 
 	ast_debug(1, "pickup attempt by %s\n", ast_channel_name(chan));
 	ast_channel_lock(chan);
-	pickup_sound = ast_strdupa(pickup_cfg->pickupsound);
-	fail_sound = ast_strdupa(pickup_cfg->pickupfailsound);
+	pickup_cfg = ast_get_chan_features_pickup_config(chan);
+	if (!pickup_cfg) {
+		ast_log(LOG_ERROR, "Unable to retrieve pickup configuration. Unable to play pickup sounds\n");
+	}
+	pickup_sound = ast_strdupa(pickup_cfg ? pickup_cfg->pickupsound : "");
+	fail_sound = ast_strdupa(pickup_cfg ? pickup_cfg->pickupfailsound : "");
 	ast_channel_unlock(chan);
 
 	/* The found channel is already locked. */

Modified: team/mmichelson/atxfer_features/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/main/manager.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/main/manager.c (original)
+++ team/mmichelson/atxfer_features/main/manager.c Thu Jun  6 17:02:48 2013
@@ -4050,7 +4050,7 @@
 	const char *context = astman_get_header(m, "Context");
 	struct ast_channel *chan = NULL;
 	char feature_code[AST_FEATURE_MAX_LEN];
-	char *digit;
+	const char *digit;
 
 	if (ast_strlen_zero(name)) {
 		astman_send_error(s, m, "No channel specified");
@@ -4067,7 +4067,8 @@
 	}
 
 	ast_channel_lock(chan);
-	if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code))) {
+	if (ast_get_builtin_feature(chan, "atxfer", feature_code, sizeof(feature_code)) ||
+			ast_strlen_zero(feature_code)) {
 		ast_channel_unlock(chan);
 		astman_send_error(s, m, "No attended transfer feature code found");
 		ast_channel_unref(chan);
@@ -4079,12 +4080,13 @@
 		pbx_builtin_setvar_helper(chan, "TRANSFER_CONTEXT", context);
 	}
 
+/* BUGBUG action_atxfer() is broken because the bridge DTMF hooks need both begin and end events to match correctly. */
 	for (digit = feature_code; *digit; ++digit) {
 		struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit };
 		ast_queue_frame(chan, &f);
 	}
 
-	for (digit = (char *)exten; digit && *digit; ++digit) {
+	for (digit = exten; *digit; ++digit) {
 		struct ast_frame f = { AST_FRAME_DTMF, .subclass.integer = *digit };
 		ast_queue_frame(chan, &f);
 	}

Modified: team/mmichelson/atxfer_features/main/stasis_message_router.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/main/stasis_message_router.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/main/stasis_message_router.c (original)
+++ team/mmichelson/atxfer_features/main/stasis_message_router.c Thu Jun  6 17:02:48 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/mmichelson/atxfer_features/res/parking/parking_manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/res/parking/parking_manager.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/res/parking/parking_manager.c (original)
+++ team/mmichelson/atxfer_features/res/parking/parking_manager.c Thu Jun  6 17:02:48 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/mmichelson/atxfer_features/res/res_agi.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/atxfer_features/res/res_agi.c?view=diff&rev=390755&r1=390754&r2=390755
==============================================================================
--- team/mmichelson/atxfer_features/res/res_agi.c (original)
+++ team/mmichelson/atxfer_features/res/res_agi.c Thu Jun  6 17:02:48 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:

[... 189 lines stripped ...]



More information about the asterisk-commits mailing list