Asterisk - The Open Source Telephony Project  18.5.0
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 <[email protected]>
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)
27 extern "C" {
28 #endif
29 
30 /*! \brief Main dialing structure. Contains global options, channels being dialed, and more! */
31 struct ast_dial;
32 
33 /*! \brief Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more! */
34 struct ast_dial_channel;
35 
36 /*! \brief Forward declaration for format capabilities, used in prerun */
37 struct ast_format_cap;
38 
39 typedef 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  */
71 struct 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  */
77 int 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  */
89 int 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  * \reval 0 success
97  */
98 int 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  */
104 enum 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  */
110 struct 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  */
116 struct 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  */
122 enum 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  */
128 enum 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  */
134 void 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  * \return Returns 0 on success, -1 on failure
140  */
141 int ast_dial_destroy(struct ast_dial *dial);
142 
143 /*! \brief Enables an option globally
144  * \param dial Dial structure to enable option on
145  * \param option Option to enable
146  * \param data Data to pass to this option (not always needed)
147  * \return Returns 0 on success, -1 on failure
148  */
149 int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
150 
151 /*! \brief Enables an option per channel
152  * \param dial Dial structure
153  * \param num Channel number to enable option on
154  * \param option Option to enable
155  * \param data Data to pass to this option (not always needed)
156  * \return Returns 0 on success, -1 on failure
157  */
158 int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
159 
160 /*! \brief Disables an option globally
161  * \param dial Dial structure to disable option on
162  * \param option Option to disable
163  * \return Returns 0 on success, -1 on failure
164  */
165 int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
166 
167 /*! \brief Disables an option per channel
168  * \param dial Dial structure
169  * \param num Channel number to disable option on
170  * \param option Option to disable
171  * \return Returns 0 on success, -1 on failure
172  */
173 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
174 
175 /*! \brief Get the reason an outgoing channel has failed
176  * \param dial Dial structure
177  * \param num Channel number to get the reason from
178  * \return Numerical cause code
179  */
180 int ast_dial_reason(struct ast_dial *dial, int num);
181 
182 /*! \brief Get the dialing channel, if prerun has been executed
183  * \param dial Dial structure
184  * \param num Channel number to get channel of
185  * \return Pointer to channel, without reference
186  */
187 struct ast_channel *ast_dial_get_channel(struct ast_dial *dial, int num);
188 
189 /*! \brief Set a callback for state changes
190  * \param dial The dial structure to watch for state changes
191  * \param callback the callback
192  * \return nothing
193  */
195 
196 /*! \brief Set user data on a dial structure
197  * \param dial The dial structure to set a user data pointer on
198  * \param user_data The user data pointer
199  * \return nothing
200  */
201 void ast_dial_set_user_data(struct ast_dial *dial, void *user_data);
202 
203 /*! \brief Return the user data on a dial structure
204  * \param dial The dial structure
205  * \return A pointer to the user data
206  */
207 void *ast_dial_get_user_data(struct ast_dial *dial);
208 
209 /*! \brief Set the maximum time (globally) allowed for trying to ring phones
210  * \param dial The dial structure to apply the time limit to
211  * \param timeout Maximum time allowed in milliseconds
212  * \return nothing
213  */
214 void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout);
215 
216 /*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
217  * \param dial The dial structure the channel belongs to
218  * \param num Channel number to set timeout on
219  * \param timeout Maximum time allowed in milliseconds
220  * \return nothing
221  */
222 void 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  */
227 const 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 */
Main Channel structure associated with a channel.
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:1151
void * ast_dial_get_user_data(struct ast_dial *dial)
Return the user data on a dial structure.
Definition: dial.c:1303
Main dialing structure. Contains global options, channels being dialed, and more! ...
Definition: dial.c:48
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:1313
void ast_dial_hangup(struct ast_dial *dial)
Hangup channels.
Definition: dial.c:1069
int ast_dial_append_channel(struct ast_dial *dial, struct ast_channel *chan)
Append a channel using an actual channel object.
Definition: dial.c:297
static int timeout
Definition: cdr_mysql.c:86
Structure to pass both assignedid values to channel drivers.
Definition: channel.h:605
const char * ast_hangup_cause_to_dial_status(int hangup_cause)
Convert a hangup cause to a publishable dial status.
Definition: dial.c:753
const char * data
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:1194
void ast_dial_set_user_data(struct ast_dial *dial, void *user_data)
Set user data on a dial structure.
Definition: dial.c:1298
void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback)
Set a callback for state changes.
Definition: dial.c:1293
ast_dial_result
List of return codes for dial run API calls.
Definition: dial.h:54
enum ast_dial_result ast_dial_join(struct ast_dial *dial)
Cancel async thread.
Definition: dial.c:1021
int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option)
Disables an option globally.
Definition: dial.c:1223
ast_dial_option
List of options that are applicable either globally or per dialed channel.
Definition: dial.h:42
enum ast_dial_result ast_dial_state(struct ast_dial *dial)
Return state of dial.
Definition: dial.c:1012
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:939
Format capabilities structure, holds formats + preference order + etc.
Definition: format_cap.c:54
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:282
struct ast_channel * ast_dial_answered(struct ast_dial *dial)
Return channel that answered.
Definition: dial.c:981
struct ast_dial * ast_dial_create(void)
New dialing structure.
Definition: dial.c:225
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:1282
struct ast_channel * ast_dial_answered_steal(struct ast_dial *dial)
Steal the channel that answered.
Definition: dial.c:993
void(* ast_dial_state_callback)(struct ast_dial *)
Definition: dial.h:39
int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option)
Disables an option per channel.
Definition: dial.c:1246
int ast_dial_reason(struct ast_dial *dial, int num)
Get the reason an outgoing channel has failed.
Definition: dial.c:1271
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:1329
Dialing channel structure. Contains per-channel dialing options, asterisk channel, and more!
Definition: dial.c:63
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:433