Asterisk - The Open Source Telephony Project GIT-master-f36a736
dial.h
Go to the documentation of this file.
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
19/*! \file
20 * \brief Dialing API
21 */
22
23#ifndef _ASTERISK_DIAL_H
24#define _ASTERISK_DIAL_H
25
26#if defined(__cplusplus) || defined(c_plusplus)
27extern "C" {
28#endif
29
30/*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
31struct ast_dial;
32
33/*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
34struct ast_dial_channel;
35
36/*! \brief Forward declaration for format capabilities, used in prerun */
37struct ast_format_cap;
38
39typedef void (*ast_dial_state_callback)(struct ast_dial *);
40
41/*! \brief List of options that are applicable either globally or per dialed channel */
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_DIAL_REPLACES_SELF, /*!< The dial operation is a replacement for the requester */
49 AST_DIAL_OPTION_SELF_DESTROY, /*!< Destroy self at end of ast_dial_run */
50 AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */
51};
52
53/*! \brief List of return codes for dial run API calls */
55 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */
56 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */
57 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */
58 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */
59 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */
60 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */
61 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */
62 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */
63 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */
64 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */
65};
66
67/*! \brief New dialing structure
68 * \note Create a dialing structure
69 * \return Returns a calloc'd ast_dial structure, NULL on failure
70 */
71struct ast_dial *ast_dial_create(void);
72
73/*! \brief Append a channel
74 * \note Appends a channel to a dialing structure
75 * \return Returns channel reference number on success, -1 on failure
76 */
77int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids);
78
79/*!
80 * \brief Append a channel using an actual channel object
81 *
82 * \param dial The ast_dial to add the channel to
83 * \param chan The channel to add to the dial
84 * \retval -1 Failure
85 * \retval non-zero The position of the channel in the list of dialed channels
86 *
87 * \note The chan ref is stolen with a successful return.
88 */
89int ast_dial_append_channel(struct ast_dial *dial, struct ast_channel *chan);
90
91/*! \brief Request all appended channels, but do not dial
92 * \param dial Dialing structure
93 * \param chan Optional dialing channel
94 * \param cap Optional requested capabilities
95 * \retval -1 failure
96 * \retval 0 success
97 */
98int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap);
99
100/*! \brief Execute dialing synchronously or asynchronously
101 * \note Dials channels in a dial structure.
102 * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
103 */
104enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async);
105
106/*! \brief Return channel that answered
107 * \note Returns the Asterisk channel that answered
108 * \param dial Dialing structure
109 */
110struct ast_channel *ast_dial_answered(struct ast_dial *dial);
111
112/*! \brief Steal the channel that answered
113 * \note Returns the Asterisk channel that answered and removes it from the dialing structure
114 * \param dial Dialing structure
115 */
116struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial);
117
118/*! \brief Return state of dial
119 * \note Returns the state of the dial attempt
120 * \param dial Dialing structure
121 */
122enum ast_dial_result ast_dial_state(struct ast_dial *dial);
123
124/*! \brief Cancel async thread
125 * \note Cancel a running async thread
126 * \param dial Dialing structure
127 */
128enum ast_dial_result ast_dial_join(struct ast_dial *dial);
129
130/*! \brief Hangup channels
131 * \note Hangup all active channels
132 * \param dial Dialing structure
133 */
134void ast_dial_hangup(struct ast_dial *dial);
135
136/*! \brief Destroys a dialing structure
137 * \note Cancels dialing and destroys (free's) the given ast_dial structure
138 * \param dial Dialing structure to free
139 * \retval 0 on success
140 * \retval -1 on failure
141 */
142int ast_dial_destroy(struct ast_dial *dial);
143
144/*! \brief Enables an option globally
145 * \param dial Dial structure to enable option on
146 * \param option Option to enable
147 * \param data Data to pass to this option (not always needed)
148 * \retval 0 on success
149 * \retval -1 on failure
150 */
151int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
152
153/*! \brief Enables an option per channel
154 * \param dial Dial structure
155 * \param num Channel number to enable option on
156 * \param option Option to enable
157 * \param data Data to pass to this option (not always needed)
158 * \retval 0 on success
159 * \retval -1 on failure
160 */
161int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
162
163/*! \brief Disables an option globally
164 * \param dial Dial structure to disable option on
165 * \param option Option to disable
166 * \retval 0 on success
167 * \retval -1 on failure
168 */
169int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
170
171/*! \brief Disables an option per channel
172 * \param dial Dial structure
173 * \param num Channel number to disable option on
174 * \param option Option to disable
175 * \retval 0 on success
176 * \retval -1 on failure
177 */
178int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
179
180/*! \brief Get the reason an outgoing channel has failed
181 * \param dial Dial structure
182 * \param num Channel number to get the reason from
183 * \return Numerical cause code
184 */
185int ast_dial_reason(struct ast_dial *dial, int num);
186
187/*! \brief Get the dialing channel, if prerun has been executed
188 * \param dial Dial structure
189 * \param num Channel number to get channel of
190 * \return Pointer to channel, without reference
191 */
192struct ast_channel *ast_dial_get_channel(struct ast_dial *dial, int num);
193
194/*! \brief Set a callback for state changes
195 * \param dial The dial structure to watch for state changes
196 * \param callback the callback
197 */
199
200/*! \brief Set user data on a dial structure
201 * \param dial The dial structure to set a user data pointer on
202 * \param user_data The user data pointer
203 */
204void ast_dial_set_user_data(struct ast_dial *dial, void *user_data);
205
206/*! \brief Return the user data on a dial structure
207 * \param dial The dial structure
208 */
209void *ast_dial_get_user_data(struct ast_dial *dial);
210
211/*! \brief Set the maximum time (globally) allowed for trying to ring phones
212 * \param dial The dial structure to apply the time limit to
213 * \param timeout Maximum time allowed in milliseconds
214 */
215void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout);
216
217/*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
218 * \param dial The dial structure the channel belongs to
219 * \param num Channel number to set timeout on
220 * \param timeout Maximum time allowed in milliseconds
221 */
222void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout);
223
224/*! \since 12
225 * \brief Convert a hangup cause to a publishable dial status
226 */
227const char *ast_hangup_cause_to_dial_status(int hangup_cause);
228
229#if defined(__cplusplus) || defined(c_plusplus)
230}
231#endif
232
233#endif /* _ASTERISK_DIAL_H */
enum ast_dial_result ast_dial_state(struct ast_dial *dial)
Return state of dial.
Definition: dial.c:1008
ast_dial_result
List of return codes for dial run API calls.
Definition: dial.h:54
@ AST_DIAL_RESULT_FAILED
Definition: dial.h:56
@ AST_DIAL_RESULT_HANGUP
Definition: dial.h:63
@ AST_DIAL_RESULT_INVALID
Definition: dial.h:55
@ AST_DIAL_RESULT_ANSWERED
Definition: dial.h:61
@ AST_DIAL_RESULT_TIMEOUT
Definition: dial.h:62
@ AST_DIAL_RESULT_TRYING
Definition: dial.h:57
@ AST_DIAL_RESULT_PROGRESS
Definition: dial.h:59
@ AST_DIAL_RESULT_RINGING
Definition: dial.h:58
@ AST_DIAL_RESULT_PROCEEDING
Definition: dial.h:60
@ AST_DIAL_RESULT_UNANSWERED
Definition: dial.h:64
void(* ast_dial_state_callback)(struct ast_dial *)
Definition: dial.h:39
void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
Set a callback for state changes.
Definition: dial.c:1269
int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device, const struct ast_assigned_ids *assignedids)
Append a channel.
Definition: dial.c:280
int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option)
Disables an option globally.
Definition: dial.c:1205
struct ast_dial * ast_dial_create(void)
New dialing structure.
Definition: dial.c:223
struct ast_channel * ast_dial_answered(struct ast_dial *dial)
Return channel that answered.
Definition: dial.c:977
void ast_dial_set_user_data(struct ast_dial *dial, void *user_data)
Set user data on a dial structure.
Definition: dial.c:1274
int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap)
Request all appended channels, but do not dial.
Definition: dial.c:431
void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout)
Set the maximum time (globally) allowed for trying to ring phones.
Definition: dial.c:1284
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition: dial.c:1074
int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option)
Disables an option per channel.
Definition: dial.c:1222
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition: dial.c:749
enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async)
Execute dialing synchronously or asynchronously.
Definition: dial.c:935
int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data)
Enables an option per channel.
Definition: dial.c:1181
enum ast_dial_result ast_dial_join(struct ast_dial *dial)
Cancel async thread.
Definition: dial.c:1017
struct ast_channel * ast_dial_answered_steal(struct ast_dial *dial)
Steal the channel that answered.
Definition: dial.c:989
void * ast_dial_get_user_data(struct ast_dial *dial)
Return the user data on a dial structure.
Definition: dial.c:1279
int ast_dial_reason(struct ast_dial *dial, int num)
Get the reason an outgoing channel has failed.
Definition: dial.c:1247
void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout)
Set the maximum time (per channel) allowed for trying to ring the phone.
Definition: dial.c:1294
ast_dial_option
List of options that are applicable either globally or per dialed channel.
Definition: dial.h:42
@ AST_DIAL_OPTION_DIAL_REPLACES_SELF
Definition: dial.h:48
@ AST_DIAL_OPTION_ANSWER_EXEC
Definition: dial.h:44
@ AST_DIAL_OPTION_RINGING
Definition: dial.h:43
@ AST_DIAL_OPTION_MUSIC
Definition: dial.h:45
@ AST_DIAL_OPTION_PREDIAL
Definition: dial.h:47
@ AST_DIAL_OPTION_DISABLE_CALL_FORWARDING
Definition: dial.h:46
@ AST_DIAL_OPTION_SELF_DESTROY
Definition: dial.h:49
@ AST_DIAL_OPTION_MAX
Definition: dial.h:50
struct ast_channel * ast_dial_get_channel(struct ast_dial *dial, int num)
Get the dialing channel, if prerun has been executed.
Definition: dial.c:1258
int ast_dial_destroy(struct ast_dial *dial)
Destroys a dialing structure.
Definition: dial.c:1091
int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data)
Enables an option globally.
Definition: dial.c:1145
int ast_dial_append_channel(struct ast_dial *dial, struct ast_channel *chan)
Append a channel using an actual channel object.
Definition: dial.c:295
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:606
Main Channel structure associated with a channel.
const char * data
Dialing channel structure. Contains per-channel dialing options, asterisk channel,...
Definition: dial.c:63
Main dialing structure. Contains global options, channels being dialed, and more!
Definition: dial.c:48
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54