[asterisk-commits] dlee: branch dlee/stasis-http r382667 - in /team/dlee/stasis-http: ./ apps/ i...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 7 17:50:54 CST 2013


Author: dlee
Date: Thu Mar  7 17:50:50 2013
New Revision: 382667

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382667
Log:
Merged revisions 382615-382664 from http://svn.asterisk.org/svn/asterisk/team/dlee/stasis-app

Modified:
    team/dlee/stasis-http/   (props changed)
    team/dlee/stasis-http/apps/app_stasis.c
    team/dlee/stasis-http/include/asterisk/app_stasis.h
    team/dlee/stasis-http/include/asterisk/channel.h
    team/dlee/stasis-http/include/asterisk/channel_internal.h
    team/dlee/stasis-http/main/channel.c
    team/dlee/stasis-http/main/channel_internal_api.c
    team/dlee/stasis-http/main/manager.c
    team/dlee/stasis-http/main/pbx.c
    team/dlee/stasis-http/res/res_stasis_websocket.c

Propchange: team/dlee/stasis-http/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Thu Mar  7 17:50:50 2013
@@ -1,1 +1,1 @@
-/team/dlee/stasis-app:1-382549
+/team/dlee/stasis-app:1-382664

Modified: team/dlee/stasis-http/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/apps/app_stasis.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/apps/app_stasis.c (original)
+++ team/dlee/stasis-http/apps/app_stasis.c Thu Mar  7 17:50:50 2013
@@ -36,9 +36,9 @@
 #include "asterisk/app_stasis.h"
 #include "asterisk/astobj2.h"
 #include "asterisk/channel.h"
-#include "asterisk/hashtab.h"
 #include "asterisk/module.h"
 #include "asterisk/stasis.h"
+#include "asterisk/strings.h"
 
 /*** DOCUMENTATION
 	<application name="Stasis" language="en_US">
@@ -99,43 +99,34 @@
 }
 
 struct stasis_app {
-	/*! Name of the Stasis application */
-	char *name;
 	/*! Callback function for this application. */
 	stasis_app_cb handler;
 	/*! Opaque data to hand to callback function. */
 	void *data;
+	/*! Name of the Stasis application */
+	char name[];
 };
-
-/*! Destructor for \ref stasis_app. */
-static void app_dtor(void *obj)
-{
-	struct stasis_app *app = obj;
-	ast_free(app->name);
-}
 
 /*! Constructor for \ref stasis_app. */
 static struct stasis_app *app_create(const char *name, stasis_app_cb handler, void *data)
 {
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	struct stasis_app *app;
+	size_t size;
 
 	ast_assert(name != NULL);
 	ast_assert(handler != NULL);
 
-	app = ao2_alloc_options(sizeof(*app), app_dtor, AO2_ALLOC_OPT_LOCK_MUTEX);
+	size = sizeof(*app) + strlen(name) + 1;
+	app = ao2_alloc_options(size, NULL, AO2_ALLOC_OPT_LOCK_MUTEX);
 
 	if (!app) {
 		return NULL;
 	}
 
-	if (!(app->name = ast_strdup(name))) {
-		return NULL;
-	}
-
+	strncpy(app->name, name, size - sizeof(*app));
 	app->handler = handler;
 	app->data = data;
 
-	ao2_ref(app, +1);
 	return app;
 }
 
@@ -145,7 +136,7 @@
 	const struct stasis_app *app = obj;
 	const char *name = flags & OBJ_KEY ? obj : app->name;
 
-	return ast_hashtab_hash_string(name);
+	return ast_str_hash(name);
 }
 
 /*! AO2 comparison function for \ref stasis_app */
@@ -173,35 +164,27 @@
 }
 
 struct stasis_app_control {
-	/*! Uniqueid of the associated channel */
-	char *channel_uniqueid;
 	/*!
 	 * When set, /c app_stasis should exit and continue in the dialplan.
 	 */
 	int continue_to_dialplan:1;
+	/*! Uniqueid of the associated channel */
+	char channel_uniqueid[];
 };
 
