mirror of
https://github.com/asterisk/asterisk.git
synced 2025-11-19 00:00:09 +00:00
ARI: WebSocket event cleanup
Stasis events (which get distributed over the ARI WebSocket) are created by subscribing to the channel_all_cached and bridge_all_cached topics, filtering out events for channels/bridges currently subscribed to. There are two issues with that. First was a race condition, where messages in-flight to the master subscribe-to-all-things topic would get sent out, even though the events happened before the channel was put into Stasis. Secondly, as the number of channels and bridges grow in the system, the work spent filtering messages becomes excessive. Since r395954, individual channels and bridges have caching topics, and can be subscribed to individually. This patch takes advantage, so that channels and bridges are subscribed to on demand, instead of filtering the global topics. The one case where filtering is still required is handling BridgeMerge messages, which are published directly to the bridge_all topic. Other than the change to how subscriptions work, this patch mostly just moves code around. Most of the work generating JSON objects from messages was moved to .to_json handlers on the message types. The callback functions handling app subscriptions were moved from res_stasis (b/c they were global to the model) to stasis/app.c (b/c they are local to the app now). (closes issue ASTERISK-21969) Reported by: Matt Jordan Review: https://reviewboard.asterisk.org/r/2754/ ........ Merged revisions 397816 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@397820 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -47,6 +47,15 @@ struct app;
|
||||
*/
|
||||
struct app *app_create(const char *name, stasis_app_cb handler, void *data);
|
||||
|
||||
/*!
|
||||
* \brief Tears down an application.
|
||||
*
|
||||
* It should be finished before calling this.
|
||||
*
|
||||
* \param app Application to unsubscribe.
|
||||
*/
|
||||
void app_shutdown(struct app *app);
|
||||
|
||||
/*!
|
||||
* \brief Deactivates an application.
|
||||
*
|
||||
@@ -95,17 +104,6 @@ void app_update(struct app *app, stasis_app_cb handler, void *data);
|
||||
*/
|
||||
const char *app_name(const struct app *app);
|
||||
|
||||
/*!
|
||||
* \brief Subscribe an application to a topic.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param topic Topic to subscribe to.
|
||||
* \return New subscription.
|
||||
* \return \c NULL on error.
|
||||
*/
|
||||
struct stasis_subscription *app_subscribe(struct app *app,
|
||||
struct stasis_topic *topic);
|
||||
|
||||
/*!
|
||||
* \brief Send a message to an application.
|
||||
*
|
||||
@@ -114,83 +112,44 @@ struct stasis_subscription *app_subscribe(struct app *app,
|
||||
*/
|
||||
void app_send(struct app *app, struct ast_json *message);
|
||||
|
||||
struct app_forwards;
|
||||
|
||||
/*!
|
||||
* \brief Send the start message to an application.
|
||||
* \brief Subscribes an application to a channel.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param chan The channel entering the application.
|
||||
* \param argc The number of arguments for the application.
|
||||
* \param argv The arguments for the application.
|
||||
* \param chan Channel to subscribe to.
|
||||
* \return 0 on success.
|
||||
* \return Non-zero on error.
|
||||
*/
|
||||
int app_send_start_msg(struct app *app, struct ast_channel *chan, int argc,
|
||||
char *argv[]);
|
||||
int app_subscribe_channel(struct app *app, struct ast_channel *chan);
|
||||
|
||||
/*!
|
||||
* \brief Send the end message to an application.
|
||||
* \brief Cancel the subscription an app has for a channel.
|
||||
*
|
||||
* \param app Subscribing application.
|
||||
* \param forwards Returned object from app_subscribe_channel().
|
||||
*/
|
||||
int app_unsubscribe_channel(struct app *app, struct ast_channel *chan);
|
||||
|
||||
/*!
|
||||
* \brief Add a bridge subscription to an existing channel subscription.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param chan The channel leaving the application.
|
||||
* \param bridge Bridge to subscribe to.
|
||||
* \return 0 on success.
|
||||
* \return Non-zero on error.
|
||||
*/
|
||||
int app_send_end_msg(struct app *app, struct ast_channel *chan);
|
||||
int app_subscribe_bridge(struct app *app, struct ast_bridge *bridge);
|
||||
|
||||
/*!
|
||||
* \brief Checks if an application is watching a given channel.
|
||||
* \brief Cancel the bridge subscription for an application.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param uniqueid Uniqueid of the channel to check about.
|
||||
* \return True (non-zero) if \a app is watching channel with given \a uniqueid
|
||||
* \return False (zero) if \a app isn't.
|
||||
*/
|
||||
int app_is_watching_channel(struct app *app, const char *uniqueid);
|
||||
|
||||
/*!
|
||||
* \brief Add a channel to an application's watch list.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param chan Channel to watch.
|
||||
* \param forwards Return from app_subscribe_channel().
|
||||
* \param bridge Bridge to subscribe to.
|
||||
* \return 0 on success.
|
||||
* \return Non-zero on error.
|
||||
*/
|
||||
int app_add_channel(struct app *app, const struct ast_channel *chan);
|
||||
|
||||
/*!
|
||||
* \brief Remove a channel from an application's watch list.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param chan Channel to watch.
|
||||
*/
|
||||
void app_remove_channel(struct app *app, const struct ast_channel *chan);
|
||||
|
||||
/*!
|
||||
* \brief Add a bridge to an application's watch list by uniqueid.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param bridge Bridge to watch.
|
||||
* \return 0 on success.
|
||||
* \return Non-zero on error.
|
||||
*/
|
||||
int app_add_bridge(struct app *app, const char *uniqueid);
|
||||
|
||||
/*!
|
||||
* \brief Remove a bridge from an application's watch list by uniqueid.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param bridge Bridge to remove.
|
||||
*/
|
||||
void app_remove_bridge(struct app* app, const char *uniqueid);
|
||||
|
||||
/*!
|
||||
* \brief Checks if an application is watching a given bridge.
|
||||
*
|
||||
* \param app Application.
|
||||
* \param uniqueid Uniqueid of the bridge to check.
|
||||
* \return True (non-zero) if \a app is watching bridge with given \a uniqueid
|
||||
* \return False (zero) if \a app isn't.
|
||||
*/
|
||||
int app_is_watching_bridge(struct app *app, const char *uniqueid);
|
||||
int app_unsubscribe_bridge(struct app *app, struct ast_bridge *bridge);
|
||||
|
||||
#endif /* _ASTERISK_RES_STASIS_APP_H */
|
||||
|
||||
Reference in New Issue
Block a user