summaryrefslogtreecommitdiff
path: root/res/stasis/app.c
diff options
context:
space:
mode:
authorKinsey Moore <kmoore@digium.com>2013-06-10 13:07:11 +0000
committerKinsey Moore <kmoore@digium.com>2013-06-10 13:07:11 +0000
commita5bbc790e7ee1417bc03f5c529a73f2604a58cdb (patch)
tree4ae804770c499e8068bc04c4b896d9a8c0447715 /res/stasis/app.c
parent0cec7dcdcd4ce053bfb27849e5bd90b181151182 (diff)
Stasis-HTTP: Flesh out bridge-related capabilities
This adds support for Stasis applications to receive bridge-related messages when the application shows interest in a given bridge. To supplement this work and test it, this also adds support for the following bridge-related Stasis-HTTP functionality: * GET stasis/bridges * GET stasis/bridges/{bridgeId} * POST stasis/bridges * DELETE stasis/bridges/{bridgeId} * POST stasis/bridges/{bridgeId}/addChannel * POST stasis/bridges/{bridgeId}/removeChannel Review: https://reviewboard.asterisk.org/r/2572/ (closes issue ASTERISK-21711) (closes issue ASTERISK-21621) (closes issue ASTERISK-21622) (closes issue ASTERISK-21623) (closes issue ASTERISK-21624) (closes issue ASTERISK-21625) (closes issue ASTERISK-21626) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@391199 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'res/stasis/app.c')
-rw-r--r--res/stasis/app.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/res/stasis/app.c b/res/stasis/app.c
index 229f4bb20..31e15c221 100644
--- a/res/stasis/app.c
+++ b/res/stasis/app.c
@@ -38,6 +38,12 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
*/
#define APP_CHANNELS_BUCKETS 7
+/*!
+ * \brief Number of buckets for the bridges container for app instances. Remember
+ * to keep it a prime number!
+ */
+#define APP_BRIDGES_BUCKETS 7
+
struct app {
/*! Callback function for this application. */
stasis_app_cb handler;
@@ -45,6 +51,8 @@ struct app {
void *data;
/*! List of channel identifiers this app instance is interested in */
struct ao2_container *channels;
+ /*! List of bridge identifiers this app instance owns */
+ struct ao2_container *bridges;
/*! Name of the Stasis application */
char name[];
};
@@ -57,6 +65,8 @@ static void app_dtor(void *obj)
app->data = NULL;
ao2_cleanup(app->channels);
app->channels = NULL;
+ ao2_cleanup(app->bridges);
+ app->bridges = NULL;
}
struct app *app_create(const char *name, stasis_app_cb handler, void *data)
@@ -84,6 +94,11 @@ struct app *app_create(const char *name, stasis_app_cb handler, void *data)
return NULL;
}
+ app->bridges = ast_str_container_alloc(APP_BRIDGES_BUCKETS);
+ if (!app->bridges) {
+ return NULL;
+ }
+
ao2_ref(app, +1);
return app;
}
@@ -106,6 +121,22 @@ void app_remove_channel(struct app* app, const struct ast_channel *chan)
ao2_find(app->channels, ast_channel_uniqueid(chan), OBJ_KEY | OBJ_NODATA | OBJ_UNLINK);
}
+int app_add_bridge(struct app *app, const char *uniqueid)
+{
+ ast_assert(uniqueid != NULL);
+ ast_assert(app != NULL);
+
+ return ast_str_container_add(app->bridges, uniqueid) ? -1 : 0;
+}
+
+void app_remove_bridge(struct app* app, const char *uniqueid)
+{
+ ast_assert(uniqueid != NULL);
+ ast_assert(app != NULL);
+
+ ao2_find(app->bridges, uniqueid, OBJ_KEY | OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE);
+}
+
/*!
* \brief Send a message to the given application.
* \param app App to send the message to.
@@ -137,3 +168,10 @@ int app_is_watching_channel(struct app *app, const char *uniqueid)
found = ao2_find(app->channels, uniqueid, OBJ_KEY);
return found != NULL;
}
+
+int app_is_watching_bridge(struct app *app, const char *uniqueid)
+{
+ RAII_VAR(char *, found, NULL, ao2_cleanup);
+ found = ao2_find(app->bridges, uniqueid, OBJ_KEY);
+ return found != NULL;
+}