[asterisk-commits] mmichelson: trunk r413060 - in /trunk: ./ main/ res/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Apr 28 09:40:31 CDT 2014


Author: mmichelson
Date: Mon Apr 28 09:40:21 2014
New Revision: 413060

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413060
Log:
Add DeviceStateChanged and PresenceStateChanged AMI events.

These events are controlled by two new modules, res_manager_devicestate
and res_manager_presencestate.

Review: https://reviewboard.asterisk.org/r/3417


Added:
    trunk/res/res_manager_devicestate.c   (with props)
    trunk/res/res_manager_presencestate.c   (with props)
Modified:
    trunk/CHANGES
    trunk/main/devicestate.c
    trunk/main/presencestate.c

Modified: trunk/CHANGES
URL: http://svnview.digium.com/svn/asterisk/trunk/CHANGES?view=diff&rev=413060&r1=413059&r2=413060
==============================================================================
--- trunk/CHANGES (original)
+++ trunk/CHANGES Mon Apr 28 09:40:21 2014
@@ -11,6 +11,14 @@
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 12 to Asterisk 13 --------------------
 ------------------------------------------------------------------------------
+
+AMI
+------------------
+ * New DeviceStateChanged and PresenceStateChanged AMI events have been added.
+   These events are emitted whenever a device state or presence state change
+   occurs. The events are controlled by res_manager_device_state.so and
+   res_manager_presence_state.so. If the high frequency of these events is
+   problematic for you, do not load these modules.
 
 ------------------------------------------------------------------------------
 --- Functionality changes from Asterisk 12.2.0 to Asterisk 12.3.0 ------------

Modified: trunk/main/devicestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/devicestate.c?view=diff&rev=413060&r1=413059&r2=413060
==============================================================================
--- trunk/main/devicestate.c (original)
+++ trunk/main/devicestate.c Mon Apr 28 09:40:21 2014
@@ -116,6 +116,30 @@
 /*** MODULEINFO
 	<support_level>core</support_level>
  ***/
+
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="DeviceStateChange">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+			<synopsis>Raised when a device state changes</synopsis>
+			<syntax>
+				<parameter name="Device">
+					<para>The device whose state has changed</para>
+				</parameter>
+				<parameter name="State">
+					<para>The new state of the device</para>
+				</parameter>
+			</syntax>
+			<description>
+				<para>This differs from the <literal>ExtensionStatus</literal>
+				event because this event is raised for all device state changes,
+				not only for changes that affect dialplan hints.</para>
+			</description>
+			<see-also>
+				<ref type="managerEvent">ExtensionStatus</ref>
+			</see-also>
+		</managerEventInstance>
+	</managerEvent>
+***/
 
 #include "asterisk.h"
 
@@ -199,7 +223,11 @@
 static struct stasis_caching_topic *device_state_topic_cached;
 static struct stasis_topic_pool *device_state_topic_pool;
 
-STASIS_MESSAGE_TYPE_DEFN(ast_device_state_message_type);
+static struct ast_manager_event_blob *devstate_to_ami(struct stasis_message *msg);
+
+STASIS_MESSAGE_TYPE_DEFN(ast_device_state_message_type,
+	.to_ami = devstate_to_ami,
+);
 
 /* Forward declarations */
 static int getproviderstate(const char *provider, const char *address);
@@ -880,3 +908,20 @@
 
 	return 0;
 }
+
+static struct ast_manager_event_blob *devstate_to_ami(struct stasis_message *msg)
+{
+	struct ast_device_state_message *dev_state;
+
+	dev_state = stasis_message_data(msg);
+
+	/* Ignore non-aggregate states */
+	if (dev_state->eid) {
+		return NULL;
+	}
+
+	return ast_manager_event_blob_create(EVENT_FLAG_CALL, "DeviceStateChange",
+		"Device: %s\r\n"
+		"State: %s\r\n",
+		dev_state->device, ast_devstate_str(dev_state->state));
+}

Modified: trunk/main/presencestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/presencestate.c?view=diff&rev=413060&r1=413059&r2=413060
==============================================================================
--- trunk/main/presencestate.c (original)
+++ trunk/main/presencestate.c Mon Apr 28 09:40:21 2014
@@ -25,6 +25,36 @@
 	<support_level>core</support_level>
  ***/
 
