[asterisk-commits] rmudgett: branch rmudgett/bridge_phase r399094 - in /team/rmudgett/bridge_pha...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Sep 13 12:28:50 CDT 2013


Author: rmudgett
Date: Fri Sep 13 12:28:46 2013
New Revision: 399094

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=399094
Log:
* Addressed mmichelson's review comments.

* Fixed users of ast_bridge_impart() not checking the return value.

* Improved the parking and CDR unit tests to clean up after themselves if
they pass.

* Attempted to improve the CEL unit tests to clean up after itself if it
passes.  Unfortunately, it is now broken because there are more events
than it expects.

Modified:
    team/rmudgett/bridge_phase/apps/confbridge/conf_chan_announce.c
    team/rmudgett/bridge_phase/channels/chan_sip.c
    team/rmudgett/bridge_phase/include/asterisk/bridge.h
    team/rmudgett/bridge_phase/main/bridge.c
    team/rmudgett/bridge_phase/main/bridge_basic.c
    team/rmudgett/bridge_phase/main/channel.c
    team/rmudgett/bridge_phase/main/core_local.c
    team/rmudgett/bridge_phase/main/core_unreal.c
    team/rmudgett/bridge_phase/main/features.c
    team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c
    team/rmudgett/bridge_phase/res/parking/parking_tests.c
    team/rmudgett/bridge_phase/res/res_pjsip_refer.c
    team/rmudgett/bridge_phase/res/stasis/control.c
    team/rmudgett/bridge_phase/tests/test_cdr.c
    team/rmudgett/bridge_phase/tests/test_cel.c

Modified: team/rmudgett/bridge_phase/apps/confbridge/conf_chan_announce.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/apps/confbridge/conf_chan_announce.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/apps/confbridge/conf_chan_announce.c (original)
+++ team/rmudgett/bridge_phase/apps/confbridge/conf_chan_announce.c Fri Sep 13 12:28:46 2013
@@ -196,7 +196,8 @@
 	ast_set_flag(&features->feature_flags, AST_BRIDGE_CHANNEL_FLAG_IMMOVABLE);
 
 	/* Impart the output channel into the bridge */
