parking.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * Jonathan Rose <jrose@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. /*! \file
  19. *
  20. * \brief Call Parking API
  21. *
  22. * \author Jonathan Rose <jrose@digium.com>
  23. */
  24. #include "asterisk/stringfields.h"
  25. #include "asterisk/bridge.h"
  26. /*!
  27. * \brief The default parking application that Asterisk expects.
  28. */
  29. #define PARK_APPLICATION "Park"
  30. /*!
  31. * \brief The default parking lot
  32. */
  33. #define DEFAULT_PARKINGLOT "default"
  34. /*!
  35. * \brief Defines the type of parked call message being published
  36. * \since 12
  37. */
  38. enum ast_parked_call_event_type {
  39. PARKED_CALL = 0,
  40. PARKED_CALL_TIMEOUT,
  41. PARKED_CALL_GIVEUP,
  42. PARKED_CALL_UNPARKED,
  43. PARKED_CALL_FAILED,
  44. PARKED_CALL_SWAP,
  45. };
  46. /*!
  47. * \brief A parked call message payload
  48. * \since 12
  49. */
  50. struct ast_parked_call_payload {
  51. struct ast_channel_snapshot *parkee; /*!< Snapshot of the channel that is parked */
  52. struct ast_channel_snapshot *retriever; /*!< Snapshot of the channel that retrieved the call (may be NULL) */
  53. enum ast_parked_call_event_type event_type; /*!< Reason for issuing the parked call message */
  54. long unsigned int timeout; /*!< Time remaining before the call times out (seconds ) */
  55. long unsigned int duration; /*!< How long the parkee has been parked (seconds) */
  56. unsigned int parkingspace; /*!< Which Parking Space the parkee occupies */
  57. AST_DECLARE_STRING_FIELDS(
  58. AST_STRING_FIELD(parkinglot); /*!< Name of the parking lot used to park the parkee */
  59. AST_STRING_FIELD(parker_dial_string); /*!< The device string used for call control on parking timeout */
  60. );
  61. };
  62. struct ast_exten;
  63. /*!
  64. * \brief Constructor for parked_call_payload objects
  65. * \since 12
  66. *
  67. * \param event_type What kind of parked call event is happening
  68. * \param parkee_snapshot channel snapshot of the parkee
  69. * \param parker_dial_string dialstring used when the call times out
  70. * \param retriever_snapshot channel snapshot of the retriever (NULL allowed)
  71. * \param parkinglot name of the parking lot where the parked call is parked
  72. * \param parkingspace what numerical parking space the parked call is parked in
  73. * \param timeout how long the parked call can remain at the point this snapshot is created before timing out
  74. * \param duration how long the parked call has currently been parked
  75. *
  76. * \retval NULL if the parked call payload can't be allocated
  77. * \retval reference to a newly created parked call payload
  78. */
  79. struct ast_parked_call_payload *ast_parked_call_payload_create(enum ast_parked_call_event_type event_type,
  80. struct ast_channel_snapshot *parkee_snapshot, const char *parker_dial_string,
  81. struct ast_channel_snapshot *retriever_snapshot, const char *parkinglot,
  82. unsigned int parkingspace, unsigned long int timeout, unsigned long int duration);
  83. /*! \addtogroup StasisTopicsAndMessages
  84. * @{
  85. */
  86. /*!
  87. * \brief accessor for the parking stasis topic
  88. * \since 12
  89. *
  90. * \retval NULL if the parking topic hasn't been created or has been disabled
  91. * \retval a pointer to the parking topic
  92. */
  93. struct stasis_topic *ast_parking_topic(void);
  94. /*!
  95. * \brief accessor for the parked call stasis message type
  96. * \since 12
  97. *
  98. * \retval NULL if the parking topic hasn't been created or has been canceled
  99. * \retval a pointer to the parked call message type
  100. */
  101. struct stasis_message_type *ast_parked_call_type(void);
  102. /*! @} */
  103. #define PARKING_MODULE_VERSION 1
  104. struct ast_module_info;
  105. /*!
  106. * \brief A function table providing parking functionality to the \ref AstBridging
  107. * Bridging API and other consumers
  108. */
  109. struct ast_parking_bridge_feature_fn_table {
  110. /*!
  111. * \brief The version of this function table. If the ABI for this table
  112. * changes, the module version (/ref PARKING_MODULE_VERSION) should be
  113. * incremented.
  114. */
  115. unsigned int module_version;
  116. /*!
  117. * \brief The name of the module that provides this parking functionality
  118. */
  119. const char *module_name;
  120. /*!
  121. * \brief Determine if the context/exten is a "parking" extension
  122. *
  123. * \retval 0 if the extension is not a parking extension
  124. * \retval 1 if the extension is a parking extension
  125. */
  126. int (* parking_is_exten_park)(const char *context, const char *exten);
  127. /*!
  128. * \brief Park the bridge and/or callers that this channel is in
  129. *
  130. * \param parker The bridge_channel parking the bridge
  131. * \param exten Optional. The extension the channel or bridge was parked at if the
  132. * call succeeds.
  133. * \param length Optional. If \c exten is specified, the size of the buffer.
  134. *
  135. * \note This is safe to be called outside of the \ref AstBridging Bridging API.
  136. *
  137. * \retval 0 on success
  138. * \retval non-zero on error
  139. */
  140. int (* parking_park_call)(struct ast_bridge_channel *parker, char *exten, size_t length);
  141. /*!
  142. * \brief Perform a blind transfer to a parking extension.
  143. *
  144. * \param parker The \ref bridge_channel object that is initiating the parking
  145. * \param context The context to blind transfer to
  146. * \param exten The extension to blind transfer to
  147. * \param parked_channel_cb Execute the following function on the channel that gets parked
  148. * \param parked_channel_data Data for the parked_channel_cb
  149. *
  150. * \note If the bridge \ref parker is in has more than one other occupant, the entire
  151. * bridge will be parked using a Local channel
  152. *
  153. * \note This is safe to be called outside of the \ref AstBridging Bridging API.
  154. *
  155. * \retval 0 on success
  156. * \retval non-zero on error
  157. */
  158. int (* parking_blind_transfer_park)(struct ast_bridge_channel *parker, const char *context,
  159. const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data);
  160. /*!
  161. * \brief Perform a direct park on a channel in a bridge.
  162. *
  163. * \param parkee The channel in the bridge to be parked.
  164. * \param parkee_uuid The UUID of the channel being packed.
  165. * \param parker_uuid The UUID of the channel performing the park.
  166. * \param app_data Data to pass to the Park application
  167. *
  168. * \note This must be called within the context of the \ref AstBridging Bridging API.
  169. * External entities should not call this method directly, but should instead use
  170. * the direct call parking method or the blind transfer method.
  171. *
  172. * \retval 0 on success
  173. * \retval non-zero on error
  174. */
  175. int (* parking_park_bridge_channel)(struct ast_bridge_channel *parkee, const char *parkee_uuid, const char *parker_uuid, const char *app_data);
  176. /*! \brief The module info for the module registering this parking provider */
  177. const struct ast_module_info *module_info;
  178. };
  179. /*!
  180. * \brief Determine if the context/exten is a "parking" extension
  181. *
  182. * \retval 0 if the extension is not a parking extension
  183. * \retval 1 if the extension is a parking extension
  184. */
  185. int ast_parking_is_exten_park(const char *context, const char *exten);
  186. /*!
  187. * \brief Park the bridge and/or callers that this channel is in
  188. *
  189. * \param parker The bridge_channel parking the bridge
  190. * \param[out] exten Optional. The parking exten to access the parking lot.
  191. * \param length Optional. If \c exten is specified, the size of the buffer.
  192. *
  193. * \note This is safe to be called outside of the \ref AstBridging Bridging API.
  194. *
  195. * \note The exten parameter was intended to return the extension the channel or
  196. * bridge was parked at if the call succeeds. However, accessing that information
  197. * is very difficult to do with the new asynchronous design. That information may
  198. * not be available anywhere by the time this function currently returns.
  199. *
  200. * Only, chan_skinny is known to call this function and use the exten parameter
  201. * for the phone display.
  202. *
  203. * \retval 0 on success
  204. * \retval non-zero on error
  205. */
  206. int ast_parking_park_call(struct ast_bridge_channel *parker, char *exten, size_t length);
  207. /*!
  208. * \brief Perform a blind transfer to a parking extension.
  209. *
  210. * \param parker The \ref bridge_channel object that is initiating the parking
  211. * \param context The context to blind transfer to
  212. * \param exten The extension to blind transfer to
  213. * \param exten The extension to blind transfer to
  214. * \param parked_channel_cb Execute the following function on the channel that gets parked
  215. * \param parked_channel_data Data for the parked_channel_cb
  216. *
  217. * \note If the bridge \ref parker is in has more than one other occupant, the entire
  218. * bridge will be parked using a Local channel
  219. *
  220. * \note This is safe to be called outside of the \ref AstBridging Bridging API.
  221. *
  222. * \retval 0 on success
  223. * \retval non-zero on error
  224. */
  225. int ast_parking_blind_transfer_park(struct ast_bridge_channel *parker, const char *context,
  226. const char *exten, transfer_channel_cb parked_channel_cb, struct transfer_channel_data *parked_channel_data);
  227. /*!
  228. * \brief Perform a direct park on a channel in a bridge.
  229. *
  230. * \param parkee The channel in the bridge to be parked.
  231. * \param parkee_uuid The UUID of the channel being packed.
  232. * \param parker_uuid The UUID of the channel performing the park.
  233. * \param app_data Data to pass to the Park application
  234. *
  235. * \note This must be called within the context of the \ref AstBridging Bridging API.
  236. * External entities should not call this method directly, but should instead use
  237. * the direct call parking method or the blind transfer method.
  238. *
  239. * \retval 0 on success
  240. * \retval non-zero on error
  241. */
  242. int ast_parking_park_bridge_channel(struct ast_bridge_channel *parkee, const char *parkee_uuid, const char *parker_uuid, const char *app_data);
  243. /*!
  244. * \brief Register a parking provider
  245. *
  246. * \param fn_table The \ref ast_parking_bridge_feature_fn_table to register
  247. *
  248. * \retval 0 on success
  249. * \retval -1 on error
  250. */
  251. int ast_parking_register_bridge_features(struct ast_parking_bridge_feature_fn_table *fn_table);
  252. /*!
  253. * \brief Unregister the current parking provider
  254. *
  255. * \param The module name of the provider to unregister
  256. *
  257. * \retval 0 if the parking provider \c module_name was unregsistered
  258. * \retval -1 on error
  259. */
  260. int ast_parking_unregister_bridge_features(const char *module_name);
  261. /*!
  262. * \brief Check whether a parking provider is registered
  263. *
  264. * \retval 0 if there is no parking provider regsistered
  265. * \retval 1 if there is a parking provider regsistered
  266. */
  267. int ast_parking_provider_registered(void);