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