[asterisk-commits] mmichelson: branch mmichelson/transfer r386622 - in /team/mmichelson/transfer...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Apr 26 13:42:53 CDT 2013


Author: mmichelson
Date: Fri Apr 26 13:42:49 2013
New Revision: 386622

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=386622
Log:
Address review feedback:

* Removed comments where they are not necessary any longer
* Created ast_channel_get_bridge() and ast_channel_is_bridged() functions
* Renamed functions where recommended.
* Fixed extraneous whitespace
* Call bridge_handle_hangup() instead of changing bridge_channel state directly
* Added a missing ast_hangup() of a local channel


Modified:
    team/mmichelson/transfer/include/asterisk/bridging.h
    team/mmichelson/transfer/include/asterisk/channel.h
    team/mmichelson/transfer/include/asterisk/framehook.h
    team/mmichelson/transfer/main/bridging.c
    team/mmichelson/transfer/main/channel.c
    team/mmichelson/transfer/main/manager.c
    team/mmichelson/transfer/main/pbx.c

Modified: team/mmichelson/transfer/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/include/asterisk/bridging.h?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/include/asterisk/bridging.h (original)
+++ team/mmichelson/transfer/include/asterisk/bridging.h Fri Apr 26 13:42:49 2013
@@ -1294,7 +1294,7 @@
  * \param hook A frame hook to attach to the new call
  * \return The success or failure result of the blind transfer
  */
-enum ast_transfer_result ast_bridge_blind_transfer(struct ast_channel *transferer,
+enum ast_transfer_result ast_bridge_transfer_blind(struct ast_channel *transferer,
 		const char *exten, const char *context, struct ast_framehook_interface *hook);
 
 /*!
@@ -1314,7 +1314,7 @@
  * \param hook A frame hook to attach to the resultant call
  * \return The success or failure of the attended transfer
  */
-enum ast_transfer_result ast_bridge_attended_transfer(struct ast_channel *to_transferee,
+enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee,
 		struct ast_channel *to_transfer_target, struct ast_framehook *hook);
 /*!
  * \brief Set channel to goto specific location after the bridge.

Modified: team/mmichelson/transfer/include/asterisk/channel.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/include/asterisk/channel.h?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/include/asterisk/channel.h (original)
+++ team/mmichelson/transfer/include/asterisk/channel.h Fri Apr 26 13:42:49 2013
@@ -4136,4 +4136,34 @@
  */
 struct stasis_topic *ast_channel_topic(struct ast_channel *chan);
 
+/*!
+ * \since 12
+ * \brief Get the bridge associated with a channel
+ *
+ * The bridge returned has its reference count incremented. Use
+ * ao2_cleanup() or ao2_ref() in order to decrement the reference
+ * count when you are finished with the bridge.
+ *
+ * \note This function expects the channel to be locked prior to
+ * being called and will not grab the channel lock.
+ *
+ * \param chan The channel whose bridge we want
+ * \retval NULL No bridge present on the channel
+ * \retval non-NULL The bridge the channel is in
+ */
+struct ast_bridge *ast_channel_get_bridge(const struct ast_channel *chan);
+
+/*!
+ * \since 12
+ * \brief Determine if a channel is in a bridge
+ *
+ * \note This function expects the channel to be locked prior to
+ * being called and will not grab the channel lock.
+ *
+ * \param chan The channel to test
+ * \retval 0 The channel is not bridged
+ * \retval non-zero The channel is bridged
+ */
+int ast_channel_is_bridged(const struct ast_channel *chan);
+
 #endif /* _ASTERISK_CHANNEL_H */

Modified: team/mmichelson/transfer/include/asterisk/framehook.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/include/asterisk/framehook.h?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/include/asterisk/framehook.h (original)
+++ team/mmichelson/transfer/include/asterisk/framehook.h Fri Apr 26 13:42:49 2013
@@ -228,7 +228,7 @@
  * provide it during the event and destruction callbacks.  It is entirely up to the
  * application using this API to manage the memory associated with the data pointer.
  *
- * \retval On success, non-negative id representing this hook on the channel 
+ * \retval On success, non-negative id representing this hook on the channel
  * \retval On failure, -1
  */
 int ast_framehook_attach(struct ast_channel *chan, struct ast_framehook_interface *i);

Modified: team/mmichelson/transfer/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/main/bridging.c?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/main/bridging.c (original)
+++ team/mmichelson/transfer/main/bridging.c Fri Apr 26 13:42:49 2013
@@ -1957,9 +1957,6 @@
 	ast_dtmf_stream(bridge_channel->chan, NULL, dtmf, 0, 0);
 }
 
