[asterisk-commits] kmoore: branch group/ari-greedy-atxfer r419314 - in /team/group/ari-greedy-at...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jul 23 10:57:40 CDT 2014
Author: kmoore
Date: Wed Jul 23 10:57:37 2014
New Revision: 419314
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=419314
Log:
Stasis: Allow prestart actions to be queued
This allows commands to be queued in a channel datastore to be executed
upon a channel entering Stasis(). This functionality is only available
from components of res_stasis.so. This functionality is required to get
a redirected channel back into the bridge for which it was destined due
to the attended transfer.
ASTERISK-23941
Review: https://reviewboard.asterisk.org/r/3729/
Modified:
team/group/ari-greedy-atxfer/res/res_stasis.c
team/group/ari-greedy-atxfer/res/stasis/command.c
team/group/ari-greedy-atxfer/res/stasis/command.h
team/group/ari-greedy-atxfer/res/stasis/control.c
team/group/ari-greedy-atxfer/res/stasis/control.h
Modified: team/group/ari-greedy-atxfer/res/res_stasis.c
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/res_stasis.c?view=diff&rev=419314&r1=419313&r2=419314
==============================================================================
--- team/group/ari-greedy-atxfer/res/res_stasis.c (original)
+++ team/group/ari-greedy-atxfer/res/res_stasis.c Wed Jul 23 10:57:37 2014
@@ -882,6 +882,9 @@
return -1;
}
+ /* Pull queued prestart commands and execute */
+ control_prestart_dispatch_all(control, chan);
+
while (!control_is_done(control)) {
RAII_VAR(struct ast_frame *, f, NULL, ast_frame_dtor);
int r;
Modified: team/group/ari-greedy-atxfer/res/stasis/command.c
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/stasis/command.c?view=diff&rev=419314&r1=419313&r2=419314
==============================================================================
--- team/group/ari-greedy-atxfer/res/stasis/command.c (original)
+++ team/group/ari-greedy-atxfer/res/stasis/command.c Wed Jul 23 10:57:37 2014
@@ -93,3 +93,61 @@
command_complete(command, retval);
}
+static void command_queue_prestart_destroy(void *obj)
+{
+ /* Clean up the container */
+ ao2_cleanup(obj);
+}
+
+static const struct ast_datastore_info command_queue_prestart = {
+ .type = "stasis-command-prestart-queue",
+ .destroy = command_queue_prestart_destroy,
+};
+
+int command_prestart_queue_command(struct ast_channel *chan,
+ stasis_app_command_cb command_fn, void *data)
+{
+ struct ast_datastore *datastore;
+ struct ao2_container *command_queue;
+ RAII_VAR(struct stasis_app_command *, command,
+ command_create(command_fn, data), ao2_cleanup);
+
+ if (!command) {
+ return -1;
+ }
+
+ datastore = ast_channel_datastore_find(chan, &command_queue_prestart, NULL);
+ if (datastore) {
+ command_queue = datastore->data;
+ ao2_link(command_queue, command);
+ return 0;
+ }
+
+ command_queue = ao2_container_alloc_list(
+ AO2_ALLOC_OPT_LOCK_MUTEX, 0, NULL, NULL);
+ if (!command_queue) {
+ return -1;
+ }
+
+ datastore = ast_datastore_alloc(&command_queue_prestart, NULL);
+ if (!datastore) {
+ ao2_cleanup(command_queue);
+ return -1;
+ }
+ ast_channel_datastore_add(chan, datastore);
+
+ datastore->data = command_queue;
+ ao2_link(command_queue, command);
+
+ return 0;
+}
+
+struct ao2_container *command_prestart_get_container(struct ast_channel *chan)
+{
+ struct ast_datastore *datastore = ast_channel_datastore_find(chan, &command_queue_prestart, NULL);
+ if (!datastore) {
+ return NULL;
+ }
+
+ return ao2_bump(datastore->data);
+}
Modified: team/group/ari-greedy-atxfer/res/stasis/command.h
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/stasis/command.h?view=diff&rev=419314&r1=419313&r2=419314
==============================================================================
--- team/group/ari-greedy-atxfer/res/stasis/command.h (original)
+++ team/group/ari-greedy-atxfer/res/stasis/command.h Wed Jul 23 10:57:37 2014
@@ -41,4 +41,31 @@
int command_join(struct stasis_app_command *command);
+/*!
+ * \brief Queue a Stasis() prestart command for a channel
+ *
+ * \pre chan must be locked
+ *
+ * \param chan The channel on which to queue the prestart command
+ * \param command_fn The callback to call for the command
+ * \param data The data to pass to the command callback
+ *
+ * \retval zero on success
+ * \retval non-zero on failure
+ */
+int command_prestart_queue_command(struct ast_channel *chan,
+ stasis_app_command_cb command_fn, void *data);
+
+/*!
+ * \brief Get the Stasis() prestart commands for a channel
+ *
+ * \pre chan must be locked
+ *
+ * \param chan The channel from which to get prestart commands
+ *
+ * \return The command prestart container for chan (must be ao2_cleanup()'d)
+ */
+struct ao2_container *command_prestart_get_container(struct ast_channel *chan);
+
+
#endif /* _ASTERISK_RES_STASIS_CONTROL_H */
Modified: team/group/ari-greedy-atxfer/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/stasis/control.c?view=diff&rev=419314&r1=419313&r2=419314
==============================================================================
--- team/group/ari-greedy-atxfer/res/stasis/control.c (original)
+++ team/group/ari-greedy-atxfer/res/stasis/control.c Wed Jul 23 10:57:37 2014
@@ -1036,3 +1036,31 @@
}
ao2_unlock(control->command_queue);
}
+
+int control_prestart_dispatch_all(struct stasis_app_control *control,
+ struct ast_channel *chan)
+{
+ struct ao2_container *command_queue;
+ int count = 0;
+ struct ao2_iterator iter;
+ struct stasis_app_command *command;
+
+ ast_channel_lock(chan);
+ command_queue = command_prestart_get_container(chan);
+ ast_channel_unlock(chan);
+ if (!command_queue) {
+ return 0;
+ }
+
+ iter = ao2_iterator_init(command_queue, AO2_ITERATOR_UNLINK);
+
+ while ((command = ao2_iterator_next(&iter))) {
+ command_invoke(command, control, chan);
+ ao2_cleanup(command);
+ ++count;
+ }
+
+ ao2_iterator_destroy(&iter);
+ ao2_cleanup(command_queue);
+ return count;
+}
Modified: team/group/ari-greedy-atxfer/res/stasis/control.h
URL: http://svnview.digium.com/svn/asterisk/team/group/ari-greedy-atxfer/res/stasis/control.h?view=diff&rev=419314&r1=419313&r2=419314
==============================================================================
--- team/group/ari-greedy-atxfer/res/stasis/control.h (original)
+++ team/group/ari-greedy-atxfer/res/stasis/control.h Wed Jul 23 10:57:37 2014
@@ -77,5 +77,16 @@
void control_mark_done(struct stasis_app_control *control);
+/*!
+ * \brief Dispatch all queued prestart commands
+ *
+ * \param control The control for chan
+ * \param channel The channel on which commands should be executed
+ *
+ * \return The number of commands executed
+ */
+int control_prestart_dispatch_all(struct stasis_app_control *control,
+ struct ast_channel *chan);
+
#endif /* _ASTERISK_RES_STASIS_CONTROL_H */
More information about the asterisk-commits
mailing list