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 | |
| 5 | #ifndef SHILL_EVENT_ |
| 6 | #define SHILL_EVENT_ |
| 7 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 8 | #include <base/basictypes.h> |
Chris Masone | 487b8bf | 2011-05-13 16:27:57 -0700 | [diff] [blame] | 9 | #include <base/callback_old.h> |
| 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 | |
| 14 | namespace base { |
| 15 | class MessageLoopProxy; |
| 16 | } // namespace base |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 17 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 18 | class Task; |
| 19 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 20 | namespace shill { |
| 21 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 22 | class IOInputHandler; |
| 23 | class InputData; |
| 24 | |
| 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 Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 28 | class EventDispatcher { |
| 29 | public: |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 30 | EventDispatcher(); |
| 31 | virtual ~EventDispatcher(); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 32 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 33 | void DispatchForever(); |
| 34 | |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 35 | // Processes all pending events that can run and returns. |
| 36 | void DispatchPendingEvents(); |
| 37 | |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 38 | // These are thin wrappers around calls of the same name in |
| 39 | // <base/message_loop_proxy.h> |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 40 | bool PostTask(Task *task); |
| 41 | bool PostDelayedTask(Task *task, int64 delay_ms); |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 42 | |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 43 | virtual IOInputHandler *CreateInputHandler( |
| 44 | int fd, |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 45 | Callback1<InputData *>::Type *callback); |
Darin Petkov | 633ac6f | 2011-07-08 13:56:13 -0700 | [diff] [blame] | 46 | |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 47 | private: |
Chris Masone | 0e1d104 | 2011-05-09 18:07:03 -0700 | [diff] [blame] | 48 | scoped_ptr<MessageLoop> dont_use_directly_; |
| 49 | scoped_refptr<base::MessageLoopProxy> message_loop_proxy_; |
Darin Petkov | 67d8ecf | 2011-07-26 16:03:30 -0700 | [diff] [blame] | 50 | |
| 51 | DISALLOW_COPY_AND_ASSIGN(EventDispatcher); |
Paul Stewart | 75897df | 2011-04-27 09:05:53 -0700 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | } // namespace shill |
| 55 | |
| 56 | #endif // SHILL_EVENT_ |