| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef WINDOW_MANAGER_EVENT_LOOP_H_ | 5 #ifndef WINDOW_MANAGER_EVENT_LOOP_H_ |
| 6 #define WINDOW_MANAGER_EVENT_LOOP_H_ | 6 #define WINDOW_MANAGER_EVENT_LOOP_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <tr1/memory> | 10 #include <tr1/memory> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "base/scoped_ptr.h" | 14 #include "base/scoped_ptr.h" |
| 15 #include "window_manager/callback.h" | 15 #include "window_manager/callback.h" |
| 16 | 16 |
| 17 namespace window_manager { | 17 namespace window_manager { |
| 18 | 18 |
| 19 // EventLoop provides an interface for fetching X events and setting | 19 // EventLoop provides an interface for fetching X events and setting |
| 20 // timeouts. | 20 // timeouts. |
| 21 class EventLoop { | 21 class EventLoop { |
| 22 public: | 22 public: |
| 23 EventLoop(); | 23 EventLoop(); |
| 24 ~EventLoop(); | 24 ~EventLoop(); |
| 25 | 25 |
| 26 // Get the number of current-registered timeouts. Used for testing. |
| 27 int num_timeouts() const { return timeout_fds_.size(); } |
| 28 |
| 26 // Loop until Exit() is called, waiting for FDs to become readable or | 29 // Loop until Exit() is called, waiting for FDs to become readable or |
| 27 // timeouts to fire. | 30 // timeouts to fire. |
| 28 void Run(); | 31 void Run(); |
| 29 | 32 |
| 30 // Exit the loop the next time we're about to wait for FDs or timeouts. | 33 // Exit the loop the next time we're about to wait for FDs or timeouts. |
| 31 void Exit() { exit_requested_ = true; } | 34 void Exit() { exit_requested_ = true; } |
| 32 | 35 |
| 33 // Start watching a file descriptor, invoking a callback when it becomes | 36 // Start watching a file descriptor, invoking a callback when it becomes |
| 34 // readable. Takes ownership of 'cb', which must be a repeatable | 37 // readable. Takes ownership of 'cb', which must be a repeatable |
| 35 // (non-self-deleting) callback. | 38 // (non-self-deleting) callback. |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 // running B's callback afterwards. We store the set here so that | 143 // running B's callback afterwards. We store the set here so that |
| 141 // RemoveFileDescriptor() can remove items from it. | 144 // RemoveFileDescriptor() can remove items from it. |
| 142 std::set<std::tr1::shared_ptr<Closure> > callbacks_to_run_; | 145 std::set<std::tr1::shared_ptr<Closure> > callbacks_to_run_; |
| 143 | 146 |
| 144 DISALLOW_COPY_AND_ASSIGN(EventLoop); | 147 DISALLOW_COPY_AND_ASSIGN(EventLoop); |
| 145 }; | 148 }; |
| 146 | 149 |
| 147 } // namespace window_manager | 150 } // namespace window_manager |
| 148 | 151 |
| 149 #endif // WINDOW_MANAGER_EVENT_LOOP_H_ | 152 #endif // WINDOW_MANAGER_EVENT_LOOP_H_ |
| OLD | NEW |