[asterisk-commits] mmichelson: branch mmichelson/transfer_stasis r392724 - /team/mmichelson/tran...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jun 24 11:20:56 CDT 2013


Author: mmichelson
Date: Mon Jun 24 11:20:54 2013
New Revision: 392724

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=392724
Log:
Switch the blind transfer message to using a bridge blob.


Modified:
    team/mmichelson/transfer_stasis/main/stasis_bridging.c

Modified: team/mmichelson/transfer_stasis/main/stasis_bridging.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/main/stasis_bridging.c?view=diff&rev=392724&r1=392723&r2=392724
==============================================================================
--- team/mmichelson/transfer_stasis/main/stasis_bridging.c (original)
+++ team/mmichelson/transfer_stasis/main/stasis_bridging.c Mon Jun 24 11:20:54 2013
@@ -714,14 +714,27 @@
 {
 	RAII_VAR(struct ast_str *, channel_state, NULL, ast_free_ptr);
 	RAII_VAR(struct ast_str *, bridge_state, NULL, ast_free_ptr);
-	struct ast_blind_transfer_message * transfer_msg = stasis_message_data(msg);
-
-	channel_state = ast_manager_build_channel_state_string_prefix(transfer_msg->transferer.channel_snapshot, "Transferer");
-	bridge_state = ast_manager_build_bridge_state_string(transfer_msg->transferer.bridge_snapshot, "");
+	struct ast_bridge_blob *blob = stasis_message_data(msg);
+	const char *exten;
+	const char *context;
+	enum ast_transfer_result result;
+	int is_external;
+
+	if (!blob) {
+		return NULL;
+	}
+
+	channel_state = ast_manager_build_channel_state_string_prefix(blob->channel, "Transferer");
+	bridge_state = ast_manager_build_bridge_state_string(blob->bridge, "");
 
 	if (!channel_state || !bridge_state) {
 		return NULL;
 	}
+
+	exten = ast_json_string_get(ast_json_object_get(blob->blob, "exten"));
+	context = ast_json_string_get(ast_json_object_get(blob->blob, "context"));
+	result = ast_json_integer_get(ast_json_object_get(blob->blob, "result"));
+	is_external = ast_json_integer_get(ast_json_object_get(blob->blob, "is_external"));
 
 	return ast_manager_event_blob_create(EVENT_FLAG_CALL, "BlindTransfer",
 			"Result: %s\r\n"
@@ -730,59 +743,33 @@
 			"IsExternal: %s\r\n"
 			"Context: %s\r\n"
 			"Extension: %s\r\n",
-			result_strs[transfer_msg->result],
+			result_strs[result],
 			ast_str_buffer(channel_state),
 			ast_str_buffer(bridge_state),
-			transfer_msg->is_external ? "Yes" : "No",
-			transfer_msg->context,
-			transfer_msg->exten);
-}
-
-static void blind_transfer_dtor(void *obj)
-{
-	struct ast_blind_transfer_message *msg = obj;
-
-	ast_string_field_free_memory(msg);
-	bridge_channel_snapshot_pair_cleanup(&msg->transferer);
-}
-
-static struct ast_blind_transfer_message *blind_transfer_message_create(int is_external,
-		enum ast_transfer_result result, struct ast_bridge_channel_pair *transferer,
-		const char *context, const char *exten)
-{
-	RAII_VAR(struct ast_blind_transfer_message *, msg, NULL, ao2_cleanup);
-
-	msg = ao2_alloc(sizeof(*msg), blind_transfer_dtor);
-	if (!msg || ast_string_field_init(msg, 32)) {
-		return NULL;
-	}
-
-	if (bridge_channel_snapshot_pair_init(transferer, &msg->transferer)) {
-		return NULL;
-	}
-
-	ast_string_field_set(msg, context, context);
-	ast_string_field_set(msg, exten, exten);
-	msg->is_external = is_external;
-	msg->result = result;
-
-	ao2_ref(msg, +1);
-	return msg;
+			is_external ? "Yes" : "No",
+			context,
+			exten);
 }
 
 void ast_bridge_publish_blind_transfer(int is_external, enum ast_transfer_result result,
 		struct ast_bridge_channel_pair *transferer, const char *context, const char *exten)
 {
-	RAII_VAR(struct ast_blind_transfer_message *, transfer_msg, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
 	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
 
-	transfer_msg = blind_transfer_message_create(is_external, result, transferer, context, exten);
-	if (!transfer_msg) {
-		return;
-	}
-
-	msg = stasis_message_create(ast_blind_transfer_type(), transfer_msg);
-	if (!msg) {
+	json_object = ast_json_pack("{s: s, s: s, s: i, s: i}",
+			"context", context, "exten", exten, "result", result, "is_external", is_external);
+
+	if (!json_object) {
+		ast_log(LOG_NOTICE, "Failed to create json bridge blob\n");
+		return;
+	}
+
+	msg = ast_bridge_blob_create(ast_blind_transfer_type(),
+			transferer->bridge, transferer->channel, json_object);
+
+	if (!msg) {
+		ast_log(LOG_NOTICE, "Failed to create blob msg\n");
 		return;
 	}
 
@@ -1055,20 +1042,20 @@
 static void transfer_cb(void *userdata, struct stasis_subscription *sub,
 		struct stasis_topic *topic, struct stasis_message *msg)
 {
-	struct ast_blind_transfer_message *xfer_msg;
+	struct ast_bridge_blob *blob;
 
 	if (ast_blind_transfer_type() != stasis_message_type(msg)) {
 		/* Don't care about other types of messages for now */
 		return;
 	}
 
-	xfer_msg = stasis_message_data(msg);
-
-	ast_log(LOG_NOTICE, "Blind transfer to %s@%s by %s\n", xfer_msg->exten,
-			xfer_msg->context, xfer_msg->transferer.channel_snapshot->name);
-	if (xfer_msg->result == AST_TRANSFER_SUCCESS) {
+	blob = stasis_message_data(msg);
+
+	ast_log(LOG_NOTICE, "Blind transfer to %s@%s by %s\n", ast_json_string_get(ast_json_object_get(blob->blob, "exten")),
+			ast_json_string_get(ast_json_object_get(blob->blob, "context")), blob->channel->name);
+	if (ast_json_integer_get(ast_json_object_get(blob->blob, "result")) == AST_TRANSFER_SUCCESS) {
 		ast_log(LOG_NOTICE, "Transfer from bridge %s was successful\n",
-				xfer_msg->transferer.bridge_snapshot->uniqueid);
+				blob->bridge->uniqueid);
 	} else {
 		ast_log(LOG_NOTICE, "Transfer was unsuccessful\n");
 	}




More information about the asterisk-commits mailing list