app.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. enum stasis_app_subscription_model {
  35. /*
  36. * \brief An application must manually subscribe to each
  37. * resource that it cares about. This is the default approach.
  38. */
  39. STASIS_APP_SUBSCRIBE_MANUAL,
  40. /*
  41. * \brief An application is automatically subscribed to all
  42. * resources in Asterisk, even if it does not control them.
  43. */
  44. STASIS_APP_SUBSCRIBE_ALL
  45. };
  46. /*!
  47. * \brief Create a res_stasis application.
  48. *
  49. * \param name Name of the application.
  50. * \param handler Callback for messages sent to the application.
  51. * \param data Data pointer provided to the callback.
  52. * \return New \c res_stasis application.
  53. * \return \c NULL on error.
  54. */
  55. struct stasis_app *app_create(const char *name, stasis_app_cb handler, void *data, enum stasis_app_subscription_model subscription_model);
  56. /*!
  57. * \brief Tears down an application.
  58. *
  59. * It should be finished before calling this.
  60. *
  61. * \param app Application to unsubscribe.
  62. */
  63. void app_shutdown(struct stasis_app *app);
  64. /*!
  65. * \brief Deactivates an application.
  66. *
  67. * Any channels currently in the application remain active (since the app might
  68. * come back), but new channels are rejected.
  69. *
  70. * \param app Application to deactivate.
  71. */
  72. void app_deactivate(struct stasis_app *app);
  73. /*!
  74. * \brief Checks whether an app is active.
  75. *
  76. * \param app Application to check.
  77. * \return True (non-zero) if app is active.
  78. * \return False (zero) if app has been deactivated.
  79. */
  80. int app_is_active(struct stasis_app *app);
  81. /*!
  82. * \brief Checks whether a deactivated app has no channels.
  83. *
  84. * \param app Application to check.
  85. * \param True (non-zero) if app is deactivated, and has no associated channels.
  86. * \param False (zero) otherwise.
  87. */
  88. int app_is_finished(struct stasis_app *app);
  89. /*!
  90. * \brief Update the handler and data for a \c res_stasis application.
  91. *
  92. * If app has been deactivated, this will reactivate it.
  93. *
  94. * \param app Application to update.
  95. * \param handler New application callback.
  96. * \param data New data pointer for the callback.
  97. */
  98. void app_update(struct stasis_app *app, stasis_app_cb handler, void *data);
  99. /*!
  100. * \brief Send a message to an application.
  101. *
  102. * \param app Application.
  103. * \param message Message to send.
  104. */
  105. void app_send(struct stasis_app *app, struct ast_json *message);
  106. struct app_forwards;
  107. /*!
  108. * \brief Create a JSON representation of a \c stasis_app
  109. *
  110. * \param app The application
  111. *
  112. * \return \c JSON blob on success
  113. * \return \c NULL on error
  114. */
  115. struct ast_json *app_to_json(const struct stasis_app *app);
  116. /*!
  117. * \brief Subscribes an application to a channel.
  118. *
  119. * \param app Application.
  120. * \param chan Channel to subscribe to.
  121. * \return 0 on success.
  122. * \return Non-zero on error.
  123. */
  124. int app_subscribe_channel(struct stasis_app *app, struct ast_channel *chan);
  125. /*!
  126. * \brief Cancel the subscription an app has for a channel.
  127. *
  128. * \param app Subscribing application.
  129. * \param chan Channel to unsubscribe from.
  130. * \return 0 on success.
  131. * \return Non-zero on error.
  132. */
  133. int app_unsubscribe_channel(struct stasis_app *app, struct ast_channel *chan);
  134. /*!
  135. * \brief Cancel the subscription an app has for a channel.
  136. *
  137. * \param app Subscribing application.
  138. * \param channel_id Id of channel to unsubscribe from.
  139. * \return 0 on success.
  140. * \return Non-zero on error.
  141. */
  142. int app_unsubscribe_channel_id(struct stasis_app *app, const char *channel_id);
  143. /*!
  144. * \brief Test if an app is subscribed to a channel.
  145. *
  146. * \param app Subscribing application.
  147. * \param channel_id Id of channel to check.
  148. * \return True (non-zero) if channel is subscribed to \a app.
  149. * \return False (zero) if channel is not subscribed.
  150. */
  151. int app_is_subscribed_channel_id(struct stasis_app *app, const char *channel_id);
  152. /*!
  153. * \brief Add a bridge subscription to an existing channel subscription.
  154. *
  155. * \param app Application.
  156. * \param bridge Bridge to subscribe to.
  157. * \return 0 on success.
  158. * \return Non-zero on error.
  159. */
  160. int app_subscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge);
  161. /*!
  162. * \brief Cancel the bridge subscription for an application.
  163. *
  164. * \param forwards Return from app_subscribe_channel().
  165. * \param bridge Bridge to subscribe to.
  166. * \return 0 on success.
  167. * \return Non-zero on error.
  168. */
  169. int app_unsubscribe_bridge(struct stasis_app *app, struct ast_bridge *bridge);
  170. /*!
  171. * \brief Cancel the subscription an app has for a bridge.
  172. *
  173. * \param app Subscribing application.
  174. * \param bridge_id Id of bridge to unsubscribe from.
  175. * \return 0 on success.
  176. * \return Non-zero on error.
  177. */
  178. int app_unsubscribe_bridge_id(struct stasis_app *app, const char *bridge_id);
  179. /*!
  180. * \brief Test if an app is subscribed to a bridge.
  181. *
  182. * \param app Subscribing application.
  183. * \param bridge_id Id of bridge to check.
  184. * \return True (non-zero) if bridge is subscribed to \a app.
  185. * \return False (zero) if bridge is not subscribed.
  186. */
  187. int app_is_subscribed_bridge_id(struct stasis_app *app, const char *bridge_id);
  188. /*!
  189. * \brief Subscribes an application to a endpoint.
  190. *
  191. * \param app Application.
  192. * \param chan Endpoint to subscribe to.
  193. * \return 0 on success.
  194. * \return Non-zero on error.
  195. */
  196. int app_subscribe_endpoint(struct stasis_app *app, struct ast_endpoint *endpoint);
  197. /*!
  198. * \brief Cancel the subscription an app has for a endpoint.
  199. *
  200. * \param app Subscribing application.
  201. * \param endpoint_id Id of endpoint to unsubscribe from.
  202. * \return 0 on success.
  203. * \return Non-zero on error.
  204. */
  205. int app_unsubscribe_endpoint_id(struct stasis_app *app, const char *endpoint_id);
  206. /*!
  207. * \brief Test if an app is subscribed to a endpoint.
  208. *
  209. * \param app Subscribing application.
  210. * \param endpoint_id Id of endpoint to check.
  211. * \return True (non-zero) if endpoint is subscribed to \a app.
  212. * \return False (zero) if endpoint is not subscribed.
  213. */
  214. int app_is_subscribed_endpoint_id(struct stasis_app *app, const char *endpoint_id);
  215. /*!
  216. * \brief Set the snapshot of the channel that this channel will replace
  217. *
  218. * \param channel The channel on which this will be set
  219. * \param replace_snapshot The snapshot of the channel that is being replaced
  220. *
  221. * \retval zero success
  222. * \retval non-zero failure
  223. */
  224. int app_set_replace_channel_snapshot(struct ast_channel *chan, struct ast_channel_snapshot *replace_snapshot);
  225. /*!
  226. * \brief Set the app that the replacement channel will be controlled by
  227. *
  228. * \param channel The channel on which this will be set
  229. * \param replace_app The app that will be controlling this channel
  230. *
  231. * \retval zero success
  232. * \retval non-zero failure
  233. */
  234. int app_set_replace_channel_app(struct ast_channel *chan, const char *replace_app);
  235. /*!
  236. * \brief Get the app that the replacement channel will be controlled by
  237. *
  238. * \param channel The channel on which this will be set
  239. *
  240. * \retval NULL on error
  241. * \return the name of the controlling app (must be ast_free()d)
  242. */
  243. char *app_get_replace_channel_app(struct ast_channel *chan);
  244. /*!
  245. * \brief Send StasisEnd message to the listening app
  246. *
  247. * \param app The app that owns the channel
  248. * \param chan The channel for which the message is being sent
  249. *
  250. * \retval zero on success
  251. * \return non-zero on failure
  252. */
  253. int app_send_end_msg(struct stasis_app *app, struct ast_channel *chan);
  254. #endif /* _ASTERISK_RES_STASIS_APP_H */