[asterisk-commits] mmichelson: branch mmichelson/transfer_stasis r391554 - /team/mmichelson/tran...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Wed Jun 12 13:31:26 CDT 2013
Author: mmichelson
Date: Wed Jun 12 13:31:24 2013
New Revision: 391554
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391554
Log:
Package common attended transfer data into a "publication" structure.
This gives us two distinct advantages:
1) It allows for a XXX comment to be removed. Now we are guaranteed to indicate
the correct parties when attended transferring a bridge.
2) It allows for an upcoming improvement to be made easily. We want to be consistent
about when we publish the transfer. When performing an attended transfer of a single
party to an application, we currently do so by queuing a bridge action. This action
runs in a separate thread. If we pass the publication data as part of the action data,
then we can hold off on publishing the stasis message until the transfer has actually
completed. Note: this also applies for blind transfers.
The one problem with this is that I've simply tacked on the publication to function calls.
The publication likely should just replace parameters since the parameters are somewhat redundant.
Also the publication parameters have not been added to the doxygen.
Modified:
team/mmichelson/transfer_stasis/main/bridging.c
Modified: team/mmichelson/transfer_stasis/main/bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/main/bridging.c?view=diff&rev=391554&r1=391553&r2=391554
==============================================================================
--- team/mmichelson/transfer_stasis/main/bridging.c (original)
+++ team/mmichelson/transfer_stasis/main/bridging.c Wed Jun 12 13:31:24 2013
@@ -5602,54 +5602,56 @@
return AST_BRIDGE_TRANSFER_SUCCESS;
}
-static void publish_attended_transfer_bridge_merge(struct ast_channel *to_transferee,
+struct stasis_attended_transfer_publish_data {
+ struct ast_bridge_channel_pair to_transferee;
+ struct ast_bridge_channel_pair to_transfer_target;
+};
+
+static void stasis_publish_data_cleanup(struct stasis_attended_transfer_publish_data *publication)
+{
+ ast_channel_unref(publication->to_transferee.channel);
+ ast_channel_unref(publication->to_transfer_target.channel);
+ ao2_cleanup(publication->to_transferee.bridge);
+ ao2_cleanup(publication->to_transfer_target.bridge);
+}
+
+static void stasis_publish_data_init(struct ast_channel *to_transferee,
struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
- struct ast_bridge *to_target_bridge, struct ast_bridge *final_bridge)
-{
- struct ast_bridge_channel_pair transferee = {
- .channel = to_transferee,
- .bridge = to_transferee_bridge,
- };
- struct ast_bridge_channel_pair target = {
- .channel = to_transfer_target,
- .bridge = to_target_bridge,
- };
-
+ struct ast_bridge *to_target_bridge,
+ struct stasis_attended_transfer_publish_data *publication)
+{
+ memset(publication, 0, sizeof(*publication));
+ publication->to_transferee.channel = ast_channel_ref(to_transferee);
+ if (to_transferee_bridge) {
+ ao2_ref(to_transferee_bridge, +1);
+ publication->to_transferee.bridge = to_transferee_bridge;
+ }
+
+ publication->to_transfer_target.channel = ast_channel_ref(to_transfer_target);
+ if (to_target_bridge) {
+ ao2_ref(to_target_bridge, +1);
+ publication->to_transfer_target.bridge = to_target_bridge;
+ }
+}
+
+static void publish_attended_transfer_bridge_merge(struct stasis_attended_transfer_publish_data *publication,
+ struct ast_bridge *final_bridge)
+{
ast_bridge_publish_attended_transfer_bridge_merge(1, AST_BRIDGE_TRANSFER_SUCCESS,
- &transferee, &target, final_bridge);
-}
-
-static void publish_attended_transfer_app(struct ast_channel *to_transferee,
- struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
- struct ast_bridge *to_target_bridge, const char *app)
-{
- struct ast_bridge_channel_pair transferee = {
- .channel = to_transferee,
- .bridge = to_transferee_bridge,
- };
- struct ast_bridge_channel_pair target = {
- .channel = to_transfer_target,
- .bridge = to_target_bridge,
- };
-
+ &publication->to_transferee, &publication->to_transfer_target, final_bridge);
+}
+
+static void publish_attended_transfer_app(struct stasis_attended_transfer_publish_data *publication,
+ const char *app)
+{
ast_bridge_publish_attended_transfer_app(1, AST_BRIDGE_TRANSFER_SUCCESS,
- &transferee, &target, app);
-}
-
-static void publish_attended_transfer_link(struct ast_channel *to_transferee,
- struct ast_bridge *to_transferee_bridge, struct ast_channel *to_transfer_target,
- struct ast_bridge *to_target_bridge, struct ast_channel *local_channel1,
- struct ast_bridge *local_bridge1, struct ast_channel *local_channel2,
- struct ast_bridge *local_bridge2)
-{
- struct ast_bridge_channel_pair transferee = {
- .channel = to_transferee,
- .bridge = to_transferee_bridge,
- };
- struct ast_bridge_channel_pair target = {
- .channel = to_transfer_target,
- .bridge = to_target_bridge,
- };
+ &publication->to_transferee, &publication->to_transfer_target, app);
+}
+
+static void publish_attended_transfer_link(struct stasis_attended_transfer_publish_data *publication,
+ struct ast_channel *local_channel1, struct ast_bridge *local_bridge1,
+ struct ast_channel *local_channel2, struct ast_bridge *local_bridge2)
+{
struct ast_bridge_channel_pair local1 = {
.channel = local_channel1,
.bridge = local_bridge1,
@@ -5661,23 +5663,14 @@
struct ast_bridge_channel_pair *locals[2] = { &local1, &local2 };
ast_bridge_publish_attended_transfer_link(1, AST_BRIDGE_TRANSFER_SUCCESS,
- &transferee, &target, locals);
+ &publication->to_transferee, &publication->to_transfer_target, locals);
}
static void publish_attended_transfer_fail(enum ast_transfer_result result,
- struct ast_channel *to_transferee, struct ast_bridge *to_transferee_bridge,
- struct ast_channel *to_transfer_target, struct ast_bridge *to_target_bridge)
-{
- struct ast_bridge_channel_pair transferee = {
- .channel = to_transferee,
- .bridge = to_transferee_bridge,
- };
- struct ast_bridge_channel_pair target = {
- .channel = to_transfer_target,
- .bridge = to_target_bridge,
- };
-
- ast_bridge_publish_attended_transfer_fail(1, result, &transferee, &target);
+ struct stasis_attended_transfer_publish_data *publication)
+{
+ ast_bridge_publish_attended_transfer_fail(1, result, &publication->to_transferee,
+ &publication->to_transfer_target);
}
/*!
@@ -5702,7 +5695,8 @@
* \retval AST_BRIDGE_TRANSFER_SUCCESS Succesfully transferred the bridge
*/
static enum ast_transfer_result attended_transfer_bridge(struct ast_channel *chan1,
- struct ast_channel *chan2, struct ast_bridge *bridge1, struct ast_bridge *bridge2)
+ struct ast_channel *chan2, struct ast_bridge *bridge1, struct ast_bridge *bridge2,
+ struct stasis_attended_transfer_publish_data *publication)
{
static const char *dest = "_attended at transfer/m";
struct ast_channel *local_chan;
@@ -5748,18 +5742,10 @@
ast_assert(local_chan2 != NULL);
- /* XXX This isn't accurate since the channels here aren't necessarily
- * labeled correctly for the publication. i.e. chan1 is not necessarily
- * bridged to the transferee.
- */
- publish_attended_transfer_link(chan1, bridge1, chan2, bridge2,
+ publish_attended_transfer_link(publication,
local_chan, bridge1, local_chan2, bridge2);
} else {
- /* XXX This isn't accurate since the channels here aren't necessarily
- * labeled correctly for the publication. i.e. chan1 is not necessarily
- * bridged to the transferee.
- */
- publish_attended_transfer_app(chan1, bridge1, chan2, bridge2, app);
+ publish_attended_transfer_app(publication, app);
}
return AST_BRIDGE_TRANSFER_SUCCESS;
}
@@ -6113,7 +6099,8 @@
struct ast_bridge_channel *to_transferee_bridge_channel,
struct ast_channel *to_transfer_target,
struct ast_bridge_channel *to_target_bridge_channel,
- struct ast_bridge *to_transferee_bridge, struct ast_bridge *to_target_bridge)
+ struct ast_bridge *to_transferee_bridge, struct ast_bridge *to_target_bridge,
+ struct stasis_attended_transfer_publish_data *publication)
{
struct ast_bridge_channel *kick_me[] = {
to_transferee_bridge_channel,
@@ -6157,13 +6144,12 @@
* stasis message if it succeeds
*/
return attended_transfer_bridge(to_transferee, to_transfer_target,
- to_transferee_bridge, to_target_bridge);
+ to_transferee_bridge, to_target_bridge, publication);
}
end:
if (res == AST_BRIDGE_TRANSFER_SUCCESS) {
- publish_attended_transfer_bridge_merge(to_transferee, to_transferee_bridge,
- to_transfer_target, to_target_bridge, final_bridge);
+ publish_attended_transfer_bridge_merge(publication, final_bridge);
}
return res;
@@ -6185,9 +6171,13 @@
int do_bridge_transfer;
enum ast_transfer_result res;
const char *app = NULL;
+ struct stasis_attended_transfer_publish_data publication;
to_transferee_bridge = acquire_bridge(to_transferee);
to_target_bridge = acquire_bridge(to_transfer_target);
+
+ stasis_publish_data_init(to_transferee, to_transferee_bridge,
+ to_transfer_target, to_target_bridge, &publication);
/* They can't both be unbridged, you silly goose! */
if (!to_transferee_bridge && !to_target_bridge) {
@@ -6252,7 +6242,7 @@
ast_bridge_lock_both(to_transferee_bridge, to_target_bridge);
res = two_bridge_attended_transfer(to_transferee, to_transferee_bridge_channel,
to_transfer_target, to_target_bridge_channel,
- to_transferee_bridge, to_target_bridge);
+ to_transferee_bridge, to_target_bridge, &publication);
ast_bridge_unlock(to_transferee_bridge);
ast_bridge_unlock(to_target_bridge);
@@ -6290,7 +6280,7 @@
}
if (do_bridge_transfer) {
- res = attended_transfer_bridge(chan_bridged, chan_unbridged, the_bridge, NULL);
+ res = attended_transfer_bridge(chan_bridged, chan_unbridged, the_bridge, NULL, &publication);
goto end;
}
@@ -6308,8 +6298,7 @@
ast_bridge_remove(the_bridge, chan_bridged);
- publish_attended_transfer_app(to_transferee, to_transferee_bridge, to_transfer_target,
- to_target_bridge, app);
+ publish_attended_transfer_app(&publication, app);
return AST_BRIDGE_TRANSFER_SUCCESS;
end:
@@ -6317,9 +6306,9 @@
* All failure paths have deferred publishing a stasis message until this point
*/
if (res != AST_BRIDGE_TRANSFER_SUCCESS) {
- publish_attended_transfer_fail(res, to_transferee, to_transferee_bridge,
- to_transfer_target, to_target_bridge);
- }
+ publish_attended_transfer_fail(res, &publication);
+ }
+ stasis_publish_data_cleanup(&publication);
return res;
}
More information about the asterisk-commits
mailing list