Add initial sketch to shill repository
BUG=chromium-os:12066
TEST=command-line
Change-Id: If1d01bf78fca80de4cc8a26e096e1967293d9738
Review URL: http://codereview.chromium.org//6575006
diff --git a/shill_event.cc b/shill_event.cc
new file mode 100644
index 0000000..6b1356a
--- /dev/null
+++ b/shill_event.cc
@@ -0,0 +1,53 @@
+// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <stdio.h>
+#include <glib.h>
+
+#include "shill/shill_event.h"
+
+namespace shill {
+
+EventQueueItem::EventQueueItem(EventDispatcher *dispatcher)
+ : dispatcher_(dispatcher) {
+ dispatcher->RegisterCallbackQueue(this);
+}
+
+EventQueueItem::~EventQueueItem() {
+ dispatcher_->UnregisterCallbackQueue(this);
+}
+
+void EventQueueItem::AlertDispatcher() {
+ dispatcher_->ExecuteOnIdle();
+}
+
+void EventDispatcher::DispatchEvents() {
+ for (size_t idx = 0; idx < queue_list_.size(); ++idx)
+ queue_list_[idx]->Dispatch();
+}
+
+static gboolean DispatchEventsHandler(gpointer data) {
+ EventDispatcher *dispatcher = static_cast<EventDispatcher *>(data);
+ dispatcher->DispatchEvents();
+ return false;
+}
+
+void EventDispatcher::ExecuteOnIdle() {
+ g_idle_add(&DispatchEventsHandler, this);
+}
+
+void EventDispatcher::RegisterCallbackQueue(EventQueueItem *queue) {
+ queue_list_.push_back(queue);
+}
+
+void EventDispatcher::UnregisterCallbackQueue(EventQueueItem *queue) {
+ for (size_t idx = 0; idx < queue_list_.size(); ++idx) {
+ if (queue_list_[idx] == queue) {
+ queue_list_.erase(queue_list_.begin() + idx);
+ return;
+ }
+ }
+}
+
+} // namespace shill