[asterisk-commits] dlee: branch dlee/stasis-app r381824 - in /team/dlee/stasis-app: apps/ includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 20 10:31:18 CST 2013


Author: dlee
Date: Wed Feb 20 10:31:15 2013
New Revision: 381824

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=381824
Log:
Changes to support stasis-http

Modified:
    team/dlee/stasis-app/apps/app_stasis.c
    team/dlee/stasis-app/include/asterisk/app_stasis.h

Modified: team/dlee/stasis-app/apps/app_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/apps/app_stasis.c?view=diff&rev=381824&r1=381823&r2=381824
==============================================================================
--- team/dlee/stasis-app/apps/app_stasis.c (original)
+++ team/dlee/stasis-app/apps/app_stasis.c Wed Feb 20 10:31:15 2013
@@ -89,13 +89,17 @@
 	/*! Name of the Stasis application */
 	char *name;
 	/*! Callback function for this application. */
-	stasis_app_handler handler;
+	stasis_app_cb handler;
 	/*! Opaque data to hand to callback function. */
 	void *data;
 	/*!
 	 * When set, /c app_stasis should exit and continue in the dialplan.
 	 */
 	int continue_to_dialplan:1;
+	/*!
+	 * When set, indicates \c app_stasis is currently running.
+	 */
+	int is_in_app_stasis:1;
 };
 
 /*! Destructor for \ref stasis_app. */
@@ -106,7 +110,7 @@
 }
 
 /*! Constructor for \ref stasis_app. */
-static struct stasis_app *app_create(const char *name, stasis_app_handler handler, void *data)
+static struct stasis_app *app_create(const char *name, stasis_app_cb handler, void *data)
 {
 	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
 
@@ -173,6 +177,19 @@
 }
 
 /*!
+ * \brief Atomically set the is_in_app_stasis flag on an \a app.
+ * \param app Application to put into stasis
+ * \param is_in_app_stasis New value of is_in_app_stasis
+ */
+static void app_set_is_in_app_stasis(struct stasis_app *app, int is_in_app_stasis)
+{
+	if (app) {
+		SCOPED_AO2LOCK(lock, app);
+		app->is_in_app_stasis = is_in_app_stasis;
+	}
+}
+
+/*!
  * \brief Send a message to the given application.
  * \param app App to send the message to.
  * \param message Message to send.
@@ -180,6 +197,25 @@
 static void app_send(struct stasis_app *app, struct ast_json *message)
 {
 	app->handler(app->data, app->name, message);
+}
+
+struct stasis_app *stasis_app_find_by_channel(struct ast_channel *chan)
+{
+	RAII_VAR(struct ao2_container *, handlers, NULL, ao2_cleanup);
+	if (chan == NULL) {
+		return NULL;
+	}
+
+	handlers = stasis_apps();
+	return ao2_find(handlers, ast_channel_uniqueid(chan), OBJ_KEY);
+}
+
+void stasis_app_continue(struct stasis_app *handler)
+{
+	SCOPED_AO2LOCK(lock, handler);
+	if (handler->is_in_app_stasis) {
+		handler->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) {
@@ -286,12 +322,25 @@
 	}
 }
 
+/*!
+ * \brief RAII_VAR dtor, which unsets \c is_in_app_stasis in addition to
+ * ao2_cleanup().
+ * \param obj \ref stasis_app object to clean up.
+ */
+static void app_unset_and_cleanup(void *obj)
+{
+	struct stasis_app *app = obj;
+	if (obj) {
+		app_set_is_in_app_stasis(app, 0);
+		ao2_cleanup(obj);
+	}
+}
 
 /*! /brief Stasis dialplan application callback */
 static int stasis_exec(struct ast_channel *chan, const char *data)
 {
 	RAII_VAR(struct ao2_container *, apps, stasis_apps(), ao2_cleanup);
-	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_app *, app, NULL, app_unset_and_cleanup);
 	RAII_VAR(struct stasis_subscription *, subscription, NULL, stasis_unsubscribe);
 	int res = 0;
 	char *parse = NULL;
@@ -320,6 +369,8 @@
 		ast_log(LOG_ERROR, "Stasis app '%s' not registered\n", args.app_name);
 		return -1;
 	}
+
+	app_set_is_in_app_stasis(app, 1);
 
 	subscription = stasis_subscribe(ast_channel_events(chan), sub_handler, app);
 
@@ -382,7 +433,7 @@
 	return 0;
 }
 
-int stasis_app_register(const char *app_name, stasis_app_handler handler, void *data)
+int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data)
 {
 	RAII_VAR(struct ao2_container *, apps, stasis_apps(), ao2_cleanup);
 	RAII_VAR(struct stasis_app *, app, NULL, ao2_cleanup);

Modified: team/dlee/stasis-app/include/asterisk/app_stasis.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-app/include/asterisk/app_stasis.h?view=diff&rev=381824&r1=381823&r2=381824
==============================================================================
--- team/dlee/stasis-app/include/asterisk/app_stasis.h (original)
+++ team/dlee/stasis-app/include/asterisk/app_stasis.h Wed Feb 20 10:31:15 2013
@@ -33,7 +33,7 @@
 #include "asterisk/json.h"
 
 /*! \brief Handler for controlling app_stasis */
-struct stasis_app_handler;
+struct stasis_app;
 
 /*!
  * \brief Send a message to the given Stasis application.
@@ -49,6 +49,23 @@
 int stasis_app_send(const char *app_name, struct ast_json *message);
 
 /*!
+ * \brief Returns the handler for the given channel
+ * \param chan Channel to handle.
+ * \return NULL channel not in Stasis application
+ * \return Pointer to app_stasis handler.
+ */
+struct stasis_app *stasis_app_find_by_channel(struct ast_channel *chan);
+
+/*!
+ * \brief Exit \c app_stasis and continue execution in the dialplan.
+ *
+ * If the channel is no longer in \c app_stasis, this function does nothing.
+ *
+ * \param handler Handler for \c app_stasis
+ */
+void stasis_app_continue(struct stasis_app *handler);
+
+/*!
  * \brief Callback for Stasis application handler.
  *
  * The message given to the handler is a borrowed copy. If you want to keep a
@@ -58,7 +75,7 @@
  * \param app_name Name of the application being dispatched to.
  * \param message Message to handle. (borrowed copy)
  */
-typedef void (*stasis_app_handler)(void *data, const char *app_name, struct ast_json *message);
+typedef void (*stasis_app_cb)(void *data, const char *app_name, struct ast_json *message);
 
 /*!
  * \brief Register a new Stasis application.
@@ -70,7 +87,7 @@
  * \return 0 for success
  * \return -1 for error.
  */
-int stasis_app_register(const char *app_name, stasis_app_handler handler, void *data);
+int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data);
 
 /*!
  * \brief Unregister a Stasis application.




More information about the asterisk-commits mailing list