[asterisk-commits] kmoore: branch kmoore/stasis-bridging_events r389967 - in /team/kmoore/stasis...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue May 28 17:05:57 CDT 2013


Author: kmoore
Date: Tue May 28 17:05:54 2013
New Revision: 389967

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389967
Log:
The great renaming and some refactoring

Added:
    team/kmoore/stasis-bridging_events/res/stasis/channel_command.c
      - copied, changed from r389842, team/kmoore/stasis-bridging_events/res/stasis/command.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_command.h
      - copied, changed from r389842, team/kmoore/stasis-bridging_events/res/stasis/command.h
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.c
      - copied, changed from r389960, team/kmoore/stasis-bridging_events/res/stasis/control.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.h
      - copied, changed from r389960, team/kmoore/stasis-bridging_events/res/stasis/control.h
    team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c   (with props)
    team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.h   (with props)
Removed:
    team/kmoore/stasis-bridging_events/res/stasis/command.c
    team/kmoore/stasis-bridging_events/res/stasis/command.h
    team/kmoore/stasis-bridging_events/res/stasis/control.c
    team/kmoore/stasis-bridging_events/res/stasis/control.h
Modified:
    team/kmoore/stasis-bridging_events/include/asterisk/stasis_app.h
    team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h
    team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_playback.h
    team/kmoore/stasis-bridging_events/res/res_stasis.c
    team/kmoore/stasis-bridging_events/res/res_stasis_answer.c
    team/kmoore/stasis-bridging_events/res/res_stasis_playback.c
    team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c
    team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c
    team/kmoore/stasis-bridging_events/res/stasis_http/resource_bridges.c
    team/kmoore/stasis-bridging_events/res/stasis_http/resource_channels.c

Modified: team/kmoore/stasis-bridging_events/include/asterisk/stasis_app.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/include/asterisk/stasis_app.h?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/include/asterisk/stasis_app.h (original)
+++ team/kmoore/stasis-bridging_events/include/asterisk/stasis_app.h Tue May 28 17:05:54 2013
@@ -42,7 +42,7 @@
  * \ref stasis_app_send.
  *
  * Finally, Stasis apps control channels through the use of the \ref
- * stasis_app_control object, and the family of \c stasis_app_control_*
+ * stasis_app_channel_control object, and the family of \c stasis_app_channel_control_*
  * functions.
  *
  * Since module unload order is based on reference counting, any module that
@@ -106,7 +106,7 @@
 /*! @{ */
 
 /*! \brief Handler for controlling a channel that's in a Stasis application */
-struct stasis_app_control;
+struct stasis_app_channel_control;
 
 /*!
  * \brief Returns the handler for the given channel.
@@ -114,7 +114,7 @@
  * \return NULL channel not in Stasis application.
  * \return Pointer to \c res_stasis handler.
  */
