[asterisk-commits] dlee: branch dlee/endpoints r386560 - in /team/dlee/endpoints: channels/ chan...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Apr 25 14:24:27 CDT 2013


Author: dlee
Date: Thu Apr 25 14:24:22 2013
New Revision: 386560

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386560
Log:
Feeling good

Modified:
    team/dlee/endpoints/channels/chan_sip.c
    team/dlee/endpoints/channels/sip/include/sip.h
    team/dlee/endpoints/include/asterisk/channel.h
    team/dlee/endpoints/include/asterisk/endpoints.h
    team/dlee/endpoints/include/asterisk/stasis_endpoints.h
    team/dlee/endpoints/main/channel_internal_api.c
    team/dlee/endpoints/main/endpoints.c

Modified: team/dlee/endpoints/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/channels/chan_sip.c?view=diff&rev=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/channels/chan_sip.c (original)
+++ team/dlee/endpoints/channels/chan_sip.c Thu Apr 25 14:24:22 2013
@@ -5327,10 +5327,8 @@
 
 	ast_rtp_dtls_cfg_free(&peer->dtls_cfg);
 
-	stasis_unsubscribe(peer->forward);
-	peer->forward = NULL;
-	ao2_cleanup(peer->topic);
-	peer->topic = NULL;
+	ast_endpoint_shutdown(peer->endpoint);
+	peer->endpoint = NULL;
 }
 
 /*! \brief Update peer data in database (if used) */
@@ -8018,7 +8016,13 @@
 	}
 
 	if (i->relatedpeer) {
-		ast_channel_forward_endpoint(tmp, i->relatedpeer->topic);
+		int r;
+		r = ast_channel_forward_endpoint(tmp, i->relatedpeer->endpoint);
+		if (r != 0) {
+			ast_channel_unref(tmp);
+			sip_pvt_lock(i);
+			return NULL;
+		}
 	}
 
 	/* If we sent in a callid, bind it to the channel. */
@@ -30727,10 +30731,7 @@
 		if (!(peer = ao2_t_alloc(sizeof(*peer), sip_destroy_peer_fn, "allocate a peer struct"))) {
 			return NULL;
 		}
