presencestate.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2011, Digium, Inc.
  5. *
  6. * David Vossel <dvossel@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. /*! \file
  19. * \brief Presence state management
  20. */
  21. #ifndef _ASTERISK_PRESSTATE_H
  22. #define _ASTERISK_PRESSTATE_H
  23. enum ast_presence_state {
  24. AST_PRESENCE_NOT_SET = 0,
  25. AST_PRESENCE_UNAVAILABLE,
  26. AST_PRESENCE_AVAILABLE,
  27. AST_PRESENCE_AWAY,
  28. AST_PRESENCE_XA,
  29. AST_PRESENCE_CHAT,
  30. AST_PRESENCE_DND,
  31. /* This is not something that a user can
  32. * set his presence to. Rather, this is returned
  33. * to indicate that presence is in some invalid
  34. * state
  35. */
  36. AST_PRESENCE_INVALID,
  37. };
  38. /*! \brief Presence state provider call back */
  39. typedef enum ast_presence_state (*ast_presence_state_prov_cb_type)(const char *data, char **subtype, char **message);
  40. /*!
  41. * \brief Convert presence state to text string for output
  42. *
  43. * \param state Current presence state
  44. */
  45. const char *ast_presence_state2str(enum ast_presence_state state);
  46. /*!
  47. * \brief Convert presence state from text to integer value
  48. *
  49. * \param val The text representing the presence state. Valid values are anything
  50. * that comes after AST_PRESENCE_ in one of the defined values.
  51. *
  52. * \return The AST_PRESENCE_ integer value
  53. */
  54. enum ast_presence_state ast_presence_state_val(const char *val);
  55. /*!
  56. * \brief Asks a presence state provider for the current presence state.
  57. *
  58. * \param presence_provider The presence provider to retrieve the state from.
  59. * \param subtype The output paramenter to store the subtype string in. Must be freed if returned
  60. * \param message The output paramenter to store the message string in. Must be freed if returned
  61. *
  62. * \retval presence state value on success,
  63. * \retval -1 on failure.
  64. */
  65. enum ast_presence_state ast_presence_state(const char *presence_provider, char **subtype, char **message);
  66. /*!
  67. * \brief Asks a presence state provider for the current presence state, bypassing the event cache
  68. *
  69. * \details Some presence state providers may perform transformations on presence data when it is
  70. * requested (such as a base64 decode). In such instances, use of the event cache is not suitable
  71. * and should be bypassed.
  72. *
  73. * \param presence_provider The presence provider to retrieve the state from.
  74. * \param subtype The output paramenter to store the subtype string in. Must be freed if returned
  75. * \param message The output paramenter to store the message string in. Must be freed if returned
  76. *
  77. * \retval presence state value on success,
  78. * \retval -1 on failure.
  79. */
  80. enum ast_presence_state ast_presence_state_nocache(const char *presence_provider, char **subtype, char **message);
  81. /*!
  82. * \brief Notify the world that a presence provider state changed.
  83. *
  84. * \param state the new presence state
  85. * \param subtype the new presence subtype
  86. * \param message the new presence message
  87. * \param fmt Presence entity whose state has changed
  88. *
  89. * The new state of the entity will be sent off to any subscribers
  90. * of the presence state. It will also be stored in the internal event
  91. * cache.
  92. *
  93. * \retval 0 Success
  94. * \retval -1 Failure
  95. */
  96. int ast_presence_state_changed(enum ast_presence_state state,
  97. const char *subtype,
  98. const char *message,
  99. const char *fmt, ...)
  100. __attribute__((format(printf, 4, 5)));
  101. /*!
  102. * \brief Notify the world that a presence provider state changed.
  103. *
  104. * \param state the new presence state
  105. * \param subtype the new presence subtype
  106. * \param message the new presence message
  107. * \param presence_provider Presence entity whose state has changed
  108. *
  109. * The new state of the entity will be sent off to any subscribers
  110. * of the presence state. It will also be stored in the internal event
  111. * cache.
  112. *
  113. * \retval 0 Success
  114. * \retval -1 Failure
  115. */
  116. int ast_presence_state_changed_literal(enum ast_presence_state state,
  117. const char *subtype,
  118. const char *message,
  119. const char *presence_provider);
  120. /*!
  121. * \brief Add presence state provider
  122. *
  123. * \param label to use in hint, like label:object
  124. * \param callback Callback
  125. *
  126. * \retval 0 success
  127. * \retval -1 failure
  128. */
  129. int ast_presence_state_prov_add(const char *label, ast_presence_state_prov_cb_type callback);
  130. /*!
  131. * \brief Remove presence state provider
  132. *
  133. * \param label to use in hint, like label:object
  134. *
  135. * \retval -1 on failure
  136. * \retval 0 on success
  137. */
  138. int ast_presence_state_prov_del(const char *label);
  139. /*!
  140. * \brief Get presence state message type
  141. * \retval Stasis message type for presence state messages
  142. * \since 12
  143. */
  144. struct stasis_message_type *ast_presence_state_message_type(void);
  145. /*!
  146. * \brief Get presence state topic
  147. * \retval Stasis topic for presence state messages
  148. * \since 12
  149. */
  150. struct stasis_topic *ast_presence_state_topic_all(void);
  151. /*!
  152. * \brief Get caching presence state topic
  153. * \retval Caching Stasis topic for presence state messages
  154. * \since 12
  155. */
  156. struct stasis_topic *ast_presence_state_topic_cached(void);
  157. /*!
  158. * \brief Backend cache for ast_presence_state_topic_cached()
  159. * \retval Cache of \ref ast_presence_state_message.
  160. * \since 12
  161. */
  162. struct stasis_cache *ast_presence_state_cache(void);
  163. /*!
  164. * \brief Stasis message payload representing a presence state update
  165. * \since 12
  166. */
  167. struct ast_presence_state_message {
  168. AST_DECLARE_STRING_FIELDS(
  169. AST_STRING_FIELD(provider); /*!< Provider that produced this presence state message */
  170. AST_STRING_FIELD(subtype); /*!< Subtype associated with this presence state message */
  171. AST_STRING_FIELD(message); /*!< The message to convey */
  172. );
  173. enum ast_presence_state state; /*!< The state associated with this presence state message */
  174. };
  175. int ast_presence_state_engine_init(void);
  176. #endif