Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(530)

Unified Diff: shill_event.cc

Issue 6575006: Add initial sketch to shill repository (Closed) Base URL: ssh://git@gitrw.chromium.org/shill.git@master
Patch Set: A few object renames and pointer conversions Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « shill_event.h ('k') | shill_logging.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « shill_event.h ('k') | shill_logging.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698