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

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


Author: kmoore
Date: Tue May 28 18:17:53 2013
New Revision: 389969

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=389969
Log:
More refactoring

Modified:
    team/kmoore/stasis-bridging_events/include/asterisk/stasis_app_impl.h
    team/kmoore/stasis-bridging_events/res/res_stasis.c
    team/kmoore/stasis-bridging_events/res/res_stasis_answer.exports.in
    team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c
    team/kmoore/stasis-bridging_events/res/stasis/bridge_command.h
    team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c
    team/kmoore/stasis-bridging_events/res/stasis/bridge_control.h
    team/kmoore/stasis-bridging_events/res/stasis/channel_command.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_command.h
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.c
    team/kmoore/stasis-bridging_events/res/stasis/channel_control.h
    team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c

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=389969&r1=389968&r2=389969
==============================================================================
--- 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 18:17:53 2013
@@ -102,7 +102,8 @@
 	char *argv[]);
 
 /*! Callback type for stasis app bridge commands */
-typedef void *(*stasis_app_bridge_command_cb)(struct stasis_app_bridge_control *control, void *data);
+typedef void *(*stasis_app_bridge_command_cb)(struct stasis_app_bridge_control *control,
+	struct ast_bridge *bridge, void *data);
 
 /*!
  * \since 12

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=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis.c (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis.c Tue May 28 18:17:53 2013
@@ -68,6 +68,7 @@
 #include "stasis/channel_control.h"
 #include "stasis/bridge_control.h"
 #include "stasis/bridge_command.h" /* for init and cleanup */
+#include "stasis/channel_command.h" /* for init and cleanup */
 #include "stasis/command_dispatch.h" /* for init and cleanup */
 #include "stasis_json/resource_events.h"
 