-	if (ast_bridge_impart(p->bridge, chan, NULL, features, AST_BRIDGE_IMPART_DEPARTABLE)) {
+	if (ast_bridge_impart(p->bridge, chan, NULL, features,
+		AST_BRIDGE_IMPART_CHAN_DEPARTABLE)) {
 		ast_bridge_features_destroy(features);
 		ast_channel_unref(chan);
 		return -1;

Modified: team/rmudgett/bridge_phase/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/channels/chan_sip.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/channels/chan_sip.c (original)
+++ team/rmudgett/bridge_phase/channels/chan_sip.c Fri Sep 13 12:28:46 2013
@@ -24986,7 +24986,8 @@
 	ast_channel_unlock(replaces_chan);
 
 	if (bridge) {
-		if (ast_bridge_impart(bridge, c, replaces_chan, NULL, AST_BRIDGE_IMPART_INDEPENDENT)) {
+		if (ast_bridge_impart(bridge, c, replaces_chan, NULL,
+			AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 			ast_hangup(c);
 		}
 	} else {

Modified: team/rmudgett/bridge_phase/include/asterisk/bridge.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/include/asterisk/bridge.h?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/include/asterisk/bridge.h (original)
+++ team/rmudgett/bridge_phase/include/asterisk/bridge.h Fri Sep 13 12:28:46 2013
@@ -470,14 +470,12 @@
 	enum ast_bridge_join_flags flags);
 
 enum ast_bridge_impart_flags {
-	/*!
-	 * \brief The caller wants to reclaim the channel using ast_bridge_depart().
-	 *
-	 * \note Defined for caller documentation purposes.
-	 */
-	AST_BRIDGE_IMPART_DEPARTABLE = (0 << 0),
+	/*! Field describing what the caller can do with the channel after it is imparted. */
+	AST_BRIDGE_IMPART_CHAN_MASK = (1 << 0),
+	/*! The caller wants to reclaim the channel using ast_bridge_depart(). */
+	AST_BRIDGE_IMPART_CHAN_DEPARTABLE = (0 << 0),
 	/*! The caller is passing channel control entirely to the bridging system. */
-	AST_BRIDGE_IMPART_INDEPENDENT = (1 << 0),
+	AST_BRIDGE_IMPART_CHAN_INDEPENDENT = (1 << 0),
 	/*! The initial bridge join does not cause a COLP exchange. */
 	AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP = (1 << 1),
 };
@@ -498,12 +496,12 @@
  * \note chan is locked by this function.
  *
  * \retval 0 on success
- * \retval -1 on failure
+ * \retval -1 on failure (Caller still has ownership of chan)
  *
  * Example usage:
  *
  * \code
- * ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_INDEPENDENT);
+ * ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_INDEPENDENT);
  * \endcode
  *
  * \details
@@ -522,13 +520,14 @@
  * parameter.
  *
  * \note If you impart a channel with
- * AST_BRIDGE_IMPART_DEPARTABLE you MUST ast_bridge_depart() the
- * channel if this call succeeds.  The bridge channel thread is
- * created join-able.  The implication is that the channel is
- * special and will not behave like a normal channel.
+ * AST_BRIDGE_IMPART_CHAN_DEPARTABLE you MUST
+ * ast_bridge_depart() the channel if this call succeeds.  The
+ * bridge channel thread is created join-able.  The implication
+ * is that the channel is special and will not behave like a
+ * normal channel.
  *
  * \note If you impart a channel with
- * AST_BRIDGE_IMPART_INDEPENDENT you must not
+ * AST_BRIDGE_IMPART_CHAN_INDEPENDENT you must not
  * ast_bridge_depart() the channel.  The bridge channel thread
  * is created non-join-able.  The channel must be treated as if
  * it were placed into the bridge by ast_bridge_join().
@@ -539,7 +538,7 @@
 	struct ast_channel *chan,
 	struct ast_channel *swap,
 	struct ast_bridge_features *features,
-	enum ast_bridge_impart_flags flags);
+	enum ast_bridge_impart_flags flags) attribute_warn_unused_result;
 
 /*!
  * \brief Depart a channel from a bridge

Modified: team/rmudgett/bridge_phase/main/bridge.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridge.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/bridge.c (original)
+++ team/rmudgett/bridge_phase/main/bridge.c Fri Sep 13 12:28:46 2013
@@ -1591,12 +1591,13 @@
 	bridge_channel->swap = swap;
 	bridge_channel->features = features;
 	bridge_channel->inhibit_colp = !!(flags & AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP);
-	bridge_channel->depart_wait = !(flags & AST_BRIDGE_IMPART_INDEPENDENT);
+	bridge_channel->depart_wait =
+		(flags & AST_BRIDGE_IMPART_CHAN_MASK) == AST_BRIDGE_IMPART_CHAN_DEPARTABLE;
 	bridge_channel->callid = ast_read_threadstorage_callid();
 
 	/* Actually create the thread that will handle the channel */
 	if (!res) {
-		if (flags & AST_BRIDGE_IMPART_INDEPENDENT) {
+		if ((flags & AST_BRIDGE_IMPART_CHAN_MASK) == AST_BRIDGE_IMPART_CHAN_INDEPENDENT) {
 			res = ast_pthread_create_detached(&bridge_channel->thread, NULL,
 				bridge_channel_ind_thread, bridge_channel);
 		} else {
@@ -2198,7 +2199,7 @@
 		}
 		ast_channel_ref(yanked_chan);
 		if (ast_bridge_impart(bridge, yanked_chan, NULL, features,
-			AST_BRIDGE_IMPART_INDEPENDENT)) {
+			AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 			/* It is possible for us to yank a channel and have some other
 			 * thread start a PBX on the channl after we yanked it. In particular,
 			 * this can theoretically happen on the ;2 of a Local channel if we
@@ -3645,7 +3646,8 @@
 		ast_hangup(local);
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
-	if (ast_bridge_impart(bridge, local, transferer, NULL, AST_BRIDGE_IMPART_INDEPENDENT)) {
+	if (ast_bridge_impart(bridge, local, transferer, NULL,
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 		ast_hangup(local);
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
@@ -3815,7 +3817,8 @@
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}
 
-	if (ast_bridge_impart(bridge1, local_chan, chan1, NULL, AST_BRIDGE_IMPART_INDEPENDENT)) {
+	if (ast_bridge_impart(bridge1, local_chan, chan1, NULL,
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 		ast_hangup(local_chan);
 		return AST_BRIDGE_TRANSFER_FAIL;
 	}

Modified: team/rmudgett/bridge_phase/main/bridge_basic.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridge_basic.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/bridge_basic.c (original)
+++ team/rmudgett/bridge_phase/main/bridge_basic.c Fri Sep 13 12:28:46 2013
@@ -2290,7 +2290,7 @@
 		ast_bridge_features_ds_set(props->recall_target, &props->transferer_features);
 		ast_channel_ref(props->recall_target);
 		if (ast_bridge_impart(props->transferee_bridge, props->recall_target, NULL, NULL,
-			AST_BRIDGE_IMPART_INDEPENDENT)) {
+			AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 			ast_hangup(props->recall_target);
 			return TRANSFER_FAIL;
 		}
@@ -2382,7 +2382,7 @@
 
 	ast_channel_ref(props->recall_target);
 	if (ast_bridge_impart(props->transferee_bridge, props->recall_target, NULL, NULL,
-		AST_BRIDGE_IMPART_INDEPENDENT)) {
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 		ast_log(LOG_ERROR, "Unable to place recall target into bridge\n");
 		ast_hangup(props->recall_target);
 		return -1;
@@ -3070,7 +3070,7 @@
 	 */
 	ast_channel_ref(props->transfer_target);
 	if (ast_bridge_impart(props->target_bridge, props->transfer_target, NULL, NULL,
-		AST_BRIDGE_IMPART_INDEPENDENT)) {
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 		ast_log(LOG_ERROR, "Unable to place transfer target into bridge.\n");
 		ast_stream_and_wait(bridge_channel->chan, props->failsound, AST_DIGIT_NONE);
 		ast_bridge_channel_write_unhold(bridge_channel);

Modified: team/rmudgett/bridge_phase/main/channel.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/channel.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/channel.c (original)
+++ team/rmudgett/bridge_phase/main/channel.c Fri Sep 13 12:28:46 2013
@@ -4424,7 +4424,7 @@
 	}
 
 	if (current_size == proposed_size && !memcmp(current, proposed, current_size)) {
-		ast_verb(3, "%s: Dropping redundant connected line update \"%s\" <%s>.\n",
+		ast_debug(1, "%s: Dropping redundant connected line update \"%s\" <%s>.\n",
 			ast_channel_name(chan),
 			S_COR(chan_connected->id.name.valid, chan_connected->id.name.str, ""),
 			S_COR(chan_connected->id.number.valid, chan_connected->id.number.str, ""));

Modified: team/rmudgett/bridge_phase/main/core_local.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/core_local.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/core_local.c (original)
+++ team/rmudgett/bridge_phase/main/core_local.c Fri Sep 13 12:28:46 2013
@@ -687,7 +687,7 @@
 		publish_local_bridge_message(p);
 		ast_answer(chan);
 		res = ast_bridge_impart(p->action.bridge.join, chan, p->action.bridge.swap,
-			p->action.bridge.features, AST_BRIDGE_IMPART_INDEPENDENT);
+			p->action.bridge.features, AST_BRIDGE_IMPART_CHAN_INDEPENDENT);
 		ao2_ref(p->action.bridge.join, -1);
 		p->action.bridge.join = NULL;
 		ao2_cleanup(p->action.bridge.swap);

Modified: team/rmudgett/bridge_phase/main/core_unreal.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/core_unreal.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/core_unreal.c (original)
+++ team/rmudgett/bridge_phase/main/core_unreal.c Fri Sep 13 12:28:46 2013
@@ -758,7 +758,8 @@
 	ast_set_flag(&features->feature_flags, flags);
 
 	/* Impart the semi2 channel into the bridge */
-	if (ast_bridge_impart(bridge, chan, NULL, features, AST_BRIDGE_IMPART_INDEPENDENT)) {
+	if (ast_bridge_impart(bridge, chan, NULL, features,
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 		ast_bridge_features_destroy(features);
 		ast_channel_unref(chan);
 		return -1;

Modified: team/rmudgett/bridge_phase/main/features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/features.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/main/features.c (original)
+++ team/rmudgett/bridge_phase/main/features.c Fri Sep 13 12:28:46 2013
@@ -676,7 +676,7 @@
 
 	/* Put peer into the bridge */
 	if (ast_bridge_impart(bridge, peer, NULL, peer_features,
-		AST_BRIDGE_IMPART_INDEPENDENT | AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP)) {
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT | AST_BRIDGE_IMPART_INHIBIT_JOIN_COLP)) {
 		ast_bridge_destroy(bridge, 0);
 		ast_bridge_features_cleanup(&chan_features);
 		bridge_failed_peer_goto(chan, peer);

Modified: team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c (original)
+++ team/rmudgett/bridge_phase/res/parking/parking_bridge_features.c Fri Sep 13 12:28:46 2013
@@ -317,7 +317,7 @@
 		}
 
 		if (ast_bridge_impart(bridge_channel->bridge, transfer_chan, NULL, NULL,
-			AST_BRIDGE_IMPART_INDEPENDENT)) {
+			AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 			ast_hangup(transfer_chan);
 			return -1;
 		}

Modified: team/rmudgett/bridge_phase/res/parking/parking_tests.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/parking/parking_tests.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/res/parking/parking_tests.c (original)
+++ team/rmudgett/bridge_phase/res/parking/parking_tests.c Fri Sep 13 12:28:46 2013
@@ -82,6 +82,12 @@
 	ast_channel_release(chan);
 }
 
+static void do_sleep(struct timespec *to_sleep)
+{
+	while ((nanosleep(to_sleep, to_sleep) == -1) && (errno == EINTR)) {
+	}
+}
+
 static int fake_fixup(struct ast_channel *clonechan, struct ast_channel *original)
 {
 	return 0;
@@ -99,7 +105,6 @@
 	struct parking_lot *test_lot;
 
 	test_cfg = parking_lot_cfg_create(name);
-
 	if (!test_cfg) {
 		return NULL;
 	}
@@ -120,7 +125,6 @@
 	}
 
 	test_lot = parking_lot_build_or_update(test_cfg, 1);
-
 	if (!test_lot) {
 		return NULL;
 	}
@@ -195,7 +199,6 @@
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_bridge *, parking_bridge, NULL, ao2_cleanup);
 
-	struct ast_bridge_features chan_features;
 	struct timespec to_sleep = {1, 0};
 
 	switch (cmd) {
@@ -219,7 +222,6 @@
 	}
 
 	chan_alice = create_alice_channel();
-
 	if (!chan_alice) {
 		ast_test_status_update(test, "Failed to create test channel to park. Test failed.\n");
 		dispose_test_lot(test_lot, 1);
@@ -227,28 +229,23 @@
 	}
 
 	ast_channel_state_set(chan_alice, AST_STATE_UP);
-
 	pbx_builtin_setvar_helper(chan_alice, "BLINDTRANSFER", ast_channel_name(chan_alice));
 
 	parking_bridge = park_application_setup(chan_alice, chan_alice, TEST_LOT_NAME, NULL);
-
 	if (!parking_bridge) {
 		ast_test_status_update(test, "Failed to get the parking bridge for '%s'. Test failed.\n", TEST_LOT_NAME);
 		dispose_test_lot(test_lot, 1);
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_bridge_features_init(&chan_features)) {
-		ast_bridge_features_cleanup(&chan_features);
-		ast_test_status_update(test, "Failed to initialize bridge features. Test failed.\n");
+	if (ast_bridge_impart(parking_bridge, chan_alice, NULL, NULL,
+		AST_BRIDGE_IMPART_CHAN_DEPARTABLE)) {
+		ast_test_status_update(test, "Failed to impart alice into parking lot. Test failed.\n");
 		dispose_test_lot(test_lot, 1);
 		return AST_TEST_FAIL;
 	}
 
-	ast_bridge_impart(parking_bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_alice);
 
@@ -256,6 +253,7 @@
 
 	if (dispose_test_lot(test_lot, 1)) {
 		ast_test_status_update(test, "Found parking lot in container after attempted removal. Test failed.\n");
+		return AST_TEST_FAIL;
 	}
 
 	return AST_TEST_PASS;
@@ -353,8 +351,6 @@
 		.time_limit = 10,
 		.resolution = PARK_ANSWERED,
 	};
-
-	struct ast_bridge_features chan_features;
 
 	switch (cmd) {
 	case TEST_INIT:
@@ -384,7 +380,6 @@
 	}
 
 	ast_channel_state_set(chan_alice, AST_STATE_UP);
-
 	pbx_builtin_setvar_helper(chan_alice, "BLINDTRANSFER", ast_channel_name(chan_alice));
 
 	parking_bridge = park_application_setup(chan_alice, chan_alice, TEST_LOT_NAME, NULL);
@@ -394,27 +389,23 @@
 		return AST_TEST_FAIL;
 	}
 
-	if (ast_bridge_features_init(&chan_features)) {
-		ast_bridge_features_cleanup(&chan_features);
-		ast_test_status_update(test, "Failed to initialize bridge features. Test failed.\n");
+	if (ast_bridge_impart(parking_bridge, chan_alice, NULL, NULL,
+		AST_BRIDGE_IMPART_CHAN_DEPARTABLE)) {
+		ast_test_status_update(test, "Failed to impart alice into parking lot. Test failed.\n");
 		dispose_test_lot(test_lot, 1);
 		return AST_TEST_FAIL;
 	}
 
-	ast_bridge_impart(parking_bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 
 	retrieved_user = parking_lot_retrieve_parked_user(test_lot, 701);
 	if (!retrieved_user) {
 		ast_test_status_update(test, "Failed to retrieve the parked user from the expected parking space. Test failed.\n");
-
 		failure = 1;
 		goto test_cleanup;
 	}
 
-	ast_test_status_update(test, "Successfully retrieved parked user from the parking lot. Validating user data. Test failed.\n");
+	ast_test_status_update(test, "Successfully retrieved parked user from the parking lot. Validating user data.\n");
 
 	if (!parked_users_match(retrieved_user, &expected_user, test)) {
 		ast_test_status_update(test, "Parked user validation failed\n");

Modified: team/rmudgett/bridge_phase/res/res_pjsip_refer.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/res_pjsip_refer.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/res/res_pjsip_refer.c (original)
+++ team/rmudgett/bridge_phase/res/res_pjsip_refer.c Fri Sep 13 12:28:46 2013
@@ -769,7 +769,7 @@
 		}
 	} else {
 		if (ast_bridge_impart(invite.bridge, session->channel, invite.channel, NULL,
-			AST_BRIDGE_IMPART_INDEPENDENT)) {
+			AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
 			response = 500;
 		}
 	}

Modified: team/rmudgett/bridge_phase/res/stasis/control.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/res/stasis/control.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/res/stasis/control.c (original)
+++ team/rmudgett/bridge_phase/res/stasis/control.c Fri Sep 13 12:28:46 2013
@@ -117,7 +117,6 @@
 	command_fn = command_fn ? : noop_cb;
 
 	command = command_create(command_fn, data);
-
 	if (!command) {
 		return NULL;
 	}
@@ -166,7 +165,6 @@
 	ast_dial_set_global_timeout(dial, dial_data->timeout);
 
 	res = ast_dial_run(dial, NULL, 0);
-
 	if (res != AST_DIAL_RESULT_ANSWERED || !(new_chan = ast_dial_answered_steal(dial))) {
 		return NULL;
 	}
@@ -176,8 +174,12 @@
 		return NULL;
 	}
 
-	ast_bridge_impart(bridge, new_chan, NULL, NULL, AST_BRIDGE_IMPART_INDEPENDENT);
-	stasis_app_control_add_channel_to_bridge(control, bridge);
+	if (ast_bridge_impart(bridge, new_chan, NULL, NULL,
+		AST_BRIDGE_IMPART_CHAN_INDEPENDENT)) {
+		ast_hangup(new_chan);
+	} else {
+		stasis_app_control_add_channel_to_bridge(control, bridge);
+	}
 
 	return NULL;
 }
@@ -566,7 +568,7 @@
 			chan,
 			NULL, /* swap channel */
 			NULL, /* features */
-			AST_BRIDGE_IMPART_DEPARTABLE);
+			AST_BRIDGE_IMPART_CHAN_DEPARTABLE);
 
 		if (res != 0) {
 			ast_log(LOG_ERROR, "Error adding channel to bridge\n");

Modified: team/rmudgett/bridge_phase/tests/test_cdr.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/tests/test_cdr.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/tests/test_cdr.c (original)
+++ team/rmudgett/bridge_phase/tests/test_cdr.c Fri Sep 13 12:28:46 2013
@@ -353,6 +353,20 @@
 	ast_channel_release(chan);
 }
 
