| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium 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 BASE_MESSAGE_PUMP_LIBEVENT_H_ | 5 #ifndef BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| 6 #define BASE_MESSAGE_PUMP_LIBEVENT_H_ | 6 #define BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
| 10 #include "base/memory/weak_ptr.h" | 10 #include "base/memory/weak_ptr.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 // MessagePump. | 31 // MessagePump. |
| 32 // | 32 // |
| 33 // NOTE: An IOObserver implementation should be extremely fast! | 33 // NOTE: An IOObserver implementation should be extremely fast! |
| 34 virtual void WillProcessIOEvent() = 0; | 34 virtual void WillProcessIOEvent() = 0; |
| 35 virtual void DidProcessIOEvent() = 0; | 35 virtual void DidProcessIOEvent() = 0; |
| 36 | 36 |
| 37 protected: | 37 protected: |
| 38 virtual ~IOObserver() {} | 38 virtual ~IOObserver() {} |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 class FileDescriptorWatcher; | |
| 42 | |
| 43 // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness | 41 // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness |
| 44 // of a file descriptor. | 42 // of a file descriptor. |
| 45 class Watcher { | 43 class Watcher { |
| 46 public: | 44 public: |
| 47 // Called from MessageLoop::Run when an FD can be read from/written to | 45 // Called from MessageLoop::Run when an FD can be read from/written to |
| 48 // without blocking | 46 // without blocking |
| 49 virtual void OnFileCanReadWithoutBlocking(int fd) = 0; | 47 virtual void OnFileCanReadWithoutBlocking(int fd) = 0; |
| 50 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0; | 48 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0; |
| 51 | 49 |
| 52 protected: | 50 protected: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 71 friend class MessagePumpLibeventTest; | 69 friend class MessagePumpLibeventTest; |
| 72 | 70 |
| 73 // Called by MessagePumpLibevent, ownership of |e| is transferred to this | 71 // Called by MessagePumpLibevent, ownership of |e| is transferred to this |
| 74 // object. | 72 // object. |
| 75 void Init(event* e); | 73 void Init(event* e); |
| 76 | 74 |
| 77 // Used by MessagePumpLibevent to take ownership of event_. | 75 // Used by MessagePumpLibevent to take ownership of event_. |
| 78 event* ReleaseEvent(); | 76 event* ReleaseEvent(); |
| 79 | 77 |
| 80 void set_pump(MessagePumpLibevent* pump) { pump_ = pump; } | 78 void set_pump(MessagePumpLibevent* pump) { pump_ = pump; } |
| 81 MessagePumpLibevent* pump() { return pump_; } | 79 MessagePumpLibevent* pump() const { return pump_; } |
| 82 | 80 |
| 83 void set_watcher(Watcher* watcher) { watcher_ = watcher; } | 81 void set_watcher(Watcher* watcher) { watcher_ = watcher; } |
| 84 | 82 |
| 85 void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump); | 83 void OnFileCanReadWithoutBlocking(int fd, MessagePumpLibevent* pump); |
| 86 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump); | 84 void OnFileCanWriteWithoutBlocking(int fd, MessagePumpLibevent* pump); |
| 87 | 85 |
| 88 event* event_; | 86 event* event_; |
| 89 MessagePumpLibevent* pump_; | 87 MessagePumpLibevent* pump_; |
| 90 Watcher* watcher_; | 88 Watcher* watcher_; |
| 91 base::WeakPtrFactory<FileDescriptorWatcher> weak_factory_; | 89 base::WeakPtrFactory<FileDescriptorWatcher> weak_factory_; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 108 // If a FileDescriptorWatcher is passed in which is already attached to | 106 // If a FileDescriptorWatcher is passed in which is already attached to |
| 109 // an event, then the effect is cumulative i.e. after the call |controller| | 107 // an event, then the effect is cumulative i.e. after the call |controller| |
| 110 // will watch both the previous event and the new one. | 108 // will watch both the previous event and the new one. |
| 111 // If an error occurs while calling this method in a cumulative fashion, the | 109 // If an error occurs while calling this method in a cumulative fashion, the |
| 112 // event previously attached to |controller| is aborted. | 110 // event previously attached to |controller| is aborted. |
| 113 // Returns true on success. | 111 // Returns true on success. |
| 114 // Must be called on the same thread the message_pump is running on. | 112 // Must be called on the same thread the message_pump is running on. |
| 115 // TODO(dkegel): switch to edge-triggered readiness notification | 113 // TODO(dkegel): switch to edge-triggered readiness notification |
| 116 bool WatchFileDescriptor(int fd, | 114 bool WatchFileDescriptor(int fd, |
| 117 bool persistent, | 115 bool persistent, |
| 118 Mode mode, | 116 int mode, |
| 119 FileDescriptorWatcher *controller, | 117 FileDescriptorWatcher *controller, |
| 120 Watcher *delegate); | 118 Watcher *delegate); |
| 121 | 119 |
| 122 void AddIOObserver(IOObserver* obs); | 120 void AddIOObserver(IOObserver* obs); |
| 123 void RemoveIOObserver(IOObserver* obs); | 121 void RemoveIOObserver(IOObserver* obs); |
| 124 | 122 |
| 125 // MessagePump methods: | 123 // MessagePump methods: |
| 126 virtual void Run(Delegate* delegate) OVERRIDE; | 124 virtual void Run(Delegate* delegate) OVERRIDE; |
| 127 virtual void Quit() OVERRIDE; | 125 virtual void Quit() OVERRIDE; |
| 128 virtual void ScheduleWork() OVERRIDE; | 126 virtual void ScheduleWork() OVERRIDE; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 event* wakeup_event_; | 170 event* wakeup_event_; |
| 173 | 171 |
| 174 ObserverList<IOObserver> io_observers_; | 172 ObserverList<IOObserver> io_observers_; |
| 175 ThreadChecker watch_file_descriptor_caller_checker_; | 173 ThreadChecker watch_file_descriptor_caller_checker_; |
| 176 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); | 174 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); |
| 177 }; | 175 }; |
| 178 | 176 |
| 179 } // namespace base | 177 } // namespace base |
| 180 | 178 |
| 181 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ | 179 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ |
| OLD | NEW |