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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 23 17:02:59 CDT 2013


Author: dlee
Date: Tue Apr 23 17:02:56 2013
New Revision: 386396

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386396
Log:
Just some thoughts on how it might work with chan_sip

Removed:
    team/dlee/endpoints/main/endpoints.c
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/stasis_endpoints.h
    team/dlee/endpoints/main/channel_internal_api.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=386396&r1=386395&r2=386396
==============================================================================
--- team/dlee/endpoints/channels/chan_sip.c (original)
+++ team/dlee/endpoints/channels/chan_sip.c Tue Apr 23 17:02:56 2013
@@ -295,6 +295,7 @@
 #include "sip/include/security_events.h"
 #include "asterisk/sip_api.h"
 #include "asterisk/app.h"
+#include "asterisk/stasis_endpoints.h"
 
 /*** DOCUMENTATION
 	<application name="SIPDtmfMode" language="en_US">
@@ -5258,6 +5259,8 @@
 {
 	ast_debug(3, "Destroying SIP peer %s\n", peer->name);
 
+	printf("%s(%s)\n", __func__, peer->name);
+
 	/*
 	 * Remove any mailbox event subscriptions for this peer before
 	 * we destroy anything.  An event subscription callback may be
@@ -5323,6 +5326,11 @@
 	peer->caps = ast_format_cap_destroy(peer->caps);
 
 	ast_rtp_dtls_cfg_free(&peer->dtls_cfg);
+
+	stasis_unsubscribe(peer->forward);
+	peer->forward = NULL;
+	ao2_cleanup(peer->topic);
+	peer->topic = NULL;
 }
 
 /*! \brief Update peer data in database (if used) */
@@ -8009,6 +8017,10 @@
 		return NULL;
 	}
 
+	if (i->relatedpeer) {
+		ast_channel_forward_endpoint(tmp, i->relatedpeer->topic);
+	}
+
 	/* If we sent in a callid, bind it to the channel. */
 	if (callid) {
 		ast_channel_callid_set(tmp, callid);
@@ -30710,7 +30722,15 @@
 		if (!(peer->the_mark))
 			firstpass = 0;
 	} else {
+		printf("%s(%s)\n", __func__, name);
+
 		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()))) {
 			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=386396&r1=386395&r2=386396
==============================================================================
--- team/dlee/endpoints/channels/sip/include/sip.h (original)
+++ team/dlee/endpoints/channels/sip/include/sip.h Tue Apr 23 17:02:56 2013
@@ -1378,6 +1378,9 @@
 	unsigned int disallowed_methods;
 	struct ast_cc_config_params *cc_params;
 
+	struct stasis_topic *topic;
+	struct stasis_subscription *forward;
+
 	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=386396&r1=386395&r2=386396
==============================================================================
--- team/dlee/endpoints/include/asterisk/channel.h (original)
+++ team/dlee/endpoints/include/asterisk/channel.h Tue Apr 23 17:02:56 2013
@@ -4138,4 +4138,18 @@
  */
 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/stasis_endpoints.h
URL: http://svnview.digium.com/svn/asterisk/team/dlee/endpoints/include/asterisk/stasis_endpoints.h?view=diff&rev=386396&r1=386395&r2=386396
==============================================================================
--- team/dlee/endpoints/include/asterisk/stasis_endpoints.h (original)
+++ team/dlee/endpoints/include/asterisk/stasis_endpoints.h Tue Apr 23 17:02:56 2013
@@ -41,23 +41,26 @@
  * \since 12
  */
 enum ast_endpoint_state {
-	/*! The endpoint cannot offer/accept channels due to configuration. */
-	AST_ENDPOINT_DISABLED,
+	/*! The endpoint is not available. */
+	AST_ENDPOINT_OFFLINE,
 	/*! The endpoint is available. */
-	AST_ENDPOINT_ACTIVE,
-	/*! The endpoint cannot offer or accept channels due to an error
-	 *  condition. */
-	AST_ENDPOINT_ERROR,
+	AST_ENDPOINT_ONLINE,
 };
 
 /*!
  * \brief A snapshot of an endpoint's state.
  *
+ * The id for an endpoint is tech/resource. The duplication is needed because
+ * there are several cases where any of the three values would be needed, and
+ * constantly splitting or reassembling would be a pain.
+ *
  * \since 12
  */
 struct ast_endpoint_snapshot {
 	AST_DECLARE_STRING_FIELDS(
-		AST_STRING_FIELD(id);	/*!< id for this endpoint. */
+		AST_STRING_FIELD(id);	/*!< unique id for this endpoint. */
+		AST_STRING_FIELD(tech);	/*!< Channel technology */
+		AST_STRING_FIELD(resource);	/*!< Tech-unique name */
 		);
 
 	/*! Endpoint state */
@@ -89,14 +92,6 @@
  * \since 12
  */
 struct stasis_message_type *ast_endpoint_snapshot_type(void);
-
-/*!
- * \brief Topic for a specific endpoint.
- * \param endpoint The endpoint.
- * \return Topic for this endpoint.
- * \return ast_endpoint_topic_all() if \a endpoint is \c NULL.
- */
-struct stasis_topic *ast_endpoint_topic(struct ast_endpoint *endpoint);
 
 /*!
  * \brief Topic for all endpoint releated messages.

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=386396&r1=386395&r2=386396
==============================================================================
--- team/dlee/endpoints/main/channel_internal_api.c (original)
+++ team/dlee/endpoints/main/channel_internal_api.c Tue Apr 23 17:02:56 2013
@@ -198,6 +198,7 @@
 	struct timeval sending_dtmf_tv;		/*!< The time this channel started sending the current digit. (Invalid if sending_dtmf_digit is zero.) */
 	struct stasis_topic *topic;			/*!< Topic for all channel's events */
 	struct stasis_subscription *forwarder;		/*!< Subscription for event forwarding to all topic */
+	struct stasis_subscription *endpoint_forward;	/*!< Subscription for event forwarding to endpoint's topic */
 };
 
 /* AST_DATA definitions, which will probably have to be re-thought since the channel will be opaque */
@@ -1369,6 +1370,7 @@
 	ast_string_field_free_memory(chan);
 
 	chan->forwarder = stasis_unsubscribe(chan->forwarder);
+	chan->endpoint_forward = stasis_unsubscribe(chan->endpoint_forward);
 
 	ao2_cleanup(chan->topic);
 	chan->topic = NULL;
@@ -1387,6 +1389,22 @@
 struct stasis_topic *ast_channel_topic(struct ast_channel *chan)
 {
 	return chan ? chan->topic : ast_channel_topic_all();
+}
+
+int ast_channel_forward_endpoint(struct ast_channel *chan,
+	struct stasis_topic *endpoint_topic)
+{
+	ast_assert(chan != NULL);
+	ast_assert(endpoint_topic != NULL);
+
+	chan->endpoint_forward =
+		stasis_forward_all(chan->topic, endpoint_topic);
+
+	if (chan->endpoint_forward == NULL) {
+		return -1;
+	}
+
+	return 0;
 }
 
 void ast_channel_internal_setup_topics(struct ast_channel *chan)




More information about the asterisk-commits mailing list