+static void safe_bridge_destroy(struct ast_bridge *bridge)
+{
+	if (!bridge) {
+		return;
+	}
+	ast_bridge_destroy(bridge, 0);
+}
+
+static void do_sleep(struct timespec *to_sleep)
+{
+	while ((nanosleep(to_sleep, to_sleep) == -1) && (errno == EINTR)) {
+	}
+}
+
 AST_TEST_DEFINE(test_cdr_channel_creation)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
@@ -499,7 +513,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -557,10 +571,9 @@
 
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
 	chan_bob = ast_channel_alloc(0, AST_STATE_DOWN, NULL, NULL, "200", NULL, NULL, ast_channel_linkedid(chan_alice), 0, CHANNEL_TECH_NAME "/Bob");
 	ast_copy_string(bob_expected.linkedid, ast_channel_linkedid(chan_bob), sizeof(bob_expected.linkedid));
@@ -575,13 +588,11 @@
 
 	ast_channel_state_set(chan_bob, AST_STATE_UP);
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_bob);
 	ast_bridge_depart(chan_alice);
@@ -646,7 +657,7 @@
 AST_TEST_DEFINE(test_cdr_single_bridge)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -688,12 +699,10 @@
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan);
 
@@ -707,8 +716,7 @@
 AST_TEST_DEFINE(test_cdr_single_bridge_continue)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge_one, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_bridge *, bridge_two, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -762,15 +770,13 @@
 	ast_setstate(chan, AST_STATE_UP);
 	EMULATE_APP_DATA(chan, 2, "Bridge", "");
 
