dial.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 1999 - 2007, Digium, Inc.
  5. *
  6. * Joshua Colp <jcolp@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. * \brief Dialing API
  20. */
  21. #ifndef _ASTERISK_DIAL_H
  22. #define _ASTERISK_DIAL_H
  23. #if defined(__cplusplus) || defined(c_plusplus)
  24. extern "C" {
  25. #endif
  26. /*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
  27. struct ast_dial;
  28. /*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
  29. struct ast_dial_channel;
  30. /*! \brief Forward declaration for format capabilities, used in prerun */
  31. struct ast_format_cap;
  32. typedef void (*ast_dial_state_callback)(struct ast_dial *);
  33. /*! \brief List of options that are applicable either globally or per dialed channel */
  34. enum ast_dial_option {
  35. AST_DIAL_OPTION_RINGING, /*!< Always indicate ringing to caller */
  36. AST_DIAL_OPTION_ANSWER_EXEC, /*!< Execute application upon answer in async mode */
  37. AST_DIAL_OPTION_MUSIC, /*!< Play music on hold instead of ringing to the calling channel */
  38. AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */
  39. AST_DIAL_OPTION_PREDIAL, /*!< Execute a predial subroutine before dialing */
  40. AST_DIAL_OPTION_DIAL_REPLACES_SELF, /*!< The dial operation is a replacement for the requester */
  41. AST_DIAL_OPTION_SELF_DESTROY, /*!< Destroy self at end of ast_dial_run */
  42. AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */
  43. };
  44. /*! \brief List of return codes for dial run API calls */
  45. enum ast_dial_result {
  46. AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */
  47. AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */
  48. AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */
  49. AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */
  50. AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */
  51. AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */
  52. AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */
  53. AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */
  54. AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */
  55. AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */
  56. };
  57. /*! \brief New dialing structure
  58. * \note Create a dialing structure
  59. * \return Returns a calloc'd ast_dial structure, NULL on failure
  60. */
  61. struct ast_dial *ast_dial_create(void);
  62. /*! \brief Append a channel
  63. * \note Appends a channel to a dialing structure
  64. * \return Returns channel reference number on success, -1 on failure
  65. */
  66. int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids);
  67. /*! \brief Request all appended channels, but do not dial
  68. * \param dial Dialing structure
  69. * \param chan Optional dialing channel
  70. * \param cap Optional requested capabilities
  71. * \retval -1 failure
  72. * \reval 0 success
  73. */
  74. int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap);
  75. /*! \brief Execute dialing synchronously or asynchronously
  76. * \note Dials channels in a dial structure.
  77. * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
  78. */
  79. enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async);
  80. /*! \brief Return channel that answered
  81. * \note Returns the Asterisk channel that answered
  82. * \param dial Dialing structure
  83. */
  84. struct ast_channel *ast_dial_answered(struct ast_dial *dial);
  85. /*! \brief Steal the channel that answered
  86. * \note Returns the Asterisk channel that answered and removes it from the dialing structure
  87. * \param dial Dialing structure
  88. */
  89. struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial);
  90. /*! \brief Return state of dial
  91. * \note Returns the state of the dial attempt
  92. * \param dial Dialing structure
  93. */
  94. enum ast_dial_result ast_dial_state(struct ast_dial *dial);
  95. /*! \brief Cancel async thread
  96. * \note Cancel a running async thread
  97. * \param dial Dialing structure
  98. */
  99. enum ast_dial_result ast_dial_join(struct ast_dial *dial);
  100. /*! \brief Hangup channels
  101. * \note Hangup all active channels
  102. * \param dial Dialing structure
  103. */
  104. void ast_dial_hangup(struct ast_dial *dial);
  105. /*! \brief Destroys a dialing structure
  106. * \note Cancels dialing and destroys (free's) the given ast_dial structure
  107. * \param dial Dialing structure to free
  108. * \return Returns 0 on success, -1 on failure
  109. */
  110. int ast_dial_destroy(struct ast_dial *dial);
  111. /*! \brief Enables an option globally
  112. * \param dial Dial structure to enable option on
  113. * \param option Option to enable
  114. * \param data Data to pass to this option (not always needed)
  115. * \return Returns 0 on success, -1 on failure
  116. */
  117. int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
  118. /*! \brief Enables an option per channel
  119. * \param dial Dial structure
  120. * \param num Channel number to enable option on
  121. * \param option Option to enable
  122. * \param data Data to pass to this option (not always needed)
  123. * \return Returns 0 on success, -1 on failure
  124. */
  125. int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
  126. /*! \brief Disables an option globally
  127. * \param dial Dial structure to disable option on
  128. * \param option Option to disable
  129. * \return Returns 0 on success, -1 on failure
  130. */
  131. int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
  132. /*! \brief Disables an option per channel
  133. * \param dial Dial structure
  134. * \param num Channel number to disable option on
  135. * \param option Option to disable
  136. * \return Returns 0 on success, -1 on failure
  137. */
  138. int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
  139. /*! \brief Get the reason an outgoing channel has failed
  140. * \param dial Dial structure
  141. * \param num Channel number to get the reason from
  142. * \return Numerical cause code
  143. */
  144. int ast_dial_reason(struct ast_dial *dial, int num);
  145. /*! \brief Get the dialing channel, if prerun has been executed
  146. * \param dial Dial structure
  147. * \param num Channel number to get channel of
  148. * \return Pointer to channel, without reference
  149. */
  150. struct ast_channel *ast_dial_get_channel(struct ast_dial *dial, int num);
  151. /*! \brief Set a callback for state changes
  152. * \param dial The dial structure to watch for state changes
  153. * \param callback the callback
  154. * \return nothing
  155. */
  156. void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback);
  157. /*! \brief Set user data on a dial structure
  158. * \param dial The dial structure to set a user data pointer on
  159. * \param user_data The user data pointer
  160. * \return nothing
  161. */
  162. void ast_dial_set_user_data(struct ast_dial *dial, void *user_data);
  163. /*! \brief Return the user data on a dial structure
  164. * \param dial The dial structure
  165. * \return A pointer to the user data
  166. */
  167. void *ast_dial_get_user_data(struct ast_dial *dial);
  168. /*! \brief Set the maximum time (globally) allowed for trying to ring phones
  169. * \param dial The dial structure to apply the time limit to
  170. * \param timeout Maximum time allowed in milliseconds
  171. * \return nothing
  172. */
  173. void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout);
  174. /*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
  175. * \param dial The dial structure the channel belongs to
  176. * \param num Channel number to set timeout on
  177. * \param timeout Maximum time allowed in milliseconds
  178. * \return nothing
  179. */
  180. void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout);
  181. /*! \since 12
  182. * \brief Convert a hangup cause to a publishable dial status
  183. */
  184. const char *ast_hangup_cause_to_dial_status(int hangup_cause);
  185. #if defined(__cplusplus) || defined(c_plusplus)
  186. }
  187. #endif
  188. #endif /* _ASTERISK_DIAL_H */