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

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


Author: kmoore
Date: Wed Jun 12 15:22:30 2013
New Revision: 391558

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=391558
Log:
Refactor AlarmClear and SpanAlarmClear in chan_dahdi and sig_analog

Added:
    team/kmoore/channel_event_refactor/channels/chan_dahdi.h   (with props)
Modified:
    team/kmoore/channel_event_refactor/channels/chan_dahdi.c
    team/kmoore/channel_event_refactor/channels/sig_analog.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=391558&r1=391557&r2=391558
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_dahdi.c (original)
+++ team/kmoore/channel_event_refactor/channels/chan_dahdi.c Wed Jun 12 15:22:30 2013
@@ -69,6 +69,7 @@
 
 #include <dahdi/user.h>
 #include <dahdi/tonezone.h>
+#include "chan_dahdi.h"
 #include "sig_analog.h"
 /* Analog signaling is currently still present in chan_dahdi for use with
  * radio. Sig_analog does not currently handle any radio operations. If
@@ -297,6 +298,26 @@
 			<para>Similar to the CLI command "pri show spans".</para>
 		</description>
 	</manager>
+	<managerEvent language="en_US" name="AlarmClear">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when an alarm is cleared on a DAHDI channel.</synopsis>
+			<syntax>
+				<parameter name="Channel">
+					<para>The channel on which the alarm was cleared.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
+	<managerEvent language="en_US" name="SpanAlarmClear">
+		<managerEventInstance class="EVENT_FLAG_SYSTEM">
+			<synopsis>Raised when an alarm is cleared on a DAHDI span.</synopsis>
+			<syntax>
+				<parameter name="Span">
+					<para>The span on which the alarm was cleared.</para>
+				</parameter>
+			</syntax>
+		</managerEventInstance>
+	</managerEvent>
  ***/
 
 #define SMDI_MD_WAIT_TIMEOUT 1500 /* 1.5 seconds */
@@ -3957,6 +3978,66 @@
 	}
 }
 
+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);
+
+	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_CALL,
+		"event",
+			"Channel", channel);
+
+	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_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_CALL,
+		"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);
+}
+
 static void handle_clear_alarms(struct dahdi_pvt *p)
 {
 #if defined(HAVE_PRI)
@@ -3966,22 +4047,10 @@
 #endif	/* defined(HAVE_PRI) */
 
 	if (report_alarms & REPORT_CHANNEL_ALARMS) {
-		ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when an alarm is cleared on a DAHDI channel.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_SYSTEM, "AlarmClear", "Channel: %d\r\n", p->channel);
+		dahdi_publish_channel_alarm_clear(p->channel);
 	}
 	if (report_alarms & REPORT_SPAN_ALARMS && p->manages_span_alarms) {
-		ast_log(LOG_NOTICE, "Alarm cleared on span %d\n", p->span);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when an alarm is cleared on a DAHDI span.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_SYSTEM, "SpanAlarmClear", "Span: %d\r\n", p->span);
+		publish_span_alarm_clear(p->span);
 	}
 }
 

Added: team/kmoore/channel_event_refactor/channels/chan_dahdi.h
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/chan_dahdi.h?view=auto&rev=391558
==============================================================================
--- team/kmoore/channel_event_refactor/channels/chan_dahdi.h (added)
+++ team/kmoore/channel_event_refactor/channels/chan_dahdi.h Wed Jun 12 15:22:30 2013
@@ -1,0 +1,30 @@
+#ifndef _CHAN_DAHDI_H
+#define _CHAN_DAHDI_H
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Kinsey Moore <kmoore at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+/*! \file
+ *
+ * \brief Interface header for chan_dahdi
+ *
+ * \author Kinsey Moore <kmoore at digium.com>
+ */
+
+void dahdi_publish_channel_alarm_clear(int channel);
+
+#endif /* _CHAN_DAHDI_H */

Propchange: team/kmoore/channel_event_refactor/channels/chan_dahdi.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/kmoore/channel_event_refactor/channels/chan_dahdi.h
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/kmoore/channel_event_refactor/channels/chan_dahdi.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/kmoore/channel_event_refactor/channels/sig_analog.c
URL: http://svnview.digium.com/svn/asterisk/team/kmoore/channel_event_refactor/channels/sig_analog.c?view=diff&rev=391558&r1=391557&r2=391558
==============================================================================
--- team/kmoore/channel_event_refactor/channels/sig_analog.c (original)
+++ team/kmoore/channel_event_refactor/channels/sig_analog.c Wed Jun 12 15:22:30 2013
@@ -47,6 +47,7 @@
 #include "asterisk/bridging.h"
 
 #include "sig_analog.h"
+#include "chan_dahdi.h"
 
 /*** DOCUMENTATION
  ***/
@@ -3086,14 +3087,7 @@
 		break;
 	case ANALOG_EVENT_NOALARM:
 		analog_set_alarm(p, 0);
-		ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", p->channel);
-		/*** DOCUMENTATION
-			<managerEventInstance>
-				<synopsis>Raised when an Alarm is cleared on an Analog channel.</synopsis>
-			</managerEventInstance>
-		***/
-		manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
-			"Channel: %d\r\n", p->channel);
+		dahdi_publish_channel_alarm_clear(p->channel);
 		break;
 	case ANALOG_EVENT_WINKFLASH:
 		if (p->inalarm) {
@@ -3735,9 +3729,7 @@
 		break;
 	case ANALOG_EVENT_NOALARM:
 		analog_set_alarm(i, 0);
-		ast_log(LOG_NOTICE, "Alarm cleared on channel %d\n", i->channel);
-		manager_event(EVENT_FLAG_SYSTEM, "AlarmClear",
-			"Channel: %d\r\n", i->channel);
+		dahdi_publish_channel_alarm_clear(i->channel);
 		break;
 	case ANALOG_EVENT_ALARM:
 		analog_set_alarm(i, 1);




More information about the asterisk-commits mailing list