stasis_app.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2012 - 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_STASIS_APP_H
  19. #define _ASTERISK_STASIS_APP_H
  20. /*! \file
  21. *
  22. * \brief Stasis Application API. See \ref res_stasis "Stasis Application API"
  23. * for detailed documentation.
  24. *
  25. * \author David M. Lee, II <dlee@digium.com>
  26. * \since 12
  27. *
  28. * \page res_stasis Stasis Application API
  29. *
  30. * This is the API that binds the Stasis dialplan application to external
  31. * Stasis applications, such as \c res_stasis_websocket.
  32. *
  33. * The associated \c res_stasis module registers a dialplan function named \c
  34. * Stasis, which uses \c res_stasis to put a channel into the named Stasis
  35. * app. As a channel enters and leaves the Stasis diaplan application, the
  36. * Stasis app receives a \c 'stasis-start' and \c 'stasis-end' events.
  37. *
  38. * Stasis apps register themselves using the \ref stasis_app_register and
  39. * stasis_app_unregister functions. Messages are sent to an appliction using
  40. * \ref stasis_app_send.
  41. *
  42. * Finally, Stasis apps control channels through the use of the \ref
  43. * stasis_app_control object, and the family of \c stasis_app_control_*
  44. * functions.
  45. *
  46. * Since module unload order is based on reference counting, any module that
  47. * uses the API defined in this file must call stasis_app_ref() when loaded,
  48. * and stasis_app_unref() when unloaded.
  49. */
  50. #include "asterisk/channel.h"
  51. /*! @{ */
  52. /*!
  53. * \brief Callback for Stasis application handler.
  54. *
  55. * The message given to the handler is a borrowed copy. If you want to keep a
  56. * reference to it, you should use \c ao2_ref() to keep it around.
  57. *
  58. * \param data Data ptr given when registered.
  59. * \param app_name Name of the application being dispatched to.
  60. * \param message Message to handle. (borrowed copy)
  61. */
  62. typedef void (*stasis_app_cb)(void *data, const char *app_name,
  63. struct ast_json *message);
  64. /*!
  65. * \brief Gets the names of all registered Stasis applications.
  66. *
  67. * \return \c ast_str_container of container names.
  68. * \return \c NULL on error.
  69. */
  70. struct ao2_container *stasis_app_get_all(void);
  71. /*!
  72. * \brief Retrieve a handle to a Stasis application by its name
  73. *
  74. * \param name The name of the registered Stasis application
  75. *
  76. * \return \c stasis_app on success.
  77. * \return \c NULL on error.
  78. */
  79. struct stasis_app *stasis_app_get_by_name(const char *name);
  80. /*!
  81. * \brief Register a new Stasis application.
  82. *
  83. * If an application is already registered with the given name, the old
  84. * application is sent a 'replaced' message and unregistered.
  85. *
  86. * \param app_name Name of this application.
  87. * \param handler Callback for application messages.
  88. * \param data Data blob to pass to the callback. Must be AO2 managed.
  89. *
  90. * \return 0 for success
  91. * \return -1 for error.
  92. */
  93. int stasis_app_register(const char *app_name, stasis_app_cb handler, void *data);
  94. /*!
  95. * \brief Register a new Stasis application that receives all Asterisk events.
  96. *
  97. * If an application is already registered with the given name, the old
  98. * application is sent a 'replaced' message and unregistered.
  99. *
  100. * \param app_name Name of this application.
  101. * \param handler Callback for application messages.
  102. * \param data Data blob to pass to the callback. Must be AO2 managed.
  103. *
  104. * \return 0 for success
  105. * \return -1 for error.
  106. */
  107. int stasis_app_register_all(const char *app_name, stasis_app_cb handler, void *data);
  108. /*!
  109. * \brief Unregister a Stasis application.
  110. * \param app_name Name of the application to unregister.
  111. */
  112. void stasis_app_unregister(const char *app_name);
  113. /*!
  114. * \brief Send a message to the given Stasis application.
  115. *
  116. * The message given to the handler is a borrowed copy. If you want to keep a
  117. * reference to it, you should use \c ao2_ref() to keep it around.
  118. *
  119. * \param app_name Name of the application to invoke.
  120. * \param message Message to send (borrowed reference)
  121. *
  122. * \return 0 for success.
  123. * \return -1 for error.
  124. */
  125. int stasis_app_send(const char *app_name, struct ast_json *message);
  126. /*! \brief Forward declare app */
  127. struct stasis_app;
  128. /*!
  129. * \brief Retrieve an application's name
  130. *
  131. * \param app An application
  132. *
  133. * \return The name of the application.
  134. */
  135. const char *stasis_app_name(const struct stasis_app *app);
  136. /*!
  137. * \brief Return the JSON representation of a Stasis application.
  138. *
  139. * \param app_name Name of the application.
  140. *
  141. * \return JSON representation of app with given name.
  142. * \return \c NULL on error.
  143. */
  144. struct ast_json *stasis_app_to_json(const char *app_name);
  145. /*!
  146. * \brief Event source information and callbacks.
  147. */
  148. struct stasis_app_event_source {
  149. /*! \brief The scheme to match against on [un]subscribes */
  150. const char *scheme;
  151. /*!
  152. * \brief Find an event source data object by the given id/name.
  153. *
  154. * \param app Application
  155. * \param id A unique identifier to search on
  156. *
  157. * \return The data object associated with the id/name.
  158. */
  159. void *(*find)(const struct stasis_app *app, const char *id);
  160. /*!
  161. * \brief Subscribe an application to an event source.
  162. *
  163. * \param app Application
  164. * \param obj an event source data object
  165. *
  166. * \return 0 on success, failure code otherwise
  167. */
  168. int (*subscribe)(struct stasis_app *app, void *obj);
  169. /*!
  170. * \brief Cancel the subscription an app has to an event source.
  171. *
  172. * \param app Application
  173. * \param id a previously subscribed object id
  174. *
  175. * \return 0 on success, failure code otherwise
  176. */
  177. int (*unsubscribe)(struct stasis_app *app, const char *id);
  178. /*!
  179. * \brief Find an event source by the given id/name.
  180. *
  181. * \param app Application
  182. * \param id A unique identifier to check
  183. *
  184. * \return true if id is subscribed, false otherwise.
  185. */
  186. int (*is_subscribed)(struct stasis_app *app, const char *id);
  187. /*!
  188. * \brief Convert event source data to json
  189. *
  190. * \param app Application
  191. * \param id json object to fill
  192. */
  193. void (*to_json)(const struct stasis_app *app, struct ast_json *json);
  194. /*! Next item in the list */
  195. AST_LIST_ENTRY(stasis_app_event_source) next;
  196. };
  197. /*!
  198. * \brief Register an application event source.
  199. *
  200. * \param obj the event source to register
  201. */
  202. void stasis_app_register_event_source(struct stasis_app_event_source *obj);
  203. /*!
  204. * \brief Register core event sources.
  205. */
  206. void stasis_app_register_event_sources(void);
  207. /*!
  208. * \brief Checks to see if the given object is a core event source
  209. *
  210. * \note core event sources are currently only endpoint, bridge, and channel.
  211. *
  212. * \param obj event source object to check
  213. *
  214. * \return non-zero if core event source, otherwise 0 (false)
  215. */
  216. int stasis_app_is_core_event_source(struct stasis_app_event_source *obj);
  217. /*!
  218. * \brief Unregister an application event source.
  219. *
  220. * \param obj the event source to unregister
  221. */
  222. void stasis_app_unregister_event_source(struct stasis_app_event_source *obj);
  223. /*!
  224. * \brief Unregister core event sources.
  225. */
  226. void stasis_app_unregister_event_sources(void);
  227. /*! \brief Return code for stasis_app_user_event */
  228. enum stasis_app_user_event_res {
  229. STASIS_APP_USER_OK,
  230. STASIS_APP_USER_APP_NOT_FOUND,
  231. STASIS_APP_USER_EVENT_SOURCE_NOT_FOUND,
  232. STASIS_APP_USER_EVENT_SOURCE_BAD_SCHEME,
  233. STASIS_APP_USER_USEREVENT_INVALID,
  234. STASIS_APP_USER_INTERNAL_ERROR,
  235. };
  236. /*!
  237. * \brief Generate a Userevent for stasis app (echo to AMI)
  238. *
  239. * \param app_name Name of the application to generate event for/to.
  240. * \param event_name Name of the Userevent.
  241. * \param source_uris URIs for the source objects to attach to event.
  242. * \param sources_count Array size of source_uris.
  243. * \param json_variables event blob variables.
  244. *
  245. * \return \ref stasis_app_user_event_res return code.
  246. */
  247. enum stasis_app_user_event_res stasis_app_user_event(const char *app_name,
  248. const char *event_name,
  249. const char **source_uris, int sources_count,
  250. struct ast_json *json_variables);
  251. /*! \brief Return code for stasis_app_[un]subscribe */
  252. enum stasis_app_subscribe_res {
  253. STASIS_ASR_OK,
  254. STASIS_ASR_APP_NOT_FOUND,
  255. STASIS_ASR_EVENT_SOURCE_NOT_FOUND,
  256. STASIS_ASR_EVENT_SOURCE_BAD_SCHEME,
  257. STASIS_ASR_INTERNAL_ERROR,
  258. };
  259. /*!
  260. * \brief Subscribes an application to a list of event sources.
  261. *
  262. * \param app_name Name of the application to subscribe.
  263. * \param event_source_uris URIs for the event sources to subscribe to.
  264. * \param event_sources_count Array size of event_source_uris.
  265. * \param json Optional output pointer for JSON representation of the app
  266. * after adding the subscription.
  267. *
  268. * \return \ref stasis_app_subscribe_res return code.
  269. *
  270. * \note Do not hold any channel locks if subscribing to a channel.
  271. */
  272. enum stasis_app_subscribe_res stasis_app_subscribe(const char *app_name,
  273. const char **event_source_uris, int event_sources_count,
  274. struct ast_json **json);
  275. /*!
  276. * \brief Unsubscribes an application from a list of event sources.
  277. *
  278. * \param app_name Name of the application to subscribe.
  279. * \param event_source_uris URIs for the event sources to subscribe to.
  280. * \param event_sources_count Array size of event_source_uris.
  281. * \param json Optional output pointer for JSON representation of the app
  282. * after adding the subscription.
  283. *
  284. * \return \ref stasis_app_subscribe_res return code.
  285. */
  286. enum stasis_app_subscribe_res stasis_app_unsubscribe(const char *app_name,
  287. const char **event_source_uris, int event_sources_count,
  288. struct ast_json **json);
  289. /*!
  290. * \brief Directly subscribe an application to a channel
  291. *
  292. * \param app_name Name of the application to subscribe.
  293. * \param chan The channel to subscribe to
  294. *
  295. * \return \ref stasis_app_subscribe_res return code.
  296. *
  297. * \note This method can be used when you already hold a channel and its
  298. * lock. This bypasses the channel lookup that would normally be
  299. * performed by \ref stasis_app_subscribe.
  300. */
  301. enum stasis_app_subscribe_res stasis_app_subscribe_channel(const char *app_name,
  302. struct ast_channel *chan);
  303. /*! @} */
  304. /*! @{ */
  305. /*! \brief Handler for controlling a channel that's in a Stasis application */
  306. struct stasis_app_control;
  307. /*! \brief Rule to check to see if an operation is allowed */
  308. struct stasis_app_control_rule {
  309. /*!
  310. * \brief Checks to see if an operation is allowed on the control
  311. *
  312. * \param control Control object to check
  313. * \return 0 on success, otherwise a failure code
  314. */
  315. enum stasis_app_control_channel_result (*check_rule)(
  316. const struct stasis_app_control *control);
  317. /*! Next item in the list */
  318. AST_LIST_ENTRY(stasis_app_control_rule) next;
  319. };
  320. /*!
  321. * \brief Registers an add channel to bridge rule.
  322. *
  323. * \param control Control object
  324. * \param rule The rule to register
  325. */
  326. void stasis_app_control_register_add_rule(
  327. struct stasis_app_control *control,
  328. struct stasis_app_control_rule *rule);
  329. /*!
  330. * \brief UnRegister an add channel to bridge rule.
  331. *
  332. * \param control Control object
  333. * \param rule The rule to unregister
  334. */
  335. void stasis_app_control_unregister_add_rule(
  336. struct stasis_app_control *control,
  337. struct stasis_app_control_rule *rule);
  338. /*!
  339. * \brief Registers a remove channel from bridge rule.
  340. *
  341. * \param control Control object
  342. * \param rule The rule to register
  343. */
  344. void stasis_app_control_register_remove_rule(
  345. struct stasis_app_control *control,
  346. struct stasis_app_control_rule *rule);
  347. /*!
  348. * \brief Unregisters a remove channel from bridge rule.
  349. *
  350. * \param control Control object
  351. * \param rule The rule to unregister
  352. */
  353. void stasis_app_control_unregister_remove_rule(
  354. struct stasis_app_control *control,
  355. struct stasis_app_control_rule *rule);
  356. /*!
  357. * \brief Returns the handler for the given channel.
  358. * \param chan Channel to handle.
  359. *
  360. * \return NULL channel not in Stasis application.
  361. * \return Pointer to \c res_stasis handler.
  362. */
  363. struct stasis_app_control *stasis_app_control_find_by_channel(
  364. const struct ast_channel *chan);
  365. /*!
  366. * \brief Returns the handler for the channel with the given id.
  367. * \param channel_id Uniqueid of the channel.
  368. *
  369. * \return NULL channel not in Stasis application, or channel does not exist.
  370. * \return Pointer to \c res_stasis handler.
  371. */
  372. struct stasis_app_control *stasis_app_control_find_by_channel_id(
  373. const char *channel_id);
  374. /*!
  375. * \brief Creates a control handler for a channel that isn't in a stasis app.
  376. * \since 12.0.0
  377. *
  378. * \param chan Channel to create controller handle for
  379. *
  380. * \return NULL on failure to create the handle
  381. * \return Pointer to \c res_stasis handler.
  382. */
  383. struct stasis_app_control *stasis_app_control_create(
  384. struct ast_channel *chan);
  385. /*!
  386. * \brief Act on a stasis app control queue until it is empty
  387. * \since 12.0.0
  388. *
  389. * \param chan Channel to handle
  390. * \param control Control object to execute
  391. */
  392. void stasis_app_control_execute_until_exhausted(
  393. struct ast_channel *chan,
  394. struct stasis_app_control *control);
  395. /*!
  396. * \brief Check if a control is marked as done
  397. * \since 12.2.0
  398. *
  399. * \param control Which control object is being evaluated
  400. */
  401. int stasis_app_control_is_done(
  402. struct stasis_app_control *control);
  403. /*!
  404. * \brief Flush the control command queue.
  405. * \since 13.9.0
  406. *
  407. * \param control Control object to flush command queue.
  408. *
  409. * \return Nothing
  410. */
  411. void stasis_app_control_flush_queue(struct stasis_app_control *control);
  412. /*!
  413. * \brief Returns the uniqueid of the channel associated with this control
  414. *
  415. * \param control Control object.
  416. *
  417. * \return Uniqueid of the associate channel.
  418. * \return \c NULL if \a control is \c NULL.
  419. */
  420. const char *stasis_app_control_get_channel_id(
  421. const struct stasis_app_control *control);
  422. /*!
  423. * \brief Dial an endpoint and bridge it to a channel in \c res_stasis
  424. *
  425. * If the channel is no longer in \c res_stasis, this function does nothing.
  426. *
  427. * \param control Control for \c res_stasis
  428. * \param endpoint The endpoint to dial.
  429. * \param exten Extension to dial if no endpoint specified.
  430. * \param context Context to use with extension.
  431. * \param timeout The amount of time to wait for answer, before giving up.
  432. *
  433. * \return 0 for success
  434. * \return -1 for error.
  435. */
  436. int stasis_app_control_dial(struct stasis_app_control *control, const char *endpoint, const char *exten,
  437. const char *context, int timeout);
  438. /*!
  439. * \brief Apply a bridge role to a channel controlled by a stasis app control
  440. *
  441. * \param control Control for \c res_stasis
  442. * \param role Role to apply
  443. *
  444. * \return 0 for success
  445. * \return -1 for error.
  446. */
  447. int stasis_app_control_add_role(struct stasis_app_control *control, const char *role);
  448. /*!
  449. * \brief Clear bridge roles currently applied to a channel controlled by a stasis app control
  450. *
  451. * \param control Control for \c res_stasis
  452. */
  453. void stasis_app_control_clear_roles(struct stasis_app_control *control);
  454. /*!
  455. * \brief Exit \c res_stasis and continue execution in the dialplan.
  456. *
  457. * If the channel is no longer in \c res_stasis, this function does nothing.
  458. *
  459. * \param control Control for \c res_stasis
  460. * \param context An optional context to continue to
  461. * \param extension An optional extension to continue to
  462. * \param priority An optional priority to continue to
  463. *
  464. * \return 0 for success
  465. * \return -1 for error.
  466. */
  467. int stasis_app_control_continue(struct stasis_app_control *control, const char *context, const char *extension, int priority);
  468. /*!
  469. * \brief Redirect a channel in \c res_stasis to a particular endpoint
  470. *
  471. * \param control Control for \c res_stasis
  472. * \param endpoint The endpoint transfer string where the channel should be sent to
  473. *
  474. * \return 0 for success
  475. * \return -1 for error
  476. */
  477. int stasis_app_control_redirect(struct stasis_app_control *control, const char *endpoint);
  478. /*!
  479. * \brief Indicate ringing to the channel associated with this control.
  480. *
  481. * \param control Control for \c res_stasis.
  482. *
  483. * \return 0 for success.
  484. * \return -1 for error.
  485. */
  486. int stasis_app_control_ring(struct stasis_app_control *control);
  487. /*!
  488. * \brief Stop locally generated ringing on the channel associated with this control.
  489. *
  490. * \param control Control for \c res_stasis.
  491. *
  492. * \return 0 for success.
  493. * \return -1 for error.
  494. */
  495. int stasis_app_control_ring_stop(struct stasis_app_control *control);
  496. /*!
  497. * \brief Send DTMF to the channel associated with this control.
  498. *
  499. * \param control Control for \c res_stasis.
  500. * \param dtmf DTMF string.
  501. * \param before Amount of time to wait before sending DTMF digits.
  502. * \param between Amount of time between each DTMF digit.
  503. * \param duration Amount of time each DTMF digit lasts for.
  504. * \param after Amount of time to wait after sending DTMF digits.
  505. *
  506. * \return 0 for success.
  507. * \return -1 for error.
  508. */
  509. int stasis_app_control_dtmf(struct stasis_app_control *control, const char *dtmf, int before, int between, unsigned int duration, int after);
  510. /*!
  511. * \brief Mute the channel associated with this control.
  512. *
  513. * \param control Control for \c res_stasis.
  514. * \param direction The direction in which the audio should be muted.
  515. * \param frametype The type of stream that should be muted.
  516. *
  517. * \return 0 for success
  518. * \return -1 for error.
  519. */
  520. int stasis_app_control_mute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
  521. /*!
  522. * \brief Unmute the channel associated with this control.
  523. *
  524. * \param control Control for \c res_stasis.
  525. * \param direction The direction in which the audio should be unmuted.
  526. * \param frametype The type of stream that should be unmuted.
  527. *
  528. * \return 0 for success
  529. * \return -1 for error.
  530. */
  531. int stasis_app_control_unmute(struct stasis_app_control *control, unsigned int direction, enum ast_frame_type frametype);
  532. /*!
  533. * \brief Answer the channel associated with this control.
  534. * \param control Control for \c res_stasis.
  535. * \return 0 for success.
  536. * \return Non-zero for error.
  537. */
  538. int stasis_app_control_answer(struct stasis_app_control *control);
  539. /*!
  540. * \brief Set a variable on the channel associated with this control to value.
  541. * \param control Control for \c res_stasis.
  542. * \param variable The name of the variable
  543. * \param value The value to set the variable to
  544. *
  545. * \return 0 for success.
  546. * \return -1 for error.
  547. */
  548. int stasis_app_control_set_channel_var(struct stasis_app_control *control, const char *variable, const char *value);
  549. /*!
  550. * \brief Place the channel associated with the control on hold.
  551. * \param control Control for \c res_stasis.
  552. */
  553. void stasis_app_control_hold(struct stasis_app_control *control);
  554. /*!
  555. * \brief Remove the channel associated with the control from hold.
  556. * \param control Control for \c res_stasis.
  557. */
  558. void stasis_app_control_unhold(struct stasis_app_control *control);
  559. /*!
  560. * \brief Play music on hold to a channel (does not affect hold status)
  561. * \param control Control for \c res_stasis.
  562. * \param moh_class class of music on hold to play (NULL allowed)
  563. */
  564. void stasis_app_control_moh_start(struct stasis_app_control *control, const char *moh_class);
  565. /*!
  566. * \brief Stop playing music on hold to a channel (does not affect hold status)
  567. * \param control Control for \c res_stasis.
  568. */
  569. void stasis_app_control_moh_stop(struct stasis_app_control *control);
  570. /*!
  571. * \brief Start playing silence to a channel.
  572. * \param control Control for \c res_stasis.
  573. */
  574. void stasis_app_control_silence_start(struct stasis_app_control *control);
  575. /*!
  576. * \brief Stop playing silence to a channel.
  577. * \param control Control for \c res_stasis.
  578. */
  579. void stasis_app_control_silence_stop(struct stasis_app_control *control);
  580. /*!
  581. * \brief Returns the most recent snapshot for the associated channel.
  582. *
  583. * The returned pointer is AO2 managed, so ao2_cleanup() when you're done.
  584. *
  585. * \param control Control for \c res_stasis.
  586. *
  587. * \return Most recent snapshot. ao2_cleanup() when done.
  588. * \return \c NULL if channel isn't in cache.
  589. */
  590. struct ast_channel_snapshot *stasis_app_control_get_snapshot(
  591. const struct stasis_app_control *control);
  592. /*!
  593. * \brief Publish a message to the \a control's channel's topic.
  594. *
  595. * \param control Control to publish to
  596. * \param message Message to publish
  597. */
  598. void stasis_app_control_publish(
  599. struct stasis_app_control *control, struct stasis_message *message);
  600. /*!
  601. * \brief Returns the stasis topic for an app
  602. *
  603. * \param app Stasis app to get topic of
  604. */
  605. struct stasis_topic *ast_app_get_topic(struct stasis_app *app);
  606. /*!
  607. * \brief Queue a control frame without payload.
  608. *
  609. * \param control Control to publish to.
  610. * \param frame_type type of control frame.
  611. *
  612. * \return zero on success
  613. * \return non-zero on failure
  614. */
  615. int stasis_app_control_queue_control(struct stasis_app_control *control,
  616. enum ast_control_frame_type frame_type);
  617. /*!
  618. * \brief Create a bridge of the specified type.
  619. *
  620. * \param type The type of bridge to be created
  621. * \param name Optional name to give to the bridge
  622. * \param id Optional Unique ID to give to the bridge
  623. *
  624. * \return New bridge.
  625. * \return \c NULL on error.
  626. */
  627. struct ast_bridge *stasis_app_bridge_create(const char *type, const char *name, const char *id);
  628. /*!
  629. * \brief Returns the bridge with the given id.
  630. * \param bridge_id Uniqueid of the bridge.
  631. *
  632. * \return NULL bridge not created by a Stasis application, or bridge does not exist.
  633. * \return Pointer to bridge.
  634. */
  635. struct ast_bridge *stasis_app_bridge_find_by_id(
  636. const char *bridge_id);
  637. /*!
  638. * \brief Finds or creates an announcer channel in a bridge that can play music on hold.
  639. *
  640. * \param bridge Bridge we want an MOH channel for
  641. *
  642. * \return NULL if the music on hold channel fails to be created or join the bridge for any reason.
  643. * \return Pointer to the ;1 end of the announcer channel chain.
  644. */
  645. struct ast_channel *stasis_app_bridge_moh_channel(
  646. struct ast_bridge *bridge);
  647. /*!
  648. * \brief Breaks down MOH channels playing on the bridge created by stasis_app_bridge_moh_channel
  649. *
  650. * \param bridge Bridge we want to stop the MOH on
  651. *
  652. * \return -1 if no moh channel could be found and stopped
  653. * \return 0 on success
  654. */
  655. int stasis_app_bridge_moh_stop(
  656. struct ast_bridge *bridge);
  657. /*!
  658. * \brief Finds an existing ARI playback channel in a bridge
  659. *
  660. * \param bridge Bridge we want to find the playback channel for
  661. *
  662. * \return NULL if the playback channel can not be found for any reason.
  663. * \return Pointer to the ;1 end of the playback channel chain.
  664. */
  665. struct ast_channel *stasis_app_bridge_playback_channel_find(
  666. struct ast_bridge *bridge);
  667. /*!
  668. * \brief Adds a channel to the list of ARI playback channels for bridges.
  669. *
  670. * \param bridge Bridge we are adding the playback channel for
  671. * \param chan Channel being added as a playback channel (must be ;1)
  672. *
  673. * \retval -1 failed to add channel for any reason
  674. * \retval 0 on success
  675. */
  676. int stasis_app_bridge_playback_channel_add(struct ast_bridge *bridge,
  677. struct ast_channel *chan,
  678. struct stasis_app_control *control);
  679. /*!
  680. * \brief remove channel from list of ARI playback channels for bridges.
  681. *
  682. * \param bridge_id The unique ID of the bridge the playback channel is in.
  683. * \param control The app control structure for the playback channel
  684. */
  685. void stasis_app_bridge_playback_channel_remove(char *bridge_id,
  686. struct stasis_app_control *control);
  687. /*!
  688. * \brief Result codes used when adding/removing channels to/from bridges.
  689. */
  690. enum stasis_app_control_channel_result {
  691. /*! The channel is okay to be added/removed */
  692. STASIS_APP_CHANNEL_OKAY = 0,
  693. /*! The channel is currently recording */
  694. STASIS_APP_CHANNEL_RECORDING
  695. };
  696. /*!
  697. * \brief Add a channel to the bridge.
  698. *
  699. * \param control Control whose channel should be added to the bridge
  700. * \param bridge Pointer to the bridge
  701. *
  702. * \return non-zero on failure
  703. * \return zero on success
  704. */
  705. int stasis_app_control_add_channel_to_bridge(
  706. struct stasis_app_control *control, struct ast_bridge *bridge);
  707. /*!
  708. * \brief Remove a channel from the bridge.
  709. *
  710. * \param control Control whose channel should be removed from the bridge
  711. * \param bridge Pointer to the bridge
  712. *
  713. * \return non-zero on failure
  714. * \return zero on success
  715. */
  716. int stasis_app_control_remove_channel_from_bridge(
  717. struct stasis_app_control *control, struct ast_bridge *bridge);
  718. /*!
  719. * \since 12
  720. * \brief Gets the bridge currently associated with a control object.
  721. *
  722. * \note If the bridge returned by this function is to be held for any
  723. * length of time, its refcount should be incremented until the
  724. * caller is finished with it.
  725. *
  726. * \param control Control object for the channel to query.
  727. *
  728. * \return Associated \ref ast_bridge.
  729. * \return \c NULL if not associated with a bridge.
  730. */
  731. struct ast_bridge *stasis_app_get_bridge(struct stasis_app_control *control);
  732. /*!
  733. * \brief Destroy the bridge.
  734. *
  735. * \param bridge_id Uniqueid of bridge to be destroyed
  736. *
  737. * \retval non-zero on failure
  738. * \retval zero on success
  739. */
  740. void stasis_app_bridge_destroy(const char *bridge_id);
  741. /*!
  742. * \brief Increment the res_stasis reference count.
  743. *
  744. * This ensures graceful shutdown happens in the proper order.
  745. */
  746. void stasis_app_ref(void);
  747. /*!
  748. * \brief Decrement the res_stasis reference count.
  749. *
  750. * This ensures graceful shutdown happens in the proper order.
  751. */
  752. void stasis_app_unref(void);
  753. /*!
  754. * \brief Get the Stasis message sanitizer for app_stasis applications
  755. *
  756. * \retval The stasis message sanitizer
  757. */
  758. struct stasis_message_sanitizer *stasis_app_get_sanitizer(void);
  759. /*!
  760. * \brief Indicate that this channel has had a StasisEnd published for it
  761. *
  762. * \param The channel that is exiting Stasis.
  763. */
  764. void stasis_app_channel_set_stasis_end_published(struct ast_channel *chan);
  765. /*!
  766. * \brief Has this channel had a StasisEnd published on it?
  767. *
  768. * \param chan The channel upon which the query rests.
  769. *
  770. * \retval 0 No
  771. * \retval 1 Yes
  772. */
  773. int stasis_app_channel_is_stasis_end_published(struct ast_channel *chan);
  774. /*!
  775. * \brief Is this channel internal to Stasis?
  776. *
  777. * \param chan The channel to check.
  778. *
  779. * \retval 0 No
  780. * \retval 1 Yes
  781. */
  782. int stasis_app_channel_is_internal(struct ast_channel *chan);
  783. /*!
  784. * \brief Mark this unreal channel and it's other half as being internal to Stasis.
  785. *
  786. * \param chan The channel to mark.
  787. *
  788. * \retval zero Success
  789. * \retval non-zero Failure
  790. */
  791. int stasis_app_channel_unreal_set_internal(struct ast_channel *chan);
  792. /*!
  793. * \brief Mark this channel as being internal to Stasis.
  794. *
  795. * \param chan The channel to mark.
  796. *
  797. * \retval zero Success
  798. * \retval non-zero Failure
  799. */
  800. int stasis_app_channel_set_internal(struct ast_channel *chan);
  801. /*!
  802. * \brief Enable/disable request/response and event logging on an application
  803. *
  804. * \param app The app to debug
  805. * \param debug If non-zero, enable debugging. If zero, disable.
  806. */
  807. void stasis_app_set_debug(struct stasis_app *app, int debug);
  808. /*!
  809. * \brief Enable/disable request/response and event logging on an application
  810. *
  811. * \param app_name The app name to debug
  812. * \param debug If non-zero, enable debugging. If zero, disable.
  813. */
  814. void stasis_app_set_debug_by_name(const char *app_name, int debug);
  815. /*!
  816. * \brief Get debug status of an application
  817. *
  818. * \param app The app to check
  819. * \return The debug flag for the app || the global debug flag
  820. */
  821. int stasis_app_get_debug(struct stasis_app *app);
  822. /*!
  823. * \brief Get debug status of an application
  824. *
  825. * \param app_name The app_name to check
  826. * \return The debug flag for the app || the global debug flag
  827. */
  828. int stasis_app_get_debug_by_name(const char *app_name);
  829. /*!
  830. * \brief Enable/disable request/response and event logging on all applications
  831. *
  832. * \param debug If non-zero, enable debugging. If zero, disable.
  833. */
  834. void stasis_app_set_global_debug(int debug);
  835. struct ast_cli_args;
  836. /*!
  837. * \brief Dump properties of a \c stasis_app to the CLI
  838. *
  839. * \param app The application
  840. * \param a The CLI arguments
  841. */
  842. void stasis_app_to_cli(const struct stasis_app *app, struct ast_cli_args *a);
  843. /*! @} */
  844. #endif /* _ASTERISK_STASIS_APP_H */