app_page: Add predial handlers for app_page.
[asterisk/asterisk.git] / include / asterisk / dial.h
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)
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 */
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 */
49 };
50
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 */
63 };
64
65 /*! \brief New dialing structure
66  * \note Create a dialing structure
67  * \return Returns a calloc'd ast_dial structure, NULL on failure
68  */
69 struct ast_dial *ast_dial_create(void);
70
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
74  */
75 int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device);
76
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
81  * \retval -1 failure
82  * \reval 0 success
83  */
84 int ast_dial_prerun(struct ast_dial *dial, struct ast_channel *chan, struct ast_format_cap *cap);
85
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).
89  */
90 enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async);
91
92 /*! \brief Return channel that answered
93  * \note Returns the Asterisk channel that answered
94  * \param dial Dialing structure
95  */
96 struct ast_channel *ast_dial_answered(struct ast_dial *dial);
97
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
101  */
102 struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial);
103
104 /*! \brief Return state of dial
105  * \note Returns the state of the dial attempt
106  * \param dial Dialing structure
107  */
108 enum ast_dial_result ast_dial_state(struct ast_dial *dial);
109
110 /*! \brief Cancel async thread
111  * \note Cancel a running async thread
112  * \param dial Dialing structure
113  */
114 enum ast_dial_result ast_dial_join(struct ast_dial *dial);
115
116 /*! \brief Hangup channels
117  * \note Hangup all active channels
118  * \param dial Dialing structure
119  */
120 void ast_dial_hangup(struct ast_dial *dial);
121
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
126  */
127 int ast_dial_destroy(struct ast_dial *dial);
128
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
134  */
135 int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
136
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
143  */
144 int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
145
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
150  */
151 int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
152
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
158  */
159 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
160
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
165  */
166 int ast_dial_reason(struct ast_dial *dial, int num);
167
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
172  */
173 struct ast_channel *ast_dial_get_channel(struct ast_dial *dial, int num);
174
175 /*! \brief Set a callback for state changes
176  * \param dial The dial structure to watch for state changes
177  * \param callback the callback
178  * \return nothing
179  */
180 void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback);
181
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
185  * \return nothing
186  */
187 void ast_dial_set_user_data(struct ast_dial *dial, void *user_data);
188
189 /*! \brief Return the user data on a dial structure
190  * \param dial The dial structure
191  * \return A pointer to the user data
192  */
193 void *ast_dial_get_user_data(struct ast_dial *dial);
194
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
198  * \return nothing
199  */
200 void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout);
201
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
206  * \return nothing
207  */
208 void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout);
209
210 /*! \since 12
211  * \brief Convert a hangup cause to a publishable dial status
212  */
213 const char *ast_hangup_cause_to_dial_status(int hangup_cause);
214
215 #if defined(__cplusplus) || defined(c_plusplus)
216 }
217 #endif
218
219 #endif /* _ASTERISK_DIAL_H */