1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_EVENT_DISPATCHER_H_ 18 #define SHILL_EVENT_DISPATCHER_H_ 19 20 #include <memory> 21 22 #include <base/callback.h> 23 #include <base/macros.h> 24 #include <base/memory/ref_counted.h> 25 #include <base/message_loop/message_loop.h> 26 27 #include "shill/net/io_handler_factory_container.h" 28 29 namespace base { 30 class MessageLoopProxy; 31 } // namespace base 32 33 34 namespace shill { 35 36 // This is the main event dispatcher. It contains a central instance, and is 37 // the entity responsible for dispatching events out of all queues to their 38 // listeners during the idle loop. 39 class EventDispatcher { 40 public: 41 EventDispatcher(); 42 virtual ~EventDispatcher(); 43 44 virtual void DispatchForever(); 45 46 // Processes all pending events that can run and returns. 47 virtual void DispatchPendingEvents(); 48 49 // These are thin wrappers around calls of the same name in 50 // <base/message_loop_proxy.h> 51 virtual void PostTask(const base::Closure& task); 52 virtual void PostDelayedTask(const base::Closure& task, int64_t delay_ms); 53 54 virtual IOHandler* CreateInputHandler( 55 int fd, 56 const IOHandler::InputCallback& input_callback, 57 const IOHandler::ErrorCallback& error_callback); 58 59 virtual IOHandler* CreateReadyHandler( 60 int fd, 61 IOHandler::ReadyMode mode, 62 const IOHandler::ReadyCallback& ready_callback); 63 64 private: 65 IOHandlerFactory* io_handler_factory_; 66 67 DISALLOW_COPY_AND_ASSIGN(EventDispatcher); 68 }; 69 70 } // namespace shill 71 72 #endif // SHILL_EVENT_DISPATCHER_H_ 73