[asterisk-commits] mmichelson: branch mmichelson/transfer_stasis r390938 - in /team/mmichelson/t...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 7 18:04:56 CDT 2013


Author: mmichelson
Date: Fri Jun  7 18:04:54 2013
New Revision: 390938

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390938
Log:
Tiptoe into the stasis pool by creating a blind transfer message type and method of publishing it.

The API for publishing a blind transfer is fine, but the actual message type on the backend will likely
change once attended transfers are added.


Modified:
    team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h
    team/mmichelson/transfer_stasis/main/stasis_bridging.c

Modified: team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h?view=diff&rev=390938&r1=390937&r2=390938
==============================================================================
--- team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h (original)
+++ team/mmichelson/transfer_stasis/include/asterisk/stasis_bridging.h Fri Jun  7 18:04:54 2013
@@ -207,6 +207,48 @@
 struct ast_json *ast_bridge_snapshot_to_json(const struct ast_bridge_snapshot *snapshot);
 
 /*!
+ * \brief Message representing blind transfer
+ */
+struct ast_blind_transfer_message {
+	AST_DECLARE_STRING_FIELDS(
+		/*! The destination context for the blind transfer */
+		AST_STRING_FIELD(context);
+		/*! The destination extension for the blind transfer */
+		AST_STRING_FIELD(exten);
+	);
+	/*! Result of the blind transfer */
+	enum ast_transfer_result result;
+	/*! If 0, was core DTMF transfer, otherwise was a native transfer */
+	int is_native;
+	/*! The bridge between the transferer and the transferee(s). May be NULL */
+	struct ast_bridge_snapshot *original_bridge;
+	/*! The channel that performed the transfer */
+	struct ast_channel_snapshot *transferer;
+};
+
+/*!
+ * \since 12
+ * \brief Message type for \ref ast_blind_transfer_message.
+ *
+ * \retval Message type for \ref ast_blind_transfer_message.
+ */
+struct stasis_message_type *ast_blind_transfer_type(void);
+
+/*!
+ * \brief Publish a blind transfer event
+ *
+ * \param is_native Whether the blind transfer is a native blind transfer
+ * \param result The success or failure of the transfer
+ * \param transferer The channel performing the transfer
+ * \param original_bridge The bridge between the transferer and transferee channels
+ * \param context The destination context for the blind transfer
+ * \param exten The destination extension for the blind transfer
+ */
+void ast_bridge_publish_blind_transfer(int is_native, enum ast_transfer_result result,
+		struct ast_channel *transferer, struct ast_bridge *original_bridge,
+		const char *context, const char *exten);
+
+/*!
  * \brief Initialize the stasis bridging topic and message types
  * \retval 0 on success
  * \retval -1 on failure

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=390938&r1=390937&r2=390938
==============================================================================
--- team/mmichelson/transfer_stasis/main/stasis_bridging.c (original)
+++ team/mmichelson/transfer_stasis/main/stasis_bridging.c Fri Jun  7 18:04:54 2013
@@ -48,6 +48,7 @@
 STASIS_MESSAGE_TYPE_DEFN(ast_bridge_merge_message_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_entered_bridge_type);
 STASIS_MESSAGE_TYPE_DEFN(ast_channel_left_bridge_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_blind_transfer_type);
 /*! @} */
 
 /*! \brief Aggregate topic for bridge messages */
@@ -310,6 +311,67 @@
 	return ast_json_ref(json_chan);
 }
 
+static void blind_transfer_dtor(void *obj)
+{
+	struct ast_blind_transfer_message *msg = obj;
+
+	ast_string_field_free_memory(msg);
+	ao2_cleanup(msg->original_bridge);
+	ao2_cleanup(msg->transferer);
+}
+
+static struct ast_blind_transfer_message *blind_transfer_message_create(int is_native,
+		enum ast_transfer_result result, struct ast_channel *transferer,
+		struct ast_bridge *original_bridge, 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 (original_bridge) {
+		msg->original_bridge = ast_bridge_snapshot_create(original_bridge);
+		if (!msg->original_bridge) {
+			return NULL;
+		}
+	}
+
+	msg->transferer = ast_channel_snapshot_create(transferer);
+	if (!msg->transferer) {
+		return NULL;
+	}
+
+	ast_string_field_set(msg, context, context);
+	ast_string_field_set(msg, exten, exten);
+	msg->is_native = is_native;
+	msg->result = result;
+
+	ao2_ref(msg, +1);
+	return msg;
+}
+
+void ast_bridge_publish_blind_transfer(int is_native, enum ast_transfer_result result,
+		struct ast_channel *transferer, struct ast_bridge *original_bridge,
+		const char *context, const char *exten)
+{
+	RAII_VAR(struct ast_blind_transfer_message *, transfer_msg, NULL, ao2_cleanup);
+	RAII_VAR(struct stasis_message *, msg, NULL, ao2_cleanup);
+
+	transfer_msg = blind_transfer_message_create(is_native, result, transferer, original_bridge, context, exten);
+	if (!transfer_msg) {
+		return;
+	}
+
+	msg = stasis_message_create(ast_blind_transfer_type(), transfer_msg);
+	if (!msg) {
+		return;
+	}
+
+	stasis_publish(ast_bridge_topic_all(), msg);
+}
+
 static void stasis_bridging_cleanup(void)
 {
 	ao2_cleanup(bridge_topic_all);
@@ -323,6 +385,7 @@
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_bridge_merge_message_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_entered_bridge_type);
 	STASIS_MESSAGE_TYPE_CLEANUP(ast_channel_left_bridge_type);
+	STASIS_MESSAGE_TYPE_CLEANUP(ast_blind_transfer_type);
 }
 
 /*! \brief snapshot ID getter for caching topic */
@@ -344,6 +407,7 @@
 	STASIS_MESSAGE_TYPE_INIT(ast_bridge_merge_message_type);
 	STASIS_MESSAGE_TYPE_INIT(ast_channel_entered_bridge_type);
 	STASIS_MESSAGE_TYPE_INIT(ast_channel_left_bridge_type);
+	STASIS_MESSAGE_TYPE_INIT(ast_blind_transfer_type);
 	bridge_topic_all = stasis_topic_create("ast_bridge_topic_all");
 	bridge_topic_all_cached = stasis_caching_topic_create(bridge_topic_all, bridge_snapshot_get_id);
 	bridge_topic_pool = stasis_topic_pool_create(bridge_topic_all);




More information about the asterisk-commits mailing list