blob: 14724bc042add5233cf34f2adb472a9b3e17b5c6 [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
Paul Stewartf0aae102011-10-19 12:11:44 -070014#include "shill/io_handler.h"
15
Chris Masone0e1d1042011-05-09 18:07:03 -070016namespace base {
17class MessageLoopProxy;
18} // namespace base
Darin Petkov67d8ecf2011-07-26 16:03:30 -070019
Chris Masone0e1d1042011-05-09 18:07:03 -070020class Task;
21
Paul Stewart75897df2011-04-27 09:05:53 -070022namespace shill {
23
Darin Petkov67d8ecf2011-07-26 16:03:30 -070024// This is the main event dispatcher. It contains a central instance, and is
25// the entity responsible for dispatching events out of all queues to their
26// listeners during the idle loop.
Paul Stewart75897df2011-04-27 09:05:53 -070027class EventDispatcher {
28 public:
Chris Masone0e1d1042011-05-09 18:07:03 -070029 EventDispatcher();
30 virtual ~EventDispatcher();
Darin Petkov633ac6f2011-07-08 13:56:13 -070031
Paul Stewartc2350ee2011-10-19 12:28:40 -070032 virtual void DispatchForever();
Chris Masone0e1d1042011-05-09 18:07:03 -070033
Darin Petkov67d8ecf2011-07-26 16:03:30 -070034 // Processes all pending events that can run and returns.
Paul Stewartc2350ee2011-10-19 12:28:40 -070035 virtual void DispatchPendingEvents();
Darin Petkov67d8ecf2011-07-26 16:03:30 -070036
Chris Masone0e1d1042011-05-09 18:07:03 -070037 // These are thin wrappers around calls of the same name in
38 // <base/message_loop_proxy.h>
Paul Stewartc2350ee2011-10-19 12:28:40 -070039 virtual bool PostTask(Task *task);
40 virtual bool PostDelayedTask(Task *task, int64 delay_ms);
Chris Masone0e1d1042011-05-09 18:07:03 -070041
Paul Stewart26b327e2011-10-19 11:38:09 -070042 virtual IOHandler *CreateInputHandler(
Darin Petkov633ac6f2011-07-08 13:56:13 -070043 int fd,
Darin Petkov67d8ecf2011-07-26 16:03:30 -070044 Callback1<InputData *>::Type *callback);
Darin Petkov633ac6f2011-07-08 13:56:13 -070045
Paul Stewartf0aae102011-10-19 12:11:44 -070046 virtual IOHandler *CreateReadyHandler(
47 int fd,
48 IOHandler::ReadyMode mode,
49 Callback1<int>::Type *callback);
50
Paul Stewart75897df2011-04-27 09:05:53 -070051 private:
Chris Masone0e1d1042011-05-09 18:07:03 -070052 scoped_ptr<MessageLoop> dont_use_directly_;
53 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
Darin Petkov67d8ecf2011-07-26 16:03:30 -070054
55 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
Paul Stewart75897df2011-04-27 09:05:53 -070056};
57
58} // namespace shill
59
Paul Stewart26b327e2011-10-19 11:38:09 -070060#endif // SHILL_EVENT_DISPATCHER_