app.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@digium.com>
  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. #ifndef _ASTERISK_RES_STASIS_APP_H
  19. #define _ASTERISK_RES_STASIS_APP_H
  20. /*! \file
  21. *
  22. * \brief Internal API for the Stasis application controller.
  23. *
  24. * \author David M. Lee, II <dlee@digium.com>
  25. * \since 12
  26. */
  27. #include "asterisk/channel.h"
  28. #include "asterisk/stasis.h"
  29. #include "asterisk/stasis_app.h"
  30. /*!
  31. * \brief Opaque pointer to \c res_stasis app structure.
  32. */
  33. struct stasis_app;
  34. /*!
  35. * \brief Create a res_stasis application.
  36. *
  37. * \param name Name of the application.
  38. * \param handler Callback for messages sent to the application.
  39. * \param data Data pointer provided to the callback.
  40. * \return New \c res_stasis application.
  41. * \return \c NULL on error.
  42. */
  43. struct stasis_app *app_create(const char *name, stasis_app_cb handler, void *data);
  44. /*!
  45. * \brief Tears down an application.
  46. *
  47. * It should be finished before calling this.
  48. *
  49. * \param app Application to unsubscribe.
  50. */
  51. void app_shutdown(struct stasis_app *app);
  52. /*!
  53. * \brief Deactivates an application.
  54. *
  55. * Any channels currently in the application remain active (since the app might
  56. * come back), but new channels are rejected.
  57. *
  58. * \param app Application to deactivate.
  59. */
  60. void app_deactivate(struct stasis_app *app);
  61. /*!
  62. * \brief Checks whether an app is active.
  63. *
  64. * \param app Application to check.
  65. * \return True (non-zero) if app is active.
  66. * \return False (zero) if app has been deactivated.
  67. */
  68. int app_is_active(struct stasis_app *app);
  69. /*!
  70. * \brief Checks whether a deactivated app has no channels.
  71. *
  72. * \param app Application to check.
  73. * \param True (non-zero) if app is deactivated, and has no associated channels.
  74. * \param False (zero) otherwise.
  75. */
  76. int app_is_finished(struct stasis_app *app);
  77. /*!
  78. * \brief Update the handler and data for a \c res_stasis application.
  79. *
  80. * If app has been deactivated, this will reactivate it.
  81. *
  82. * \param app Application to update.
  83. * \param handler New application callback.
  84. * \param data New data pointer for the callback.
  85. */
  86. void app_update(struct stasis_app *app, stasis_app_cb handler, void *data);
  87. /*!
  88. * \brief Return an application's name.
  89. *
  90. * \param app Application.
  91. * \return Name of the application.
  92. * \return \c NULL is \a app is \c NULL.
  93. */
  94. const char *app_name(const struct stasis_app *app);
  95. /*!
  96. * \brief Send a message to an application.
  97. *
  98. * \param app Application.
  99. * \param message Message to send.
  100. */
  101. void app_send(struct stasis_app *app, struct ast_json *message);
  102. struct app_forwards;
  103. struct ast_json *app_to_json(const struct stasis_app *app);
  104. /*!
  105. * \brief Subscribes an application to a channel.
  106. *
  107. * \param app Application.
  108. * \param chan Channel to subscribe to.
  109. * \return 0 on success.
  110. * \return Non-zero on error.
  111. */
  112. int app_subscribe_channel(struct stasis_app *app, struct ast_channel *chan);
  113. /*!
  114. * \brief Cancel the subscription an app has for a channel.
  115. *
  116. * \param app Subscribing application.
  117. * \param chan Channel to unsubscribe from.
  118. * \return 0 on success.
  119. * \return Non-zero on error.
  120. */
  121. int app_unsubscribe_channel(struct stasis_app *app, struct ast_channel *chan);
  122. /*!
  123. * \brief Cancel the subscription an app has for a channel.
  124. *
  125. * \param app Subscribing application.
  126. * \param channel_id Id of channel to unsubscribe from.
  127. * \return 0 on success.
  128. * \return Non-zero on error.
  129. */
  130. int app_unsubscribe_channel_id(struct stasis_app *app, const char *channel_id);
  131. /*!
  132. * \brief Test if an app is subscribed to a channel.
  133. *
  134. * \param app Subscribing application.
  135. * \param channel_id Id of channel to check.
  136. * \return True (non-zero) if channel is subscribed to \a app.
  137. * \return False (zero) if channel is not subscribed.
  138. */
  139. int app_is_subscribed_channel_id(struct stasis_app *app, const char *channel_id);
  140. /*!
  141. * \brief Add a bridge subscription to an existing channel subscription.
  142. *
  143. * \param app Application.
  144. * \param bridge Bridge to subscribe to.
  145. * \return 0 on success.
  146. * \return Non-zero on error.
  147. */
  148. int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge);
  149. /*!
  150. * \brief Cancel the bridge subscription for an application.
  151. *
  152. * \param forwards Return from app_subscribe_channel().
  153. * \param bridge Bridge to subscribe to.
  154. * \return 0 on success.
  155. * \return Non-zero on error.
  156. */
  157. int app_unsubscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge);
  158. /*!
  159. * \brief Cancel the subscription an app has for a bridge.
  160. *
  161. * \param app Subscribing application.
  162. * \param bridge_id Id of bridge to unsubscribe from.
  163. * \return 0 on success.
  164. * \return Non-zero on error.
  165. */
  166. int app_unsubscribe_bridge_id(struct stasis_app *app, const char *bridge_id);
  167. /*!
  168. * \brief Test if an app is subscribed to a bridge.
  169. *
  170. * \param app Subscribing application.
  171. * \param bridge_id Id of bridge to check.
  172. * \return True (non-zero) if bridge is subscribed to \a app.
  173. * \return False (zero) if bridge is not subscribed.
  174. */
  175. int app_is_subscribed_bridge_id(struct stasis_app *app, const char *bridge_id);
  176. /*!
  177. * \brief Subscribes an application to a endpoint.
  178. *
  179. * \param app Application.
  180. * \param chan Endpoint to subscribe to.
  181. * \return 0 on success.
  182. * \return Non-zero on error.
  183. */
  184. int app_subscribe_endpoint(struct stasis_app *app, struct ast_endpoint *endpoint);
  185. /*!
  186. * \brief Cancel the subscription an app has for a endpoint.
  187. *
  188. * \param app Subscribing application.
  189. * \param endpoint_id Id of endpoint to unsubscribe from.
  190. * \return 0 on success.
  191. * \return Non-zero on error.
  192. */
  193. int app_unsubscribe_endpoint_id(struct stasis_app *app, const char *endpoint_id);
  194. /*!
  195. * \brief Test if an app is subscribed to a endpoint.
  196. *
  197. * \param app Subscribing application.
  198. * \param endpoint_id Id of endpoint to check.
  199. * \return True (non-zero) if endpoint is subscribed to \a app.
  200. * \return False (zero) if endpoint is not subscribed.
  201. */
  202. int app_is_subscribed_endpoint_id(struct stasis_app *app, const char *endpoint_id);
  203. /*!
  204. * \brief Set the snapshot of the channel that this channel will replace
  205. *
  206. * \param channel The channel on which this will be set
  207. * \param replace_snapshot The snapshot of the channel that is being replaced
  208. *
  209. * \retval zero success
  210. * \retval non-zero failure
  211. */
  212. int app_set_replace_channel_snapshot(struct ast_channel *chan, struct ast_channel_snapshot *replace_snapshot);
  213. /*!
  214. * \brief Set the app that the replacement channel will be controlled by
  215. *
  216. * \param channel The channel on which this will be set
  217. * \param replace_app The app that will be controlling this channel
  218. *
  219. * \retval zero success
  220. * \retval non-zero failure
  221. */
  222. int app_set_replace_channel_app(struct ast_channel *chan, const char *replace_app);
  223. /*!
  224. * \brief Get the app that the replacement channel will be controlled by
  225. *
  226. * \param channel The channel on which this will be set
  227. *
  228. * \retval NULL on error
  229. * \return the name of the controlling app (must be ast_free()d)
  230. */
  231. char *app_get_replace_channel_app(struct ast_channel *chan);
  232. /*!
  233. * \brief Replace channel topic forwards for the old channel with forwards for the new channel
  234. *
  235. * \param app The app that owns the channel
  236. * \param old_id The unique ID of the channel to be replaced
  237. * \param new_chan The channel that is replacing the old one
  238. *
  239. * \retval zero on success
  240. * \return non-zero on failure
  241. */
  242. int app_replace_channel_forwards(struct stasis_app *app, const char *old_id, struct ast_channel *new_chan);
  243. #endif /* _ASTERISK_RES_STASIS_APP_H */