-		if (!(peer->topic = stasis_topic_create(name))) {
-			return NULL;
-		}
-		if (!(peer->forward = stasis_forward_all(peer->topic, ast_endpoint_topic_all()))) {
+		if (!(peer->endpoint = ast_endpoint_create("SIP", name))) {
 			return NULL;
 		}
 		if (!(peer->caps = ast_format_cap_alloc_nolock())) {

Modified: team/dlee/endpoints/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/channels/sip/include/sip.h?view=diff&rev=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/channels/sip/include/sip.h (original)
+++ team/dlee/endpoints/channels/sip/include/sip.h Thu Apr 25 14:24:22 2013
@@ -1378,8 +1378,7 @@
 	unsigned int disallowed_methods;
 	struct ast_cc_config_params *cc_params;
 
-	struct stasis_topic *topic;
-	struct stasis_subscription *forward;
+	struct ast_endpoint *endpoint;
 
 	struct ast_rtp_dtls_cfg dtls_cfg;
 };

Modified: team/dlee/endpoints/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/channel.h?view=diff&rev=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/include/asterisk/channel.h (original)
+++ team/dlee/endpoints/include/asterisk/channel.h Thu Apr 25 14:24:22 2013
@@ -4138,18 +4138,4 @@
  */
 struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
 
-/*!
- * \since 12
- * \brief Forward a channels messages to its endpoint's topic.
- *
- * This forward is unsubscribed when the channel is disposed of.
- *
- * \param chan Channel.
- * \param endpoint_topic Topic of the corresponding endpoint.
- * \retval 0 on success.
- * \retval Non-zero on error.
- */
-int ast_channel_forward_endpoint(struct ast_channel *chan,
-	struct stasis_topic *endpoint_topic);
-
 #endif /* _ASTERISK_CHANNEL_H */

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=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/include/asterisk/endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/endpoints.h Thu Apr 25 14:24:22 2013
@@ -54,14 +54,25 @@
  * \brief Create an endpoint struct.
  *
  * The endpoint is created with a state of OFFLINE and max_channels of -1
- * (unlimited).
+ * (unlimited). While \ref ast_endpoint is AO2 managed, you have to
+ * shut it down with ast_endpoint_shutdown() to clean up references from
+ * subscriptions.
  *
  * \param tech Technology for this endpoint.
  * \param resource Name of this endpoint.
  * \return Newly created endpoint.
  * \return \c NULL on error.
+ * \since 12
  */
 struct ast_endpoint *ast_endpoint_create(const char *tech, const char *resource);
+
+/*!
+ * \brief Shutsdown an \ref ast_endpoint.
+ *
+ * \param endpoint Endpoint to shut down.
+ * \since 12
+ */
+void ast_endpoint_shutdown(struct ast_endpoint *endpoint);
 
 /*!
  * \brief Gets the technology of the given endpoint.
@@ -110,4 +121,19 @@
 void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
 	int max_channels);
 
+
+/*!
+ * \since 12
+ * \brief Forward a channels messages to its endpoint's topic.
+ *
+ * This forward is unsubscribed when the channel is disposed of.
+ *
+ * \param chan Channel.
+ * \param endpoint_topic Topic of the corresponding endpoint.
+ * \retval 0 on success.
+ * \retval Non-zero on error.
+ */
+int ast_channel_forward_endpoint(struct ast_channel *chan,
+	struct ast_endpoint *endpoint);
+
 #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=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis_endpoints.h Thu Apr 25 14:24:22 2013
@@ -61,6 +61,8 @@
 	int max_channels;
 	/*! Number of channels currently active on this endpoint */
 	int current_channels;
+	/*! Channel ids */
+	char *channel_ids[];
 };
 
 /*!

Modified: team/dlee/endpoints/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/channel_internal_api.c?view=diff&rev=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/main/channel_internal_api.c (original)
+++ team/dlee/endpoints/main/channel_internal_api.c Thu Apr 25 14:24:22 2013
@@ -39,11 +39,13 @@
 #include <fcntl.h>
 
 #include "asterisk/channel.h"
-#include "asterisk/stringfields.h"
+#include "asterisk/channel_internal.h"
 #include "asterisk/data.h"
+#include "asterisk/endpoints.h"
 #include "asterisk/indications.h"
 #include "asterisk/stasis_channels.h"
-#include "asterisk/channel_internal.h"
+#include "asterisk/stasis_endpoints.h"
+#include "asterisk/stringfields.h"
 #include "asterisk/test.h"
 
 /*!
@@ -1392,13 +1394,13 @@
 }
 
 int ast_channel_forward_endpoint(struct ast_channel *chan,
-	struct stasis_topic *endpoint_topic)
+	struct ast_endpoint *endpoint)
 {
 	ast_assert(chan != NULL);
-	ast_assert(endpoint_topic != NULL);
+	ast_assert(endpoint != NULL);
 
 	chan->endpoint_forward =
-		stasis_forward_all(chan->topic, endpoint_topic);
+		stasis_forward_all(chan->topic, ast_endpoint_topic(endpoint));
 
 	if (chan->endpoint_forward == NULL) {
 		return -1;

Modified: team/dlee/endpoints/main/endpoints.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/main/endpoints.c?view=diff&rev=386560&r1=386559&r2=386560
==============================================================================
--- team/dlee/endpoints/main/endpoints.c (original)
+++ team/dlee/endpoints/main/endpoints.c Thu Apr 25 14:24:22 2013
@@ -85,15 +85,10 @@
 
 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);
+	/* The router should be shut down already */
+	ast_assert(endpoint->router == NULL);
 
 	stasis_unsubscribe(endpoint->forward);
 	endpoint->forward = NULL;
@@ -111,6 +106,8 @@
 	struct ast_endpoint *endpoint = data;
 	struct ast_channel_snapshot *snapshot = stasis_message_data(message);
 