-static void app_control_dtor(void *obj)
-{
-	struct stasis_app_control *control = obj;
-	ast_free(control->channel_uniqueid);
-}
-
 static struct stasis_app_control *control_create(const char *uniqueid)
 {
-	RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
-
-	control = ao2_alloc(sizeof(*control), app_control_dtor);
+	struct stasis_app_control *control;
+	size_t size;
+
+	size = sizeof(*control) + strlen(uniqueid) + 1;
+	control = ao2_alloc(size, NULL);
 	if (!control) {
 		return NULL;
 	}
 
-	control->channel_uniqueid = ast_strdup(uniqueid);
-	if (!control->channel_uniqueid) {
-		return NULL;
-	}
-
-	ao2_ref(control, +1);
+	strncpy(control->channel_uniqueid, uniqueid, size - sizeof(*control));
+
 	return control;
 }
 
@@ -241,7 +224,9 @@
 	control->continue_to_dialplan = 1;
 }
 
-struct ast_json *stasis_app_event_create(const char *event_name, const struct ast_channel_snapshot *channel_info, const struct ast_json *extra_info) {
+struct ast_json *stasis_app_event_create(const char *event_name,
+					 const struct ast_channel_snapshot *channel_info,
+					 const struct ast_json *extra_info) {
 	RAII_VAR(struct ast_json *, message, NULL, ast_json_unref);
 	int r;
 
@@ -356,11 +341,13 @@
 {
 	RAII_VAR(struct ao2_container *, controls, NULL, ao2_cleanup);
 
-	if (control) {
-		controls = app_controls();
-		ao2_unlink_flags(controls, control, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
-		ao2_cleanup(control);
-	}
+	if (!control) {
+		return;
+	}
+
+	controls = app_controls();
+	ao2_unlink_flags(controls, control, OBJ_POINTER | OBJ_UNLINK | OBJ_NODATA);
+	ao2_cleanup(control);
 }
 
 /*! /brief Stasis dialplan application callback */

Modified: team/dlee/stasis-http/include/asterisk/app_stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/app_stasis.h?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/include/asterisk/app_stasis.h (original)
+++ team/dlee/stasis-http/include/asterisk/app_stasis.h Thu Mar  7 17:50:50 2013
@@ -55,7 +55,7 @@
  * \brief Callback for Stasis application handler.
  *
  * The message given to the handler is a borrowed copy. If you want to keep a
- * reference to it, you should use \c ast_ref() to keep it around.
+ * reference to it, you should use \c ao2_ref() to keep it around.
  *
  * \param data Data ptr given when registered.
  * \param app_name Name of the application being dispatched to.
@@ -85,7 +85,7 @@
  * \brief Send a message to the given Stasis application.
  *
  * The message given to the handler is a borrowed copy. If you want to keep a
- * reference to it, you should use \c ast_ref() to keep it around.
+ * reference to it, you should use \c ao2_ref() to keep it around.
  *
  * \param app_name Name of the application to invoke.
  * \param message Message to send (borrowed reference)

Modified: team/dlee/stasis-http/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/channel.h?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/include/asterisk/channel.h (original)
+++ team/dlee/stasis-http/include/asterisk/channel.h Thu Mar  7 17:50:50 2013
@@ -4167,14 +4167,14 @@
  * \retval Topic for channel's events.
  * \retval \c NULL if \a chan is \c NULL.
  */
-struct stasis_topic *ast_channel_events(struct ast_channel *chan);
+struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
 
 /*!
  * \since 12
  * \brief A topic which publishes the events for all channels.
  * \retval Topic for all channel events.
  */
-struct stasis_topic *ast_channel_events_all(void);
+struct stasis_topic *ast_channel_topic_all(void);
 
 /*!
  * \since 12
@@ -4183,13 +4183,13 @@
  *
  * \retval Topic for all channel events.
  */
-struct stasis_caching_topic *ast_channel_events_all_cached(void);
+struct stasis_caching_topic *ast_channel_topic_all_cached(void);
 
 /*!
  * \since 12
  * \brief Variable set event.
  */
-struct ast_channel_varset_event {
+struct ast_channel_varset {
 	/*! Channel variable was set on (or NULL for global variable) */
 	struct ast_channel_snapshot *snapshot;
 	/*! Variable name */
@@ -4200,21 +4200,21 @@
 
 /*!
  * \since 12
- * \brief Message type for \ref ast_channel_varset_event messages.
- *
- * \retval Message type for \ref ast_channel_varset_event messages.
- */
-struct stasis_message_type *ast_channel_varset_event(void);
+ * \brief Message type for \ref ast_channel_varset messages.
+ *
+ * \retval Message type for \ref ast_channel_varset messages.
+ */
+struct stasis_message_type *ast_channel_varset(void);
 
 /*!
  * \since 12
- * \brief Publish a \ref ast_channel_varset_event for a channel.
+ * \brief Publish a \ref ast_channel_varset for a channel.
  *
  * \param chan Channel to pulish the event for, or \c NULL for 'none'.
  * \param variable Name of the variable being set
  * \param value Value.
  */
-void ast_channel_send_varset_event(struct ast_channel *chan,
-				   const char *variable, const char *value);
+void ast_channel_publish_varset(struct ast_channel *chan,
+				const char *variable, const char *value);
 
 #endif /* _ASTERISK_CHANNEL_H */

Modified: team/dlee/stasis-http/include/asterisk/channel_internal.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/include/asterisk/channel_internal.h?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/include/asterisk/channel_internal.h (original)
+++ team/dlee/stasis-http/include/asterisk/channel_internal.h Thu Mar  7 17:50:50 2013
@@ -23,5 +23,5 @@
 void ast_channel_internal_finalize(struct ast_channel *chan);
 int ast_channel_internal_is_finalized(struct ast_channel *chan);
 void ast_channel_internal_cleanup(struct ast_channel *chan);
-void ast_channel_internal_setup_events(struct ast_channel *chan);
+void ast_channel_internal_setup_topics(struct ast_channel *chan);
 

Modified: team/dlee/stasis-http/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/channel.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/main/channel.c (original)
+++ team/dlee/stasis-http/main/channel.c Thu Mar  7 17:50:50 2013
@@ -155,11 +155,11 @@
 /*! \brief Message type for channel snapshot events */
 static struct stasis_message_type *__channel_snapshot;
 
-static struct stasis_message_type *__channel_varset_event;
-
-struct stasis_topic *__channel_events_all;
-
-struct stasis_caching_topic *__channel_events_all_cached;
+static struct stasis_message_type *__channel_varset;
+
+struct stasis_topic *__channel_topic_all;
+
+struct stasis_caching_topic *__channel_topic_all_cached;
 
 /*! \brief map AST_CAUSE's to readable string representations
  *
@@ -239,24 +239,24 @@
 		return;
 	}
 
-	ast_assert(ast_channel_events(chan) != NULL);
-	stasis_publish(ast_channel_events(chan), message);
-}
-
-static void channel_varset_event_dtor(void *obj)
-{
-	struct ast_channel_varset_event *event = obj;
+	ast_assert(ast_channel_topic(chan) != NULL);
+	stasis_publish(ast_channel_topic(chan), message);
+}
+
+static void channel_varset_dtor(void *obj)
+{
+	struct ast_channel_varset *event = obj;
 	ao2_cleanup(event->snapshot);
 	ast_free(event->variable);
 	ast_free(event->value);
 }
 
-void ast_channel_send_varset_event(struct ast_channel *chan, const char *name, const char *value)
-{
-	RAII_VAR(struct ast_channel_varset_event *, event, NULL, ao2_cleanup);
+void ast_channel_publish_varset(struct ast_channel *chan, const char *name, const char *value)
+{
+	RAII_VAR(struct ast_channel_varset *, event, NULL, ao2_cleanup);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
-	event = ao2_alloc(sizeof(*event), channel_varset_event_dtor);
+	event = ao2_alloc(sizeof(*event), channel_varset_dtor);
 	if (!event) {
 		return;
 	}
@@ -273,15 +273,15 @@
 		return;
 	}
 
-	msg = stasis_message_create(ast_channel_varset_event(), event);
+	msg = stasis_message_create(ast_channel_varset(), event);
 	if (!msg) {
 		return;
 	}
 
 	if (chan) {
-		stasis_publish(ast_channel_events(chan), msg);
+		stasis_publish(ast_channel_topic(chan), msg);
 	} else {
-		stasis_publish(ast_channel_events_all(), msg);
+		stasis_publish(ast_channel_topic_all(), msg);
 	}
 }
 
@@ -291,7 +291,7 @@
 	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
 
 	message = stasis_cache_clear_create(ast_channel_snapshot(), ast_channel_uniqueid(chan));
-	stasis_publish(ast_channel_events(chan), message);
+	stasis_publish(ast_channel_topic(chan), message);
 }
 
 struct ast_variable *ast_channeltype_list(void)
@@ -1153,7 +1153,7 @@
 		ast_channel_linkedid_set(tmp, ast_channel_uniqueid(tmp));
 	}
 
-	ast_channel_internal_setup_events(tmp);
+	ast_channel_internal_setup_topics(tmp);
 
 	if (!ast_strlen_zero(name_fmt)) {
 		char *slash, *slash2;
@@ -8631,10 +8631,12 @@
 {
 	ao2_cleanup(__channel_snapshot);
 	__channel_snapshot = NULL;
-	ao2_cleanup(__channel_events_all);
-	__channel_events_all = NULL;
-	stasis_caching_unsubscribe(__channel_events_all_cached);
-	__channel_events_all_cached = NULL;
+	ao2_cleanup(__channel_varset);
+	__channel_varset = NULL;
+	ao2_cleanup(__channel_topic_all);
+	__channel_topic_all = NULL;
+	stasis_caching_unsubscribe(__channel_topic_all_cached);
+	__channel_topic_all_cached = NULL;
 	ast_data_unregister(NULL);
 	ast_cli_unregister_multiple(cli_channel, ARRAY_LEN(cli_channel));
 	if (channels) {
@@ -8663,10 +8665,10 @@
 	}
 
 	__channel_snapshot = stasis_message_type_create("ast_channel_snapshot");
-	__channel_varset_event = stasis_message_type_create("ast_channel_varset_event");
-
-	__channel_events_all = stasis_topic_create("ast_channel_events_all");
-	__channel_events_all_cached = stasis_caching_topic_create(__channel_events_all, channel_snapshot_get_id);
+	__channel_varset = stasis_message_type_create("ast_channel_varset");
+
+	__channel_topic_all = stasis_topic_create("ast_channel_topic_all");
+	__channel_topic_all_cached = stasis_caching_topic_create(__channel_topic_all, channel_snapshot_get_id);
 
 	ast_cli_register_multiple(cli_channel, ARRAY_LEN(cli_channel));
 
@@ -11302,9 +11304,9 @@
 	return snapshot;
 }
 
-struct stasis_message_type *ast_channel_varset_event(void)
-{
-	return __channel_varset_event;
+struct stasis_message_type *ast_channel_varset(void)
+{
+	return __channel_varset;
 }
 
 struct stasis_message_type *ast_channel_snapshot(void)
@@ -11312,14 +11314,14 @@
 	return __channel_snapshot;
 }
 
-struct stasis_topic *ast_channel_events_all(void)
-{
-	return __channel_events_all;
-}
-
-struct stasis_caching_topic *ast_channel_events_all_cached(void)
-{
-	return __channel_events_all_cached;
+struct stasis_topic *ast_channel_topic_all(void)
+{
+	return __channel_topic_all;
+}
+
+struct stasis_caching_topic *ast_channel_topic_all_cached(void)
+{
+	return __channel_topic_all_cached;
 }
 
 /* DO NOT PUT ADDITIONAL FUNCTIONS BELOW THIS BOUNDARY

Modified: team/dlee/stasis-http/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/channel_internal_api.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/main/channel_internal_api.c (original)
+++ team/dlee/stasis-http/main/channel_internal_api.c Thu Mar  7 17:50:50 2013
@@ -1384,15 +1384,15 @@
 	return chan->finalized;
 }
 
-struct stasis_topic *ast_channel_events(struct ast_channel *chan)
+struct stasis_topic *ast_channel_topic(struct ast_channel *chan)
 {
 	return chan->topic;
 }
 
-void ast_channel_internal_setup_events(struct ast_channel *chan)
+void ast_channel_internal_setup_topics(struct ast_channel *chan)
 {
 	ast_assert(chan->topic == NULL);
 	ast_assert(chan->forwarder == NULL);
 	chan->topic = stasis_topic_create(chan->uniqueid);
-	chan->forwarder = stasis_forward_all(chan->topic, ast_channel_events_all());
-}
+	chan->forwarder = stasis_forward_all(chan->topic, ast_channel_topic_all());
+}

Modified: team/dlee/stasis-http/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/manager.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/main/manager.c (original)
+++ team/dlee/stasis-http/main/manager.c Thu Mar  7 17:50:50 2013
@@ -7559,11 +7559,11 @@
 				stasis_message_data(update->new_snapshot);
 			channel_snapshot_update(old_snapshot, new_snapshot);
 		}
-	} else if (stasis_message_type(message) == ast_channel_varset_event()) {
-		struct ast_channel_varset_event *event = stasis_message_data(message);
-		const char *name = event->snapshot ?event->snapshot->name : "none";
-		const char *uniqueid = event->snapshot ?event->snapshot->uniqueid : "none";
-		channel_varset(name, uniqueid, event->variable, event->value);
+	} else if (stasis_message_type(message) == ast_channel_varset()) {
+		struct ast_channel_varset *varset = stasis_message_data(message);
+		const char *name = varset->snapshot ? varset->snapshot->name : "none";
+		const char *uniqueid = varset->snapshot ? varset->snapshot->uniqueid : "none";
+		channel_varset(name, uniqueid, varset->variable, varset->value);
 	}
 }
 
@@ -7686,7 +7686,7 @@
 
 	if (!channel_state_sub) {
 		channel_state_sub = stasis_subscribe(
-			stasis_caching_get_topic(ast_channel_events_all_cached()),
+			stasis_caching_get_topic(ast_channel_topic_all_cached()),
 			channel_event_cb, NULL);
 	}
 

Modified: team/dlee/stasis-http/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/main/pbx.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/main/pbx.c (original)
+++ team/dlee/stasis-http/main/pbx.c Thu Mar  7 17:50:50 2013
@@ -11453,7 +11453,7 @@
 			ast_verb(2, "Setting global variable '%s' to '%s'\n", name, value);
 		newvariable = ast_var_assign(name, value);
 		AST_LIST_INSERT_HEAD(headp, newvariable, entries);
-		ast_channel_send_varset_event(chan, name, value);
+		ast_channel_publish_varset(chan, name, value);
 	}
 
 	if (chan)

Modified: team/dlee/stasis-http/res/res_stasis_websocket.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-http/res/res_stasis_websocket.c?view=diff&rev=382667&r1=382666&r2=382667
==============================================================================
--- team/dlee/stasis-http/res/res_stasis_websocket.c (original)
+++ team/dlee/stasis-http/res/res_stasis_websocket.c Thu Mar  7 17:50:50 2013
@@ -36,10 +36,10 @@
 
 #include "asterisk/app_stasis.h"
 #include "asterisk/astobj2.h"
-#include "asterisk/hashtab.h"
 #include "asterisk/http_websocket.h"
 #include "asterisk/json.h"
 #include "asterisk/module.h"
+#include "asterisk/strings.h"
 #include "asterisk/utils.h"
 
 /*! WebSocket protocol for Stasis */
@@ -109,7 +109,7 @@
 	const struct stasis_app *app = obj;
 	const char *name = flags & OBJ_KEY ? obj : app->name;
 
-	return ast_hashtab_hash_string(name);
+	return ast_str_hash(name);
 }
 
 /*! Comparison function for stasis_app */
@@ -273,7 +273,9 @@
 	i = ao2_iterator_init(stasis_session.stasis_apps, 0);
 	while ((app = ao2_iterator_next(&i))) {
 		stasis_app_unregister(app->name);
-	}
+		ao2_cleanup(app);
+	}
+	ao2_iterator_destroy(&i);
 	ao2_cleanup(stasis_session.stasis_apps);
 
 	ast_websocket_unref(session);




More information about the asterisk-commits mailing list