OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); | 93 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); |
94 }; | 94 }; |
95 | 95 |
96 enum Mode { | 96 enum Mode { |
97 WATCH_READ = 1 << 0, | 97 WATCH_READ = 1 << 0, |
98 WATCH_WRITE = 1 << 1, | 98 WATCH_WRITE = 1 << 1, |
99 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE | 99 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE |
100 }; | 100 }; |
101 | 101 |
102 MessagePumpLibevent(); | 102 MessagePumpLibevent(); |
103 virtual ~MessagePumpLibevent(); | |
104 | 103 |
105 // Have the current thread's message loop watch for a a situation in which | 104 // Have the current thread's message loop watch for a a situation in which |
106 // reading/writing to the FD can be performed without blocking. | 105 // reading/writing to the FD can be performed without blocking. |
107 // Callers must provide a preallocated FileDescriptorWatcher object which | 106 // Callers must provide a preallocated FileDescriptorWatcher object which |
108 // can later be used to manage the lifetime of this event. | 107 // can later be used to manage the lifetime of this event. |
109 // If a FileDescriptorWatcher is passed in which is already attached to | 108 // If a FileDescriptorWatcher is passed in which is already attached to |
110 // an event, then the effect is cumulative i.e. after the call |controller| | 109 // an event, then the effect is cumulative i.e. after the call |controller| |
111 // will watch both the previous event and the new one. | 110 // will watch both the previous event and the new one. |
112 // If an error occurs while calling this method in a cumulative fashion, the | 111 // If an error occurs while calling this method in a cumulative fashion, the |
113 // event previously attached to |controller| is aborted. | 112 // event previously attached to |controller| is aborted. |
114 // Returns true on success. | 113 // Returns true on success. |
115 // Must be called on the same thread the message_pump is running on. | 114 // Must be called on the same thread the message_pump is running on. |
116 // TODO(dkegel): switch to edge-triggered readiness notification | 115 // TODO(dkegel): switch to edge-triggered readiness notification |
117 bool WatchFileDescriptor(int fd, | 116 bool WatchFileDescriptor(int fd, |
118 bool persistent, | 117 bool persistent, |
119 Mode mode, | 118 Mode mode, |
120 FileDescriptorWatcher *controller, | 119 FileDescriptorWatcher *controller, |
121 Watcher *delegate); | 120 Watcher *delegate); |
122 | 121 |
123 void AddIOObserver(IOObserver* obs); | 122 void AddIOObserver(IOObserver* obs); |
124 void RemoveIOObserver(IOObserver* obs); | 123 void RemoveIOObserver(IOObserver* obs); |
125 | 124 |
126 // MessagePump methods: | 125 // MessagePump methods: |
127 virtual void Run(Delegate* delegate) OVERRIDE; | 126 virtual void Run(Delegate* delegate) OVERRIDE; |
128 virtual void Quit() OVERRIDE; | 127 virtual void Quit() OVERRIDE; |
129 virtual void ScheduleWork() OVERRIDE; | 128 virtual void ScheduleWork() OVERRIDE; |
130 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; | 129 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; |
131 | 130 |
| 131 protected: |
| 132 virtual ~MessagePumpLibevent(); |
| 133 |
132 private: | 134 private: |
133 friend class MessagePumpLibeventTest; | 135 friend class MessagePumpLibeventTest; |
134 | 136 |
135 void WillProcessIOEvent(); | 137 void WillProcessIOEvent(); |
136 void DidProcessIOEvent(); | 138 void DidProcessIOEvent(); |
137 | 139 |
138 // Risky part of constructor. Returns true on success. | 140 // Risky part of constructor. Returns true on success. |
139 bool Init(); | 141 bool Init(); |
140 | 142 |
141 // Called by libevent to tell us a registered FD can be read/written to. | 143 // Called by libevent to tell us a registered FD can be read/written to. |
(...skipping 28 matching lines...) Expand all Loading... |
170 event* wakeup_event_; | 172 event* wakeup_event_; |
171 | 173 |
172 ObserverList<IOObserver> io_observers_; | 174 ObserverList<IOObserver> io_observers_; |
173 ThreadChecker watch_file_descriptor_caller_checker_; | 175 ThreadChecker watch_file_descriptor_caller_checker_; |
174 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); | 176 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); |
175 }; | 177 }; |
176 | 178 |
177 } // namespace base | 179 } // namespace base |
178 | 180 |
179 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ | 181 #endif // BASE_MESSAGE_PUMP_LIBEVENT_H_ |
OLD | NEW |