[asterisk-commits] mjordan: trunk r396392 - in /trunk: apps/confbridge/ channels/ include/asteri...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Aug 8 09:13:14 CDT 2013


Author: mjordan
Date: Thu Aug  8 09:13:05 2013
New Revision: 396392

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=396392
Log:
Hide the Surrogate channels from external consumers; kill Masquerade events

This patch does three things:
1. It provides a Surrogate channel technology with a consolidated
   "implementation detail flag" on the channel technology. This tells
   consumers of Stasis that the creation of this channel is an implementation
   detail in Asterisk and can be ignored (if they so choose). This
   consolidates the conference recorder/announcer flags as well - these flags
   had no additional meaning beyond "ignore this channel please".

2. It modifies allocation of a channel in two ways:
   (a) If a channel technology can be determined from the name, we set it
       directly in the allocation routine. This prevents the initial
       publication of the message from going out with a NULL channel technology
       where possible. This lets Stasis consumers get the right channel
       technology on the first publication.
   (b) It reorganizes allocation to make use of the 'finalized' property on the
       channel. This was already used to know that a channel had completely
       finished its construction in the masquerade routine; now we also use it
       to know whether or not the setting of certain channel properties is
       occurring during or post construction. The various set routines were
       modified accordingly as well.

3. The masquerade event is now dead, Jim. It no longer served any purpose
   whatsoever - if you perform a call pickup you'll get a Pickup event;
   if you perform an attended transfer you will still get those events; if you
   steal a channel to put it elsewhere you'll get the corresponding NewExten or
   BridgeEnter events.

Review: https://reviewboard.asterisk.org/r/2740

Modified:
    trunk/apps/confbridge/conf_chan_announce.c
    trunk/apps/confbridge/conf_chan_record.c
    trunk/channels/chan_bridge_media.c
    trunk/include/asterisk/channel.h
    trunk/main/cel.c
    trunk/main/channel.c
    trunk/main/channel_internal_api.c
    trunk/main/manager_bridges.c
    trunk/main/manager_channels.c

Modified: trunk/apps/confbridge/conf_chan_announce.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/confbridge/conf_chan_announce.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/apps/confbridge/conf_chan_announce.c (original)
+++ trunk/apps/confbridge/conf_chan_announce.c Thu Aug  8 09:13:05 2013
@@ -134,7 +134,7 @@
 	.send_text = ast_unreal_sendtext,
 	.queryoption = ast_unreal_queryoption,
 	.setoption = ast_unreal_setoption,
-	.properties = AST_CHAN_TP_ANNOUNCER,
+	.properties = AST_CHAN_TP_INTERNAL,
 };
 
 struct ast_channel_tech *conf_announce_get_tech(void)

Modified: trunk/apps/confbridge/conf_chan_record.c
URL: http://svnview.digium.com/svn/asterisk/trunk/apps/confbridge/conf_chan_record.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/apps/confbridge/conf_chan_record.c (original)
+++ trunk/apps/confbridge/conf_chan_record.c Thu Aug  8 09:13:05 2013
@@ -86,7 +86,7 @@
 	.call = rec_call,
 	.read = rec_read,
 	.write = rec_write,
-	.properties = AST_CHAN_TP_RECORDER,
+	.properties = AST_CHAN_TP_INTERNAL,
 };
 
 struct ast_channel_tech *conf_record_get_tech(void)

Modified: trunk/channels/chan_bridge_media.c
URL: http://svnview.digium.com/svn/asterisk/trunk/channels/chan_bridge_media.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/channels/chan_bridge_media.c (original)
+++ trunk/channels/chan_bridge_media.c Thu Aug  8 09:13:05 2013
@@ -89,7 +89,7 @@
 	.send_text = ast_unreal_sendtext,
 	.queryoption = ast_unreal_queryoption,
 	.setoption = ast_unreal_setoption,
-	.properties = AST_CHAN_TP_ANNOUNCER,
+	.properties = AST_CHAN_TP_INTERNAL,
 };
 
 static struct ast_channel_tech record_tech = {
@@ -111,7 +111,7 @@
 	.send_text = ast_unreal_sendtext,
 	.queryoption = ast_unreal_queryoption,
 	.setoption = ast_unreal_setoption,
-	.properties = AST_CHAN_TP_RECORDER,
+	.properties = AST_CHAN_TP_INTERNAL,
 };
 
 static struct ast_channel *media_request_helper(struct ast_format_cap *cap,

Modified: trunk/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/channel.h?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/include/asterisk/channel.h (original)
+++ trunk/include/asterisk/channel.h Thu Aug  8 09:13:05 2013
@@ -864,15 +864,11 @@
 	 */
 	AST_CHAN_TP_CREATESJITTER = (1 << 1),
 	/*!
-	 * \brief Channels have this property if they are an implementation detail
-	 * used for announcing messages; i.e. to a bridge
+	 * \brief Channels with this particular technology are an implementation detail of
+	 * Asterisk and should generally not be exposed or manipulated by the outside
+	 * world
 	 */
-	AST_CHAN_TP_ANNOUNCER = (1 << 2),
-	/*!
-	 * \brief Channels have this property if they are an implementation detail
-	 * used for recording audio; i.e. from a bridge
-	 */
-	AST_CHAN_TP_RECORDER = (1 << 3),
+	AST_CHAN_TP_INTERNAL = (1 << 2),
 };
 
 /*! \brief ast_channel flags */

