2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@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.
20 * \brief Device state management
22 * To subscribe to device state changes, use the generic ast_event_subscribe
23 * method. For an example, see apps/app_queue.c.
25 * \todo Currently, when the state of a device changes, the device state provider
26 * calls one of the functions defined here to queue an object to say that the
27 * state of a device has changed. However, this does not include the new state.
28 * Another thread processes these device state change objects and calls the
29 * device state provider's callback to figure out what the new state is. It
30 * would make a lot more sense for the new state to be included in the original
31 * function call that says the state of a device has changed. However, it
32 * will take a lot of work to change this.
34 * \arg See \ref AstExtState
37 #ifndef _ASTERISK_DEVICESTATE_H
38 #define _ASTERISK_DEVICESTATE_H
40 #if defined(__cplusplus) || defined(c_plusplus)
44 /*! \brief Device States
45 * \note The order of these states may not change because they are included
46 * in Asterisk events which may be transmitted across the network to
49 enum ast_device_state {
50 AST_DEVICE_UNKNOWN, /*!< Device is valid but channel didn't know state */
51 AST_DEVICE_NOT_INUSE, /*!< Device is not used */
52 AST_DEVICE_INUSE, /*!< Device is in use */
53 AST_DEVICE_BUSY, /*!< Device is busy */
54 AST_DEVICE_INVALID, /*!< Device is invalid */
55 AST_DEVICE_UNAVAILABLE, /*!< Device is unavailable */
56 AST_DEVICE_RINGING, /*!< Device is ringing */
57 AST_DEVICE_RINGINUSE, /*!< Device is ringing *and* in use */
58 AST_DEVICE_ONHOLD, /*!< Device is on hold */
61 /*! \brief Devicestate provider call back */
62 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
65 * \brief Convert device state to text string for output
67 * \param devstate Current device state
69 const char *devstate2str(enum ast_device_state devstate);
72 * \brief Convert device state to text string that is easier to parse
74 * \param devstate Current device state
76 const char *ast_devstate_str(enum ast_device_state devstate);
79 * \brief Convert device state from text to integer value
81 * \param val The text representing the device state. Valid values are anything
82 * that comes after AST_DEVICE_ in one of the defined values.
84 * \return The AST_DEVICE_ integer value
86 enum ast_device_state ast_devstate_val(const char *val);
89 * \brief Search the Channels by Name
91 * \param device like a dial string
93 * Search the Device in active channels by compare the channel name against
94 * the device name. Compared are only the first chars to the first '-' char.
96 * \retval AST_DEVICE_UNKNOWN if no channel found
97 * \retval AST_DEVICE_INUSE if a channel is found
99 enum ast_device_state ast_parse_device_state(const char *device);
102 * \brief Asks a channel for device state
104 * \param device like a dial string
106 * Asks a channel for device state, data is normally a number from a dial string
107 * used by the low level module
108 * Tries the channel device state callback if not supported search in the
109 * active channels list for the device.
111 * \retval an AST_DEVICE_??? state
112 * \retval -1 on failure
114 enum ast_device_state ast_device_state(const char *device);
117 * \brief Tells Asterisk the State for Device is changed
119 * \param state the new state of the device
120 * \param fmt device name like a dial string with format parameters
122 * The new state of the device will be sent off to any subscribers
123 * of device states. It will also be stored in the internal event
126 * \retval 0 on success
127 * \retval -1 on failure
129 int ast_devstate_changed(enum ast_device_state state, const char *fmt, ...)
130 __attribute__ ((format (printf, 2, 3)));
133 * \brief Tells Asterisk the State for Device is changed
135 * \param state the new state of the device
136 * \param device device name like a dial string with format parameters
138 * The new state of the device will be sent off to any subscribers
139 * of device states. It will also be stored in the internal event
142 * \retval 0 on success
143 * \retval -1 on failure
145 int ast_devstate_changed_literal(enum ast_device_state state, const char *device);
148 * \brief Tells Asterisk the State for Device is changed
150 * \param fmt device name like a dial string with format parameters
152 * Asterisk polls the new extension states and calls the registered
153 * callbacks for the changed extensions
155 * \retval 0 on success
156 * \retval -1 on failure
158 * \note This is deprecated in favor of ast_devstate_changed()
160 int ast_device_state_changed(const char *fmt, ...)
161 __attribute__ ((format (printf, 1, 2)));
164 * \brief Tells Asterisk the State for Device is changed
166 * \param device device name like a dial string
168 * Asterisk polls the new extension states and calls the registered
169 * callbacks for the changed extensions
171 * \retval 0 on success
172 * \retval -1 on failure
174 * \note This is deprecated in favor of ast_devstate_changed_literal()
176 int ast_device_state_changed_literal(const char *device);
179 * \brief Add device state provider
181 * \param label to use in hint, like label:object
182 * \param callback Callback
187 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback);
190 * \brief Remove device state provider
192 * \param label to use in hint, like label:object
194 * \retval -1 on failure
195 * \retval 0 on success
197 int ast_devstate_prov_del(const char *label);
200 * \brief An object to hold state when calculating aggregate device state
202 struct ast_devstate_aggregate;
205 * \brief Initialize aggregate device state
207 * \param agg the state object
211 void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg);
214 * \brief Add a device state to the aggregate device state
216 * \param agg the state object
217 * \param state the state to add
221 void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state);
224 * \brief Get the aggregate device state result
226 * \param agg the state object
228 * \return the aggregate device state after adding some number of device states.
230 enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg);
233 * \brief You shouldn't care about the contents of this struct
235 * This struct is only here so that it can be easily declared on the stack.
237 struct ast_devstate_aggregate {
238 unsigned int all_unavail:1;
239 unsigned int all_busy:1;
240 unsigned int all_free:1;
241 unsigned int all_on_hold:1;
243 unsigned int in_use:1;
247 #if defined(__cplusplus) || defined(c_plusplus)
251 #endif /* _ASTERISK_DEVICESTATE_H */