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