-	bridge_one = ast_bridge_basic_new();
-	ast_test_validate(test, bridge_one != NULL);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge_one, chan, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	bridge = ast_bridge_basic_new();
+	ast_test_validate(test, bridge != NULL);
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan);
 
@@ -788,7 +794,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -851,17 +857,15 @@
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
 
-	ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
 
 	EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
 	ast_setstate(chan_bob, AST_STATE_UP);
 	EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
 
-	ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_alice);
 	ast_bridge_depart(chan_bob);
@@ -878,7 +882,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -944,16 +948,13 @@
 	EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
 	ast_setstate(chan_bob, AST_STATE_UP);
 	EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_alice);
 	ast_bridge_depart(chan_bob);
@@ -971,7 +972,7 @@
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -1066,29 +1067,25 @@
 
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
 
 	EMULATE_APP_DATA(chan_bob, 1, "Answer", "");
 	ast_setstate(chan_bob, AST_STATE_UP);
 	EMULATE_APP_DATA(chan_bob, 2, "Bridge", "");
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	EMULATE_APP_DATA(chan_charlie, 1, "Answer", "");
 	ast_setstate(chan_charlie, AST_STATE_UP);
 	EMULATE_APP_DATA(chan_charlie, 2, "Bridge", "");
-	ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_alice);
 	ast_bridge_depart(chan_bob);
