blob: 4127f31a53b9f1e22628a0f7e10c5e1279ec9f64 [file] [log] [blame]
Paul Stewart5f06a0e2012-12-20 11:11:33 -08001// Copyright (c) 2012 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
Ben Chanc45688b2014-07-02 23:50:45 -07005#ifndef SHILL_EVENT_DISPATCHER_H_
6#define SHILL_EVENT_DISPATCHER_H_
Paul Stewart75897df2011-04-27 09:05:53 -07007
Ben Chancd477322014-10-17 14:19:30 -07008#include <memory>
9
Eric Shienbrood3e20a232012-02-16 11:35:56 -050010#include <base/callback.h>
Ben Chancc67c522014-09-03 07:19:18 -070011#include <base/macros.h>
Chris Masone487b8bf2011-05-13 16:27:57 -070012#include <base/memory/ref_counted.h>
Ben Chana0ddf462014-02-06 11:32:42 -080013#include <base/message_loop/message_loop.h>
Chris Masone0e1d1042011-05-09 18:07:03 -070014
Peter Qiu40a01482014-10-31 11:54:23 -070015#include "shill/net/io_handler_factory_container.h"
Paul Stewartf0aae102011-10-19 12:11:44 -070016
Chris Masone0e1d1042011-05-09 18:07:03 -070017namespace base {
18class MessageLoopProxy;
19} // namespace base
Darin Petkov67d8ecf2011-07-26 16:03:30 -070020
Chris Masone0e1d1042011-05-09 18:07:03 -070021
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 Stewarta794cd62015-06-16 13:13:10 -070039 virtual bool PostTask(const base::Closure& task);
40 virtual bool PostDelayedTask(const base::Closure& task, int64_t delay_ms);
Chris Masone0e1d1042011-05-09 18:07:03 -070041
Paul Stewarta794cd62015-06-16 13:13:10 -070042 virtual IOHandler* CreateInputHandler(
Darin Petkov633ac6f2011-07-08 13:56:13 -070043 int fd,
Paul Stewarta794cd62015-06-16 13:13:10 -070044 const IOHandler::InputCallback& input_callback,
45 const IOHandler::ErrorCallback& error_callback);
Darin Petkov633ac6f2011-07-08 13:56:13 -070046
Paul Stewarta794cd62015-06-16 13:13:10 -070047 virtual IOHandler* CreateReadyHandler(
Paul Stewartf0aae102011-10-19 12:11:44 -070048 int fd,
49 IOHandler::ReadyMode mode,
Paul Stewarta794cd62015-06-16 13:13:10 -070050 const IOHandler::ReadyCallback& ready_callback);
Paul Stewartf0aae102011-10-19 12:11:44 -070051
Paul Stewart75897df2011-04-27 09:05:53 -070052 private:
Ben Chancd477322014-10-17 14:19:30 -070053 std::unique_ptr<base::MessageLoop> dont_use_directly_;
Chris Masone0e1d1042011-05-09 18:07:03 -070054 scoped_refptr<base::MessageLoopProxy> message_loop_proxy_;
Paul Stewarta794cd62015-06-16 13:13:10 -070055 IOHandlerFactory* io_handler_factory_;
Darin Petkov67d8ecf2011-07-26 16:03:30 -070056
57 DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
Paul Stewart75897df2011-04-27 09:05:53 -070058};
59
60} // namespace shill
61
Ben Chanc45688b2014-07-02 23:50:45 -070062#endif // SHILL_EVENT_DISPATCHER_H_