@@ -570,7 +571,6 @@
 	while (!channel_control_is_done(control)) {
 		RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
 		int r;
-		int command_count;
 
 		if (channel_control_is_bridged(control)) {
 			r = 0;
@@ -583,13 +583,6 @@
 			ast_debug(3, "%s: Poll error\n",
 				  ast_channel_uniqueid(chan));
 			break;
-		}
-
-		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 || channel_control_is_bridged(control)) {
@@ -993,6 +986,10 @@
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
+	if (channel_command_init()) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
 	channel_router = stasis_message_router_create(stasis_caching_get_topic(ast_channel_topic_all_cached()));
 	if (!channel_router) {
 		return AST_MODULE_LOAD_FAILURE;
@@ -1033,6 +1030,8 @@
 	stasis_message_router_unsubscribe_and_join(bridge_router);
 	bridge_router = NULL;
 
+	command_dispatch_cleanup();
+	channel_command_cleanup();
 	bridge_command_cleanup();
 
 	ao2_cleanup(apps_registry);

Modified: team/kmoore/stasis-bridging_events/res/res_stasis_answer.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/res_stasis_answer.exports.in?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/res_stasis_answer.exports.in (original)
+++ team/kmoore/stasis-bridging_events/res/res_stasis_answer.exports.in Tue May 28 18:17:53 2013
@@ -1,6 +1,6 @@
 {
 	global:
-		LINKER_SYMBOL_PREFIXstasis_app_control_answer;
+		LINKER_SYMBOL_PREFIXstasis_app_channel_control_answer;
 	local:
 		*;
 };

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=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_command.c Tue May 28 18:17:53 2013
@@ -28,6 +28,7 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "bridge_command.h"
+#include "bridge_control.h"
 #include "command_dispatch.h"
 
 #include "asterisk/lock.h"
@@ -96,7 +97,7 @@
 void bridge_command_invoke(struct stasis_app_bridge_command *command,
 	struct stasis_app_bridge_control *control)
 {
-	void *retval = command->callback(control, command->data);
+	void *retval = command->callback(control, bridge_control_get_bridge(control), command->data);
 	bridge_command_complete(command, retval);
 }
 

Modified: team/kmoore/stasis-bridging_events/res/stasis/bridge_command.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/bridge_command.h?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_command.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_command.h Tue May 28 18:17:53 2013
@@ -16,8 +16,8 @@
  * at the top of the source tree.
  */
 
-#ifndef _ASTERISK_RES_STASIS_COMMAND_H
-#define _ASTERISK_RES_STASIS_COMMAND_H
+#ifndef _ASTERISK_RES_STASIS_BRIDGE_COMMAND_H
+#define _ASTERISK_RES_STASIS_BRIDGE_COMMAND_H
 
 /*! \file
  *
@@ -41,7 +41,6 @@
 void *bridge_command_join(struct stasis_app_bridge_command *command);
 
 int bridge_command_queue(struct stasis_app_bridge_command *command);
-
 void bridge_command_cleanup(void);
 int bridge_command_init(void);
-#endif /* _ASTERISK_RES_STASIS_CONTROL_H */
+#endif /* _ASTERISK_RES_STASIS_BRIDGE_COMMAND_H */

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=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_control.c Tue May 28 18:17:53 2013
@@ -190,7 +190,7 @@
 
 static void *app_bridge_control_add_channel(
 	struct stasis_app_bridge_control *control,
-	void *data)
+	struct ast_bridge *bridge, void *data)
 {
 	struct ast_channel *channel = data;
 	RAII_VAR(struct stasis_app_channel_control *, channel_control,
@@ -204,7 +204,7 @@
 	ast_bridge_leave_hook(features, bridge_depart_cb, NULL, NULL, 1);
 	channel_control_strip_pbx(channel_control);
 
-	res = ast_bridge_impart(control->bridge, channel, NULL, features, 0);
+	res = ast_bridge_impart(bridge, channel, NULL, features, 0);
 	if (res) {
 		channel_control_restore_pbx(channel_control);
 	} else {
@@ -236,7 +236,7 @@
 
 static void *app_bridge_control_remove_channel(
 	struct stasis_app_bridge_control *control,
-	void *data)
+	struct ast_bridge *bridge, void *data)
 {
 	struct ast_channel *channel = data;
 	return !ast_bridge_depart(channel) ? &OK : &FAIL;
@@ -264,7 +264,7 @@
 
 static void *app_bridge_control_destroy(
 	struct stasis_app_bridge_control *control,
-	void *data)
+	struct ast_bridge *bridge, void *data)
 {
 	stasis_app_remove_bridge_control(control);
 	return &OK;
@@ -289,3 +289,7 @@
 	return 0;
 }
 
+struct ast_bridge *bridge_control_get_bridge(struct stasis_app_bridge_control *control)
+{
+	return control->bridge;
+}

Modified: team/kmoore/stasis-bridging_events/res/stasis/bridge_control.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/bridge_control.h?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/bridge_control.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/bridge_control.h Tue May 28 18:17:53 2013
@@ -39,4 +39,5 @@
  */
 struct stasis_app_bridge_control *bridge_control_create(int flags);
 
+struct ast_bridge *bridge_control_get_bridge(struct stasis_app_bridge_control *control);
 #endif /* _ASTERISK_RES_STASIS_BRIDGE_CONTROL_H */

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_command.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_command.c?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_command.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_command.c Tue May 28 18:17:53 2013
@@ -28,6 +28,8 @@
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 
 #include "channel_command.h"
+#include "channel_control.h"
+#include "command_dispatch.h"
 
 #include "asterisk/lock.h"
 #include "asterisk/stasis_app_impl.h"
@@ -36,6 +38,7 @@
 	ast_mutex_t lock;
 	ast_cond_t condition;
 	stasis_app_channel_command_cb callback;
+	struct stasis_app_channel_control *control;
 	void *data;
 	void *retval;
 	int is_done:1;
@@ -49,6 +52,7 @@
 }
 
 struct stasis_app_channel_command *channel_command_create(
+	struct stasis_app_channel_control *control,
 	stasis_app_channel_command_cb callback, void *data)
 {
 	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
@@ -60,6 +64,7 @@
 
 	ast_mutex_init(&command->lock);
 	ast_cond_init(&command->condition, 0);
+	command->control = control;
 	command->callback = callback;
 	command->data = data;
 
@@ -87,9 +92,35 @@
 }
 
 void channel_command_invoke(struct stasis_app_channel_command *command,
-	struct stasis_app_channel_control *control, struct ast_channel *chan)
+	struct stasis_app_channel_control *control)
 {
-	void *retval = command->callback(control, chan, command->data);
+	void *retval = command->callback(control, channel_control_get_channel(control), command->data);
 	channel_command_complete(command, retval);
 }
 
+struct stasis_message_type *channel_command_type(void);
+STASIS_MESSAGE_TYPE_DEFN(channel_command_type);
+
+static void channel_command_cb(void *data, struct stasis_subscription *sub, struct stasis_topic *topic, struct stasis_message *msg)
+{
+	struct stasis_app_channel_command *command = stasis_message_data(msg);
+	channel_command_invoke(command, command->control);
+}
+
+int channel_command_queue(struct stasis_app_channel_command *command)
+{
+	return command_dispatch_send(channel_command_type(), command);
+}
+
+int channel_command_init(void)
+{
+	if (STASIS_MESSAGE_TYPE_INIT(channel_command_type)) {
+		return -1;
+	}
+	return command_dispatch_register(channel_command_type(), channel_command_cb);
+}
+
+void channel_command_cleanup(void)
+{
+	STASIS_MESSAGE_TYPE_CLEANUP(channel_command_type);
+}

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_command.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_command.h?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_command.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_command.h Tue May 28 18:17:53 2013
@@ -16,8 +16,8 @@
  * at the top of the source tree.
  */
 
-#ifndef _ASTERISK_RES_STASIS_COMMAND_H
-#define _ASTERISK_RES_STASIS_COMMAND_H
+#ifndef _ASTERISK_RES_STASIS_CHANNEL_COMMAND_H
+#define _ASTERISK_RES_STASIS_CHANNEL_COMMAND_H
 
 /*! \file
  *
@@ -32,11 +32,15 @@
 struct stasis_app_channel_command;
 
 struct stasis_app_channel_command *channel_command_create(
+	struct stasis_app_channel_control *control,
 	stasis_app_channel_command_cb callback, void *data);
 
 void channel_command_invoke(struct stasis_app_channel_command *command,
-	struct stasis_app_channel_control *control, struct ast_channel *chan);
+	struct stasis_app_channel_control *control);
 
 void *channel_command_join(struct stasis_app_channel_command *command);
 
-#endif /* _ASTERISK_RES_STASIS_CONTROL_H */
+int channel_command_queue(struct stasis_app_channel_command *command);
+void channel_command_cleanup(void);
+int channel_command_init(void);
+#endif /* _ASTERISK_RES_STASIS_CHANNEL_COMMAND_H */

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_control.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.c?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_control.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.c Tue May 28 18:17:53 2013
@@ -30,12 +30,11 @@
 #include "asterisk/stasis_channels.h"
 
 #include "channel_command.h"
+#include "command_dispatch.h"
 #include "channel_control.h"
 
 /* XXX needs a destructor */
 struct stasis_app_channel_control {
-	/*! Queue of commands to dispatch on the channel */
-	struct ao2_container *command_queue;
 	/*!
 	 * When set, /c app_stasis should exit and continue in the dialplan.
 	 */
@@ -59,9 +58,6 @@
 		return NULL;
 	}
 
-	control->command_queue = ao2_container_alloc_list(
-		AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
-
 	control->channel = channel;
 
 	return control;
@@ -73,14 +69,15 @@
 {
 	RAII_VAR(struct stasis_app_channel_command *, command, NULL, ao2_cleanup);
 
-	command = channel_command_create(command_fn, data);
+	command = channel_command_create(control, command_fn, data);
 
 	if (!command) {
 		return NULL;
 	}
 
-	/* command_queue is a thread safe list; no lock needed */
-	ao2_link(control->command_queue, command);
+	if (channel_command_queue(command)) {
+		return NULL;
+	}
 
 	ao2_ref(command, +1);
 	return command;
@@ -181,27 +178,6 @@
 	enum ast_control_frame_type frame_type)
 {
 	return ast_queue_control(control->channel, frame_type);
-}
-
-int channel_control_dispatch_all(struct stasis_app_channel_control *control,
-	struct ast_channel *chan)
-{
-	int count = 0;
-	struct ao2_iterator i;
-	void *obj;
-
-	ast_assert(control->channel == chan);
-
-	i = ao2_iterator_init(control->command_queue, AO2_ITERATOR_UNLINK);
-
-	while ((obj = ao2_iterator_next(&i))) {
-		RAII_VAR(struct stasis_app_channel_command *, command, obj, ao2_cleanup);
-		channel_command_invoke(command, control, chan);
-		++count;
-	}
-
-	ao2_iterator_destroy(&i);
-	return count;
 }
 
 void channel_control_set_bridged(struct stasis_app_channel_control *control, int bridged)
@@ -229,3 +205,8 @@
 	ast_channel_unlock(control->channel);
 	control->pbx = NULL;
 }
+
+struct ast_channel *channel_control_get_channel(struct stasis_app_channel_control *control)
+{
+	return control->channel;
+}

Modified: team/kmoore/stasis-bridging_events/res/stasis/channel_control.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/stasis-bridging_events/res/stasis/channel_control.h?view=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/channel_control.h (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/channel_control.h Tue May 28 18:17:53 2013
@@ -38,24 +38,14 @@
  */
 struct stasis_app_channel_control *channel_control_create(struct ast_channel *channel);
 
-/*!
- * \brief Dispatch all commands enqueued to this control.
- *
- * \param control Control object to dispatch.
- * \param chan Associated channel.
- * \return Number of commands executed
- */
-int channel_control_dispatch_all(struct stasis_app_channel_control *control,
-	struct ast_channel *chan);
-
 int channel_control_is_done(struct stasis_app_channel_control *control);
 
 void channel_control_continue(struct stasis_app_channel_control *control);
 
 int channel_control_is_bridged(struct stasis_app_channel_control *control);
-
 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);
+struct ast_channel *channel_control_get_channel(struct stasis_app_channel_control *control);
 
 #endif /* _ASTERISK_RES_STASIS_CONTROL_H */

Modified: 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=diff&rev=389969&r1=389968&r2=389969
==============================================================================
--- team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c (original)
+++ team/kmoore/stasis-bridging_events/res/stasis/command_dispatch.c Tue May 28 18:17:53 2013
@@ -68,7 +68,7 @@
 
 void command_dispatch_cleanup(void)
 {
-	stasis_message_router_unsubscribe(command_dispatch_router);
+	stasis_message_router_unsubscribe_and_join(command_dispatch_router);
 	command_dispatch_router = NULL;
 	ao2_cleanup(command_dispatch_topic);
 	command_dispatch_topic = NULL;




More information about the asterisk-commits mailing list