Modified: trunk/main/cel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cel.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/main/cel.c (original)
+++ trunk/main/cel.c Thu Aug  8 09:13:05 2013
@@ -1103,7 +1103,7 @@
 	if (!snapshot) {
 		return 0;
 	}
-	return snapshot->tech_properties & (AST_CHAN_TP_ANNOUNCER | AST_CHAN_TP_RECORDER);
+	return snapshot->tech_properties & AST_CHAN_TP_INTERNAL;
 }
 
 static void cel_snapshot_update_cb(void *data, struct stasis_subscription *sub,

Modified: trunk/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/main/channel.c (original)
+++ trunk/main/channel.c Thu Aug  8 09:13:05 2013
@@ -830,6 +830,16 @@
 	return NULL;
 }
 
+/*! \brief Channel technology used to extract a channel from a running application. The
+ * channel created with this technology will be immediately hung up - most external
+ * applications won't ever want to see this.
+ */
+static const struct ast_channel_tech surrogate_tech = {
+	.type = "Surrogate",
+	.description = "Surrogate channel used to pull channel from an application",
+	.properties = AST_CHAN_TP_INTERNAL,
+};
+
 static const struct ast_channel_tech null_tech = {
 	.type = "NULL",
 	.description = "Null channel (should not see this)",
@@ -852,6 +862,7 @@
 	struct ast_sched_context *schedctx;
 	struct ast_timer *timer;
 	struct timeval now;
+	const struct ast_channel_tech *channel_tech;
 
 	/* If shutting down, don't allocate any new channels */
 	if (ast_shutting_down()) {
@@ -965,9 +976,6 @@
 		ast_channel_name_set(tmp, "-**Unknown**");
 	}
 
-	/* Reminder for the future: under what conditions do we NOT want to track cdrs on channels? */
-
-	/* These 4 variables need to be set up for the cdr_init() to work right */
 	if (amaflag != AST_AMA_NONE) {
 		ast_channel_amaflags_set(tmp, amaflag);
 	} else {
@@ -977,39 +985,39 @@
 	if (!ast_strlen_zero(acctcode)) {
 		ast_channel_accountcode_set(tmp, acctcode);
 	}
+	ast_channel_language_set(tmp, ast_defaultlanguage);
 
 	ast_channel_context_set(tmp, S_OR(context, "default"));
 	ast_channel_exten_set(tmp, S_OR(exten, "s"));
 	ast_channel_priority_set(tmp, 1);
 
-	ast_atomic_fetchadd_int(&chancount, +1);
-
 	headp = ast_channel_varshead(tmp);
 	AST_LIST_HEAD_INIT_NOLOCK(headp);
 
 	ast_pbx_hangup_handler_init(tmp);
 	AST_LIST_HEAD_INIT_NOLOCK(ast_channel_datastores(tmp));
-
 	AST_LIST_HEAD_INIT_NOLOCK(ast_channel_autochans(tmp));
 
-	ast_channel_language_set(tmp, ast_defaultlanguage);
-
-	ast_channel_tech_set(tmp, &null_tech);
-
+	channel_tech = ast_get_channel_tech(tech);
+	if (!channel_tech && !ast_strlen_zero(tech2)) {
+		channel_tech = ast_get_channel_tech(tech2);
+	}
+	if (channel_tech) {
+		ast_channel_tech_set(tmp, channel_tech);
+	} else {
+		ast_channel_tech_set(tmp, &null_tech);
+	}
+
+	ast_channel_internal_finalize(tmp);
+
+	ast_atomic_fetchadd_int(&chancount, +1);
 	ao2_link(channels, tmp);
 
 	/*
-	 * And now, since the channel structure is built, and has its name, let's
-	 * call the manager event generator with this Newchannel event. This is the
-	 * proper and correct place to make this call, but you sure do have to pass
-	 * a lot of data into this func to do it here!
+	 * And now, since the channel structure is built, and has its name, let
+	 * the world know of its existance
 	 */
-	if (ast_get_channel_tech(tech) || (tech2 && ast_get_channel_tech(tech2))) {
-		ast_channel_publish_snapshot(tmp);
-	}
-
-	ast_channel_internal_finalize(tmp);
-	ast_publish_channel_state(tmp);
+	ast_channel_publish_snapshot(tmp);
 	return tmp;
 }
 
@@ -6376,7 +6384,7 @@
 		struct ast_party_connected_line connected;
 		struct ast_party_redirecting redirecting;
 	} exchange;
