endpoints.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * Asterisk -- An open source telephony toolkit.
  3. *
  4. * Copyright (C) 2013, Digium, Inc.
  5. *
  6. * David M. Lee, II <dlee@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. #ifndef _ASTERISK_ENDPOINTS_H
  19. #define _ASTERISK_ENDPOINTS_H
  20. /*! \file
  21. *
  22. * \brief Endpoint abstractions.
  23. *
  24. * \author David M. Lee, II <dlee@digium.com>
  25. * \since 12
  26. *
  27. * An endpoint is an external device/system that may offer/accept channels
  28. * to/from Asterisk. While this is a very useful concept for end users, it is
  29. * surprisingly \a not a core concept within Asterisk iteself.
  30. *
  31. * This file defines \ref ast_endpoint as a seperate object, which channel
  32. * drivers may use to expose their concept of an endpoint. As the channel driver
  33. * creates channels, it can use ast_endpoint_add_channel() to associate channels
  34. * to the endpoint. This updates the endpoint appropriately, and forwards all of
  35. * the channel's events to the endpoint's topic.
  36. *
  37. * In order to avoid excessive locking on the endpoint object itself, the
  38. * mutable state is not accessible via getters. Instead, you can create a
  39. * snapshot using ast_endpoint_snapshot_create() to get a consistent snapshot of
  40. * the internal state.
  41. */
  42. #include "asterisk/json.h"
  43. /*!
  44. * \brief Valid states for an endpoint.
  45. * \since 12
  46. */
  47. enum ast_endpoint_state {
  48. /*! The endpoint state is not known. */
  49. AST_ENDPOINT_UNKNOWN,
  50. /*! The endpoint is not available. */
  51. AST_ENDPOINT_OFFLINE,
  52. /*! The endpoint is available. */
  53. AST_ENDPOINT_ONLINE,
  54. };
  55. /*!
  56. * \brief Returns a string representation of the given endpoint state.
  57. *
  58. * \param state Endpoint state.
  59. * \return String representation of \a state.
  60. * \return \c "?" if \a state isn't in \ref ast_endpoint_state.
  61. */
  62. const char *ast_endpoint_state_to_string(enum ast_endpoint_state state);
  63. /*!
  64. * \brief Opaque struct representing an endpoint.
  65. *
  66. * An endpoint is an external device/system that may offer/accept channels
  67. * to/from Asterisk.
  68. *
  69. * \since 12
  70. */
  71. struct ast_endpoint;
  72. /*!
  73. * \brief Finds the endpoint with the given tech[/resource] id.
  74. *
  75. * Endpoints are refcounted, so ao2_cleanup() when you're done.
  76. *
  77. * \note The resource portion of an ID is optional. If not provided,
  78. * an aggregate endpoint for the entire technology is returned.
  79. * These endpoints must not be modified, but can be subscribed
  80. * to in order to receive updates for all endpoints of a given
  81. * technology.
  82. *
  83. * \param id Tech[/resource] id to look for.
  84. * \return Associated endpoint.
  85. * \return \c NULL if not found.
  86. *
  87. * \since 12
  88. */
  89. struct ast_endpoint *ast_endpoint_find_by_id(const char *id);
  90. /*!
  91. * \brief Create an endpoint struct.
  92. *
  93. * The endpoint is created with a state of UNKNOWN and max_channels of -1
  94. * (unlimited). While \ref ast_endpoint is AO2 managed, you have to
  95. * shut it down with ast_endpoint_shutdown() to clean up references from
  96. * subscriptions.
  97. *
  98. * \param tech Technology for this endpoint.
  99. * \param resource Name of this endpoint.
  100. * \return Newly created endpoint.
  101. * \return \c NULL on error.
  102. * \since 12
  103. */
  104. struct ast_endpoint *ast_endpoint_create(const char *tech, const char *resource);
  105. /*!
  106. * \brief Shutsdown an \ref ast_endpoint.
  107. *
  108. * \param endpoint Endpoint to shut down.
  109. * \since 12
  110. */
  111. void ast_endpoint_shutdown(struct ast_endpoint *endpoint);
  112. /*!
  113. * \brief Gets the technology of the given endpoint.
  114. *
  115. * This is an immutable string describing the channel provider technology
  116. * (SIP, IAX2, etc.).
  117. *
  118. * \param endpoint The endpoint.
  119. * \return Tec of the endpoint.
  120. * \return \c NULL if endpoint is \c NULL.
  121. * \since 12
  122. */
  123. const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint);
  124. /*!
  125. * \brief Gets the resource name of the given endpoint.
  126. *
  127. * This is unique for the endpoint's technology, and immutable.
  128. *
  129. * \note If the endpoint being queried is a technology aggregate
  130. * endpoint, this will be an empty string.
  131. *
  132. * \param endpoint The endpoint.
  133. * \return Resource name of the endpoint.
  134. * \return \c NULL if endpoint is \c NULL.
  135. * \since 12
  136. */
  137. const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint);
  138. /*!
  139. * \brief Gets the tech/resource id of the given endpoint.
  140. *
  141. * This is unique across all endpoints, and immutable.
  142. *
  143. * \param endpoint The endpoint.
  144. * \return Tech/resource id of the endpoint.
  145. * \return \c NULL if endpoint is \c NULL.
  146. * \since 12
  147. */
  148. const char *ast_endpoint_get_id(const struct ast_endpoint *endpoint);
  149. /*!
  150. * \brief Gets the state of the given endpoint.
  151. *
  152. * \param endpoint The endpoint.
  153. * \return state.
  154. * \return \c AST_ENDPOINT_UNKNOWN if endpoint is \c NULL.
  155. * \since 13.4
  156. */
  157. enum ast_endpoint_state ast_endpoint_get_state(const struct ast_endpoint *endpoint);
  158. /*!
  159. * \brief Updates the state of the given endpoint.
  160. *
  161. * \param endpoint Endpoint to modify.
  162. * \param state New state.
  163. * \since 12
  164. */
  165. void ast_endpoint_set_state(struct ast_endpoint *endpoint,
  166. enum ast_endpoint_state state);
  167. /*!
  168. * \brief Updates the maximum number of channels an endpoint supports.
  169. *
  170. * Set to -1 for unlimited channels.
  171. *
  172. * \param endpoint Endpoint to modify.
  173. * \param max_channels Maximum number of concurrent channels this endpoint
  174. * supports.
  175. */
  176. void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
  177. int max_channels);
  178. /*!
  179. * \since 12
  180. * \brief Adds a channel to the given endpoint.
  181. *
  182. * This updates the endpoint's statistics, as well as forwarding all of the
  183. * channel's messages to the endpoint's topic.
  184. *
  185. * The channel is automagically removed from the endpoint when it is disposed
  186. * of.
  187. *
  188. * \param endpoint
  189. * \param chan Channel.
  190. * \retval 0 on success.
  191. * \retval Non-zero on error.
  192. */
  193. int ast_endpoint_add_channel(struct ast_endpoint *endpoint,
  194. struct ast_channel *chan);
  195. #endif /* _ASTERISK_ENDPOINTS_H */