-/* XXX These buffer sizes could use more consideration. Currently
- * just numbers pulled out of thin air.
- */
 struct blind_transfer_data {
 	char exten[AST_MAX_EXTENSION];
 	char context[AST_MAX_CONTEXT];
@@ -1969,7 +1966,7 @@
 		struct blind_transfer_data *blind_data)
 {
 	ast_async_goto(bridge_channel->chan, blind_data->context, blind_data->exten, 1);
-	ast_bridge_change_state(bridge_channel, AST_BRIDGE_CHANNEL_STATE_HANGUP);
+	bridge_handle_hangup(bridge_channel);
 }
 
 /*!
@@ -4498,28 +4495,6 @@
 	return channels;
 }
 
-/*! Signed linear format capabilities structure that can be reused */
-static struct ast_format_cap *slin_cap;
-
-/*!
- * \internal
- * \brief Initialize reusable signed linear format cap
- * \retval 0 Success
- * \retval non-zero failure
- */
-static int initialize_slin_cap(void)
-{
-	struct ast_format slin_format;
-
-	slin_cap = ast_format_cap_alloc_nolock();
-	if (!slin_cap) {
-		return -1;
-	}
-
-	ast_format_cap_set(slin_cap, ast_getformatbyname("slin", &slin_format));
-	return 0;
-}
-
 /*!
  * \internal
  * \brief Transfer an entire bridge to a specific destination.
@@ -4539,20 +4514,22 @@
  * \param hook Framehook to attach to local channel
  * \return The success or failure of the operation
  */