-	struct ast_channel *clonechan, *chans[2];
+	struct ast_channel *clonechan;
 	struct ast_channel *bridged;
 	struct ast_format rformat;
 	struct ast_format wformat;
@@ -6458,42 +6466,6 @@
 
 	ast_debug(4, "Actually Masquerading %s(%d) into the structure of %s(%d)\n",
 		ast_channel_name(clonechan), ast_channel_state(clonechan), ast_channel_name(original), ast_channel_state(original));
-
-	chans[0] = clonechan;
-	chans[1] = original;
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a masquerade occurs between two channels, wherein the Clone channel's internal information replaces the Original channel's information.</synopsis>
-			<syntax>
-				<parameter name="Clone">
-					<para>The name of the channel whose information will be going into the Original channel.</para>
-				</parameter>
-				<parameter name="CloneUniqueid">
-					<para>The uniqueid of the channel whose information will be going into the Original channel.</para>
-				</parameter>
-				<parameter name="CloneState">
-					<para>The current state of the clone channel.</para>
-				</parameter>
-				<parameter name="Original">
-					<para>The name of the channel whose information will be replaced by the Clone channel's information.</para>
-				</parameter>
-				<parameter name="OriginalUniqueid">
-					<para>The uniqueid of the channel whose information will be replaced by the Clone channel's information.</para>
-				</parameter>
-				<parameter name="OriginalState">
-					<para>The current state of the original channel.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	ast_manager_event_multichan(EVENT_FLAG_CALL, "Masquerade", 2, chans,
-		"Clone: %s\r\n"
-		"CloneUniqueid: %s\r\n"
-		"CloneState: %s\r\n"
-		"Original: %s\r\n"
-		"OriginalUniqueid: %s\r\n"
-		"OriginalState: %s\r\n",
-		ast_channel_name(clonechan), ast_channel_uniqueid(clonechan), ast_state2str(ast_channel_state(clonechan)), ast_channel_name(original), ast_channel_uniqueid(original), ast_state2str(ast_channel_state(original)));
 
 	/*
 	 * Remember the original read/write formats.  We turn off any
@@ -7549,6 +7521,7 @@
 		ao2_ref(channels, -1);
 		channels = NULL;
 	}
+	ast_channel_unregister(&surrogate_tech);
 }
 
 void ast_channels_init(void)
@@ -7558,6 +7531,8 @@
 	if (channels) {
 		ao2_container_register("channels", channels, prnt_channel_key);
 	}
+
+	ast_channel_register(&surrogate_tech);
 
 	ast_stasis_channels_init();
 

Modified: trunk/main/channel_internal_api.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/channel_internal_api.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/main/channel_internal_api.c (original)
+++ trunk/main/channel_internal_api.c Thu Aug  8 09:13:05 2013
@@ -426,13 +426,13 @@
 	if ((assert_on_null)) ast_assert(!ast_strlen_zero(value)); \
 	if (!strcmp(value, chan->field)) return; \
 	ast_string_field_set(chan, field, value); \
-	if (publish) ast_channel_publish_snapshot(chan); \
+	if (publish && ast_channel_internal_is_finalized(chan)) ast_channel_publish_snapshot(chan); \
 } \
   \
 void ast_channel_##field##_build_va(struct ast_channel *chan, const char *fmt, va_list ap) \
 { \
 	ast_string_field_build_va(chan, field, fmt, ap); \
-	if (publish) ast_channel_publish_snapshot(chan); \
+	if (publish && ast_channel_internal_is_finalized(chan)) ast_channel_publish_snapshot(chan); \
 } \
 void ast_channel_##field##_build(struct ast_channel *chan, const char *fmt, ...) \
 { \
@@ -1481,7 +1481,6 @@
 
 	chan->topics = stasis_cp_single_create(
 		ast_channel_cache_all(), topic_name);
-
 	if (!chan->topics) {
 		return -1;
 	}

Modified: trunk/main/manager_bridges.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager_bridges.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/main/manager_bridges.c (original)
+++ trunk/main/manager_bridges.c Thu Aug  8 09:13:05 2013
@@ -381,7 +381,7 @@
 	}
 
 	snapshot = stasis_message_data(msg);
-	if (snapshot->tech_properties & (AST_CHAN_TP_ANNOUNCER | AST_CHAN_TP_RECORDER)) {
+	if (snapshot->tech_properties & AST_CHAN_TP_INTERNAL) {
 		return 0;
 	}
 

Modified: trunk/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/manager_channels.c?view=diff&rev=396392&r1=396391&r2=396392
==============================================================================
--- trunk/main/manager_channels.c (original)
+++ trunk/main/manager_channels.c Thu Aug  8 09:13:05 2013
@@ -383,7 +383,7 @@
 		return NULL;
 	}
 
-	if (snapshot->tech_properties & (AST_CHAN_TP_ANNOUNCER | AST_CHAN_TP_RECORDER)) {
+	if (snapshot->tech_properties & AST_CHAN_TP_INTERNAL) {
 		ast_free(out);
 		return NULL;
 	}




More information about the asterisk-commits mailing list