Make a couple of changes to help AMI events to be more clear in what is occurring.
authorMark Michelson <mmichelson@digium.com>
Fri, 2 Aug 2013 14:13:04 +0000 (14:13 +0000)
committerMark Michelson <mmichelson@digium.com>
Fri, 2 Aug 2013 14:13:04 +0000 (14:13 +0000)
* BridgeEnter now contains the unique ID of the channel that is to be swapped out, if applicable.
* There is a ParkedCallSwap event that is sent when a parked channel has a new channel take its place.

(closes issue ASTERISK-22193)
reported by Mark Michelson

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

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@396107 65c4cc65-6c06-0410-ace0-fbb531ad65f3

include/asterisk/parking.h
include/asterisk/stasis_bridges.h
main/bridge_channel.c
main/cel.c
main/manager_bridges.c
main/stasis_bridges.c
res/parking/parking_bridge.c
res/parking/parking_manager.c

index b9c80d4..2514985 100644 (file)
@@ -45,6 +45,7 @@ enum ast_parked_call_event_type {
        PARKED_CALL_GIVEUP,
        PARKED_CALL_UNPARKED,
        PARKED_CALL_FAILED,
+       PARKED_CALL_SWAP,
 };
 
 /*!
index 7fa059f..d82bcff 100644 (file)
@@ -215,8 +215,10 @@ struct stasis_message *ast_bridge_blob_create(struct stasis_message_type *type,
  *
  * \param bridge The bridge a channel entered
  * \param chan The channel that entered the bridge
+ * \param swap The channel being swapped out of the bridge
  */
-void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan);
+void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan,
+               struct ast_channel *swap);
 
 /*!
  * \since 12
index f0163ff..c782ec6 100644 (file)
@@ -1429,7 +1429,7 @@ int bridge_channel_internal_push(struct ast_bridge_channel *bridge_channel)
                bridge->v_table->name,
                bridge->uniqueid);
 
-       ast_bridge_publish_enter(bridge, bridge_channel->chan);
+       ast_bridge_publish_enter(bridge, bridge_channel->chan, swap ? swap->chan : NULL);
        if (swap) {
                ast_bridge_channel_leave_bridge(swap, BRIDGE_CHANNEL_STATE_END_NO_DISSOLVE);
                bridge_channel_internal_pull(swap);
index 2b5306e..befb2b2 100644 (file)
@@ -1304,6 +1304,9 @@ static void cel_parking_cb(
        case PARKED_CALL_FAILED:
                reason = "ParkedCallFailed";
                break;
+       case PARKED_CALL_SWAP:
+               reason = "ParkedCallSwap";
+               break;
        }
 
        extra = ast_json_pack("{s: s}", "reason", reason);
index 5d831b5..77533c6 100644 (file)
@@ -58,6 +58,9 @@ static struct stasis_message_router *bridge_state_router;
                        <syntax>
                                <bridge_snapshot/>
                                <channel_snapshot/>
+                               <parameter name="SwapUniqueid">
+                                       <para>The uniqueid of the channel being swapped out of the bridge</para>
+                               </parameter>
                        </syntax>
                </managerEventInstance>
        </managerEvent>
@@ -247,9 +250,11 @@ static void channel_enter_cb(void *data, struct stasis_subscription *sub,
                                    struct stasis_topic *topic,
                                    struct stasis_message *message)
 {
+       static const char *swap_name = "SwapUniqueid: ";
        struct ast_bridge_blob *blob = stasis_message_data(message);
        RAII_VAR(struct ast_str *, bridge_text, NULL, ast_free);
        RAII_VAR(struct ast_str *, channel_text, NULL, ast_free);
+       const char *swap_id;
 
        bridge_text = ast_manager_build_bridge_state_string(blob->bridge, "");
        channel_text = ast_manager_build_channel_state_string(blob->channel);
@@ -257,11 +262,17 @@ static void channel_enter_cb(void *data, struct stasis_subscription *sub,
                return;
        }
 
+       swap_id = ast_json_string_get(ast_json_object_get(blob->blob, "swap"));
+
        manager_event(EVENT_FLAG_CALL, "BridgeEnter",
                "%s"
-               "%s",
+               "%s"
+               "%s%s%s",
                ast_str_buffer(bridge_text),
-               ast_str_buffer(channel_text));
+               ast_str_buffer(channel_text),
+               swap_id ? swap_name : "",
+               S_OR(swap_id, ""),
+               swap_id ? "\r\n" : "");
 }
 
 static void channel_leave_cb(void *data, struct stasis_subscription *sub,
index 251f9d7..a3eeef6 100644 (file)
@@ -380,11 +380,20 @@ struct stasis_message *ast_bridge_blob_create(
        return msg;
 }
 
-void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan)
+void ast_bridge_publish_enter(struct ast_bridge *bridge, struct ast_channel *chan,
+               struct ast_channel *swap)
 {
        RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+       RAII_VAR(struct ast_json *, blob, NULL, ao2_cleanup);
 
-       msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, NULL);
+       if (swap) {
+               blob = ast_json_pack("{s: s}", "swap", ast_channel_uniqueid(swap));
+               if (!blob) {
+                       return;
+               }
+       }
+
+       msg = ast_bridge_blob_create(ast_channel_entered_bridge_type(), bridge, chan, blob);
        if (!msg) {
                return;
        }
index 04250bf..55d8533 100644 (file)
@@ -254,6 +254,8 @@ static int bridge_parking_push(struct ast_bridge_parking *self, struct ast_bridg
                                ast_channel_name(bridge_channel->chan));
                }
 
+               publish_parked_call(pu, PARKED_CALL_SWAP);
+
                return 0;
        }
 
index 65a9ef0..f952ff2 100644 (file)
@@ -526,6 +526,9 @@ static void parked_call_message_response(struct ast_parked_call_payload *parked_
        case PARKED_CALL_UNPARKED:
                event_type = "UnParkedCall";
                break;
+       case PARKED_CALL_SWAP:
+               event_type = "ParkedCallSwap";
+               break;
        case PARKED_CALL_FAILED:
                /* PARKED_CALL_FAILED doesn't currently get a message and is used exclusively for bridging */
                return;