+	ast_assert(endpoint != NULL);
+
 	ao2_lock(endpoint);
 	if (!ao2_find(endpoint->channel_ids, snapshot->uniqueid, OBJ_NODATA)) {
 		ast_str_container_add(endpoint->channel_ids,
@@ -127,6 +124,8 @@
 	struct ast_endpoint *endpoint = data;
 	struct stasis_cache_clear *clear = stasis_message_data(message);
 
+	ast_assert(endpoint != NULL);
+
 	ao2_lock(endpoint);
 	ao2_find(endpoint->channel_ids, clear->id,
 		OBJ_NODATA | OBJ_UNLINK);
@@ -148,8 +147,12 @@
 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);
 	int r = 0;
+
+	ast_assert(tech != NULL);
+	ast_assert(resource != NULL);
+
+	ast_debug(3, "%s(%s, %s)\n", __func__, tech, resource);
 
 	endpoint = ao2_alloc(sizeof(*endpoint), endpoint_dtor);
 	if (!endpoint) {
@@ -165,15 +168,14 @@
 
 	ast_string_field_set(endpoint, tech, tech);
 	ast_string_field_set(endpoint, resource, resource);
-
-	ast_str_set(&full_name, 0, "endpoint:%s/%s", tech, resource);
+	ast_string_field_build(endpoint, id, "%s/%s", tech, resource);
 
 	endpoint->channel_ids = ast_str_container_alloc(ENDPOINT_BUCKETS);
 	if (!endpoint->channel_ids) {
 		return NULL;
 	}
 
-	endpoint->topic = stasis_topic_create(ast_str_buffer(full_name));
+	endpoint->topic = stasis_topic_create(endpoint->id);
 	if (!endpoint->topic) {
 		return NULL;
 	}
@@ -204,7 +206,23 @@
 
 const char *ast_endpoint_get_tech(const struct ast_endpoint *endpoint)
 {
+	ast_assert(endpoint != NULL);
 	return endpoint->tech;
+}
+
+void ast_endpoint_shutdown(struct ast_endpoint *endpoint)
+{
+	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
+
+	ast_assert(endpoint != NULL);
+
+	message = stasis_cache_clear_create(ast_endpoint_snapshot_type(), endpoint->id);
+	if (message) {
+		stasis_publish(endpoint->topic, message);
+	}
+
+	stasis_message_router_unsubscribe(endpoint->router);
+	endpoint->router = NULL;
 }
 
 const char *ast_endpoint_get_resource(const struct ast_endpoint *endpoint)
@@ -220,6 +238,8 @@
 void ast_endpoint_set_state(struct ast_endpoint *endpoint,
 	enum ast_endpoint_state state)
 {
+	ast_assert(endpoint != NULL);
+	ast_debug(3, "%s(%s, %d)\n", __func__, endpoint->id, state);
 	ao2_lock(endpoint);
 	endpoint->state = state;
 	ao2_unlock(endpoint);
@@ -229,6 +249,8 @@
 void ast_endpoint_set_max_channels(struct ast_endpoint *endpoint,
 	int max_channels)
 {
+	ast_assert(endpoint != NULL);
+	ast_debug(3, "%s(%s, %d)\n", __func__, endpoint->id, max_channels);
 	ao2_lock(endpoint);
 	endpoint->max_channels = max_channels;
 	ao2_unlock(endpoint);
@@ -239,6 +261,7 @@
 {
 	struct ast_endpoint_snapshot *snapshot = obj;
 
+	ast_assert(snapshot != NULL);
 	ast_string_field_free_memory(snapshot);
 }
 
@@ -246,8 +269,14 @@
 	struct ast_endpoint *endpoint)
 {
 	RAII_VAR(struct ast_endpoint_snapshot *, snapshot, NULL, ao2_cleanup);
-
-	snapshot = ao2_alloc(sizeof(*snapshot), endpoint_snapshot_dtor);
+	int channel_count;
+	SCOPED_AO2LOCK(lock, endpoint);
+
+	channel_count = ao2_container_count(endpoint->channel_ids);
+
+	snapshot = ao2_alloc(
+		sizeof(*snapshot) * channel_count * sizeof(char *),
+		endpoint_snapshot_dtor);
 
 	if (ast_string_field_init(snapshot, 80) != 0) {
 		return NULL;
@@ -258,10 +287,8 @@
 	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;
 }




More information about the asterisk-commits mailing list