blob: 217c35b108e2a61bd0c8f866562ac85c59beec6c [file] [log] [blame]
Paul Stewart75897df2011-04-27 09:05:53 -07001// 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 Petkov67d8ecf2011-07-26 16:03:30 -07005#include "shill/shill_event.h"
6
Paul Stewart75897df2011-04-27 09:05:53 -07007#include <stdio.h>
8#include <glib.h>
9
Chris Masone487b8bf2011-05-13 16:27:57 -070010#include <base/callback_old.h>
Chris Masone0e1d1042011-05-09 18:07:03 -070011#include <base/message_loop_proxy.h>
12
Paul Stewart25379f12011-05-26 06:41:38 -070013#include "shill/glib_io_handler.h"
Paul Stewart75897df2011-04-27 09:05:53 -070014
15namespace shill {
16
Chris Masone0e1d1042011-05-09 18:07:03 -070017EventDispatcher::EventDispatcher()
18 : dont_use_directly_(new MessageLoopForUI),
19 message_loop_proxy_(base::MessageLoopProxy::CreateForCurrentThread()) {
20}
Paul Stewarta43d9232011-05-10 11:40:22 -070021
Chris Masone0e1d1042011-05-09 18:07:03 -070022EventDispatcher::~EventDispatcher() {}
23
24void EventDispatcher::DispatchForever() {
25 MessageLoop::current()->Run();
26}
27
Darin Petkov67d8ecf2011-07-26 16:03:30 -070028void EventDispatcher::DispatchPendingEvents() {
29 MessageLoop::current()->RunAllPending();
30}
31
32bool EventDispatcher::PostTask(Task *task) {
mukesh agrawalf60e4062011-05-27 13:13:41 -070033 return message_loop_proxy_->PostTask(FROM_HERE, task);
Chris Masone0e1d1042011-05-09 18:07:03 -070034}
35
Darin Petkov67d8ecf2011-07-26 16:03:30 -070036bool EventDispatcher::PostDelayedTask(Task *task, int64 delay_ms) {
mukesh agrawalf60e4062011-05-27 13:13:41 -070037 return message_loop_proxy_->PostDelayedTask(FROM_HERE, task, delay_ms);
Chris Masone0e1d1042011-05-09 18:07:03 -070038}
39
40IOInputHandler *EventDispatcher::CreateInputHandler(
41 int fd,
Darin Petkov67d8ecf2011-07-26 16:03:30 -070042 Callback1<InputData *>::Type *callback) {
Chris Masone0e1d1042011-05-09 18:07:03 -070043 return new GlibIOInputHandler(fd, callback);
Paul Stewarta43d9232011-05-10 11:40:22 -070044}
45
Paul Stewart75897df2011-04-27 09:05:53 -070046} // namespace shill