@@ -1629,7 +1626,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -1683,14 +1680,12 @@
 
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-
-	ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+
+	do_sleep(&to_sleep);
 
 	ast_bridge_depart(chan_caller);
 	ast_bridge_depart(chan_callee);
@@ -1706,7 +1701,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_caller, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_callee, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -1760,14 +1755,11 @@
 
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_callee, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_caller, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
 	ast_bridge_depart(chan_caller);
 	ast_bridge_depart(chan_callee);
 
@@ -1784,7 +1776,7 @@
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_charlie, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_david, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -1922,24 +1914,19 @@
 	bridge = ast_bridge_basic_new();
 	ast_test_validate(test, bridge != NULL);
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE));
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_david, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE));
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE));
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_test_validate(test, 0 == ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE));
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_test_validate(test, 0 == ast_bridge_depart(chan_alice));
-	ast_test_validate(test, 0 == ast_bridge_depart(chan_bob));
-	ast_test_validate(test, 0 == ast_bridge_depart(chan_charlie));
-	ast_test_validate(test, 0 == ast_bridge_depart(chan_david));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_charlie, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_david, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_depart(chan_alice));
+	ast_test_validate(test, !ast_bridge_depart(chan_bob));
+	ast_test_validate(test, !ast_bridge_depart(chan_charlie));
+	ast_test_validate(test, !ast_bridge_depart(chan_david));
 
 	HANGUP_CHANNEL(chan_alice, AST_CAUSE_NORMAL);
 	HANGUP_CHANNEL(chan_bob, AST_CAUSE_NORMAL);
