[asterisk-commits] kmoore: branch kmoore/channel_event_refactor r391899 - /team/kmoore/channel_e...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 14 16:33:20 CDT 2013


Author: kmoore
Date: Fri Jun 14 16:33:18 2013
New Revision: 391899

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391899
Log:
Simplify event publishing using ast_manager_publish_event

Modified:
    team/kmoore/channel_event_refactor/channels/chan_dahdi.c
    team/kmoore/channel_event_refactor/channels/chan_sip.c

Modified: team/kmoore/channel_event_refactor/channels/chan_dahdi.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_dahdi.c?view=diff&rev=391899&r1=391898&r2=391899
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_dahdi.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_dahdi.c Fri Jun 14 16:33:18 2013
@@ -4068,62 +4068,28 @@
 
 void dahdi_publish_channel_alarm_clear(int channel)
 {
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 
 	ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
-	json_object = ast_json_pack("{s: s, s: i, s: {s: i}}",
-		"type", "AlarmClear",
-		"class_type", EVENT_FLAG_SYSTEM,
-		"event",
-			"Channel", channel);
-
-	if (!json_object) {
+	body = ast_json_pack("{s: i}", "Channel", channel);
+	if (!body) {
 		return;
 	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
+	
+	ast_manager_publish_event("AlarmClear", EVENT_FLAG_SYSTEM, body);
+}
+
+static void publish_span_alarm_clear(int span)
+{
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+
+	ast_log(LOG_NOTICE, "Alarm cleared on span %d\n", span);
+	body = ast_json_pack("{s: i}", "Span", span);
+	if (!body) {
 		return;
 	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
-}
-
-static void publish_span_alarm_clear(int span)
-{
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
-
-	ast_log(LOG_NOTICE, "Alarm cleared on span %d\n", span);
-	json_object = ast_json_pack("{s: s, s: i, s: {s: i}}",
-		"type", "SpanAlarmClear",
-		"class_type", EVENT_FLAG_SYSTEM,
-		"event",
-			"Span", span);
-
-	if (!json_object) {
-		return;
-	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
-		return;
-	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
+	
+	ast_manager_publish_event("SpanAlarmClear", EVENT_FLAG_SYSTEM, body);
 }
 
 static void handle_clear_alarms(struct dahdi_pvt *p)
@@ -8197,62 +8163,30 @@
 
 static void publish_span_alarm(int span, const char *alarm_txt)
 {
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
-
-	json_object = ast_json_pack("{s: s, s: i, s: {s: i, s: s}}",
-		"type", "SpanAlarm",
-		"class_type", EVENT_FLAG_SYSTEM,
-		"event",
-			"Span", span,
-			"Alarm", alarm_txt);
-
-	if (!json_object) {
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+
+	body = ast_json_pack("{s: i, s: s}",
+		"Span", span,
+		"Alarm", alarm_txt);
+	if (!body) {
 		return;
 	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
+	
+	ast_manager_publish_event("SpanAlarm", EVENT_FLAG_SYSTEM, body);
+}
+
+static void publish_channel_alarm(int channel, const char *alarm_txt)
+{
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
+
+	body = ast_json_pack("{s: i, s: s}",
+		"Channel", channel,
+		"Alarm", alarm_txt);
+	if (!body) {
 		return;
 	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
-}
-
-static void publish_channel_alarm(int channel, const char *alarm_txt)
-{
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
-
-	json_object = ast_json_pack("{s: s, s: i, s: {s: i, s: s}}",
-		"type", "Alarm",
-		"class_type", EVENT_FLAG_SYSTEM,
-		"event",
-			"Channel", channel,
-			"Alarm", alarm_txt);
-
-	if (!json_object) {
-		return;
-	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
-		return;
-	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
+	
+	ast_manager_publish_event("Alarm", EVENT_FLAG_SYSTEM, body);
 }
 
 static void handle_alarms(struct dahdi_pvt *p, int alms)
@@ -10287,36 +10221,23 @@
 
 void dahdi_publish_dnd_state(int channel, const char *status)
 {
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 	RAII_VAR(struct ast_str *, dahdichan, ast_str_create(32), ast_free);
+	if (!dahdichan) {
+		return;
+	}
 
 	ast_str_set(&dahdichan, 0, "DAHDI/%d", channel);
 
 	ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", channel);
-	json_object = ast_json_pack("{s: s, s: i, s: {s: s, s: s}}",
-		"type", "DNDState",
-		"class_type", EVENT_FLAG_SYSTEM,
-		"event",
-			"Channel", ast_str_buffer(dahdichan),
-			"Status", status);
-
-	if (!json_object) {
+	body = ast_json_pack("{s: s, s: s}",
+		"Channel", ast_str_buffer(dahdichan),
+		"Status", status);
+	if (!body) {
 		return;
 	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
-		return;
-	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
+	
+	ast_manager_publish_event("DNDState", EVENT_FLAG_SYSTEM, body);
 }
 
 /*! \brief enable or disable the chan_dahdi Do-Not-Disturb mode for a DAHDI channel

Modified: team/kmoore/channel_event_refactor/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_sip.c?view=diff&rev=391899&r1=391898&r2=391899
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_sip.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_sip.c Fri Jun 14 16:33:18 2013
@@ -20062,40 +20062,18 @@
 
 static void publish_qualify_peer_done(const char *id, const char *peer)
 {
-	RAII_VAR(struct stasis_message *, message, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json_payload *, payload, NULL, ao2_cleanup);
-	RAII_VAR(struct ast_json *, json_object, NULL, ast_json_unref);
+	RAII_VAR(struct ast_json *, body, NULL, ast_json_unref);
 
 	if (ast_strlen_zero(id)) {
-		json_object = ast_json_pack("{s: s, s: i, s: {s: s}}",
-			"type", "SIPQualifyPeerDone",
-			"class_type", EVENT_FLAG_CALL,
-			"event",
-				"Peer", peer);
+		body = ast_json_pack("{s: s}", "Peer", peer);
 	} else {
-		json_object = ast_json_pack("{s: s, s: i, s: {s: s, s: s}}",
-			"type", "SIPQualifyPeerDone",
-			"class_type", EVENT_FLAG_CALL,
-			"event",
-				"ActionID", id,
-				"Peer", peer);
-	}
-
-	if (!json_object) {
+		body = ast_json_pack("{s: s, s: s}", "Peer", peer, "ActionID", id);
+	}
+	if (!body) {
 		return;
 	}
-
-	payload = ast_json_payload_create(json_object);
-	if (!payload) {
-		return;
-	}
-
-	message = stasis_message_create(ast_manager_get_generic_type(), payload);
-	if (!message) {
-		return;
-	}
-
-	stasis_publish(ast_manager_get_topic(), message);
+	
+	ast_manager_publish_event("SIPQualifyPeerDone", EVENT_FLAG_CALL, body);
 }
 
 /*! \brief Send qualify message to peer from cli or manager. Mostly for debugging. */




More information about the asterisk-commits mailing list