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 * \arg See \ref AstExtState 00023 */ 00024 00025 #ifndef _ASTERISK_DEVICESTATE_H 00026 #define _ASTERISK_DEVICESTATE_H 00027 00028 #if defined(__cplusplus) || defined(c_plusplus) 00029 extern "C" { 00030 #endif 00031 /*! @name DeviceStates */ 00032 /*! \@{ */ 00033 #define AST_DEVICE_UNKNOWN 0 /*!< Device is valid but channel didn't know state */ 00034 #define AST_DEVICE_NOT_INUSE 1 /*!< Device is not used */ 00035 #define AST_DEVICE_INUSE 2 /*!< Device is in use */ 00036 #define AST_DEVICE_BUSY 3 /*!< Device is busy */ 00037 #define AST_DEVICE_INVALID 4 /*!< Device is invalid */ 00038 #define AST_DEVICE_UNAVAILABLE 5 /*!< Device is unavailable */ 00039 #define AST_DEVICE_RINGING 6 /*!< Device is ringing */ 00040 #define AST_DEVICE_RINGINUSE 7 /*!< Device is ringing *and* in use */ 00041 #define AST_DEVICE_ONHOLD 8 /*!< Device is on hold */ 00042 /*! \@} */ 00043 00044 /*! \brief Devicestate watcher call back */ 00045 typedef int (*ast_devstate_cb_type)(const char *dev, int state, void *data); 00046 00047 /*! \brief Devicestate provider call back */ 00048 typedef int (*ast_devstate_prov_cb_type)(const char *data); 00049 00050 /*! \brief Convert device state to text string for output 00051 * \param devstate Current device state 00052 */ 00053 const char *devstate2str(int devstate); 00054 00055 /*! \brief Search the Channels by Name 00056 * \param device like a dialstring 00057 * Search the Device in active channels by compare the channelname against 00058 * the devicename. Compared are only the first chars to the first '-' char. 00059 * Returns an AST_DEVICE_UNKNOWN if no channel found or 00060 * AST_DEVICE_INUSE if a channel is found 00061 */ 00062 int ast_parse_device_state(const char *device); 00063 00064 /*! \brief Asks a channel for device state 00065 * \param device like a dialstring 00066 * Asks a channel for device state, data is normaly a number from dialstring 00067 * used by the low level module 00068 * Trys the channel devicestate callback if not supported search in the 00069 * active channels list for the device. 00070 * Returns an AST_DEVICE_??? state -1 on failure 00071 */ 00072 int ast_device_state(const char *device); 00073 00074 /*! \brief Tells Asterisk the State for Device is changed 00075 * \param fmt devicename like a dialstring with format parameters 00076 * Asterisk polls the new extensionstates and calls the registered 00077 * callbacks for the changed extensions 00078 * Returns 0 on success, -1 on failure 00079 */ 00080 int ast_device_state_changed(const char *fmt, ...) 00081 __attribute__ ((format (printf, 1, 2))); 00082 00083 00084 /*! \brief Tells Asterisk the State for Device is changed 00085 * \param device devicename like a dialstring 00086 * Asterisk polls the new extensionstates and calls the registered 00087 * callbacks for the changed extensions 00088 * Returns 0 on success, -1 on failure 00089 */ 00090 int ast_device_state_changed_literal(const char *device); 00091 00092 /*! \brief Registers a device state change callback 00093 * \param callback Callback 00094 * \param data to pass to callback 00095 * The callback is called if the state for extension is changed 00096 * Return -1 on failure, ID on success 00097 */ 00098 int ast_devstate_add(ast_devstate_cb_type callback, void *data); 00099 00100 /*! \brief Unregisters a device state change callback 00101 * \param callback Callback 00102 * \param data to pass to callback 00103 * The callback is called if the state for extension is changed 00104 * Return -1 on failure, ID on success 00105 */ 00106 void ast_devstate_del(ast_devstate_cb_type callback, void *data); 00107 00108 /*! \brief Add device state provider 00109 * \param label to use in hint, like label:object 00110 * \param callback Callback 00111 * \retval -1 failure 00112 * \retval 0 success 00113 */ 00114 int ast_devstate_prov_add(const char *label, ast_devstate_prov_cb_type callback); 00115 00116 /*! \brief Remove device state provider 00117 * \param label to use in hint, like label:object 00118 * \return nothing 00119 */ 00120 void ast_devstate_prov_del(const char *label); 00121 00122 int ast_device_state_engine_init(void); 00123 00124 #if defined(__cplusplus) || defined(c_plusplus) 00125 } 00126 #endif 00127 00128 #endif /* _ASTERISK_DEVICESTATE_H */