Index: shill_event.cc |
diff --git a/shill_event.cc b/shill_event.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..6b1356ad15feb1b2a72182a4344eeebe434f8668 |
--- /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 |