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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « shill_event.h ('k') | shill_logging.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdio.h>
6 #include <glib.h>
7
8 #include "shill/shill_event.h"
9
10 namespace shill {
11
12 EventQueueItem::EventQueueItem(EventDispatcher *dispatcher)
13 : dispatcher_(dispatcher) {
14 dispatcher->RegisterCallbackQueue(this);
15 }
16
17 EventQueueItem::~EventQueueItem() {
18 dispatcher_->UnregisterCallbackQueue(this);
19 }
20
21 void EventQueueItem::AlertDispatcher() {
22 dispatcher_->ExecuteOnIdle();
23 }
24
25 void EventDispatcher::DispatchEvents() {
26 for (size_t idx = 0; idx < queue_list_.size(); ++idx)
27 queue_list_[idx]->Dispatch();
28 }
29
30 static gboolean DispatchEventsHandler(gpointer data) {
31 EventDispatcher *dispatcher = static_cast<EventDispatcher *>(data);
32 dispatcher->DispatchEvents();
33 return false;
34 }
35
36 void EventDispatcher::ExecuteOnIdle() {
37 g_idle_add(&DispatchEventsHandler, this);
38 }
39
40 void EventDispatcher::RegisterCallbackQueue(EventQueueItem *queue) {
41 queue_list_.push_back(queue);
42 }
43
44 void EventDispatcher::UnregisterCallbackQueue(EventQueueItem *queue) {
45 for (size_t idx = 0; idx < queue_list_.size(); ++idx) {
46 if (queue_list_[idx] == queue) {
47 queue_list_.erase(queue_list_.begin() + idx);
48 return;
49 }
50 }
51 }
52
53 } // namespace shill
OLDNEW
« 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