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 #if defined(__cplusplus) || defined(c_plusplus) 00041 extern "C" { 00042 #endif 00043 00044 /*! \brief Device States 00045 * \note The order of these states may not change because they are included 00046 * in Asterisk events which may be transmitted across the network to 00047 * other servers. 00048 */ 00049 enum ast_device_state { 00050 AST_DEVICE_UNKNOWN, /*!< Device is valid but channel didn't know state */ 00051 AST_DEVICE_NOT_INUSE, /*!< Device is not used */ 00052 AST_DEVICE_INUSE, /*!< Device is in use */ 00053 AST_DEVICE_BUSY, /*!< Device is busy */ 00054 AST_DEVICE_INVALID, /*!< Device is invalid */ 00055 AST_DEVICE_UNAVAILABLE, /*!< Device is unavailable */ 00056 AST_DEVICE_RINGING, /*!< Device is ringing */ 00057 AST_DEVICE_RINGINUSE, /*!< Device is ringing *and* in use */ 00058 AST_DEVICE_ONHOLD, /*!< Device is on hold */ 00059 }; 00060 00061 /*! \brief Devicestate provider call back */ 00062 typedef enum ast_device_state (*ast_devstate_prov_cb_type)(const char *data); 00063 00064 /*! 00065 * \brief Convert device state to text string for output 00066 * 00067 * \param devstate Current device state 00068 */ 00069 const char *devstate2str(enum ast_device_state devstate); 00070 00071 /*! 00072 * \brief Convert device state to text string that is easier to parse 00073 * 00074 * \param devstate Current device state 00075 */ 00076 const char *ast_devstate_str(enum ast_device_state devstate); 00077 00078 /*! 00079 * \brief Convert device state from text to integer value 00080 * 00081 * \param val The text representing the device state. Valid values are anything 00082 * that comes after AST_DEVICE_ in one of the defined values. 00083 * 00084 * \return The AST_DEVICE_ integer value 00085 */ 00086 enum ast_device_state ast_devstate_val(const char *val); 00087 00088 /*! 00089 * \brief Search the Channels by Name 00090 * 00091 * \param device like a dial string 00092 * 00093 * Search the Device in active channels by compare the channel name against 00094 * the device name. Compared are only the first chars to the first '-' char. 00095 * 00096 * \retval AST_DEVICE_UNKNOWN if no channel found 00097 * \retval AST_DEVICE_INUSE if a channel is found 00098 */ 00099 enum ast_device_state ast_parse_device_state(const char *device); 00100 00101 /*! 00102 * \brief Asks a channel for device state 00103 * 00104 * \param device like a dial string 00105 * 00106 * Asks a channel for device state, data is normally a number from a dial string 00107 * used by the low level module 00108 * Tries the channel device state callback if not supported search in the 00109 * active channels list for the device. 00110 * 00111 * \retval an AST_DEVICE_??? state 00112 * \retval -1 on failure 00113 */ 00114 enum ast_device_state ast_device_state(const char *device); 00115 00116 /*! 00117 * \brief Tells Asterisk the State for Device is changed 00118 * 00119 * \param state the new state of the device 00120 * \param fmt device name like a dial string with format parameters 00121 * 00122 * The new state of the device will be sent off to any subscribers 00123 * of device states. It will also be stored in the internal event 00124 * cache. 00125 * 00126 * \retval 0 on success 00127 * \retval -1 on failure 00128 */ 00129 int ast_devstate_changed(enum ast_device_state state, const char *fmt, ...) 00130 __attribute__((format(printf, 2, 3))); 00131 00132 /*! 00133 * \brief Tells Asterisk the State for Device is changed 00134 * 00135 * \param state the new state of the device 00136 * \param device device name like a dial string with format parameters 00137 * 00138 * The new state of the device will be sent off to any subscribers 00139 * of device states. It will also be stored in the internal event 00140 * cache. 00141 * 00142 * \retval 0 on success 00143 * \retval -1 on failure 00144 */ 00145 int ast_devstate_changed_literal(enum ast_device_state state, const char *device); 00146 00147 /*! 00148 * \brief Tells Asterisk the State for Device is changed 00149 * 00150 * \param fmt device name like a dial string with format parameters 00151 * 00152 * Asterisk polls the new extension states and calls the registered 00153 * callbacks for the changed extensions 00154 * 00155 * \retval 0 on success 00156 * \retval -1 on failure 00157 * 00158 * \note This is deprecated in favor of ast_devstate_changed() 00159 */ 00160 int ast_device_state_changed(const char *fmt, ...) 00161 __attribute__((format(printf, 1, 2))); 00162 00163 /*! 00164 * \brief Tells Asterisk the State for Device is changed 00165 * 00166 * \param device device name like a dial string 00167 * 00168 * Asterisk polls the new extension states and calls the registered 00169 * callbacks for the changed extensions 00170 * 00171 * \retval 0 on success 00172 * \retval -1 on failure 00173 * 00174 * \note This is deprecated in favor of ast_devstate_changed_literal() 00175 */ 00176 int ast_device_state_changed_literal(const char *device); 00177 00178 /*! 00179 * \brief Add device state provider 00180 * 00181 * \param label to use in hint, like label:object 00182 * \param callback Callback 00183 * 00184 * \retval 0 success 00185 * \retval -1 failure 00186 */ 00187 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback); 00188 00189 /*! 00190 * \brief Remove device state provider 00191 * 00192 * \param label to use in hint, like label:object 00193 * 00194 * \retval -1 on failure 00195 * \retval 0 on success 00196 */ 00197 int ast_devstate_prov_del(const char *label); 00198 00199 #if defined(__cplusplus) || defined(c_plusplus) 00200 } 00201 #endif 00202 00203 #endif /* _ASTERISK_DEVICESTATE_H */