[asterisk-commits] dlee: branch dlee/endpoints r386445 - in /team/dlee/endpoints: include/asteri...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Apr 24 14:45:04 CDT 2013
Author: dlee
Date: Wed Apr 24 14:45:00 2013
New Revision: 386445
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386445
Log:
Looking good
Added:
team/dlee/endpoints/main/endpoints.c
- copied, changed from r386395, team/dlee/endpoints/main/endpoints.c
Modified:
team/dlee/endpoints/include/asterisk/endpoints.h
team/dlee/endpoints/include/asterisk/stasis_endpoints.h
team/dlee/endpoints/main/stasis_endpoints.c
Modified: team/dlee/endpoints/include/asterisk/endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/endpoints.h?view=diff&rev=386445&r1=386444&r2=386445
==============================================================================
--- team/dlee/endpoints/include/asterisk/endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/endpoints.h Wed Apr 24 14:45:00 2013
@@ -30,6 +30,17 @@
#include "asterisk/json.h"
/*!
+ * \brief Valid states for an endpoint.
+ * \since 12
+ */
+enum ast_endpoint_state {
+ /*! The endpoint is not available. */
+ AST_ENDPOINT_OFFLINE,
+ /*! The endpoint is available. */
+ AST_ENDPOINT_ONLINE,
+};
+
+/*!
* \brief Opaque struct representing an endpoint.
*
* And an endpoint is an external device/system that may offer/accept channels
@@ -42,31 +53,61 @@
/*!
* \brief Create an endpoint struct.
*
+ * The endpoint is created with a state of OFFLINE and max_channels of -1
+ * (unlimited).
+ *
* \param tech Technology for this endpoint.
- * \param name Name of this endpoint.
+ * \param resource Name of this endpoint.
* \return Newly created endpoint.
* \return \c NULL on error.
*/
-struct ast_endpoint *ast_endpoint_create(const char *tech, const char *name);
+struct ast_endpoint *ast_endpoint_create(const char *tech, const char *resource);
/*!
* \brief Gets the technology of the given endpoint.
+ *
+ * This is an immutable string describing the channel provider technology
+ * (SIP, IAX2, etc.).
*
* \param endpoint The endpoint.
* \return Tec of the endpoint.
* \return \c NULL if endpoint is \c NULL.
* \since 12
*/
-const char *ast_endpoint_get_tech(struct ast_endpoint *endpoint);
+const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint);
/*!
- * \brief Gets the name of the given endpoint.
+ * \brief Gets the resource name of the given endpoint.
+ *
+ * This is unique for the endpoint's technology, and immutable.
*
* \param endpoint The endpoint.
- * \return Name of the endpoint.
+ * \return Resource name of the endpoint.
* \return \c NULL if endpoint is \c NULL.
* \since 12
*/
-const char *ast_endpoint_get_name(struct ast_endpoint *endpoint);
+const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint);
+
+/*!
+ * \brief Updates the state of the given endpoint.
+ *
+ * \param endpoint Endpoint to modify.
+ * \param state New state.
+ * \since 12
+ */
+void ast_endpoint_set_state(struct ast_endpoint *endpoint,
+ enum ast_endpoint_state state);
+
+/*!
+ * \brief Updates the maximum number of channels an endpoint supports.
+ *
+ * Set to -1 for unlimited channels.
+ *
+ * \param endpoint Endpoint to modify.
+ * \param max_channels Maximum number of concurrent channels this endpoint
+ * supports.
+ */
+void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
+ int max_channels);
#endif /* _ASTERISK_ENDPOINTS_H */
Modified: team/dlee/endpoints/include/asterisk/stasis_endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis_endpoints.h?view=diff&rev=386445&r1=386444&r2=386445
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis_endpoints.h Wed Apr 24 14:45:00 2013
@@ -35,17 +35,6 @@
/*! \addtogroup StasisTopicsAndMessages
* @{
*/
-
-/*!
- * \brief Valid states for an endpoint.
- * \since 12
- */
-enum ast_endpoint_state {
- /*! The endpoint is not available. */
- AST_ENDPOINT_OFFLINE,
- /*! The endpoint is available. */
- AST_ENDPOINT_ONLINE,
-};
/*!
* \brief A snapshot of an endpoint's state.
@@ -94,6 +83,26 @@
struct stasis_message_type *ast_endpoint_snapshot_type(void);
/*!
+ * \brief Create a snapshot of an endpoint
+ * \param endpoint Endpoint to snap a shot of.
+ * \return Snapshot of the endpoint.
+ * \return \c NULL on error.
+ * \since 12
+ */
+struct ast_endpoint_snapshot *ast_endpoint_snapshot_create(
+ struct ast_endpoint *endpoint);
+
+/*!
+ * \brief Returns the topic for a specific endpoint.
+ *
+ * \param endpoint The endpoint.
+ * \return The topic for the given endpoint.
+ * \return ast_endpoint_topic_all() if endpoint is \c NULL.
+ * \since 12
+ */
+struct stasis_topic *ast_endpoint_topic(struct ast_endpoint *endpoint);
+
+/*!
* \brief Topic for all endpoint releated messages.
* \since 12
*/
Copied: team/dlee/endpoints/main/endpoints.c (from r386395, team/dlee/endpoints/main/endpoints.c)
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/endpoints.c?view=diff&rev=386445&p1=team/dlee/endpoints/main/endpoints.c&r1=386395&p2=team/dlee/endpoints/main/endpoints.c&r2=386445
==============================================================================
--- team/dlee/endpoints/main/endpoints.c (original)
+++ team/dlee/endpoints/main/endpoints.c Wed Apr 24 14:45:00 2013
@@ -35,20 +35,59 @@
#include "asterisk/endpoints.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stasis_message_router.h"
#include "asterisk/stringfields.h"
struct ast_endpoint {
AST_DECLARE_STRING_FIELDS(
- AST_STRING_FIELD(tech); /*!< Technology for the endpoint. */
- AST_STRING_FIELD(name); /*!< Name of the endpoint. */
+ AST_STRING_FIELD(tech); /*!< Technology (SIP, IAX2, etc.). */
+ AST_STRING_FIELD(resource); /*!< Name, unique to the tech. */
+ AST_STRING_FIELD(id); /*!< tech/resource id */
);
+ /*! Endpoint's current state */
+ enum ast_endpoint_state state;
+ /*! Max channels for this endpoint. -1 means unlimited or unknown. */
+ int max_channels;
+ /*! Topic for this endpoint's messages */
struct stasis_topic *topic;
+ /*!
+ * Forwarding subscription sending messages to ast_endpoint_topic_all()
+ */
struct stasis_subscription *forward;
+ /*! Router for handling this endpoint's messages */
+ struct stasis_message_router *router;
};
+static void endpoint_publish_snapshot(struct ast_endpoint *endpoint)
+{
+ RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+ ast_assert(endpoint != NULL);
+ ast_assert(endpoint->topic != NULL);
+
+ snapshot = ast_endpoint_snapshot_create(endpoint);
+ if (!snapshot) {
+ return;
+ }
+ message = stasis_message_create(ast_endpoint_snapshot_type(), snapshot);
+ if (!message) {
+ return;
+ }
+ stasis_publish(endpoint->topic, message);
+}
+
static void endpoint_dtor(void *obj)
{
+ RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
struct ast_endpoint *endpoint = obj;
+
+ message = stasis_cache_clear_create(ast_endpoint_snapshot_type(), endpoint->id);
+ if (message) {
+ stasis_publish(endpoint->topic, message);
+ }
+
+ stasis_message_router_unsubscribe(endpoint->router);
stasis_unsubscribe(endpoint->forward);
endpoint->forward = NULL;
@@ -59,7 +98,33 @@
ast_string_field_free_memory(endpoint);
}
-struct ast_endpoint *ast_endpoint_create(const char *tech, const char *name)
+static void endpoint_channel_snapshot(void *data,
+ struct stasis_subscription *sub, struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ struct stasis_endpoint *endpoint = data;
+ struct ast_channel_snapshot *snapshot =
+}
+
+static void endpoint_cache_clear(void *data,
+ struct stasis_subscription *sub, struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ struct stasis_endpoint *endpoint = data;
+}
+
+static void endpoint_default(void *data,
+ struct stasis_subscription *sub, struct stasis_topic *topic,
+ struct stasis_message *message)
+{
+ struct stasis_endpoint *endpoint = data;
+
+ if (stasis_subscription_final_message(sub, message)) {
+ ao2_cleanup(endpoint);
+ }
+}
+
+struct ast_endpoint *ast_endpoint_create(const char *tech, const char *resource)
{
RAII_VAR(struct ast_endpoint *, endpoint, NULL, ao2_cleanup);
RAII_VAR(struct ast_str *, full_name, NULL, ast_free);
@@ -69,14 +134,17 @@
return NULL;
}
+ endpoint->max_channels = -1;
+ endpoint->state = AST_ENDPOINT_OFFLINE;
+
if (ast_string_field_init(endpoint, 80) != 0) {
return NULL;
}
ast_string_field_set(endpoint, tech, tech);
- ast_string_field_set(endpoint, name, name);
-
- ast_str_set(&full_name, 0, "endpoint:%s/%s", tech, name);
+ ast_string_field_set(endpoint, resource, resource);
+
+ ast_str_set(&full_name, 0, "endpoint:%s/%s", tech, resource);
endpoint->topic = stasis_topic_create(ast_str_buffer(full_name));
if (!endpoint->topic) {
return NULL;
@@ -88,21 +156,76 @@
return NULL;
}
+ endpoint->router = stasis_message_router_create(endpoint->topic);
+ if (!endpoint->router) {
+ return NULL;
+ }
+
+ endpoint_publish_snapshot(endpoint);
+
return endpoint;
}
-const char *ast_endpoint_get_tech(struct ast_endpoint *endpoint)
+const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
{
return endpoint->tech;
}
-const char *ast_endpoint_get_name(struct ast_endpoint *endpoint)
-{
- return endpoint->name;
+const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
+{
+ return endpoint->resource;
}
struct stasis_topic *ast_endpoint_topic(struct ast_endpoint *endpoint)
{
- return endpoint->topic;
-}
-
+ return endpoint ? endpoint->topic : ast_endpoint_topic_all();
+}
+
+void ast_endpoint_set_state(struct ast_endpoint *endpoint,
+ enum ast_endpoint_state state)
+{
+ ao2_lock(endpoint);
+ endpoint->state = state;
+ ao2_unlock(endpoint);
+ endpoint_publish_snapshot(endpoint);
+}
+
+void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
+ int max_channels)
+{
+ ao2_lock(endpoint);
+ endpoint->max_channels = max_channels;
+ ao2_unlock(endpoint);
+ endpoint_publish_snapshot(endpoint);
+}
+
+static void endpoint_snapshot_dtor(void *obj)
+{
+ struct ast_endpoint_snapshot *snapshot = obj;
+
+ ast_string_field_free_memory(snapshot);
+}
+
+struct ast_endpoint_snapshot *ast_endpoint_snapshot_create(
+ struct ast_endpoint *endpoint)
+{
+ RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
+
+ snapshot = ao2_alloc(sizeof(*snapshot), endpoint_snapshot_dtor);
+
+ if (ast_string_field_init(snapshot, 80) != 0) {
+ return NULL;
+ }
+
+ ast_string_field_build(snapshot, id, "%s/%s", endpoint->tech,
+ endpoint->resource);
+ ast_string_field_set(snapshot, tech, endpoint->tech);
+ ast_string_field_set(snapshot, resource, endpoint->resource);
+
+ ao2_lock(endpoint);
+ snapshot->state = endpoint->state;
+ snapshot->max_channels = endpoint->max_channels;
+ ao2_unlock(endpoint);
+
+ return snapshot;
+}
Modified: team/dlee/endpoints/main/stasis_endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/stasis_endpoints.c?view=diff&rev=386445&r1=386444&r2=386445
==============================================================================
--- team/dlee/endpoints/main/stasis_endpoints.c (original)
+++ team/dlee/endpoints/main/stasis_endpoints.c Wed Apr 24 14:45:00 2013
@@ -110,7 +110,7 @@
}
if (!endpoint_topic_all_cached) {
- endpoint_topic_all_cached =
+ endpoint_topic_all_cached =
stasis_caching_topic_create(
endpoint_topic_all, endpoint_snapshot_get_id);
}
More information about the asterisk-commits
mailing list