+/*** DOCUMENTATION
+	<managerEvent language="en_US" name="PresenceStateChange">
+		<managerEventInstance class="EVENT_FLAG_CALL">
+			<synopsis>Raised when a presence state changes</synopsis>
+			<syntax>
+				<parameter name="Presentity">
+					<para>The entity whose presence state has changed</para>
+				</parameter>
+				<parameter name="Status">
+					<para>The new status of the presentity</para>
+				</parameter>
+				<parameter name="Subtype">
+					<para>The new subtype of the presentity</para>
+				</parameter>
+				<parameter name="Message">
+					<para>The new message of the presentity</para>
+				</parameter>
+			</syntax>
+			<description>
+				<para>This differs from the <literal>PresenceStatus</literal>
+				event because this event is raised for all presence state changes,
+				not only for changes that affect dialplan hints.</para>
+			</description>
+			<see-also>
+				<ref type="managerEvent">PresenceStatus</ref>
+			</see-also>
+		</managerEventInstance>
+	</managerEvent>
+***/
+
 #include "asterisk.h"
 
 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
@@ -52,7 +82,11 @@
 	{ "dnd", AST_PRESENCE_DND},
 };
 
-STASIS_MESSAGE_TYPE_DEFN(ast_presence_state_message_type);
+static struct ast_manager_event_blob *presence_state_to_ami(struct stasis_message *msg);
+
+STASIS_MESSAGE_TYPE_DEFN(ast_presence_state_message_type,
+	.to_ami = presence_state_to_ami,
+);
 struct stasis_topic *presence_state_topic_all;
 struct stasis_cache *presence_state_cache;
 struct stasis_caching_topic *presence_state_topic_cached;
@@ -351,3 +385,17 @@
 	return 0;
 }
 
+static struct ast_manager_event_blob *presence_state_to_ami(struct stasis_message *msg)
+{
+	struct ast_presence_state_message *presence_state = stasis_message_data(msg);
+
+	return ast_manager_event_blob_create(EVENT_FLAG_CALL, "PresenceStateChange",
+		"Presentity: %s\r\n"
+		"Status: %s\r\n"
+		"Subtype: %s\r\n"
+		"Message: %s\r\n",
+		presence_state->provider,
+		ast_presence_state2str(presence_state->state),
+		presence_state->subtype,
+		presence_state->message);
+}

Added: trunk/res/res_manager_devicestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_manager_devicestate.c?view=auto&rev=413060
==============================================================================
--- trunk/res/res_manager_devicestate.c (added)
+++ trunk/res/res_manager_devicestate.c Mon Apr 28 09:40:21 2014
@@ -1,0 +1,50 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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.
+ */
+
+#include "asterisk.h"
+#include "asterisk/module.h"
+#include "asterisk/stasis.h"
+#include "asterisk/devicestate.h"
+
+static struct stasis_forward *topic_forwarder;
+
+static int unload_module(void)
+{
+	topic_forwarder = stasis_forward_cancel(topic_forwarder);
+	return 0;
+}
+
+static int load_module(void)
+{
+	struct stasis_topic *manager_topic;
+
+	manager_topic = ast_manager_get_topic();
+	if (!manager_topic) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	topic_forwarder = stasis_forward_all(ast_device_state_topic_all(), manager_topic);
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Device State Topic Forwarder",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
+	);

Propchange: trunk/res/res_manager_devicestate.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/res/res_manager_devicestate.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/res/res_manager_devicestate.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/res/res_manager_presencestate.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_manager_presencestate.c?view=auto&rev=413060
==============================================================================
--- trunk/res/res_manager_presencestate.c (added)
+++ trunk/res/res_manager_presencestate.c Mon Apr 28 09:40:21 2014
@@ -1,0 +1,50 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2014, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson 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.
+ */
+
+#include "asterisk.h"
+#include "asterisk/module.h"
+#include "asterisk/stasis.h"
+#include "asterisk/presencestate.h"
+
+static struct stasis_forward *topic_forwarder;
+
+static int unload_module(void)
+{
+	topic_forwarder = stasis_forward_cancel(topic_forwarder);
+	return 0;
+}
+
+static int load_module(void)
+{
+	struct stasis_topic *manager_topic;
+
+	manager_topic = ast_manager_get_topic();
+	if (!manager_topic) {
+		return AST_MODULE_LOAD_DECLINE;
+	}
+
+	topic_forwarder = stasis_forward_all(ast_presence_state_topic_all(), manager_topic);
+
+	return AST_MODULE_LOAD_SUCCESS;
+}
+
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Manager Presence State Topic Forwarder",
+		.load = load_module,
+		.unload = unload_module,
+		.load_pri = AST_MODPRI_DEVSTATE_CONSUMER,
+	);

Propchange: trunk/res/res_manager_presencestate.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/res/res_manager_presencestate.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/res/res_manager_presencestate.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list