mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
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
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user