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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Feb 12 16:43:10 CST 2008


Author: russell
Date: Tue Feb 12 16:43:09 2008
New Revision: 103507

URL: http://svn.digium.com/view/asterisk?view=rev&rev=103507
Log:
Add code which pulls the device state for each server out of the event cache
when the state of a device changes on any one server.  Next, process the collection
of device states and determine the new aggregate device state ...

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

Modified: team/russell/events/include/asterisk/event.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event.h?view=diff&rev=103507&r1=103506&r2=103507
==============================================================================
--- team/russell/events/include/asterisk/event.h (original)
+++ team/russell/events/include/asterisk/event.h Tue Feb 12 16:43:09 2008
@@ -116,6 +116,8 @@
 struct ast_event_sub *ast_event_subscribe_new(enum ast_event_type type, 
 	ast_event_cb_t cb, void *userdata);
 
+void ast_event_sub_destroy(struct ast_event_sub *sub);
+
 int ast_event_sub_append_ie_uint(struct ast_event_sub *sub,
 	enum ast_event_ie_type, uint32_t uint);
 

Modified: team/russell/events/main/devicestate.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/devicestate.c?view=diff&rev=103507&r1=103506&r2=103507
==============================================================================
--- team/russell/events/main/devicestate.c (original)
+++ team/russell/events/main/devicestate.c Tue Feb 12 16:43:09 2008
@@ -562,6 +562,68 @@
 	ast_free(sc);
 }
 
+#define MAX_SERVERS 64
+struct change_collection {
+	struct devstate_change states[MAX_SERVERS];
+	size_t num_states;
+};
+
+static void devstate_cache_cb(const struct ast_event *event, void *data)
+{
+	struct change_collection *collection = data;
+	int i;
+	const struct ast_eid *eid;
+
+	if (collection->num_states == ARRAY_LEN(collection->states)) {
+		ast_log(LOG_ERROR, "More per-server state values than we have room for (MAX_SERVERS is %d)\n",
+			MAX_SERVERS);
+		return;
+	}
+
+	if (!(eid = ast_event_get_ie_raw(event, AST_EVENT_IE_EID))) {
+		ast_log(LOG_ERROR, "Device state change event with no EID\n");
+		return;
+	}
+
+	i = collection->num_states;
+
+	collection->states[i].state = ast_event_get_ie_uint(event, AST_EVENT_IE_STATE);
+	collection->states[i].eid = *eid;
+
+	collection->num_states++;
+}
+
+static void process_collection(struct change_collection *collection)
+{
+	/* XXX */
+}
+
+static void handle_devstate_change(struct devstate_change *sc)
+{
+	struct ast_event_sub *tmp_sub;
+	struct change_collection collection = {
+		.num_states = 0,
+	};
+
+	if (!(tmp_sub = ast_event_subscribe_new(AST_EVENT_DEVICE_STATE_CHANGE, devstate_cache_cb, &collection))) {
+		ast_log(LOG_ERROR, "Failed to create subscription\n");
+		return;
+	}
+
+	if (ast_event_sub_append_ie_str(tmp_sub, AST_EVENT_IE_DEVICE, sc->device)) {
+		ast_log(LOG_ERROR, "Failed to append device IE\n");
+		ast_event_sub_destroy(tmp_sub);
+		return;
+	}
+
+	/* Populate the collection of device states from the cache */
+	ast_event_dump_cache(tmp_sub);
+
+	process_collection(&collection);
+
+	ast_event_sub_destroy(tmp_sub);
+}
+
 static void *run_devstate_collector(void *data)
 {
 	for (;;) {
@@ -572,7 +634,7 @@
 			ast_cond_wait(&devstate_collector.cond, &devstate_collector.lock);
 		ast_mutex_unlock(&devstate_collector.lock);
 
-		/* XXX */
+		handle_devstate_change(sc);
 
 		destroy_devstate_change(sc);
 	}

Modified: team/russell/events/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/event.c?view=diff&rev=103507&r1=103506&r2=103507
==============================================================================
--- team/russell/events/main/event.c (original)
+++ team/russell/events/main/event.c Tue Feb 12 16:43:09 2008
@@ -513,7 +513,7 @@
 	return sub;
 }
 
-static void ast_event_sub_destroy(struct ast_event_sub *sub)
+void ast_event_sub_destroy(struct ast_event_sub *sub)
 {
 	struct ast_event_ie_val *ie_val;
 




More information about the svn-commits mailing list