Mon Jun 27 16:50:53 2011

Asterisk developer's documentation


devicestate.h

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 1999 - 2005, Digium, Inc.
00005  *
00006  * Mark Spencer <markster@digium.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  * \brief Device state management
00021  *
00022  * To subscribe to device state changes, use the generic ast_event_subscribe
00023  * method.  For an example, see apps/app_queue.c.
00024  *
00025  * \todo Currently, when the state of a device changes, the device state provider
00026  * calls one of the functions defined here to queue an object to say that the
00027  * state of a device has changed.  However, this does not include the new state.
00028  * Another thread processes these device state change objects and calls the
00029  * device state provider's callback to figure out what the new state is.  It
00030  * would make a lot more sense for the new state to be included in the original
00031  * function call that says the state of a device has changed.  However, it
00032  * will take a lot of work to change this.
00033  *
00034  * \arg See \ref AstExtState
00035  */
00036 
00037 #ifndef _ASTERISK_DEVICESTATE_H
00038 #define _ASTERISK_DEVICESTATE_H
00039 
00040 #include "asterisk/channelstate.h"
00041 
00042 #if defined(__cplusplus) || defined(c_plusplus)
00043 extern "C" {
00044 #endif
00045 
00046 /*! \brief Device States
00047  *  \note The order of these states may not change because they are included
00048  *        in Asterisk events which may be transmitted across the network to
00049  *        other servers.
00050  */
00051 enum ast_device_state {
00052    AST_DEVICE_UNKNOWN,      /*!< Device is valid but channel didn't know state */
00053    AST_DEVICE_NOT_INUSE,    /*!< Device is not used */
00054    AST_DEVICE_INUSE,        /*!< Device is in use */
00055    AST_DEVICE_BUSY,         /*!< Device is busy */
00056    AST_DEVICE_INVALID,      /*!< Device is invalid */
00057    AST_DEVICE_UNAVAILABLE,  /*!< Device is unavailable */
00058    AST_DEVICE_RINGING,      /*!< Device is ringing */
00059    AST_DEVICE_RINGINUSE,    /*!< Device is ringing *and* in use */
00060    AST_DEVICE_ONHOLD,       /*!< Device is on hold */
00061    AST_DEVICE_TOTAL,        /*/ Total num of device states, used for testing */
00062 };
00063 
00064 /*! \brief Devicestate provider call back */
00065 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data);
00066 
00067 /*!
00068  * \brief Convert channel state to devicestate
00069  *
00070  * \param chanstate Current channel state
00071  * \since 1.6.1
00072  */
00073 enum ast_device_state ast_state_chan2dev(enum ast_channel_state chanstate);
00074 
00075 /*!
00076  * \brief Convert device state to text string for output
00077  *
00078  * \param devstate Current device state
00079  */
00080 const char *devstate2str(enum ast_device_state devstate) attribute_pure __attribute__((deprecated));
00081 const char *ast_devstate2str(enum ast_device_state devstate) attribute_pure;
00082 
00083 /*!
00084  * \brief Convert device state to text string that is easier to parse
00085  *
00086  * \param devstate Current device state
00087  */
00088 const char *ast_devstate_str(enum ast_device_state devstate) attribute_pure;
00089 
00090 /*!
00091  * \brief Convert device state from text to integer value
00092  *
00093  * \param val The text representing the device state.  Valid values are anything
00094  *        that comes after AST_DEVICE_ in one of the defined values.
00095  *
00096  * \return The AST_DEVICE_ integer value
00097  */
00098 enum ast_device_state ast_devstate_val(const char *val);
00099 
00100 /*!
00101  * \brief Search the Channels by Name
00102  *
00103  * \param device like a dial string
00104  *
00105  * Search the Device in active channels by compare the channel name against
00106  * the device name. Compared are only the first chars to the first '-' char.
00107  *
00108  * \retval AST_DEVICE_UNKNOWN if no channel found
00109  * \retval AST_DEVICE_INUSE if a channel is found
00110  */
00111 enum ast_device_state ast_parse_device_state(const char *device);
00112 
00113 /*!
00114  * \brief Asks a channel for device state
00115  *
00116  * \param device like a dial string
00117  *
00118  * Asks a channel for device state, data is normally a number from a dial string
00119  * used by the low level module
00120  * Tries the channel device state callback if not supported search in the
00121  * active channels list for the device.
00122  *
00123  * \retval an AST_DEVICE_??? state
00124  * \retval -1 on failure
00125  */
00126 enum ast_device_state ast_device_state(const char *device);
00127 
00128 /*!
00129  * \brief Tells Asterisk the State for Device is changed
00130  *
00131  * \param state the new state of the device
00132  * \param fmt device name like a dial string with format parameters
00133  *
00134  * The new state of the device will be sent off to any subscribers
00135  * of device states.  It will also be stored in the internal event
00136  * cache.
00137  *
00138  * \retval 0 on success
00139  * \retval -1 on failure
00140  */
00141 int ast_devstate_changed(enum ast_device_state state, const char *fmt, ...)
00142    __attribute__((format(printf, 2, 3)));
00143 
00144 /*!
00145  * \brief Tells Asterisk the State for Device is changed
00146  *
00147  * \param state the new state of the device
00148  * \param device device name like a dial string with format parameters
00149  *
00150  * The new state of the device will be sent off to any subscribers
00151  * of device states.  It will also be stored in the internal event
00152  * cache.
00153  *
00154  * \retval 0 on success
00155  * \retval -1 on failure
00156  */
00157 int ast_devstate_changed_literal(enum ast_device_state state, const char *device);
00158 
00159 /*!
00160  * \brief Tells Asterisk the State for Device is changed.
00161  * (Accept change notification, add it to change queue.)
00162  *
00163  * \param fmt device name like a dial string with format parameters
00164  *
00165  * Asterisk polls the new extension states and calls the registered
00166  * callbacks for the changed extensions
00167  *
00168  * \retval 0 on success
00169  * \retval -1 on failure
00170  *
00171  * \note This is deprecated in favor of ast_devstate_changed()
00172  * \version 1.6.1 deprecated
00173  */
00174 int ast_device_state_changed(const char *fmt, ...)
00175    __attribute__((deprecated,format(printf, 1, 2)));
00176 
00177 /*!
00178  * \brief Tells Asterisk the State for Device is changed
00179  *
00180  * \param device device name like a dial string
00181  *
00182  * Asterisk polls the new extension states and calls the registered
00183  * callbacks for the changed extensions
00184  *
00185  * \retval 0 on success
00186  * \retval -1 on failure
00187  *
00188  * \note This is deprecated in favor of ast_devstate_changed_literal()
00189  * \version 1.6.1 deprecated
00190  */
00191 int ast_device_state_changed_literal(const char *device)
00192    __attribute__((deprecated));
00193 
00194 /*!
00195  * \brief Add device state provider
00196  *
00197  * \param label to use in hint, like label:object
00198  * \param callback Callback
00199  *
00200  * \retval 0 success
00201  * \retval -1 failure
00202  */
00203 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback);
00204 
00205 /*!
00206  * \brief Remove device state provider
00207  *
00208  * \param label to use in hint, like label:object
00209  *
00210  * \retval -1 on failure
00211  * \retval 0 on success
00212  */
00213 int ast_devstate_prov_del(const char *label);
00214 
00215 /*!
00216  * \brief An object to hold state when calculating aggregate device state
00217  */
00218 struct ast_devstate_aggregate;
00219 
00220 /*!
00221  * \brief Initialize aggregate device state
00222  *
00223  * \param[in] agg the state object
00224  *
00225  * \return nothing
00226  * \since 1.6.1
00227  */
00228 void ast_devstate_aggregate_init(struct ast_devstate_aggregate *agg);
00229 
00230 /*!
00231  * \brief Add a device state to the aggregate device state
00232  *
00233  * \param[in] agg the state object
00234  * \param[in] state the state to add
00235  *
00236  * \return nothing
00237  * \since 1.6.1
00238  */
00239 void ast_devstate_aggregate_add(struct ast_devstate_aggregate *agg, enum ast_device_state state);
00240 
00241 /*!
00242  * \brief Get the aggregate device state result
00243  *
00244  * \param[in] agg the state object
00245  *
00246  * \return the aggregate device state after adding some number of device states.
00247  * \since 1.6.1
00248  */
00249 enum ast_device_state ast_devstate_aggregate_result(struct ast_devstate_aggregate *agg);
00250 
00251 /*!
00252  * \brief You shouldn't care about the contents of this struct
00253  *
00254  * This struct is only here so that it can be easily declared on the stack.
00255  */
00256 struct ast_devstate_aggregate {
00257    unsigned int all_unknown:1;
00258    unsigned int all_unavail:1;
00259    unsigned int all_busy:1;
00260    unsigned int all_free:1;
00261    unsigned int on_hold:1;
00262    unsigned int busy:1;
00263    unsigned int in_use:1;
00264    unsigned int ring:1;
00265 };
00266 
00267 /*!
00268  * \brief Enable distributed device state processing.
00269  *
00270  * \details
00271  * By default, Asterisk assumes that device state change events will only be
00272  * originating from one instance.  If a module gets loaded and configured such
00273  * that multiple instances of Asterisk will be sharing device state, this
00274  * function should be called to enable distributed device state processing.
00275  * It is off by default to save on unnecessary processing.
00276  *
00277  * \retval 0 success
00278  * \retval -1 failure
00279  */
00280 int ast_enable_distributed_devstate(void);
00281 
00282 #if defined(__cplusplus) || defined(c_plusplus)
00283 }
00284 #endif
00285 
00286 #endif /* _ASTERISK_DEVICESTATE_H */

Generated on Mon Jun 27 16:50:53 2011 for Asterisk - The Open Source Telephony Project by  doxygen 1.4.7