@@ -1955,7 +1942,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	RAII_VAR(struct ast_cdr_config *, config, ao2_alloc(sizeof(*config), NULL),
 			ao2_cleanup);
 	struct timespec to_sleep = {1, 0};
@@ -2017,14 +2004,11 @@
 			| AST_BRIDGE_FLAG_SWAP_INHIBIT_FROM | AST_BRIDGE_FLAG_TRANSFER_PROHIBITED);
 	ast_test_validate(test, bridge != NULL);
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
-	ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_alice, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
+	ast_test_validate(test, !ast_bridge_impart(bridge, chan_bob, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE));
+	do_sleep(&to_sleep);
 	ast_bridge_depart(chan_alice);
 	ast_bridge_depart(chan_bob);
 
@@ -2128,8 +2112,7 @@
 	ast_channel_accountcode_set(chan, "XXX");
 
 	/* Wait one second so we get a duration. */
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 
 	ast_cdr_setuserfield(ast_channel_name(chan), "foobar");
 	ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
@@ -2277,8 +2260,7 @@
 
 	CREATE_ALICE_CHANNEL(chan, &caller, &expected);
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 
 	/* Disable the CDR */
 	ast_test_validate(test, ast_cdr_set_property(ast_channel_name(chan), AST_CDR_FLAG_DISABLE) == 0);
