[svn-commits] russell: branch russell/events r103656 - in /team/russell/events: include/ast...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Feb 13 09:11:39 CST 2008


Author: russell
Date: Wed Feb 13 09:11:39 2008
New Revision: 103656

URL: http://svn.digium.com/view/asterisk?view=rev&rev=103656
Log:
Generate an event that represents the aggregate device state across all servers.

Modified:
    team/russell/events/include/asterisk/event_defs.h
    team/russell/events/main/devicestate.c

Modified: team/russell/events/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event_defs.h?view=diff&rev=103656&r1=103655&r2=103656
==============================================================================
--- team/russell/events/include/asterisk/event_defs.h (original)
+++ team/russell/events/include/asterisk/event_defs.h Wed Feb 13 09:11:39 2008
@@ -29,12 +29,12 @@
  * \note These values can *never* change. */
 enum ast_event_type {
 	/*! Reserved to provide the ability to subscribe to all events.  A specific
-	    event should never have a payload of 0. */
+	 *  event should never have a payload of 0. */
 	AST_EVENT_ALL    = 0x00,
 	/*! This event type is reserved for use by third-party modules to create
-	    custom events without having to modify this file. 
-	    \note There are no "custom" IE types, because IEs only have to be
-	    unique to the event itself, not necessarily across all events. */
+	 *  custom events without having to modify this file. 
+	 *  \note There are no "custom" IE types, because IEs only have to be
+	 *  unique to the event itself, not necessarily across all events. */
 	AST_EVENT_CUSTOM = 0x01,
 	/*! Voicemail message waiting indication */
 	AST_EVENT_MWI          = 0x02,
@@ -42,11 +42,14 @@
 	AST_EVENT_SUB          = 0x03,
 	/*! Someone has unsubscribed from events */
 	AST_EVENT_UNSUB        = 0x04,
+	/*! The aggregate state of a device across all servers configured to be
+	 *  a part of a device state cluster has changed. */
+	AST_EVENT_DEVICE_STATE = 0x05,
 	/*! The state of a device has changed on _one_ server.  This should not be used
 	 *  directly, in general.  Use AST_EVENT_DEVICE_STATE instead. */
-	AST_EVENT_DEVICE_STATE_CHANGE = 0x05,
+	AST_EVENT_DEVICE_STATE_CHANGE = 0x06,
 	/*! Number of event types.  This should be the last event type + 1 */
-	AST_EVENT_TOTAL        = 0x06,
+	AST_EVENT_TOTAL        = 0x07,
 };
 
 /*! \brief Event Information Element types */

Modified: team/russell/events/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/devicestate.c?view=diff&rev=103656&r1=103655&r2=103656
==============================================================================
--- team/russell/events/main/devicestate.c (original)
+++ team/russell/events/main/devicestate.c Wed Feb 13 09:11:39 2008
@@ -677,11 +677,12 @@
 	return AST_DEVICE_NOT_INUSE;
 }
 
-static void process_collection(struct change_collection *collection)
+static void process_collection(const char *device, struct change_collection *collection)
 {
 	int i;
 	struct ast_devstate_aggregate agg;
 	enum ast_device_state state;
+	struct ast_event *event;
 
 	ast_devstate_aggregate_init(&agg);
 
@@ -690,7 +691,34 @@
 
 	state = ast_devstate_aggregate_result(&agg);
 
-	/* XXX */
+	event = ast_event_get_cached(AST_EVENT_DEVICE_STATE,
+		AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device,
+		AST_EVENT_IE_END);
+	
+	if (event) {
+		enum ast_device_state old_state;
+
+		old_state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
+		
+		ast_event_destroy(event);
+
+		if (state == old_state) {
+			/* No change since last reported device state */
+			return;
+		}
+	}
+
+	event = ast_event_new(AST_EVENT_DEVICE_STATE,
+		AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device,
+		AST_EVENT_IE_STATE, AST_EVENT_IE_PLTYPE_UINT, state,
+		AST_EVENT_IE_END);
+	
+	if (!event)
+		return;
+
+	ast_event_queue_and_cache(event,
+		AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR,
+		AST_EVENT_IE_END);
 }
 
 static void handle_devstate_change(struct devstate_change *sc)
@@ -714,7 +742,7 @@
 	/* Populate the collection of device states from the cache */
 	ast_event_dump_cache(tmp_sub);
 
-	process_collection(&collection);
+	process_collection(sc->device, &collection);
 
 	ast_event_sub_destroy(tmp_sub);
 }




More information about the svn-commits mailing list