struct stasis_app_control *stasis_app_control_create(struct ast_channel *chan)
{
- return control_create(chan);
+ return control_create(chan, NULL);
}
struct stasis_app_control *stasis_app_control_find_by_channel(
return -1;
}
- control = control_create(chan);
+ control = control_create(chan, app);
if (!control) {
ast_log(LOG_ERROR, "Allocated failed\n");
return -1;
#include "command.h"
#include "control.h"
+#include "app.h"
#include "asterisk/dial.h"
#include "asterisk/bridge.h"
#include "asterisk/bridge_after.h"
*/
struct ast_silence_generator *silgen;
/*!
+ * The app for which this control was created
+ */
+ struct stasis_app *app;
+ /*!
* When set, /c app_stasis should exit and continue in the dialplan.
*/
int is_done:1;
ao2_cleanup(control->command_queue);
ast_cond_destroy(&control->wait_cond);
+ ao2_cleanup(control->app);
}
-struct stasis_app_control *control_create(struct ast_channel *channel)
+struct stasis_app_control *control_create(struct ast_channel *channel, struct stasis_app *app)
{
RAII_VAR(struct stasis_app_control *, control, NULL, ao2_cleanup);
int res;
return NULL;
}
+ control->app = ao2_bump(app);
+
res = ast_cond_init(&control->wait_cond, NULL);
if (res != 0) {
ast_log(LOG_ERROR, "Error initializing ast_cond_t: %s\n",
ast_channel_pbx_set(control->channel, control->pbx);
control->pbx = NULL;
+ app_unsubscribe_bridge(control->app, control->bridge);
+
/* No longer in the bridge */
control->bridge = NULL;
*/
SCOPED_AO2LOCK(lock, control);
+ /* Ensure the controlling application is subscribed early enough
+ * to receive the ChannelEnteredBridge message. This works in concert
+ * with the subscription handled in the Stasis application execution
+ * loop */
+ app_subscribe_bridge(control->app, bridge);
+
/* Save off the channel's PBX */
ast_assert(control->pbx == NULL);
if (!control->pbx) {
* \brief Create a control object.
*
* \param channel Channel to control.
+ * \param app stasis_app for which this control is being created.
+ *
* \return New control object.
* \return \c NULL on error.
*/
-struct stasis_app_control *control_create(struct ast_channel *channel);
+struct stasis_app_control *control_create(struct ast_channel *channel, struct stasis_app *app);
/*!
* \brief Dispatch all commands enqueued to this control.