-static enum ast_transfer_result blind_transfer_bridge(struct ast_channel *transferer, 
+static enum ast_transfer_result blind_transfer_bridge(struct ast_channel *transferer,
 		struct ast_bridge *bridge, const char *exten, const char *context,
 		struct ast_framehook_interface *hook)
 {
 	struct ast_channel *local;
-	char chan_name[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2]; 
+	char chan_name[AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2];
 	int cause;
 
 	snprintf(chan_name, sizeof(chan_name), "%s@%s", exten, context);
-	local = ast_request("Local", slin_cap, transferer, chan_name, &cause);
+	local = ast_request("Local", ast_channel_nativeformats(transferer), transferer,
+			chan_name, &cause);
 	if (!local) {
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
 	if (hook && ast_framehook_attach(local, hook) < 0) {
+		ast_hangup(local);
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
 	if (ast_call(local, chan_name, 0)) {
@@ -4613,7 +4590,7 @@
  * \retval 0 Successfully queued the action
  * \retval non-zero Failed to queue the action
  */
-static int queue_blind_transfer_bridge_action(struct ast_channel *transferee,
+static int bridge_channel_queue_blind_transfer(struct ast_channel *transferee,
 		const char *exten, const char *context, struct ast_framehook_interface *hook)
 {
 	RAII_VAR(struct ast_bridge_channel *, transferee_bridge_channel, NULL, ao2_cleanup);
@@ -4669,11 +4646,6 @@
 		ao2_ref(transferer_bridge_channel, +1);
 	}
 
-	/* XXX the second parameter here is a channel to potentially put into autoservice.
-	 * We only would need to put the transferer into autoservice if this is called
-	 * from the transferer's thread that is servicing the channel. Would this
-	 * ever happen?
-	 */
 	parking_exten = ast_get_parking_exten(exten, NULL, context);
 	if (parking_exten) {
 		return ast_park_blind_xfer(bridge, transferer, parking_exten) == 0 ?
@@ -4684,7 +4656,7 @@
 	return PARKING_NOT_APPLICABLE;
 }
 
-enum ast_transfer_result ast_bridge_blind_transfer(struct ast_channel *transferer,
+enum ast_transfer_result ast_bridge_transfer_blind(struct ast_channel *transferer,
 		const char *exten, const char *context, struct ast_framehook_interface *hook)
 {
 	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
@@ -4694,13 +4666,12 @@
 	int transfer_prohibited;
 	enum try_parking_result parking_result;
 
-	{
-		SCOPED_LOCK(lock, transferer, ast_channel_lock, ast_channel_unlock);
-		bridge = ast_channel_internal_bridge(transferer);
-		if (!bridge) {
-			return AST_BRIDGE_TRANSFER_INVALID;
-		}
-		ao2_ref(bridge, +1);
+	ast_channel_lock(transferer);
+	bridge = ast_channel_get_bridge(transferer);
+	ast_channel_unlock(transferer);
+
+	if (!bridge) {
+		return AST_BRIDGE_TRANSFER_INVALID;
 	}
 
 	parking_result = try_parking(bridge, transferer);
@@ -4725,7 +4696,7 @@
 		}
 		transfer_prohibited = ast_test_flag(&bridge->feature_flags,
 				AST_BRIDGE_FLAG_TRANSFER_PROHIBITED);
-		do_bridge_transfer = ast_test_flag(&bridge->feature_flags, 
+		do_bridge_transfer = ast_test_flag(&bridge->feature_flags,
 				AST_BRIDGE_FLAG_TRANSFER_BRIDGE_ONLY) ||
 				ao2_container_count(channels) > 2;
 	}
@@ -4745,7 +4716,7 @@
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
 
-	if (queue_blind_transfer_bridge_action(transferee, exten, context, hook)) {
+	if (bridge_channel_queue_blind_transfer(transferee, exten, context, hook)) {
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
 
@@ -4753,7 +4724,7 @@
 	return AST_BRIDGE_TRANSFER_SUCCESS;
 }
 
-enum ast_transfer_result ast_bridge_attended_transfer(struct ast_channel *to_transferee,
+enum ast_transfer_result ast_bridge_transfer_attended(struct ast_channel *to_transferee,
 		struct ast_channel *to_transfer_target, struct ast_framehook *hook)
 {
 	/* First, check the validity of scenario. If invalid, return AST_BRIDGE_TRANSFER_INVALID. The following are invalid:
@@ -5372,11 +5343,6 @@
 		return -1;
 	}
 
-	if (initialize_slin_cap()) {
-		bridge_shutdown();
-		return -1;
-	}
-
 	ast_bridging_init_basic();
 
 /* BUGBUG need AMI action equivalents to the CLI commands. */

Modified: team/mmichelson/transfer/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/main/channel.c?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/main/channel.c (original)
+++ team/mmichelson/transfer/main/channel.c Fri Apr 26 13:42:49 2013
@@ -11297,3 +11297,21 @@
 {
 	ao2_unlink(channels, chan);
 }
+
+struct ast_bridge *ast_channel_get_bridge(const struct ast_channel *chan)
+{
+	struct ast_bridge *bridge;
+
+	bridge = ast_channel_internal_bridge(chan);
+	if (!bridge) {
+		return NULL;
+	}
+	ao2_ref(bridge, +1);
+	return bridge;
+}
+
+int ast_channel_is_bridged(const struct ast_channel *chan)
+{
+	RAII_VAR(struct ast_bridge *, bridge, ast_channel_get_bridge(chan), ao2_cleanup);
+	return bridge != 0;
+}

Modified: team/mmichelson/transfer/main/manager.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/main/manager.c?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/main/manager.c (original)
+++ team/mmichelson/transfer/main/manager.c Fri Apr 26 13:42:49 2013
@@ -3918,8 +3918,8 @@
 	if (ast_strlen_zero(context)) {
 		context = ast_channel_context(chan);
 	}
-	
-	switch (ast_bridge_blind_transfer(chan, exten, context, NULL)) {
+
+	switch (ast_bridge_transfer_blind(chan, exten, context, NULL)) {
 	case AST_BRIDGE_TRANSFER_NOT_PERMITTED:
 		astman_send_error(s, m, "Transfer not permitted");
 		break;
@@ -3933,7 +3933,7 @@
 		astman_send_ack(s, m, "Transfer succeeded");
 		break;
 	}
-	
+
 	return 0;
 }
 

Modified: team/mmichelson/transfer/main/pbx.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer/main/pbx.c?view=diff&rev=386622&r1=386621&r2=386622
==============================================================================
--- team/mmichelson/transfer/main/pbx.c (original)
+++ team/mmichelson/transfer/main/pbx.c Fri Apr 26 13:42:49 2013
@@ -9394,7 +9394,8 @@
 	} tmpvars = { 0, };
 
 	ast_channel_lock(chan);
-	if (ast_channel_internal_bridge(chan) || ast_channel_pbx(chan)) { /* This channel is currently in the PBX */
+	/* Channels in a bridge or running a PBX can be sent directly to the specified destination */
+	if (ast_channel_is_bridged(chan) || ast_channel_pbx(chan)) {
 		if (ast_test_flag(ast_channel_flags(chan), AST_FLAG_IN_AUTOLOOP)) {
 			priority += 1;
 		}




More information about the asterisk-commits mailing list