blob: bd066efd6342f5071430e9019e14394c500796b5 [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>
Eric Shienbrood3e20a232012-02-16 11:35:56 -05009#include <base/callback.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070010#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 -070020
Paul Stewart75897df2011-04-27 09:05:53 -070021namespace shill {
22
Darin Petkov67d8ecf2011-07-26 16:03:30 -070023// This is the main event dispatcher. It contains a central instance, and is
24// the entity responsible for dispatching events out of all queues to their
25// listeners during the idle loop.
Paul Stewart75897df2011-04-27 09:05:53 -070026class EventDispatcher {
27 public:
Chris Masone0e1d1042011-05-09 18:07:03 -070028 EventDispatcher();
29 virtual ~EventDispatcher();
Darin Petkov633ac6f2011-07-08 13:56:13 -070030
Paul Stewartc2350ee2011-10-19 12:28:40 -070031 virtual void DispatchForever();
Chris Masone0e1d1042011-05-09 18:07:03 -070032
Darin Petkov67d8ecf2011-07-26 16:03:30 -070033 // Processes all pending events that can run and returns.
Paul Stewartc2350ee2011-10-19 12:28:40 -070034 virtual void DispatchPendingEvents();
Darin Petkov67d8ecf2011-07-26 16:03:30 -070035
Chris Masone0e1d1042011-05-09 18:07:03 -070036 // These are thin wrappers around calls of the same name in
37 // <base/message_loop_proxy.h>
Eric Shienbrood3e20a232012-02-16 11:35:56 -050038 virtual bool PostTask(const base::Closure &task);
39 virtual bool PostDelayedTask(const base::Closure &task, int64 delay_ms);
Chris Masone0e1d1042011-05-09 18:07:03 -070040
Paul Stewart26b327e2011-10-19 11:38:09 -070041 virtual IOHandler *CreateInputHandler(
Darin Petkov633ac6f2011-07-08 13:56:13 -070042 int fd,
Eric Shienbrood3e20a232012-02-16 11:35:56 -050043 const base::Callback<void(InputData *)> &callback);
Darin Petkov633ac6f2011-07-08 13:56:13 -070044
Paul Stewartf0aae102011-10-19 12:11:44 -070045 virtual IOHandler *CreateReadyHandler(
46 int fd,
47 IOHandler::ReadyMode mode,
Eric Shienbrood3e20a232012-02-16 11:35:56 -050048 const base::Callback<void(int)> &callback);
Paul Stewartf0aae102011-10-19 12:11:44 -070049
Paul Stewart75897df2011-04-27 09:05:53 -070050 private:
Chris Masone0e1d1042011-05-09 18:07:03 -070051 scoped_ptr<MessageLoop> dont_use_directly_;
52 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
Darin Petkov67d8ecf2011-07-26 16:03:30 -070053
54 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
Paul Stewart75897df2011-04-27 09:05:53 -070055};
56
57} // namespace shill
58
Paul Stewart26b327e2011-10-19 11:38:09 -070059#endif // SHILL_EVENT_DISPATCHER_