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_LOOP_MESSAGE_PUMP_LIBEVENT_H_ | 5 #ifndef BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ |
6 #define BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ | 6 #define BASE_MESSAGE_LOOP_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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); | 91 DISALLOW_COPY_AND_ASSIGN(FileDescriptorWatcher); |
92 }; | 92 }; |
93 | 93 |
94 enum Mode { | 94 enum Mode { |
95 WATCH_READ = 1 << 0, | 95 WATCH_READ = 1 << 0, |
96 WATCH_WRITE = 1 << 1, | 96 WATCH_WRITE = 1 << 1, |
97 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE | 97 WATCH_READ_WRITE = WATCH_READ | WATCH_WRITE |
98 }; | 98 }; |
99 | 99 |
100 MessagePumpLibevent(); | 100 MessagePumpLibevent(); |
101 virtual ~MessagePumpLibevent(); | |
102 | 101 |
103 // Have the current thread's message loop watch for a a situation in which | 102 // Have the current thread's message loop watch for a a situation in which |
104 // reading/writing to the FD can be performed without blocking. | 103 // reading/writing to the FD can be performed without blocking. |
105 // Callers must provide a preallocated FileDescriptorWatcher object which | 104 // Callers must provide a preallocated FileDescriptorWatcher object which |
106 // can later be used to manage the lifetime of this event. | 105 // can later be used to manage the lifetime of this event. |
107 // If a FileDescriptorWatcher is passed in which is already attached to | 106 // If a FileDescriptorWatcher is passed in which is already attached to |
108 // 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| |
109 // will watch both the previous event and the new one. | 108 // will watch both the previous event and the new one. |
110 // 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 |
111 // event previously attached to |controller| is aborted. | 110 // event previously attached to |controller| is aborted. |
112 // Returns true on success. | 111 // Returns true on success. |
113 // 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. |
114 // TODO(dkegel): switch to edge-triggered readiness notification | 113 // TODO(dkegel): switch to edge-triggered readiness notification |
115 bool WatchFileDescriptor(int fd, | 114 bool WatchFileDescriptor(int fd, |
116 bool persistent, | 115 bool persistent, |
117 int mode, | 116 int mode, |
118 FileDescriptorWatcher *controller, | 117 FileDescriptorWatcher *controller, |
119 Watcher *delegate); | 118 Watcher *delegate); |
120 | 119 |
121 void AddIOObserver(IOObserver* obs); | 120 void AddIOObserver(IOObserver* obs); |
122 void RemoveIOObserver(IOObserver* obs); | 121 void RemoveIOObserver(IOObserver* obs); |
123 | 122 |
124 // MessagePump methods: | 123 // MessagePump methods: |
125 virtual void Run(Delegate* delegate) OVERRIDE; | 124 virtual void Run(Delegate* delegate) OVERRIDE; |
126 virtual void Quit() OVERRIDE; | 125 virtual void Quit() OVERRIDE; |
127 virtual void ScheduleWork() OVERRIDE; | 126 virtual void ScheduleWork() OVERRIDE; |
128 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; | 127 virtual void ScheduleDelayedWork(const TimeTicks& delayed_work_time) OVERRIDE; |
129 | 128 |
| 129 protected: |
| 130 virtual ~MessagePumpLibevent(); |
| 131 |
130 private: | 132 private: |
131 friend class MessagePumpLibeventTest; | 133 friend class MessagePumpLibeventTest; |
132 | 134 |
133 void WillProcessIOEvent(); | 135 void WillProcessIOEvent(); |
134 void DidProcessIOEvent(); | 136 void DidProcessIOEvent(); |
135 | 137 |
136 // Risky part of constructor. Returns true on success. | 138 // Risky part of constructor. Returns true on success. |
137 bool Init(); | 139 bool Init(); |
138 | 140 |
139 // Called by libevent to tell us a registered FD can be read/written to. | 141 // Called by libevent to tell us a registered FD can be read/written to. |
(...skipping 28 matching lines...) Expand all Loading... |
168 event* wakeup_event_; | 170 event* wakeup_event_; |
169 | 171 |
170 ObserverList<IOObserver> io_observers_; | 172 ObserverList<IOObserver> io_observers_; |
171 ThreadChecker watch_file_descriptor_caller_checker_; | 173 ThreadChecker watch_file_descriptor_caller_checker_; |
172 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); | 174 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); |
173 }; | 175 }; |
174 | 176 |
175 } // namespace base | 177 } // namespace base |
176 | 178 |
177 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ | 179 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ |
OLD | NEW |