Sat Apr 26 2014 22:01:39

Asterisk developer's documentation


presencestate.h
Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (C) 2011, Digium, Inc.
00005  *
00006  * David Vossel <dvossel@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 Presence state management
00021  */
00022 
00023 #ifndef _ASTERISK_PRESSTATE_H
00024 #define _ASTERISK_PRESSTATE_H
00025 
00026 enum ast_presence_state {
00027    AST_PRESENCE_NOT_SET = 0,
00028    AST_PRESENCE_UNAVAILABLE,
00029    AST_PRESENCE_AVAILABLE,
00030    AST_PRESENCE_AWAY,
00031    AST_PRESENCE_XA,
00032    AST_PRESENCE_CHAT,
00033    AST_PRESENCE_DND,
00034    /* This is not something that a user can
00035     * set his presence to. Rather, this is returned
00036     * to indicate that presence is in some invalid
00037     * state
00038     */
00039    AST_PRESENCE_INVALID,
00040 };
00041 
00042 /*! \brief Presence state provider call back */
00043 typedef enum ast_presence_state (*ast_presence_state_prov_cb_type)(const char *data, char **subtype, char **message);
00044 
00045 /*!
00046  * \brief Convert presence state to text string for output
00047  *
00048  * \param state Current presence state
00049  */
00050 const char *ast_presence_state2str(enum ast_presence_state state);
00051 
00052 /*!
00053  * \brief Convert presence state from text to integer value
00054  *
00055  * \param val The text representing the presence state.  Valid values are anything
00056  *        that comes after AST_PRESENCE_ in one of the defined values.
00057  *
00058  * \return The AST_PRESENCE_ integer value
00059  */
00060 enum ast_presence_state ast_presence_state_val(const char *val);
00061 
00062 /*!
00063  * \brief Asks a presence state provider for the current presence state.
00064  *
00065  * \param presence_provider, The presence provider to retrieve the state from.
00066  * \param subtype, The output paramenter to store the subtype string in. Must be freed if returned
00067  * \param message, The output paramenter to store the message string in. Must be freed if returned
00068  *
00069  * \retval presence state value on success,
00070  * \retval -1 on failure.
00071  */
00072 enum ast_presence_state ast_presence_state(const char *presence_provider, char **subtype, char **message);
00073 
00074 /*!
00075  * \brief Asks a presence state provider for the current presence state, bypassing the event cache
00076  *
00077  * \details Some presence state providers may perform transformations on presence data when it is
00078  * requested (such as a base64 decode). In such instances, use of the event cache is not suitable
00079  * and should be bypassed.
00080  *
00081  * \param presence_provider, The presence provider to retrieve the state from.
00082  * \param subtype, The output paramenter to store the subtype string in. Must be freed if returned
00083  * \param message, The output paramenter to store the message string in. Must be freed if returned
00084  *
00085  * \retval presence state value on success,
00086  * \retval -1 on failure.
00087  */
00088 enum ast_presence_state ast_presence_state_nocache(const char *presence_provider, char **subtype, char **message);
00089 
00090 /*!
00091  * \brief Notify the world that a presence provider state changed.
00092  *
00093  * \param state the new presence state
00094  * \param subtype the new presence subtype
00095  * \param message the new presence message
00096  * \param fmt Presence entity whose state has changed
00097  *
00098  * The new state of the entity will be sent off to any subscribers
00099  * of the presence state. It will also be stored in the internal event
00100  * cache.
00101  *
00102  * \retval 0 Success
00103  * \retval -1 Failure
00104  */
00105 int ast_presence_state_changed(enum ast_presence_state state,
00106       const char *subtype,
00107       const char *message,
00108       const char *fmt, ...)
00109    __attribute__((format(printf, 4, 5)));
00110 
00111 /*!
00112  * \brief Notify the world that a presence provider state changed.
00113  *
00114  * \param state the new presence state
00115  * \param subtype the new presence subtype
00116  * \param message the new presence message
00117  * \param presence_provider Presence entity whose state has changed
00118  *
00119  * The new state of the entity will be sent off to any subscribers
00120  * of the presence state. It will also be stored in the internal event
00121  * cache.
00122  *
00123  * \retval 0 Success
00124  * \retval -1 Failure
00125  */
00126 int ast_presence_state_changed_literal(enum ast_presence_state state,
00127       const char *subtype,
00128       const char *message,
00129       const char *presence_provider);
00130 
00131 /*!
00132  * \brief Add presence state provider
00133  *
00134  * \param label to use in hint, like label:object
00135  * \param callback Callback
00136  *
00137  * \retval 0 success
00138  * \retval -1 failure
00139  */
00140 int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback);
00141 
00142 /*!
00143  * \brief Remove presence state provider
00144  *
00145  * \param label to use in hint, like label:object
00146  *
00147  * \retval -1 on failure
00148  * \retval 0 on success
00149  */
00150 int ast_presence_state_prov_del(const char *label);
00151 
00152 int ast_presence_state_engine_init(void);
00153 #endif
00154