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_MAX, /*!< End terminator -- must always remain last */
46 /*! \brief List of return codes for dial run API calls */
47 enum ast_dial_result {
48 AST_DIAL_RESULT_INVALID, /*!< Invalid options were passed to run function */
49 AST_DIAL_RESULT_FAILED, /*!< Attempts to dial failed before reaching critical state */
50 AST_DIAL_RESULT_TRYING, /*!< Currently trying to dial */
51 AST_DIAL_RESULT_RINGING, /*!< Dial is presently ringing */
52 AST_DIAL_RESULT_PROGRESS, /*!< Dial is presently progressing */
53 AST_DIAL_RESULT_PROCEEDING, /*!< Dial is presently proceeding */
54 AST_DIAL_RESULT_ANSWERED, /*!< A channel was answered */
55 AST_DIAL_RESULT_TIMEOUT, /*!< Timeout was tripped, nobody answered */
56 AST_DIAL_RESULT_HANGUP, /*!< Caller hung up */
57 AST_DIAL_RESULT_UNANSWERED, /*!< Nobody answered */
60 /*! \brief New dialing structure
61 * \note Create a dialing structure
62 * \return Returns a calloc'd ast_dial structure, NULL on failure
64 struct ast_dial *ast_dial_create(void);
66 /*! \brief Append a channel
67 * \note Appends a channel to a dialing structure
68 * \return Returns channel reference number on success, -1 on failure
70 int ast_dial_append(struct ast_dial *dial, const char *tech, const char *device);
72 /*! \brief Execute dialing synchronously or asynchronously
73 * \note Dials channels in a dial structure.
74 * \return Returns dial result code. (TRYING/INVALID/FAILED/ANSWERED/TIMEOUT/UNANSWERED).
76 enum ast_dial_result ast_dial_run(struct ast_dial *dial, struct ast_channel *chan, int async);
78 /*! \brief Return channel that answered
79 * \note Returns the Asterisk channel that answered
80 * \param dial Dialing structure
82 struct ast_channel *ast_dial_answered(struct ast_dial *dial);
84 /*! \brief Return state of dial
85 * \note Returns the state of the dial attempt
86 * \param dial Dialing structure
88 enum ast_dial_result ast_dial_state(struct ast_dial *dial);
90 /*! \brief Cancel async thread
91 * \note Cancel a running async thread
92 * \param dial Dialing structure
94 enum ast_dial_result ast_dial_join(struct ast_dial *dial);
96 /*! \brief Hangup channels
97 * \note Hangup all active channels
98 * \param dial Dialing structure
100 void ast_dial_hangup(struct ast_dial *dial);
102 /*! \brief Destroys a dialing structure
103 * \note Cancels dialing and destroys (free's) the given ast_dial structure
104 * \param dial Dialing structure to free
105 * \return Returns 0 on success, -1 on failure
107 int ast_dial_destroy(struct ast_dial *dial);
109 /*! \brief Enables an option globally
110 * \param dial Dial structure to enable option on
111 * \param option Option to enable
112 * \param data Data to pass to this option (not always needed)
113 * \return Returns 0 on success, -1 on failure
115 int ast_dial_option_global_enable(struct ast_dial *dial, enum ast_dial_option option, void *data);
117 /*! \brief Enables an option per channel
118 * \param dial Dial structure
119 * \param num Channel number to enable option on
120 * \param option Option to enable
121 * \param data Data to pass to this option (not always needed)
122 * \return Returns 0 on success, -1 on failure
124 int ast_dial_option_enable(struct ast_dial *dial, int num, enum ast_dial_option option, void *data);
126 /*! \brief Disables an option globally
127 * \param dial Dial structure to disable option on
128 * \param option Option to disable
129 * \return Returns 0 on success, -1 on failure
131 int ast_dial_option_global_disable(struct ast_dial *dial, enum ast_dial_option option);
133 /*! \brief Disables an option per channel
134 * \param dial Dial structure
135 * \param num Channel number to disable option on
136 * \param option Option to disable
137 * \return Returns 0 on success, -1 on failure
139 int ast_dial_option_disable(struct ast_dial *dial, int num, enum ast_dial_option option);
141 /*! \brief Set a callback for state changes
142 * \param dial The dial structure to watch for state changes
143 * \param callback the callback
146 void ast_dial_set_state_callback(struct ast_dial *dial, ast_dial_state_callback callback);
148 #if defined(__cplusplus) || defined(c_plusplus)
152 #endif /* _ASTERISK_DIAL_H */