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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jun 12 22:56:31 CDT 2013


Author: kmoore
Date: Wed Jun 12 22:56:29 2013
New Revision: 391594

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391594
Log:
Refactor and document Alarm and SpanAlarm

Modified:
    team/kmoore/channel_event_refactor/channels/chan_dahdi.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=391594&r1=391593&r2=391594
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_dahdi.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_dahdi.c Wed Jun 12 22:56:29 2013
@@ -330,6 +330,32 @@
 						<enum name="enabled"/>
 						<enum name="disabled"/>
 					</enumlist>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="Alarm">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when an alarm is set on a DAHDI channel.</synopsis>
+			<syntax>
+				<parameter name="Channel">
+					<para>The channel on which the alarm occurred.</para>
+				</parameter>
+				<parameter name="Alarm">
+					<para>A textual description of the alarm that occurred.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="SpanAlarm">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when an alarm is set on a DAHDI span.</synopsis>
+			<syntax>
+				<parameter name="Span">
+					<para>The span on which the alarm occurred.</para>
+				</parameter>
+				<parameter name="Alarm">
+					<para>A textual description of the alarm that occurred.</para>
 				</parameter>
 			</syntax>
 		</managerEventInstance>
@@ -4033,7 +4059,7 @@
 	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_CALL,
+		"class_type", EVENT_FLAG_SYSTEM,
 		"event",
 			"Span", span);
 
@@ -8123,6 +8149,66 @@
 	}
 }
 
+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) {
+		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);
+}
+
+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);
+}
+
 static void handle_alarms(struct dahdi_pvt *p, int alms)
 {
 	const char *alarm_str;
@@ -8136,28 +8222,12 @@
 	alarm_str = alarm2str(alms);
 	if (report_alarms & REPORT_CHANNEL_ALARMS) {
 		ast_log(LOG_WARNING, "Detected alarm on channel %d: %s\n", p->channel, alarm_str);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when an alarm is set on a DAHDI channel.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_SYSTEM, "Alarm",
-					  "Alarm: %s\r\n"
-					  "Channel: %d\r\n",
-					  alarm_str, p->channel);
+		publish_channel_alarm(p->channel, alarm_str);
 	}
 
 	if (report_alarms & REPORT_SPAN_ALARMS && p->manages_span_alarms) {
 		ast_log(LOG_WARNING, "Detected alarm on span %d: %s\n", p->span, alarm_str);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when an alarm is set on a DAHDI span.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_SYSTEM, "SpanAlarm",
-					  "Alarm: %s\r\n"
-					  "Span: %d\r\n",
-					  alarm_str, p->span);
+		publish_span_alarm(p->span, alarm_str);
 	}
 }
 




More information about the asterisk-commits mailing list