@@ -2380,8 +2362,7 @@
 	ast_copy_string(fork_expected_two.uniqueid, ast_channel_uniqueid(chan), sizeof(fork_expected_two.uniqueid));
 	ast_copy_string(fork_expected_two.linkedid, ast_channel_linkedid(chan), sizeof(fork_expected_two.linkedid));
 
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 
 	/* Test blowing away variables */
 	ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_1") == 0);
@@ -2399,8 +2380,7 @@
 
 	/* Test keep variables; setting a new answer time */
 	ast_setstate(chan, AST_STATE_UP);
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
-	}
+	do_sleep(&to_sleep);
 	ast_test_validate(test, ast_cdr_setvar(ast_channel_name(chan), "test_variable", "record_2") == 0);
 	ast_test_validate(test, ast_cdr_getvar(ast_channel_name(chan), "test_variable", varbuffer, sizeof(varbuffer)) == 0);
 	ast_test_validate(test, strcmp(varbuffer, "record_2") == 0);

Modified: team/rmudgett/bridge_phase/tests/test_cel.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/tests/test_cel.c?view=diff&rev=399094&r1=399093&r2=399094
==============================================================================
--- team/rmudgett/bridge_phase/tests/test_cel.c (original)
+++ team/rmudgett/bridge_phase/tests/test_cel.c Fri Sep 13 12:28:46 2013
@@ -87,7 +87,8 @@
 
 static void do_sleep(void)
 {
-	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR));
+	while ((nanosleep(&to_sleep, &to_sleep) == -1) && (errno == EINTR)) {
+	}
 }
 
 #define APPEND_EVENT(chan, ev_type, userevent, extra) do { \
