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 typedef void (*ast_dial_state_callback)(struct ast_dial *);
38 /*! \brief List of options that are applicable either globally or per dialed channel */
39 enum ast_dial_option {
40 AST_DIAL_OPTION_RINGING, /*!< Always indicate ringing to caller */
41 AST_DIAL_OPTION_ANSWER_EXEC, /*!< Execute application upon answer in async mode */
42 AST_DIAL_OPTION_MUSIC, /*!< Play music on hold instead of ringing to the calling channel */
43 AST_DIAL_OPTION_DISABLE_CALL_FORWARDING, /*!< Disable call forwarding on channels */
44 AST_DIAL_OPTION_MAX, /*!< End terminator -- must always remain last */
47 /*! \brief List of return codes for dial run API calls */
48 enum ast_dial_result {
49 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */
50 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */
51 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */
52 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */
53 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */
54 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */
55 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */
56 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */
57 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */
58 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */
61 /*! \brief New dialing structure
62 * \note Create a dialing structure
63 * \return Returns a calloc'd ast_dial structure, NULL on failure
65 struct ast_dial *ast_dial_create(void);
67 /*! \brief Append a channel
68 * \note Appends a channel to a dialing structure
69 * \return Returns channel reference number on success, -1 on failure
71 int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device);
73 /*! \brief Execute dialing synchronously or asynchronously
74 * \note Dials channels in a dial structure.
75 * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
77 enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async);
79 /*! \brief Return channel that answered
80 * \note Returns the Asterisk channel that answered
81 * \param dial Dialing structure
83 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
89 struct ast_channel *ast_dial_answered_steal(struct ast_dial *dial);
91 /*! \brief Return state of dial
92 * \note Returns the state of the dial attempt
93 * \param dial Dialing structure
95 enum ast_dial_result ast_dial_state(struct ast_dial *dial);
97 /*! \brief Cancel async thread
98 * \note Cancel a running async thread
99 * \param dial Dialing structure
101 enum ast_dial_result ast_dial_join(struct ast_dial *dial);
103 /*! \brief Hangup channels
104 * \note Hangup all active channels
105 * \param dial Dialing structure
107 void ast_dial_hangup(struct ast_dial *dial);
109 /*! \brief Destroys a dialing structure
110 * \note Cancels dialing and destroys (free's) the given ast_dial structure
111 * \param dial Dialing structure to free
112 * \return Returns 0 on success, -1 on failure
114 int ast_dial_destroy(struct ast_dial *dial);
116 /*! \brief Enables an option globally
117 * \param dial Dial structure to enable option on
118 * \param option Option to enable
119 * \param data Data to pass to this option (not always needed)
120 * \return Returns 0 on success, -1 on failure
122 int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
124 /*! \brief Enables an option per channel
125 * \param dial Dial structure
126 * \param num Channel number to enable option on
127 * \param option Option to enable
128 * \param data Data to pass to this option (not always needed)
129 * \return Returns 0 on success, -1 on failure
131 int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
133 /*! \brief Disables an option globally
134 * \param dial Dial structure to disable option on
135 * \param option Option to disable
136 * \return Returns 0 on success, -1 on failure
138 int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
140 /*! \brief Disables an option per channel
141 * \param dial Dial structure
142 * \param num Channel number to disable option on
143 * \param option Option to disable
144 * \return Returns 0 on success, -1 on failure
146 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
148 /*! \brief Set a callback for state changes
149 * \param dial The dial structure to watch for state changes
150 * \param callback the callback
153 void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback);
155 /*! \brief Set the maximum time (globally) allowed for trying to ring phones
156 * \param dial The dial structure to apply the time limit to
157 * \param timeout Maximum time allowed
160 void ast_dial_set_global_timeout(struct ast_dial *dial, int timeout);
162 /*! \brief Set the maximum time (per channel) allowed for trying to ring the phone
163 * \param dial The dial structure the channel belongs to
164 * \param num Channel number to set timeout on
165 * \param timeout Maximum time allowed
168 void ast_dial_set_timeout(struct ast_dial *dial, int num, int timeout);
170 #if defined(__cplusplus) || defined(c_plusplus)
174 #endif /* _ASTERISK_DIAL_H */