-struct stasis_app_control *stasis_app_control_find_by_channel(
+struct stasis_app_channel_control *stasis_app_channel_control_find_by_channel(
 	const struct ast_channel *chan);
 
 /*!
@@ -123,7 +123,7 @@
  * \return NULL channel not in Stasis application, or channel does not exist.
  * \return Pointer to \c res_stasis handler.
  */
-struct stasis_app_control *stasis_app_control_find_by_channel_id(
+struct stasis_app_channel_control *stasis_app_channel_control_find_by_channel_id(
 	const char *channel_id);
 
 /*!
@@ -133,8 +133,8 @@
  * \return Uniqueid of the associate channel.
  * \return \c NULL if \a control is \c NULL.
  */
-const char *stasis_app_control_get_channel_id(
-	const struct stasis_app_control *control);
+const char *stasis_app_channel_control_get_channel_id(
+	const struct stasis_app_channel_control *control);
 
 /*!
  * \brief Exit \c res_stasis and continue execution in the dialplan.
@@ -143,7 +143,7 @@
  *
  * \param control Control for \c res_stasis
  */
-void stasis_app_control_continue(struct stasis_app_control *control);
+void stasis_app_channel_control_continue(struct stasis_app_channel_control *control);
 
 /*!
  * \brief Answer the channel associated with this control.
@@ -151,7 +151,7 @@
  * \return 0 for success.
  * \return Non-zero for error.
  */
-int stasis_app_control_answer(struct stasis_app_control *control);
+int stasis_app_channel_control_answer(struct stasis_app_channel_control *control);
 
 /*!
  * \brief Returns the most recent snapshot for the associated channel.
@@ -162,8 +162,8 @@
  * \return Most recent snapshot. ao2_cleanup() when done.
  * \return \c NULL if channel isn't in cache.
  */
-struct ast_channel_snapshot *stasis_app_control_get_snapshot(
-	const struct stasis_app_control *control);
+struct ast_channel_snapshot *stasis_app_channel_control_get_snapshot(
+	const struct stasis_app_channel_control *control);
 
 /*!
  * \brief Publish a message to the \a control's channel's topic.
@@ -171,8 +171,8 @@
  * \param control Control to publish to
  * \param message Message to publish
  */
-void stasis_app_control_publish(
-	struct stasis_app_control *control, struct stasis_message *message);
+void stasis_app_channel_control_publish(
+	struct stasis_app_channel_control *control, struct stasis_message *message);
 
 /*!
  * \brief Queue a control frame without payload.
@@ -183,7 +183,7 @@
  * \return zero on success
  * \return non-zero on failure
  */
-int stasis_app_control_queue_control(struct stasis_app_control *control,
+int stasis_app_channel_control_queue_control(struct stasis_app_channel_control *control,
 	enum ast_control_frame_type frame_type);
 
 /*! \brief Handler for controlling a bridge that is managed by a Stasis application */

Modified: team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h (original)
+++ team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h Tue May 28 17:05:54 2013
@@ -37,8 +37,8 @@
  * \brief Control a channel using \c stasis_app.
  *
  * This function blocks until the channel hangs up, or
- * stasis_app_control_continue() is called on the channel's \ref
- * stasis_app_control struct.
+ * stasis_app_channel_control_continue() is called on the channel's \ref
+ * stasis_app_channel_control struct.
  *
  * \param chan Channel to control with Stasis.
  * \param app_name Application controlling the channel.
@@ -49,7 +49,7 @@
 	char *argv[]);
 
 /*! Callback type for stasis app commands */
-typedef void *(*stasis_app_command_cb)(struct stasis_app_control *control,
+typedef void *(*stasis_app_channel_command_cb)(struct stasis_app_channel_control *control,
 	struct ast_channel *chan, void *data);
 
 /*!
@@ -66,8 +66,8 @@
  * \return Return value from \a command.
  * \return \c NULL on error.
  */
-void *stasis_app_send_command(struct stasis_app_control *control,
-	stasis_app_command_cb command, void *data);
+void *stasis_app_send_channel_command(struct stasis_app_channel_control *control,
+	stasis_app_channel_command_cb command, void *data);
 
 /*!
  * \since 12
@@ -82,16 +82,16 @@
  * \return 0 on success.
  * \return Non-zero on error.
  */
-int stasis_app_send_command_async(struct stasis_app_control *control,
-	stasis_app_command_cb command, void *data);
+int stasis_app_send_channel_command_async(struct stasis_app_channel_control *control,
+	stasis_app_channel_command_cb command, void *data);
 
 /*!
  * \since 12
  * \brief Control a bridge using \c stasis_app.
  *
  * This function blocks until the bridge hangs up, or
- * stasis_app_control_continue() is called on the bridge's \ref
- * stasis_app_control struct.
+ * stasis_app_channel_control_continue() is called on the bridge's \ref
+ * stasis_app_channel_control struct.
  *
  * \param bridge Channel to control with Stasis.
  * \param app_name Application controlling the bridge.

Modified: team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_playback.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_playback.h?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_playback.h (original)
+++ team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_playback.h Tue May 28 17:05:54 2013
@@ -84,8 +84,8 @@
  * \return Playback control object.
  * \return \c NULL on error.
  */
-struct stasis_app_playback *stasis_app_control_play_uri(
-	struct stasis_app_control *control, const char *file,
+struct stasis_app_playback *stasis_app_channel_control_play_uri(
+	struct stasis_app_channel_control *control, const char *file,
 	const char *language, int skipms, long offsetms);
 
 /*!

Modified: team/kmoore/stasis-bridging_events/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/res_stasis.c?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis.c (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis.c Tue May 28 17:05:54 2013
@@ -29,7 +29,7 @@
  * called by <code>app_stasis.so</code> to give control of a channel to the
  * Stasis application code from the dialplan.
  *
- * While a channel is in stasis_app_exec(), it has a \ref stasis_app_control
+ * While a channel is in stasis_app_exec(), it has a \ref stasis_app_channel_control
  * object, which may be used to control the channel.
  *
  * To control the channel, commands may be sent to channel using
@@ -65,9 +65,10 @@
 #include "asterisk/stasis_message_router.h"
 #include "asterisk/strings.h"
 #include "stasis/app.h"
-#include "stasis/control.h"
+#include "stasis/channel_control.h"
 #include "stasis/bridge_control.h"
 #include "stasis/bridge_command.h" /* for init and cleanup */
+#include "stasis/command_dispatch.h" /* for init and cleanup */
 #include "stasis_json/resource_events.h"
 
 /*! Time to wait for a frame in the application */
@@ -124,24 +125,24 @@
 	}
 }
 
-/*! AO2 hash function for \ref stasis_app_control */
+/*! AO2 hash function for \ref stasis_app_channel_control */
 static int control_hash(const void *obj, const int flags)
 {
-	const struct stasis_app_control *control = obj;
+	const struct stasis_app_channel_control *control = obj;
 	const char *id = flags & OBJ_KEY ?
-		obj : stasis_app_control_get_channel_id(control);
+		obj : stasis_app_channel_control_get_channel_id(control);
 
 	return ast_str_hash(id);
 }
 
-/*! AO2 comparison function for \ref stasis_app_control */
+/*! AO2 comparison function for \ref stasis_app_channel_control */
 static int control_compare(void *lhs, void *rhs, int flags)
 {
-	const struct stasis_app_control *lhs_control = lhs;
-	const struct stasis_app_control *rhs_control = rhs;
-	const char *lhs_id = stasis_app_control_get_channel_id(lhs_control);
+	const struct stasis_app_channel_control *lhs_control = lhs;
+	const struct stasis_app_channel_control *rhs_control = rhs;
+	const char *lhs_id = stasis_app_channel_control_get_channel_id(lhs_control);
 	const char *rhs_id = flags & OBJ_KEY ?
-		rhs : stasis_app_control_get_channel_id(rhs_control);
+		rhs : stasis_app_channel_control_get_channel_id(rhs_control);
 
 	if (strcmp(lhs_id, rhs_id) == 0) {
 		return CMP_MATCH | CMP_STOP;
@@ -150,18 +151,18 @@
 	}
 }
 
-struct stasis_app_control *stasis_app_control_find_by_channel(
+struct stasis_app_channel_control *stasis_app_channel_control_find_by_channel(
 	const struct ast_channel *chan)
 {
 	if (chan == NULL) {
 		return NULL;
 	}
 
-	return stasis_app_control_find_by_channel_id(
+	return stasis_app_channel_control_find_by_channel_id(
 		ast_channel_uniqueid(chan));
 }
 
-struct stasis_app_control *stasis_app_control_find_by_channel_id(
+struct stasis_app_channel_control *stasis_app_channel_control_find_by_channel_id(
 	const char *channel_id)
 {
 	return ao2_find(app_controls, channel_id, OBJ_KEY);
@@ -409,7 +410,7 @@
  * \brief In addition to running ao2_cleanup(), this function also removes the
  * object from the app_controls container.
  */
-static void control_unlink(struct stasis_app_control *control)
+static void control_unlink(struct stasis_app_channel_control *control)
 {
 	if (!control) {
 		return;
@@ -535,7 +536,7 @@
 	SCOPED_MODULE_USE(ast_module_info->self);
 
 	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
-	RAII_VAR(struct stasis_app_control *, control, NULL, control_unlink);
+	RAII_VAR(struct stasis_app_channel_control *, control, NULL, control_unlink);
 	int res = 0;
 
 	ast_assert(chan != NULL);
@@ -547,7 +548,7 @@
 		return -1;
 	}
 
-	control = control_create(chan);
+	control = channel_control_create(chan);
 	if (!control) {
 		ast_log(LOG_ERROR, "Allocated failed\n");
 		return -1;
@@ -566,12 +567,12 @@
 		return -1;
 	}
 
-	while (!control_is_done(control)) {
+	while (!channel_control_is_done(control)) {
 		RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
 		int r;
 		int command_count;
 
-		if (control_is_bridged(control)) {
+		if (channel_control_is_bridged(control)) {
 			r = 0;
 			usleep(MAX_WAIT_MS);
 		} else {
@@ -584,14 +585,14 @@
 			break;
 		}
 
-		command_count = control_dispatch_all(control, chan);
+		command_count = channel_control_dispatch_all(control, chan);
 
 		if (command_count > 0 && ast_channel_fdno(chan) == -1) {
 			/* Command drained the channel; wait for next frame */
 			continue;
 		}
 
-		if (r == 0 || control_is_bridged(control)) {
+		if (r == 0 || channel_control_is_bridged(control)) {
 			/* Timeout */
 			continue;
 		}
@@ -610,7 +611,7 @@
 				/* Continue on in the dialplan */
 				ast_debug(3, "%s: Hangup\n",
 					ast_channel_uniqueid(chan));
-				control_continue(control);
+				channel_control_continue(control);
 			}
 			break;
 		default:
@@ -984,6 +985,10 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
+	if (command_dispatch_init()) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
 	if (bridge_command_init()) {
 		return AST_MODULE_LOAD_FAILURE;
 	}

Modified: team/kmoore/stasis-bridging_events/res/res_stasis_answer.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/res_stasis_answer.c?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis_answer.c (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis_answer.c Tue May 28 17:05:54 2013
@@ -38,28 +38,28 @@
 static int OK = 0;
 static int FAIL = -1;
 
-static void *app_control_answer(struct stasis_app_control *control,
+static void *app_control_answer(struct stasis_app_channel_control *control,
 	struct ast_channel *chan, void *data)
 {
 	const int delay = 0;
 	const int cdr_answer = 1;
 	ast_debug(3, "%s: Answering",
-		stasis_app_control_get_channel_id(control));
+		stasis_app_channel_control_get_channel_id(control));
 	return __ast_answer(chan, delay, cdr_answer) == 0 ? &OK : &FAIL;
 }
 
-int stasis_app_control_answer(struct stasis_app_control *control)
+int stasis_app_channel_control_answer(struct stasis_app_channel_control *control)
 {
 	int *retval;
 
 	ast_debug(3, "%s: Sending answer command\n",
-		stasis_app_control_get_channel_id(control));
+		stasis_app_channel_control_get_channel_id(control));
 
-	retval = stasis_app_send_command(control, app_control_answer, NULL);
+	retval = stasis_app_send_channel_command(control, app_control_answer, NULL);
 
 	if (retval == NULL || *retval != 0) {
 		ast_log(LOG_WARNING, "%s: Failed to answer channel",
-			stasis_app_control_get_channel_id(control));
+			stasis_app_channel_control_get_channel_id(control));
 		return -1;
 	}
 

Modified: team/kmoore/stasis-bridging_events/res/res_stasis_playback.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/res_stasis_playback.c?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis_playback.c (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis_playback.c Tue May 28 17:05:54 2013
@@ -65,7 +65,7 @@
 		AST_STRING_FIELD(language);	/*!< Preferred language */
 		);
 	/*! Control object for the channel we're playing back to */
-	struct stasis_app_control *control;
+	struct stasis_app_channel_control *control;
 	/*! Number of milliseconds to skip before playing */
 	long offsetms;
 	/*! Number of milliseconds to skip for forward/reverse operations */
@@ -133,13 +133,13 @@
 	}
 
 	message = ast_channel_blob_create_from_cache(
-		stasis_app_control_get_channel_id(playback->control),
+		stasis_app_channel_control_get_channel_id(playback->control),
 		stasis_app_playback_snapshot_type(), json);
 	if (message == NULL) {
 		return;
 	}
 
-	stasis_app_control_publish(playback->control, message);
+	stasis_app_channel_control_publish(playback->control, message);
 }
 
 static void playback_cleanup(struct stasis_app_playback *playback)
@@ -189,7 +189,7 @@
 	playback_publish(playback);
 }
 
-static void *play_uri(struct stasis_app_control *control,
+static void *play_uri(struct stasis_app_channel_control *control,
 	struct ast_channel *chan, void *data)
 {
 	RAII_VAR(struct stasis_app_playback *, playback, NULL,
@@ -251,8 +251,8 @@
 	ast_string_field_free_memory(playback);
 }
 
-struct stasis_app_playback *stasis_app_control_play_uri(
-	struct stasis_app_control *control, const char *uri,
+struct stasis_app_playback *stasis_app_channel_control_play_uri(
+	struct stasis_app_channel_control *control, const char *uri,
 	const char *language, int skipms, long offsetms)
 {
 	RAII_VAR(struct stasis_app_playback *, playback, NULL, ao2_cleanup);
@@ -263,7 +263,7 @@
 	}
 
 	ast_debug(3, "%s: Sending play(%s) command\n",
-		stasis_app_control_get_channel_id(control), uri);
+		stasis_app_channel_control_get_channel_id(control), uri);
 
 	playback = ao2_alloc(sizeof(*playback), playback_dtor);
 	if (!playback || ast_string_field_init(playback, 128)) {
@@ -287,7 +287,7 @@
 	playback_publish(playback);
 
 	/* A ref is kept in the playbacks container; no need to bump */
-	stasis_app_send_command_async(control, play_uri, playback);
+	stasis_app_send_channel_command_async(control, play_uri, playback);
 
 	/* Although this should be bumped for the caller */
 	ao2_ref(playback, +1);
@@ -357,13 +357,13 @@
 {
 	SCOPED_AO2LOCK(lock, playback);
 	playback->state = STASIS_PLAYBACK_STATE_STOPPED;
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_STOP);
 }
 
 static int playback_restart(struct stasis_app_playback *playback)
 {
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_RESTART);
 }
 
@@ -372,7 +372,7 @@
 	SCOPED_AO2LOCK(lock, playback);
 	playback->state = STASIS_PLAYBACK_STATE_PAUSED;
 	playback_publish(playback);
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_SUSPEND);
 }
 
@@ -381,19 +381,19 @@
 	SCOPED_AO2LOCK(lock, playback);
 	playback->state = STASIS_PLAYBACK_STATE_PLAYING;
 	playback_publish(playback);
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_SUSPEND);
 }
 
 static int playback_reverse(struct stasis_app_playback *playback)
 {
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_REVERSE);
 }
 
 static int playback_forward(struct stasis_app_playback *playback)
 {
-	return stasis_app_control_queue_control(playback->control,
+	return stasis_app_channel_control_queue_control(playback->control,
 		AST_CONTROL_STREAM_FORWARD);
 }
 

Modified: team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c Tue May 28 17:05:54 2013
@@ -28,10 +28,10 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "bridge_command.h"
+#include "command_dispatch.h"
 
 #include "asterisk/lock.h"
 #include "asterisk/stasis.h"
-#include "asterisk/stasis_message_router.h"
 #include "asterisk/stasis_app_impl.h"
 
 struct stasis_app_bridge_command {
@@ -100,10 +100,8 @@
 	bridge_command_complete(command, retval);
 }
 
-struct stasis_topic *bridge_command_topic;
 struct stasis_message_type *bridge_command_type(void);
 STASIS_MESSAGE_TYPE_DEFN(bridge_command_type);
-struct stasis_message_router *bridge_command_router;
 
 static void bridge_command_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
 {
@@ -113,42 +111,18 @@
 
 int bridge_command_queue(struct stasis_app_bridge_command *command)
 {
-	RAII_VAR(struct stasis_message *, msg, stasis_message_create(bridge_command_type(), command), ao2_cleanup);
-	if (!msg) {
-		return -1;
-	}
-	stasis_publish(bridge_command_topic, msg);
-	return 0;
+	return command_dispatch_send(bridge_command_type(), command);
 }
 
 int bridge_command_init(void)
 {
-	int res = 0;
 	if (STASIS_MESSAGE_TYPE_INIT(bridge_command_type)) {
 		return -1;
 	}
-	bridge_command_topic = stasis_topic_create("bridge_command_topic");
-	if (!bridge_command_topic) {
-		return -1;
-	}
-	bridge_command_router = stasis_message_router_create(bridge_command_topic);
-	if (!bridge_command_router) {
-		return -1;
-	}
-
-	res = stasis_message_router_add(bridge_command_router, bridge_command_type(), bridge_command_cb, NULL);
-	if (res) {
-		return -1;
-	}
-
-	return 0;
+	return command_dispatch_register(bridge_command_type(), bridge_command_cb);
 }
 
 void bridge_command_cleanup(void)
 {
-	stasis_message_router_unsubscribe(bridge_command_router);
-	bridge_command_router = NULL;
-	ao2_cleanup(bridge_command_topic);
-	bridge_command_topic = NULL;
 	STASIS_MESSAGE_TYPE_CLEANUP(bridge_command_type);
 }

Modified: team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c?view=diff&rev=389967&r1=389966&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c Tue May 28 17:05:54 2013
@@ -31,7 +31,7 @@
 
 #include "bridge_command.h"
 #include "bridge_control.h"
-#include "control.h"
+#include "channel_control.h"
 
 static int OK = 0;
 static int FAIL = -1;
@@ -181,10 +181,10 @@
 
 static int bridge_depart_cb(struct ast_bridge *bridge, struct ast_bridge_channel *bridge_channel, void *hook_pvt)
 {
-	RAII_VAR(struct stasis_app_control *, channel_control,
-		stasis_app_control_find_by_channel(bridge_channel->chan), ao2_cleanup);
-	control_restore_pbx(channel_control);
-	control_set_bridged(channel_control, 0);
+	RAII_VAR(struct stasis_app_channel_control *, channel_control,
+		stasis_app_channel_control_find_by_channel(bridge_channel->chan), ao2_cleanup);
+	channel_control_restore_pbx(channel_control);
+	channel_control_set_bridged(channel_control, 0);
 	return -1;
 }
 
@@ -193,8 +193,8 @@
 	void *data)
 {
 	struct ast_channel *channel = data;
-	RAII_VAR(struct stasis_app_control *, channel_control,
-		stasis_app_control_find_by_channel(channel), ao2_cleanup);
+	RAII_VAR(struct stasis_app_channel_control *, channel_control,
+		stasis_app_channel_control_find_by_channel(channel), ao2_cleanup);
 	int res;
 	struct ast_bridge_features *features = ast_bridge_features_new();
 	if (!features) {
@@ -202,13 +202,13 @@
 	}
 
 	ast_bridge_leave_hook(features, bridge_depart_cb, NULL, NULL, 1);
-	control_strip_pbx(channel_control);
+	channel_control_strip_pbx(channel_control);
 
 	res = ast_bridge_impart(control->bridge, channel, NULL, features, 0);
 	if (res) {
-		control_restore_pbx(channel_control);
+		channel_control_restore_pbx(channel_control);
 	} else {
-		control_set_bridged(channel_control, 1);
+		channel_control_set_bridged(channel_control, 1);
 	}
 
 	return !res ? &OK : &FAIL;

Copied: team/kmoore/stasis-bridging_events/res/stasis/channel_command.c (from r389842, team/kmoore/stasis-bridging_events/res/stasis/command.c)
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_command.c?view=diff&rev=389967&p1=team/kmoore/stasis-bridging_events/res/stasis/command.c&r1=389842&p2=team/kmoore/stasis-bridging_events/res/stasis/channel_command.c&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/command.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_command.c Tue May 28 17:05:54 2013
@@ -27,33 +27,33 @@
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
-#include "command.h"
+#include "channel_command.h"
 
 #include "asterisk/lock.h"
 #include "asterisk/stasis_app_impl.h"
 
-struct stasis_app_command {
+struct stasis_app_channel_command {
 	ast_mutex_t lock;
 	ast_cond_t condition;
-	stasis_app_command_cb callback;
+	stasis_app_channel_command_cb callback;
 	void *data;
 	void *retval;
 	int is_done:1;
 };
 
-static void command_dtor(void *obj)
+static void channel_command_dtor(void *obj)
 {
-	struct stasis_app_command *command = obj;
+	struct stasis_app_channel_command *command = obj;
 	ast_mutex_destroy(&command->lock);
 	ast_cond_destroy(&command->condition);
 }
 
-struct stasis_app_command *command_create(
-	stasis_app_command_cb callback, void *data)
+struct stasis_app_channel_command *channel_command_create(
+	stasis_app_channel_command_cb callback, void *data)
 {
-	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
 
-	command = ao2_alloc(sizeof(*command), command_dtor);
+	command = ao2_alloc(sizeof(*command), channel_command_dtor);
 	if (!command) {
 		return NULL;
 	}
@@ -67,7 +67,7 @@
 	return command;
 }
 
-static void command_complete(struct stasis_app_command *command, void *retval)
+static void channel_command_complete(struct stasis_app_channel_command *command, void *retval)
 {
 	SCOPED_MUTEX(lock, &command->lock);
 
@@ -76,7 +76,7 @@
 	ast_cond_signal(&command->condition);
 }
 
-void *command_join(struct stasis_app_command *command)
+void *channel_command_join(struct stasis_app_channel_command *command)
 {
 	SCOPED_MUTEX(lock, &command->lock);
 	while (!command->is_done) {
@@ -86,10 +86,10 @@
 	return command->retval;
 }
 
-void command_invoke(struct stasis_app_command *command,
-	struct stasis_app_control *control, struct ast_channel *chan)
+void channel_command_invoke(struct stasis_app_channel_command *command,
+	struct stasis_app_channel_control *control, struct ast_channel *chan)
 {
 	void *retval = command->callback(control, chan, command->data);
-	command_complete(command, retval);
+	channel_command_complete(command, retval);
 }
 

Copied: team/kmoore/stasis-bridging_events/res/stasis/channel_command.h (from r389842, team/kmoore/stasis-bridging_events/res/stasis/command.h)
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_command.h?view=diff&rev=389967&p1=team/kmoore/stasis-bridging_events/res/stasis/command.h&r1=389842&p2=team/kmoore/stasis-bridging_events/res/stasis/channel_command.h&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/command.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_command.h Tue May 28 17:05:54 2013
@@ -29,14 +29,14 @@
 
 #include "asterisk/stasis_app_impl.h"
 
-struct stasis_app_command;
+struct stasis_app_channel_command;
 
-struct stasis_app_command *command_create(
-	stasis_app_command_cb callback, void *data);
+struct stasis_app_channel_command *channel_command_create(
+	stasis_app_channel_command_cb callback, void *data);
 
-void command_invoke(struct stasis_app_command *command,
-	struct stasis_app_control *control, struct ast_channel *chan);
+void channel_command_invoke(struct stasis_app_channel_command *command,
+	struct stasis_app_channel_control *control, struct ast_channel *chan);
 
-void *command_join(struct stasis_app_command *command);
+void *channel_command_join(struct stasis_app_channel_command *command);
 
 #endif /* _ASTERISK_RES_STASIS_CONTROL_H */

Copied: team/kmoore/stasis-bridging_events/res/stasis/channel_control.c (from r389960, team/kmoore/stasis-bridging_events/res/stasis/control.c)
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.c?view=diff&rev=389967&p1=team/kmoore/stasis-bridging_events/res/stasis/control.c&r1=389960&p2=team/kmoore/stasis-bridging_events/res/stasis/channel_control.c&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.c Tue May 28 17:05:54 2013
@@ -29,11 +29,11 @@
 
 #include "asterisk/stasis_channels.h"
 
-#include "command.h"
-#include "control.h"
+#include "channel_command.h"
+#include "channel_control.h"
 
 /* XXX needs a destructor */
-struct stasis_app_control {
+struct stasis_app_channel_control {
 	/*! Queue of commands to dispatch on the channel */
 	struct ao2_container *command_queue;
 	/*!
@@ -50,9 +50,9 @@
 	int bridged;
 };
 
-struct stasis_app_control *control_create(struct ast_channel *channel)
-{
-	struct stasis_app_control *control;
+struct stasis_app_channel_control *channel_control_create(struct ast_channel *channel)
+{
+	struct stasis_app_channel_control *control;
 
 	control = ao2_alloc(sizeof(*control), NULL);
 	if (!control) {
@@ -67,13 +67,13 @@
 	return control;
 }
 
-static struct stasis_app_command *exec_command(
-	struct stasis_app_control *control, stasis_app_command_cb command_fn,
+static struct stasis_app_channel_command *exec_channel_command(
+	struct stasis_app_channel_control *control, stasis_app_channel_command_cb command_fn,
 	void *data)
 {
-	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
-
-	command = command_create(command_fn, data);
+	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
+
+	command = channel_command_create(command_fn, data);
 
 	if (!command) {
 		return NULL;
@@ -86,13 +86,13 @@
 	return command;
 }
 
-int control_is_done(struct stasis_app_control *control)
+int channel_control_is_done(struct stasis_app_channel_control *control)
 {
 	/* Called from stasis_app_exec thread; no lock needed */
 	return control->is_done;
 }
 
-static void *app_control_continue(struct stasis_app_control *control,
+static void *app_channel_control_continue(struct stasis_app_channel_control *control,
 	struct ast_channel *chan, void *data)
 {
 	/* Called from stasis_app_exec thread; no lock needed */
@@ -100,13 +100,13 @@
 	return NULL;
 }
 
-void stasis_app_control_continue(struct stasis_app_control *control)
-{
-	stasis_app_send_command_async(control, app_control_continue, NULL);
-}
-
-struct ast_channel_snapshot *stasis_app_control_get_snapshot(
-	const struct stasis_app_control *control)
+void stasis_app_channel_control_continue(struct stasis_app_channel_control *control)
+{
+	stasis_app_send_channel_command_async(control, app_channel_control_continue, NULL);
+}
+
+struct ast_channel_snapshot *stasis_app_channel_control_get_snapshot(
+	const struct stasis_app_channel_control *control)
 {
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 	struct stasis_caching_topic *caching_topic;
@@ -116,7 +116,7 @@
 	ast_assert(caching_topic != NULL);
 
 	msg = stasis_cache_get(caching_topic, ast_channel_snapshot_type(),
-		stasis_app_control_get_channel_id(control));
+		stasis_app_channel_control_get_channel_id(control));
 	if (!msg) {
 		return NULL;
 	}
@@ -128,33 +128,33 @@
 	return snapshot;
 }
 
-void *stasis_app_send_command(struct stasis_app_control *control,
-	stasis_app_command_cb command_fn, void *data)
-{
-	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
+void *stasis_app_send_channel_command(struct stasis_app_channel_control *control,
+	stasis_app_channel_command_cb command_fn, void *data)
+{
+	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
 
 	if (control == NULL) {
 		return NULL;
 	}
 
-	command = exec_command(control, command_fn, data);
+	command = exec_channel_command(control, command_fn, data);
 	if (!command) {
 		return NULL;
 	}
 
-	return command_join(command);
-}
-
-int stasis_app_send_command_async(struct stasis_app_control *control,
-	stasis_app_command_cb command_fn, void *data)
-{
-	RAII_VAR(struct stasis_app_command *, command, NULL, ao2_cleanup);
+	return channel_command_join(command);
+}
+
+int stasis_app_send_channel_command_async(struct stasis_app_channel_control *control,
+	stasis_app_channel_command_cb command_fn, void *data)
+{
+	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
 
 	if (control == NULL) {
 		return -1;
 	}
 
-	command = exec_command(control, command_fn, data);
+	command = exec_channel_command(control, command_fn, data);
 	if (!command) {
 		return -1;
 	}
@@ -162,14 +162,14 @@
 	return 0;
 }
 
-const char *stasis_app_control_get_channel_id(
-	const struct stasis_app_control *control)
+const char *stasis_app_channel_control_get_channel_id(
+	const struct stasis_app_channel_control *control)
 {
 	return ast_channel_uniqueid(control->channel);
 }
 
-void stasis_app_control_publish(
-	struct stasis_app_control *control, struct stasis_message *message)
+void stasis_app_channel_control_publish(
+	struct stasis_app_channel_control *control, struct stasis_message *message)
 {
 	if (!control || !control->channel || !message) {
 		return;
@@ -177,13 +177,13 @@
 	stasis_publish(ast_channel_topic(control->channel), message);
 }
 
-int stasis_app_control_queue_control(struct stasis_app_control *control,
+int stasis_app_channel_control_queue_control(struct stasis_app_channel_control *control,
 	enum ast_control_frame_type frame_type)
 {
 	return ast_queue_control(control->channel, frame_type);
 }
 
-int control_dispatch_all(struct stasis_app_control *control,
+int channel_control_dispatch_all(struct stasis_app_channel_control *control,
 	struct ast_channel *chan)
 {
 	int count = 0;
@@ -195,8 +195,8 @@
 	i = ao2_iterator_init(control->command_queue, AO2_ITERATOR_UNLINK);
 
 	while ((obj = ao2_iterator_next(&i))) {
-		RAII_VAR(struct stasis_app_command *, command, obj, ao2_cleanup);
-		command_invoke(command, control, chan);
+		RAII_VAR(struct stasis_app_channel_command *, command, obj, ao2_cleanup);
+		channel_command_invoke(command, control, chan);
 		++count;
 	}
 
@@ -204,17 +204,17 @@
 	return count;
 }
 
-void control_set_bridged(struct stasis_app_control *control, int bridged)
+void channel_control_set_bridged(struct stasis_app_channel_control *control, int bridged)
 {
 	control->bridged = bridged;
 }
 
-int control_is_bridged(struct stasis_app_control *control)
+int channel_control_is_bridged(struct stasis_app_channel_control *control)
 {
 	return control->bridged;
 }
 
-void control_strip_pbx(struct stasis_app_control *control)
+void channel_control_strip_pbx(struct stasis_app_channel_control *control)
 {
 	ast_channel_lock(control->channel);
 	control->pbx = ast_channel_pbx(control->channel);
@@ -222,7 +222,7 @@
 	ast_channel_unlock(control->channel);
 }
 
-void control_restore_pbx(struct stasis_app_control *control)
+void channel_control_restore_pbx(struct stasis_app_channel_control *control)
 {
 	ast_channel_lock(control->channel);
 	ast_channel_pbx_set(control->channel, control->pbx);

Copied: team/kmoore/stasis-bridging_events/res/stasis/channel_control.h (from r389960, team/kmoore/stasis-bridging_events/res/stasis/control.h)
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.h?view=diff&rev=389967&p1=team/kmoore/stasis-bridging_events/res/stasis/control.h&r1=389960&p2=team/kmoore/stasis-bridging_events/res/stasis/channel_control.h&r2=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/control.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.h Tue May 28 17:05:54 2013
@@ -36,7 +36,7 @@
  * \return New control object.
  * \return \c NULL on error.
  */
-struct stasis_app_control *control_create(struct ast_channel *channel);
+struct stasis_app_channel_control *channel_control_create(struct ast_channel *channel);
 
 /*!
  * \brief Dispatch all commands enqueued to this control.
@@ -45,17 +45,17 @@
  * \param chan Associated channel.
  * \return Number of commands executed
  */
-int control_dispatch_all(struct stasis_app_control *control,
+int channel_control_dispatch_all(struct stasis_app_channel_control *control,
 	struct ast_channel *chan);
 
-int control_is_done(struct stasis_app_control *control);
+int channel_control_is_done(struct stasis_app_channel_control *control);
 
-void control_continue(struct stasis_app_control *control);
+void channel_control_continue(struct stasis_app_channel_control *control);
 
-int control_is_bridged(struct stasis_app_control *control);
+int channel_control_is_bridged(struct stasis_app_channel_control *control);
 
-void control_restore_pbx(struct stasis_app_control *control);
-void control_strip_pbx(struct stasis_app_control *control);
-void control_set_bridged(struct stasis_app_control *control, int bridged);
+void channel_control_restore_pbx(struct stasis_app_channel_control *control);
+void channel_control_strip_pbx(struct stasis_app_channel_control *control);
+void channel_control_set_bridged(struct stasis_app_channel_control *control, int bridged);
 
 #endif /* _ASTERISK_RES_STASIS_CONTROL_H */

Added: team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c?view=auto&rev=389967
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c (added)
+++ team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c Tue May 28 17:05:54 2013
@@ -1,0 +1,75 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * David M. Lee, II <dlee at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Stasis application command support.
+ *

[... 251 lines stripped ...]



More information about the asterisk-commits mailing list