Wed Jan 8 2020 09:49:46

Asterisk developer's documentation


devicestate.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <markster@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 Device state management
21  *
22  * To subscribe to device state changes, use the generic ast_event_subscribe
23  * method. For an example, see apps/app_queue.c.
24  *
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.
33  *
34  * \arg See \ref AstExtState
35  */
36 
37 #ifndef _ASTERISK_DEVICESTATE_H
38 #define _ASTERISK_DEVICESTATE_H
39 
40 #include "asterisk/channelstate.h"
41 
42 #if defined(__cplusplus) || defined(c_plusplus)
43 extern "C" {
44 #endif
45 
46 /*! \brief Device States
47  * \note The order of these states may not change because they are included
48  * in Asterisk events which may be transmitted across the network to
49  * other servers.
50  */
52  AST_DEVICE_UNKNOWN, /*!< Device is valid but channel didn't know state */
53  AST_DEVICE_NOT_INUSE, /*!< Device is not used */
54  AST_DEVICE_INUSE, /*!< Device is in use */
55  AST_DEVICE_BUSY, /*!< Device is busy */
56  AST_DEVICE_INVALID, /*!< Device is invalid */
57  AST_DEVICE_UNAVAILABLE, /*!< Device is unavailable */
58  AST_DEVICE_RINGING, /*!< Device is ringing */
59  AST_DEVICE_RINGINUSE, /*!< Device is ringing *and* in use */
60  AST_DEVICE_ONHOLD, /*!< Device is on hold */
61  AST_DEVICE_TOTAL, /*/ Total num of device states, used for testing */
62 };
63 
64 /*! \brief Device State Cachability
65  * \note This is used to define the cachability of a device state when set.
66  */
68  AST_DEVSTATE_NOT_CACHABLE, /*!< This device state is not cachable */
69  AST_DEVSTATE_CACHABLE, /*!< This device state is cachable */
70 };
71 
72 /*! \brief Devicestate provider call back */
73 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
74 
75 /*!
76  * \brief Convert channel state to devicestate
77  *
78  * \param chanstate Current channel state
79  * \since 1.6.1
80  */
82 
83 /*!
84  * \brief Convert device state to text string for output
85  *
86  * \param devstate Current device state
87  */
88 const char *devstate2str(enum ast_device_state devstate) attribute_pure __attribute__((deprecated));
89 const char *ast_devstate2str(enum ast_device_state devstate) attribute_pure;
90 
91 /*!
92  * \brief Convert device state to text string that is easier to parse
93  *
94  * \param devstate Current device state
95  */
96 const char *ast_devstate_str(enum ast_device_state devstate) attribute_pure;
97 
98 /*!
99  * \brief Convert device state from text to integer value
100  *
101  * \param val The text representing the device state. Valid values are anything
102  * that comes after AST_DEVICE_ in one of the defined values.
103  *
104  * \return The AST_DEVICE_ integer value
105  */
106 enum ast_device_state ast_devstate_val(const char *val);
107 
108 /*!
109  * \brief Search the Channels by Name
110  *
111  * \param device like a dial string
112  *
113  * Search the Device in active channels by compare the channel name against
114  * the device name. Compared are only the first chars to the first '-' char.
115  *
116  * \retval AST_DEVICE_UNKNOWN if no channel found
117  * \retval AST_DEVICE_INUSE if a channel is found
118  */
119 enum ast_device_state ast_parse_device_state(const char *device);
120 
121 /*!
122  * \brief Asks a channel for device state
123  *
124  * \param device like a dial string
125  *
126  * Asks a channel for device state, data is normally a number from a dial string
127  * used by the low level module
128  * Tries the channel device state callback if not supported search in the
129  * active channels list for the device.
130  *
131  * \retval an AST_DEVICE_??? state
132  */
133 enum ast_device_state ast_device_state(const char *device);
134 
135 /*!
136  * \brief Tells Asterisk the State for Device is changed
137  *
138  * \param state the new state of the device
139  * \param cachable whether this device state is cachable
140  * \param fmt device name like a dial string with format parameters
141  *
142  * The new state of the device will be sent off to any subscribers
143  * of device states. It will also be stored in the internal event
144  * cache.
145  *
146  * \retval 0 on success
147  * \retval -1 on failure
148  */
149 int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt, ...)
150  __attribute__((format(printf, 3, 4)));
151 
152 /*!
153  * \brief Tells Asterisk the State for Device is changed
154  *
155  * \param state the new state of the device
156  * \param cachable whether this device state is cachable
157  * \param device device name like a dial string with format parameters
158  *
159  * The new state of the device will be sent off to any subscribers
160  * of device states. It will also be stored in the internal event
161  * cache.
162  *
163  * \retval 0 on success
164  * \retval -1 on failure
165  */
166 int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device);
167 
168 /*!
169  * \brief Tells Asterisk the State for Device is changed.
170  * (Accept change notification, add it to change queue.)
171  *
172  * \param fmt device name like a dial string with format parameters
173  *
174  * Asterisk polls the new extension states and calls the registered
175  * callbacks for the changed extensions
176  *
177  * \retval 0 on success
178  * \retval -1 on failure
179  *
180  * \note This is deprecated in favor of ast_devstate_changed()
181  * \version 1.6.1 deprecated
182  */
183 int ast_device_state_changed(const char *fmt, ...)
184  __attribute__((deprecated,format(printf, 1, 2)));
185 
186 /*!
187  * \brief Tells Asterisk the State for Device is changed
188  *
189  * \param device device name like a dial string
190  *
191  * Asterisk polls the new extension states and calls the registered
192  * callbacks for the changed extensions
193  *
194  * \retval 0 on success
195  * \retval -1 on failure
196  *
197  * \note This is deprecated in favor of ast_devstate_changed_literal()
198  * \version 1.6.1 deprecated
199  */
200 int ast_device_state_changed_literal(const char *device)
201  __attribute__((deprecated));
202 
203 /*!
204  * \brief Add device state provider
205  *
206  * \param label to use in hint, like label:object
207  * \param callback Callback
208  *
209  * \retval 0 success
210  * \retval -1 failure
211  */
212 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback);
213 
214 /*!
215  * \brief Remove device state provider
216  *
217  * \param label to use in hint, like label:object
218  *
219  * \retval -1 on failure
220  * \retval 0 on success
221  */
222 int ast_devstate_prov_del(const char *label);
223 
224 /*!
225  * \brief An object to hold state when calculating aggregate device state
226  */
228 
229 /*!
230  * \brief Initialize aggregate device state
231  *
232  * \param[in] agg the state object
233  *
234  * \return nothing
235  * \since 1.6.1
236  */
237 void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg);
238 
239 /*!
240  * \brief Add a device state to the aggregate device state
241  *
242  * \param[in] agg the state object
243  * \param[in] state the state to add
244  *
245  * \return nothing
246  * \since 1.6.1
247  */
248 void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state);
249 
250 /*!
251  * \brief Get the aggregate device state result
252  *
253  * \param[in] agg the state object
254  *
255  * \return the aggregate device state after adding some number of device states.
256  * \since 1.6.1
257  */
258 enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg);
259 
260 /*!
261  * \brief You shouldn't care about the contents of this struct
262  *
263  * This struct is only here so that it can be easily declared on the stack.
264  */
265 struct ast_devstate_aggregate {
266  unsigned int ringing:1;
267  unsigned int inuse:1;
269 };
270 
271 /*!
272  * \brief Enable distributed device state processing.
273  *
274  * \details
275  * By default, Asterisk assumes that device state change events will only be
276  * originating from one instance. If a module gets loaded and configured such
277  * that multiple instances of Asterisk will be sharing device state, this
278  * function should be called to enable distributed device state processing.
279  * It is off by default to save on unnecessary processing.
280  *
281  * \retval 0 success
282  * \retval -1 failure
283  */
285 
286 #if defined(__cplusplus) || defined(c_plusplus)
287 }
288 #endif
289 
290 #endif /* _ASTERISK_DEVICESTATE_H */
enum sip_cc_notify_state state
Definition: chan_sip.c:842
const char * ast_devstate2str(enum ast_device_state devstate) attribute_pure
Find devicestate as text message for output.
Definition: devicestate.c:215
#define attribute_pure
Definition: compiler.h:35
ast_device_state
Device States.
Definition: devicestate.h:51
Definition: ast_expr2.c:325
const char * devstate2str(enum ast_device_state devstate) attribute_pure
Convert device state to text string for output.
Definition: devicestate.c:221
enum ast_device_state ast_parse_device_state(const char *device)
Search the Channels by Name.
Definition: devicestate.c:271
int ast_enable_distributed_devstate(void)
Enable distributed device state processing.
Definition: devicestate.c:796
int ast_devstate_prov_del(const char *label)
Remove device state provider.
Definition: devicestate.c:389
ast_channel_state
ast_channel states
Definition: channelstate.h:35
Channel states.
int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback)
Add device state provider.
Definition: devicestate.c:371
enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg)
Get the aggregate device state result.
Definition: devicestate.c:791
int ast_devstate_changed(enum ast_device_state state, enum ast_devstate_cache cachable, const char *fmt,...)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:516
enum ast_device_state ast_devstate_val(const char *val)
Convert device state from text to integer value.
Definition: devicestate.c:244
int ast_device_state_changed(const char *fmt,...)
Tells Asterisk the State for Device is changed. (Accept change notification, add it to change queue...
Definition: devicestate.c:528
enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate)
Convert channel state to devicestate.
Definition: devicestate.c:226
int ast_device_state_changed_literal(const char *device)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:511
void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state)
Add a device state to the aggregate device state.
Definition: devicestate.c:764
const char * ast_devstate_str(enum ast_device_state devstate) attribute_pure
Convert device state to text string that is easier to parse.
Definition: devicestate.c:239
ast_devstate_cache
Device State Cachability.
Definition: devicestate.h:67
enum ast_device_state(* ast_devstate_prov_cb_type)(const char *data)
Devicestate provider call back.
Definition: devicestate.h:73
void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg)
Initialize aggregate device state.
Definition: devicestate.c:758
You shouldn&#39;t care about the contents of this struct.
Definition: devicestate.h:265
int ast_devstate_changed_literal(enum ast_device_state state, enum ast_devstate_cache cachable, const char *device)
Tells Asterisk the State for Device is changed.
Definition: devicestate.c:472
static snd_pcm_format_t format
Definition: chan_alsa.c:93