Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 5 | #ifndef SHILL_EVENT_DISPATCHER_ |
| 6 | #define SHILL_EVENT_DISPATCHER_ |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 7 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 8 | #include <base/basictypes.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 9 | #include <base/callback.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 10 | #include <base/memory/ref_counted.h> |
| 11 | #include <base/memory/scoped_ptr.h> |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 12 | #include <base/message_loop.h> |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 13 | |
Paul Stewart | f0aae10 | 2011-10-19 12:11:44 -0700 | [diff] [blame] | 14 | #include "shill/io_handler.h" |
| 15 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 16 | namespace base { |
| 17 | class MessageLoopProxy; |
| 18 | } // namespace base |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 19 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 20 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 21 | namespace shill { |
| 22 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 23 | // 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 Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 26 | class EventDispatcher { |
| 27 | public: |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 28 | EventDispatcher(); |
| 29 | virtual ~EventDispatcher(); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 30 | |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 31 | virtual void DispatchForever(); |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 32 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 33 | // Processes all pending events that can run and returns. |
Paul Stewart | c2350ee | 2011-10-19 12:28:40 -0700 | [diff] [blame] | 34 | virtual void DispatchPendingEvents(); |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 35 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 36 | // These are thin wrappers around calls of the same name in |
| 37 | // <base/message_loop_proxy.h> |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 38 | virtual bool PostTask(const base::Closure &task); |
| 39 | virtual bool PostDelayedTask(const base::Closure &task, int64 delay_ms); |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 40 | |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 41 | virtual IOHandler *CreateInputHandler( |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 42 | int fd, |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 43 | const base::Callback<void(InputData *)> &callback); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 44 | |
Paul Stewart | f0aae10 | 2011-10-19 12:11:44 -0700 | [diff] [blame] | 45 | virtual IOHandler *CreateReadyHandler( |
| 46 | int fd, |
| 47 | IOHandler::ReadyMode mode, |
Eric Shienbrood | 3e20a23 | 2012-02-16 11:35:56 -0500 | [diff] [blame] | 48 | const base::Callback<void(int)> &callback); |
Paul Stewart | f0aae10 | 2011-10-19 12:11:44 -0700 | [diff] [blame] | 49 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 50 | private: |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 51 | scoped_ptr<MessageLoop> dont_use_directly_; |
| 52 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 53 | |
| 54 | DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 55 | }; |
| 56 | |
| 57 | } // namespace shill |
| 58 | |
Paul Stewart | 26b327e | 2011-10-19 11:38:09 -0700 | [diff] [blame] | 59 | #endif // SHILL_EVENT_DISPATCHER_ |