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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 28 22:56:55 CDT 2013


Author: rmudgett
Date: Fri Jun 28 22:56:53 2013
New Revision: 393259

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=393259
Log:
Change after bridge callback failed to also pass the channel.

Modified:
    team/rmudgett/bridge_phase/include/asterisk/bridging.h
    team/rmudgett/bridge_phase/main/bridging.c

Modified: team/rmudgett/bridge_phase/include/asterisk/bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/include/asterisk/bridging.h?view=diff&rev=393259&r1=393258&r2=393259
==============================================================================
--- team/rmudgett/bridge_phase/include/asterisk/bridging.h (original)
+++ team/rmudgett/bridge_phase/include/asterisk/bridging.h Fri Jun 28 22:56:53 2013
@@ -1663,12 +1663,13 @@
  * \brief After bridge callback failed.
  * \since 12.0.0
  *
+ * \param chan Channel failing the callback.
+ * \param data Extra data what setup the callback wanted to pass.
  * \param reason Reason callback is failing.
- * \param data Extra data what setup the callback wanted to pass.
- *
- * \return Nothing
- */
-typedef void (*ast_after_bridge_cb_failed)(enum ast_after_bridge_cb_reason reason, void *data);
+ *
+ * \return Nothing
+ */
+typedef void (*ast_after_bridge_cb_failed)(struct ast_channel *chan, void *data, enum ast_after_bridge_cb_reason reason);
 
 /*!
  * \brief After bridge callback function.

Modified: team/rmudgett/bridge_phase/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/rmudgett/bridge_phase/main/bridging.c?view=diff&rev=393259&r1=393258&r2=393259
==============================================================================
--- team/rmudgett/bridge_phase/main/bridging.c (original)
+++ team/rmudgett/bridge_phase/main/bridging.c Fri Jun 28 22:56:53 2013
@@ -2548,7 +2548,7 @@
 	}
 }
 
-static void after_bridge_move_channel_fail(enum ast_after_bridge_cb_reason reason, void *data)
+static void after_bridge_move_channel_fail(struct ast_channel *chan_bridged, void *data, enum ast_after_bridge_cb_reason reason)
 {
 	RAII_VAR(struct ast_channel *, chan_target, data, ao2_cleanup);
 
@@ -3167,8 +3167,11 @@
 {
 	struct after_bridge_cb_ds *after_bridge = data;
 
+	/* The datastore should never be destroyed with a failed callback still active. */
+	ast_assert(after_bridge->failed == NULL);
+
 	if (after_bridge->failed) {
-		after_bridge->failed(AST_AFTER_BRIDGE_CB_REASON_DESTROY, after_bridge->data);
+		after_bridge->failed(NULL, after_bridge->data, AST_AFTER_BRIDGE_CB_REASON_DESTROY);
 		after_bridge->failed = NULL;
 	}
 	ast_free(after_bridge);
@@ -3211,35 +3214,43 @@
 {
 	struct ast_datastore *datastore;
 
-	ast_channel_lock(chan);
 	datastore = ast_channel_datastore_find(chan, &after_bridge_cb_info, NULL);
 	if (datastore && ast_channel_datastore_remove(chan, datastore)) {
 		datastore = NULL;
 	}
+
+	return datastore;
+}
+
+static void ast_after_bridge_callback_replace(struct ast_channel *chan, enum ast_after_bridge_cb_reason reason, struct ast_datastore *new_datastore)
+{
+	struct ast_datastore *old_datastore;
+
+	ast_channel_lock(chan);
+	old_datastore = after_bridge_cb_remove(chan);
+	if (new_datastore) {
+		ast_channel_datastore_add(chan, new_datastore);
+	}
 	ast_channel_unlock(chan);
-
-	return datastore;
+	if (old_datastore) {
+		struct after_bridge_cb_ds *after_bridge = old_datastore->data;
+
+		if (after_bridge->failed) {
+			after_bridge->failed(chan, after_bridge->data, reason);
+			after_bridge->failed = NULL;
+		}
+		ast_datastore_free(old_datastore);
+	}
 }
 
 void ast_after_bridge_callback_discard(struct ast_channel *chan, enum ast_after_bridge_cb_reason reason)
 {
-	struct ast_datastore *datastore;
-
-	datastore = after_bridge_cb_remove(chan);
-	if (datastore) {
-		struct after_bridge_cb_ds *after_bridge = datastore->data;
-
-		if (after_bridge && after_bridge->failed) {
-			after_bridge->failed(reason, after_bridge->data);
-			after_bridge->failed = NULL;
-		}
-		ast_datastore_free(datastore);
-	}
-}
-
-/*!
- * \internal
- * \brief Run any after bridge callback if possible.
+	ast_after_bridge_callback_replace(chan, reason, NULL);
+}
+
+/*!
+ * \internal
+ * \brief Run any after bridge callback.
  * \since 12.0.0
  *
  * \param chan Channel to run after bridge callback.
@@ -3251,21 +3262,17 @@
 	struct ast_datastore *datastore;
 	struct after_bridge_cb_ds *after_bridge;
 
-	if (ast_check_hangup(chan)) {
-		return;
-	}
-
 	/* Get after bridge goto datastore. */
+	ast_channel_lock(chan);
 	datastore = after_bridge_cb_remove(chan);
+	ast_channel_unlock(chan);
 	if (!datastore) {
 		return;
 	}
 
 	after_bridge = datastore->data;
-	if (after_bridge) {
-		after_bridge->failed = NULL;
-		after_bridge->callback(chan, after_bridge->data);
-	}
+	after_bridge->failed = NULL;
+	after_bridge->callback(chan, after_bridge->data);
 
 	/* Discard after bridge callback datastore. */
 	ast_datastore_free(datastore);
@@ -3300,11 +3307,8 @@
 	datastore->data = after_bridge;
 
 	/* Put it on the channel replacing any existing one. */
-	ast_channel_lock(chan);
-	ast_after_bridge_callback_discard(chan, AST_AFTER_BRIDGE_CB_REASON_REPLACED);
-	ast_channel_datastore_add(chan, datastore);
-	ast_channel_unlock(chan);
-
+	ast_after_bridge_callback_replace(chan, AST_AFTER_BRIDGE_CB_REASON_REPLACED,
+		datastore);
 	return 0;
 }
 




More information about the asterisk-commits mailing list