[asterisk-commits] dlee: branch dlee/stasis-vtable r390177 - /team/dlee/stasis-vtable/main/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 30 22:12:14 CDT 2013


Author: dlee
Date: Thu May 30 22:12:12 2013
New Revision: 390177

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=390177
Log:
Refactor VarSet message to use the .to_ami virtual function

Modified:
    team/dlee/stasis-vtable/main/manager_channels.c
    team/dlee/stasis-vtable/main/stasis_channels.c

Modified: team/dlee/stasis-vtable/main/manager_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/main/manager_channels.c?view=diff&rev=390177&r1=390176&r2=390177
==============================================================================
--- team/dlee/stasis-vtable/main/manager_channels.c (original)
+++ team/dlee/stasis-vtable/main/manager_channels.c Thu May 30 22:12:12 2013
@@ -710,49 +710,6 @@
 	}
 }
 
-static void channel_varset_cb(void *data, struct stasis_subscription *sub,
-	struct stasis_topic *topic, struct stasis_message *message)
-{
-	struct ast_channel_blob *obj = stasis_message_data(message);
-	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
-	const char *variable = ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
-	const char *value = ast_json_string_get(ast_json_object_get(obj->blob, "value"));
-
-	if (obj->snapshot) {
-		channel_event_string = ast_manager_build_channel_state_string(obj->snapshot);
-	} else {
-		channel_event_string = ast_str_create(35);
-		ast_str_set(&channel_event_string, 0,
-			    "Channel: none\r\n"
-			    "Uniqueid: none\r\n");
-	}
-
-	if (!channel_event_string) {
-		return;
-	}
-
-	/*** DOCUMENTATION
-		<managerEventInstance>
-			<synopsis>Raised when a variable is set to a particular value.</synopsis>
-			<syntax>
-				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
-				<parameter name="Variable">
-					<para>The variable being set.</para>
-				</parameter>
-				<parameter name="Value">
-					<para>The new value of the variable.</para>
-				</parameter>
-			</syntax>
-		</managerEventInstance>
-	***/
-	manager_event(EVENT_FLAG_DIALPLAN, "VarSet",
-		      "%s"
-		      "Variable: %s\r\n"
-		      "Value: %s\r\n",
-		      ast_str_buffer(channel_event_string),
-		      variable, value);
-}
-
 static int userevent_exclusion_cb(const char *key)
 {
 	if (!strcmp("type", key)) {
@@ -1280,11 +1237,6 @@
 					 NULL);
 
 	ret |= stasis_message_router_add(message_router,
-					 ast_channel_varset_type(),
-					 channel_varset_cb,
-					 NULL);
-
-	ret |= stasis_message_router_add(message_router,
 					 ast_channel_user_event_type(),
 					 channel_user_event_cb,
 					 NULL);

Modified: team/dlee/stasis-vtable/main/stasis_channels.c
URL: http://svnview.digium.com/svn/asterisk/team/dlee/stasis-vtable/main/stasis_channels.c?view=diff&rev=390177&r1=390176&r2=390177
==============================================================================
--- team/dlee/stasis-vtable/main/stasis_channels.c (original)
+++ team/dlee/stasis-vtable/main/stasis_channels.c Thu May 30 22:12:12 2013
@@ -36,29 +36,24 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/stasis_channels.h"
 
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="VarSet">
+		<managerEventInstance class="EVENT_FLAG_DIALPLAN">
+			<synopsis>Raised when a variable is set to a particular value.</synopsis>
+			<syntax>
+				<xi:include xpointer="xpointer(/docs/managerEvent[@name='Newchannel']/managerEventInstance/syntax/parameter)" />
+				<parameter name="Variable">
+					<para>The variable being set.</para>
+				</parameter>
+				<parameter name="Value">
+					<para>The new value of the variable.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+***/
+
 #define NUM_MULTI_CHANNEL_BLOB_BUCKETS 7
-
-/*!
- * @{ \brief Define channel message types.
- */
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_snapshot_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_dial_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_varset_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_user_event_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_handler_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_start_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_stop_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_start_type);
-STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_stop_type);
-/*! @} */
 
 /*! \brief Topic for all channels */
 struct stasis_topic *channel_topic_all;
@@ -487,6 +482,39 @@
 	}
 
 	publish_message_for_channel_topics(msg, chan);
+}
+
+static struct ast_manager_event_blob *varset_to_ami(struct stasis_message *msg)
+{
+	RAII_VAR(struct ast_manager_event_blob *, ev, NULL, ao2_cleanup);
+	RAII_VAR(struct ast_str *, channel_event_string, NULL, ast_free);
+	struct ast_channel_blob *obj = stasis_message_data(msg);
+	const char *variable =
+		ast_json_string_get(ast_json_object_get(obj->blob, "variable"));
+	const char *value =
+		ast_json_string_get(ast_json_object_get(obj->blob, "value"));
+
+	if (obj->snapshot) {
+		channel_event_string =
+			ast_manager_build_channel_state_string(obj->snapshot);
+	} else {
+		channel_event_string = ast_str_create(35);
+		ast_str_set(&channel_event_string, 0,
+			    "Channel: none\r\n"
+			    "Uniqueid: none\r\n");
+	}
+
+	if (!channel_event_string) {
+		return NULL;
+	}
+
+	ev = ast_manager_event_blob_create(EVENT_FLAG_DIALPLAN, "VarSet",
+		"%s"
+		"Variable: %s\r\n"
+		"Value: %s\r\n",
+		ast_str_buffer(channel_event_string), variable, value);
+
+	return ao2_ref1(ev);
 }
 
 void ast_publish_channel_state(struct ast_channel *chan)
@@ -574,6 +602,31 @@
 	return strcmp(old_snapshot->caller_number, new_snapshot->caller_number) == 0 &&
 		strcmp(old_snapshot->caller_name, new_snapshot->caller_name) == 0;
 }
+
+/*!
+ * @{ \brief Define channel message types.
+ */
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_snapshot_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_dial_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_varset_type,
+	.to_ami = varset_to_ami,
+	);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_user_event_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_request_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_begin_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_dtmf_end_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_hold_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_unhold_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_start_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_chanspy_stop_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_fax_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_hangup_handler_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_start_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_moh_stop_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_start_type);
+STASIS_MESSAGE_TYPE_DEFN(ast_channel_monitor_stop_type);
+
+/*! @} */
 
 static void stasis_channels_cleanup(void)
 {




More information about the asterisk-commits mailing list