[asterisk-commits] dlee: branch dlee/ASTERISK-21970 r394420 - in /team/dlee/ASTERISK-21970/res: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jul 15 19:00:52 CDT 2013


Author: dlee
Date: Mon Jul 15 19:00:51 2013
New Revision: 394420

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394420
Log:
Deactivate apps instead of unregistering them.

Modified:
    team/dlee/ASTERISK-21970/res/res_stasis.c
    team/dlee/ASTERISK-21970/res/stasis/app.c
    team/dlee/ASTERISK-21970/res/stasis/app.h

Modified: team/dlee/ASTERISK-21970/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21970/res/res_stasis.c?view=diff&rev=394420&r1=394419&r2=394420
==============================================================================
--- team/dlee/ASTERISK-21970/res/res_stasis.c (original)
+++ team/dlee/ASTERISK-21970/res/res_stasis.c Mon Jul 15 19:00:51 2013
@@ -547,6 +547,11 @@
 	if (!app) {
 		ast_log(LOG_ERROR,
 			"Stasis app '%s' not registered\n", app_name);
+		return -1;
+	}
+	if (!app_is_active(app)) {
+		ast_log(LOG_ERROR,
+			"Stasis app '%s' not active\n", app_name);
 		return -1;
 	}
 
@@ -680,10 +685,20 @@
 
 void stasis_app_unregister(const char *app_name)
 {
-	if (app_name) {
-		ao2_cleanup(ao2_find(
-				apps_registry, app_name, OBJ_KEY | OBJ_UNLINK));
-	}
+	RAII_VAR(struct app *, app, NULL, ao2_cleanup);
+
+	if (!app_name) {
+		return;
+	}
+
+	app = ao2_find(apps_registry, app_name, OBJ_KEY);
+	if (!app) {
+		ast_log(LOG_ERROR,
+			"Stasis app '%s' not registered\n", app_name);
+		return;
+	}
+
+	app_deactivate(app);
 }
 
 void stasis_app_ref(void)

Modified: team/dlee/ASTERISK-21970/res/stasis/app.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21970/res/stasis/app.c?view=diff&rev=394420&r1=394419&r2=394420
==============================================================================
--- team/dlee/ASTERISK-21970/res/stasis/app.c (original)
+++ team/dlee/ASTERISK-21970/res/stasis/app.c Mon Jul 15 19:00:51 2013
@@ -144,7 +144,38 @@
  */
 void app_send(struct app *app, struct ast_json *message)
 {
-	app->handler(app->data, app->name, message);
+	stasis_app_cb handler;
+	RAII_VAR(void *, data, NULL, ao2_cleanup);
+
+	/* Copy off mutable state with lock held */
+	{
+		SCOPED_AO2LOCK(lock, app);
+		handler = app->handler;
+		ao2_ref(app->data, +1);
+		data = app->data;
+		/* Name is immutable; no need to copy */
+	}
+
+	if (!handler) {
+		ast_log(LOG_WARNING,
+			"Inactive application %s missed message\n", app->name);
+		return;
+	}
+	handler(data, app->name, message);
+}
+
+void app_deactivate(struct app *app)
+{
+	SCOPED_AO2LOCK(lock, app);
+	app->handler = NULL;
+	ao2_cleanup(app->data);
+	app->data = NULL;
+}
+
+int app_is_active(struct app *app)
+{
+	SCOPED_AO2LOCK(lock, app);
+	return app->handler != NULL;
 }
 
 void app_update(struct app *app, stasis_app_cb handler, void *data)
@@ -153,7 +184,9 @@
 
 	app->handler = handler;
 	ao2_cleanup(app->data);
-	ao2_ref(data, +1);
+	if (data) {
+		ao2_ref(data, +1);
+	}
 	app->data = data;
 }
 

Modified: team/dlee/ASTERISK-21970/res/stasis/app.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/ASTERISK-21970/res/stasis/app.h?view=diff&rev=394420&r1=394419&r2=394420
==============================================================================
--- team/dlee/ASTERISK-21970/res/stasis/app.h (original)
+++ team/dlee/ASTERISK-21970/res/stasis/app.h Mon Jul 15 19:00:51 2013
@@ -48,7 +48,28 @@
 struct app *app_create(const char *name, stasis_app_cb handler, void *data);
 
 /*!
+ * \brief Deactivates an application.
+ *
+ * Any channels currently in the application remain active (since the app might
+ * come back), but new channels are rejected.
+ *
+ * \param app Application to deactivate.
+ */
+void app_deactivate(struct app *app);
+
+/*!
+ * \brief Checks whether an app is active.
+ *
+ * \param app Application to check.
+ * \return True (non-zero) if app is active.
+ * \return False (zero) if app has been deactivated.
+ */
+int app_is_active(struct app *app);
+
+/*!
  * \brief Update the handler and data for a \c res_stasis application.
+ *
+ * If app has been deactivated, this will reactivate it.
  *
  * \param app Application to update.
  * \param handler New application callback.




More information about the asterisk-commits mailing list