@@ -109,7 +110,7 @@
 	} while (0)
 
 #define BRIDGE_EXIT(channel, bridge) do { \
-	ast_test_validate(test, 0 == ast_bridge_depart(channel)); \
+	ast_test_validate(test, !ast_bridge_depart(channel)); \
 	BRIDGE_EXIT_EVENT(channel, bridge); \
 	mid_test_sync(); \
 	} while (0)
@@ -129,7 +130,7 @@
 	} while (0)
 
 #define BRIDGE_ENTER(channel, bridge) do { \
-	ast_test_validate(test, 0 == ast_bridge_impart(bridge, channel, NULL, NULL, AST_BRIDGE_IMPART_DEPARTABLE)); \
+	ast_test_validate(test, !ast_bridge_impart(bridge, channel, NULL, NULL, AST_BRIDGE_IMPART_CHAN_DEPARTABLE)); \
 	do_sleep(); \
 	BRIDGE_ENTER_EVENT(channel, bridge); \
 	mid_test_sync(); \
@@ -266,6 +267,14 @@
 	ast_channel_release(chan);
 }
 
+static void safe_bridge_destroy(struct ast_bridge *bridge)
+{
+	if (!bridge) {
+		return;
+	}
+	ast_bridge_destroy(bridge, 0);
+}
+
 AST_TEST_DEFINE(test_cel_channel_creation)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
@@ -381,7 +390,7 @@
 AST_TEST_DEFINE(test_cel_single_bridge)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 
 	struct ast_party_caller caller = ALICE_CALLERID;
 
@@ -420,7 +429,7 @@
 AST_TEST_DEFINE(test_cel_single_bridge_continue)
 {
 	RAII_VAR(struct ast_channel *, chan, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);
 	struct ast_party_caller caller = ALICE_CALLERID;
 
 	switch (cmd) {
@@ -462,7 +471,7 @@
 {
 	RAII_VAR(struct ast_channel *, chan_alice, NULL, safe_channel_release);
 	RAII_VAR(struct ast_channel *, chan_bob, NULL, safe_channel_release);
-	RAII_VAR(struct ast_bridge *, bridge, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_bridge *, bridge, NULL, safe_bridge_destroy);

[... 100 lines stripped ...]



More information about the asterisk-commits mailing list