blob: d540fbdde4c409c101eaa3cabc8cb942f32fde94 [file] [log] [blame]
Darin Petkov633ac6f2011-07-08 13:56:13 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Paul Stewart75897df2011-04-27 09:05:53 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Paul Stewart26b327e2011-10-19 11:38:09 -07005#ifndef SHILL_EVENT_DISPATCHER_
6#define SHILL_EVENT_DISPATCHER_
Paul Stewart75897df2011-04-27 09:05:53 -07007
Chris Masone0e1d1042011-05-09 18:07:03 -07008#include <base/basictypes.h>
Chris Masone487b8bf2011-05-13 16:27:57 -07009#include <base/callback_old.h>
10#include <base/memory/ref_counted.h>
11#include <base/memory/scoped_ptr.h>
Chris Masone0e1d1042011-05-09 18:07:03 -070012#include <base/message_loop.h>
Chris Masone0e1d1042011-05-09 18:07:03 -070013
14namespace base {
15class MessageLoopProxy;
16} // namespace base
Darin Petkov67d8ecf2011-07-26 16:03:30 -070017
Chris Masone0e1d1042011-05-09 18:07:03 -070018class Task;
19
Paul Stewart75897df2011-04-27 09:05:53 -070020namespace shill {
21
Darin Petkov67d8ecf2011-07-26 16:03:30 -070022class InputData;
Paul Stewart26b327e2011-10-19 11:38:09 -070023class IOHandler;
Darin Petkov67d8ecf2011-07-26 16:03:30 -070024
25// This is the main event dispatcher. It contains a central instance, and is
26// the entity responsible for dispatching events out of all queues to their
27// listeners during the idle loop.
Paul Stewart75897df2011-04-27 09:05:53 -070028class EventDispatcher {
29 public:
Chris Masone0e1d1042011-05-09 18:07:03 -070030 EventDispatcher();
31 virtual ~EventDispatcher();
Darin Petkov633ac6f2011-07-08 13:56:13 -070032
Chris Masone0e1d1042011-05-09 18:07:03 -070033 void DispatchForever();
34
Darin Petkov67d8ecf2011-07-26 16:03:30 -070035 // Processes all pending events that can run and returns.
36 void DispatchPendingEvents();
37
Chris Masone0e1d1042011-05-09 18:07:03 -070038 // These are thin wrappers around calls of the same name in
39 // <base/message_loop_proxy.h>
Darin Petkov67d8ecf2011-07-26 16:03:30 -070040 bool PostTask(Task *task);
41 bool PostDelayedTask(Task *task, int64 delay_ms);
Chris Masone0e1d1042011-05-09 18:07:03 -070042
Paul Stewart26b327e2011-10-19 11:38:09 -070043 virtual IOHandler *CreateInputHandler(
Darin Petkov633ac6f2011-07-08 13:56:13 -070044 int fd,
Darin Petkov67d8ecf2011-07-26 16:03:30 -070045 Callback1<InputData *>::Type *callback);
Darin Petkov633ac6f2011-07-08 13:56:13 -070046
Paul Stewart75897df2011-04-27 09:05:53 -070047 private:
Chris Masone0e1d1042011-05-09 18:07:03 -070048 scoped_ptr<MessageLoop> dont_use_directly_;
49 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
Darin Petkov67d8ecf2011-07-26 16:03:30 -070050
51 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
Paul Stewart75897df2011-04-27 09:05:53 -070052};
53
54} // namespace shill
55
Paul Stewart26b327e2011-10-19 11:38:09 -070056#endif // SHILL_EVENT_DISPATCHER_