| 1 | /* |
| 2 | * Asterisk -- An open source telephony toolkit. |
| 3 | * |
| 4 | * Copyright (C) 2013, Digium, Inc. |
| 5 | * |
| 6 | * David M. Lee, II <[email protected]> |
| 7 | * |
| 8 | * See http://www.asterisk.org for more information about |
| 9 | * the Asterisk project. Please do not directly contact |
| 10 | * any of the maintainers of this project for assistance; |
| 11 | * the project provides a web site, mailing lists and IRC |
| 12 | * channels for your use. |
| 13 | * |
| 14 | * This program is free software, distributed under the terms of |
| 15 | * the GNU General Public License Version 2. See the LICENSE file |
| 16 | * at the top of the source tree. |
| 17 | */ |
| 18 | |
| 19 | #ifndef _ASTERISK_RES_STASIS_CONTROL_H |
| 20 | #define _ASTERISK_RES_STASIS_CONTROL_H |
| 21 | |
| 22 | /*! \file |
| 23 | * |
| 24 | * \brief Internal API for the Stasis application controller. |
| 25 | * |
| 26 | * \author David M. Lee, II <[email protected]> |
| 27 | * \since 12 |
| 28 | */ |
| 29 | |
| 30 | #include "asterisk/stasis_app.h" |
| 31 | |
| 32 | /*! |
| 33 | * \brief Create a control object. |
| 34 | * |
| 35 | * \param channel Channel to control. |
| 36 | * \param app stasis_app for which this control is being created. |
| 37 | * |
| 38 | * \return New control object. |
| 39 | * \retval NULL on error. |
| 40 | */ |
| 41 | struct stasis_app_control *control_create(struct ast_channel *channel, struct stasis_app *app); |
| 42 | |
| 43 | /*! |
| 44 | * \brief Flush the control command queue. |
| 45 | * \since 13.9.0 |
| 46 | * |
| 47 | * \param control Control object to flush command queue. |
| 48 | */ |
| 49 | void control_flush_queue(struct stasis_app_control *control); |
| 50 | |
| 51 | /*! |
| 52 | * \brief Dispatch all commands enqueued to this control. |
| 53 | * |
| 54 | * \param control Control object to dispatch. |
| 55 | * \param chan Associated channel. |
| 56 | * \return Number of commands executed |
| 57 | */ |
| 58 | int control_dispatch_all(struct stasis_app_control *control, |
| 59 | struct ast_channel *chan); |
| 60 | |
| 61 | /*! |
| 62 | * \brief Blocks until \a control's command queue has a command available. |
| 63 | * |
| 64 | * \param control Control to block on. |
| 65 | */ |
| 66 | void control_wait(struct stasis_app_control *control); |
| 67 | |
| 68 | /*! |
| 69 | * \brief Returns the count of items in a control's command queue. |
| 70 | * |
| 71 | * \param control Control to count commands on |
| 72 | * |
| 73 | * \return number of commands in the command que |
| 74 | */ |
| 75 | int control_command_count(struct stasis_app_control *control); |
| 76 | |
| 77 | /*! |
| 78 | * \brief Returns true if control_continue() has been called on this \a control. |
| 79 | * |
| 80 | * \param control Control to query. |
| 81 | * \retval True (non-zero) if control_continue() has been called. |
| 82 | * \retval False (zero) otherwise. |
| 83 | */ |
| 84 | int control_is_done(struct stasis_app_control *control); |
| 85 | |
| 86 | void control_mark_done(struct stasis_app_control *control); |
| 87 | |
| 88 | /*! |
| 89 | * \brief Dispatch all queued prestart commands |
| 90 | * |
| 91 | * \param control The control for chan |
| 92 | * \param chan The channel on which commands should be executed |
| 93 | * |
| 94 | * \return The number of commands executed |
| 95 | */ |
| 96 | int control_prestart_dispatch_all(struct stasis_app_control *control, |
| 97 | struct ast_channel *chan); |
| 98 | |
| 99 | /*! |
| 100 | * \brief Returns the pointer (non-reffed) to the app associated with this control |
| 101 | * |
| 102 | * \param control Control to query. |
| 103 | * |
| 104 | * \return A pointer to the associated stasis_app |
| 105 | */ |
| 106 | struct stasis_app *control_app(struct stasis_app_control *control); |
| 107 | |
| 108 | /*! |
| 109 | * \brief Set the application the control object belongs to |
| 110 | * |
| 111 | * \param control The control for the channel |
| 112 | * \param app The application this control will now belong to |
| 113 | * |
| 114 | * \note This will unref control's previous app by 1, and bump app by 1 |
| 115 | */ |
| 116 | void control_set_app(struct stasis_app_control *control, struct stasis_app *app); |
| 117 | |
| 118 | /*! |
| 119 | * \brief Returns the name of the application we are moving to |
| 120 | * |
| 121 | * \param control The control for the channel |
| 122 | * |
| 123 | * \return The name of the application we are moving to |
| 124 | */ |
| 125 | char *control_next_app(struct stasis_app_control *control); |
| 126 | |
| 127 | /*! |
| 128 | * \brief Free any memory that was allocated for switching applications via |
| 129 | * /channels/{channelId}/move |
| 130 | * |
| 131 | * \param control The control for the channel |
| 132 | */ |
| 133 | void control_move_cleanup(struct stasis_app_control *control); |
| 134 | |
| 135 | /*! |
| 136 | * \brief Returns the list of arguments to pass to the application we are moving to |
| 137 | * |
| 138 | * \note If you wish to get the size of the list, control_next_app_args_size should be |
| 139 | * called before this, as this function will steal the elements from the string vector |
| 140 | * and set the size to 0. |
| 141 | * |
| 142 | * \param control The control for the channel |
| 143 | * |
| 144 | * \return The arguments to pass to the application we are moving to |
| 145 | */ |
| 146 | char **control_next_app_args(struct stasis_app_control *control); |
| 147 | |
| 148 | /*! |
| 149 | * \brief Returns the number of arguments to be passed to the application we are moving to |
| 150 | * |
| 151 | * \note This should always be called before control_next_app_args, as calling that function |
| 152 | * will steal all elements from the string vector and set the size to 0. |
| 153 | * |
| 154 | * \param control The control for the channel |
| 155 | * |
| 156 | * \return The number of arguments to be passed to the application we are moving to |
| 157 | */ |
| 158 | int control_next_app_args_size(struct stasis_app_control *control); |
| 159 | |
| 160 | /*! |
| 161 | * \brief Command callback for adding a channel to a bridge |
| 162 | * |
| 163 | * \param control The control for chan |
| 164 | * \param chan The channel on which commands should be executed |
| 165 | * \param data Bridge to be passed to the callback |
| 166 | */ |
| 167 | int control_add_channel_to_bridge(struct stasis_app_control *control, struct ast_channel *chan, void *data); |
| 168 | |
| 169 | /*! |
| 170 | * \brief Command for swapping a channel in a bridge |
| 171 | * |
| 172 | * \param control The control for chan |
| 173 | * \param chan The channel on which commands should be executed |
| 174 | * \param bridge Bridge to be passed to the callback |
| 175 | * \param swap Channel to swap with when joining the bridge |
| 176 | */ |
| 177 | int control_swap_channel_in_bridge(struct stasis_app_control *control, struct ast_bridge *bridge, struct ast_channel *chan, struct ast_channel *swap); |
| 178 | |
| 179 | /*! |
| 180 | * \brief Stop playing silence to a channel right now. |
| 181 | * \since 13.9.0 |
| 182 | * |
| 183 | * \param control The control for chan |
| 184 | */ |
| 185 | void control_silence_stop_now(struct stasis_app_control *control); |
| 186 | |
| 187 | |
| 188 | #endif /* _ASTERISK_RES_STASIS_CONTROL_H */ |