Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 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 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 5 | #include "shill/shill_event.h" |
| 6 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | #include <stdio.h> |
| 8 | #include <glib.h> |
| 9 | |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 10 | #include <base/callback_old.h> |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 11 | #include <base/message_loop_proxy.h> |
| 12 | |
Paul Stewart | 25379f1 | 2011-05-26 06:41:38 -0700 | [diff] [blame] | 13 | #include "shill/glib_io_handler.h" |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 14 | |
| 15 | namespace shill { |
| 16 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 17 | EventDispatcher::EventDispatcher() |
| 18 | : dont_use_directly_(new MessageLoopForUI), |
| 19 | message_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()) { |
| 20 | } |
Paul Stewart | a43d923 | 2011-05-10 11:40:22 -0700 | [diff] [blame] | 21 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 22 | EventDispatcher::~EventDispatcher() {} |
| 23 | |
| 24 | void EventDispatcher::DispatchForever() { |
| 25 | MessageLoop::current()->Run(); |
| 26 | } |
| 27 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 28 | void EventDispatcher::DispatchPendingEvents() { |
| 29 | MessageLoop::current()->RunAllPending(); |
| 30 | } |
| 31 | |
| 32 | bool EventDispatcher::PostTask(Task *task) { |
mukesh agrawal | f60e406 | 2011-05-27 13:13:41 -0700 | [diff] [blame] | 33 | return message_loop_proxy_->PostTask(FROM_HERE, task); |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 34 | } |
| 35 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 36 | bool EventDispatcher::PostDelayedTask(Task *task, int64 delay_ms) { |
mukesh agrawal | f60e406 | 2011-05-27 13:13:41 -0700 | [diff] [blame] | 37 | return message_loop_proxy_->PostDelayedTask(FROM_HERE, task, delay_ms); |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | IOInputHandler *EventDispatcher::CreateInputHandler( |
| 41 | int fd, |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 42 | Callback1<InputData *>::Type *callback) { |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 43 | return new GlibIOInputHandler(fd, callback); |
Paul Stewart | a43d923 | 2011-05-10 11:40:22 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 46 | } // namespace shill |