Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Side by Side Diff: message_loop/message_pump_libevent.h

Issue 1921183002: Add a mechanism to extend a libevent based message pump. (Closed) Base URL: https://chromium.googlesource.com/external/github.com/domokit/base@master
Patch Set: added test case Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « message_loop/message_loop.cc ('k') | message_loop/message_pump_libevent.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/message_loop/message_pump.h" 10 #include "base/message_loop/message_pump.h"
(...skipping 19 matching lines...) Expand all
30 // MessagePump. 30 // MessagePump.
31 // 31 //
32 // NOTE: An IOObserver implementation should be extremely fast! 32 // NOTE: An IOObserver implementation should be extremely fast!
33 virtual void WillProcessIOEvent() = 0; 33 virtual void WillProcessIOEvent() = 0;
34 virtual void DidProcessIOEvent() = 0; 34 virtual void DidProcessIOEvent() = 0;
35 35
36 protected: 36 protected:
37 virtual ~IOObserver() {} 37 virtual ~IOObserver() {}
38 }; 38 };
39 39
40 // Called to poll for events during each loop.
41 // Should return true if any events were processed.
42 class EventSource {
43 public:
44 EventSource() {}
45
46 virtual bool Poll() = 0;
47
48 protected:
49 virtual ~EventSource() {}
50 };
51
40 // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness 52 // Used with WatchFileDescriptor to asynchronously monitor the I/O readiness
41 // of a file descriptor. 53 // of a file descriptor.
42 class Watcher { 54 class Watcher {
43 public: 55 public:
44 // Called from MessageLoop::Run when an FD can be read from/written to 56 // Called from MessageLoop::Run when an FD can be read from/written to
45 // without blocking 57 // without blocking
46 virtual void OnFileCanReadWithoutBlocking(int fd) = 0; 58 virtual void OnFileCanReadWithoutBlocking(int fd) = 0;
47 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0; 59 virtual void OnFileCanWriteWithoutBlocking(int fd) = 0;
48 60
49 protected: 61 protected:
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // TODO(dkegel): switch to edge-triggered readiness notification 127 // TODO(dkegel): switch to edge-triggered readiness notification
116 bool WatchFileDescriptor(int fd, 128 bool WatchFileDescriptor(int fd,
117 bool persistent, 129 bool persistent,
118 int mode, 130 int mode,
119 FileDescriptorWatcher *controller, 131 FileDescriptorWatcher *controller,
120 Watcher *delegate); 132 Watcher *delegate);
121 133
122 void AddIOObserver(IOObserver* obs); 134 void AddIOObserver(IOObserver* obs);
123 void RemoveIOObserver(IOObserver* obs); 135 void RemoveIOObserver(IOObserver* obs);
124 136
137 void SetEventSource(EventSource* event_source);
138 void ClearEventSource();
139
125 // MessagePump methods: 140 // MessagePump methods:
126 void Run(Delegate* delegate) override; 141 void Run(Delegate* delegate) override;
127 void Quit() override; 142 void Quit() override;
128 void ScheduleWork() override; 143 void ScheduleWork() override;
129 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override; 144 void ScheduleDelayedWork(const TimeTicks& delayed_work_time) override;
130 145
131 private: 146 private:
132 friend class MessagePumpLibeventTest; 147 friend class MessagePumpLibeventTest;
133 148
134 void WillProcessIOEvent(); 149 void WillProcessIOEvent();
135 void DidProcessIOEvent(); 150 void DidProcessIOEvent();
136 151
152 bool PollEventSource();
153
137 // Risky part of constructor. Returns true on success. 154 // Risky part of constructor. Returns true on success.
138 bool Init(); 155 bool Init();
139 156
140 // Called by libevent to tell us a registered FD can be read/written to. 157 // Called by libevent to tell us a registered FD can be read/written to.
141 static void OnLibeventNotification(int fd, short flags, 158 static void OnLibeventNotification(int fd, short flags,
142 void* context); 159 void* context);
143 160
144 // Unix pipe used to implement ScheduleWork() 161 // Unix pipe used to implement ScheduleWork()
145 // ... callback; called by libevent inside Run() when pipe is ready to read 162 // ... callback; called by libevent inside Run() when pipe is ready to read
146 static void OnWakeup(int socket, short flags, void* context); 163 static void OnWakeup(int socket, short flags, void* context);
(...skipping 15 matching lines...) Expand all
162 event_base* event_base_; 179 event_base* event_base_;
163 180
164 // ... write end; ScheduleWork() writes a single byte to it 181 // ... write end; ScheduleWork() writes a single byte to it
165 int wakeup_pipe_in_; 182 int wakeup_pipe_in_;
166 // ... read end; OnWakeup reads it and then breaks Run() out of its sleep 183 // ... read end; OnWakeup reads it and then breaks Run() out of its sleep
167 int wakeup_pipe_out_; 184 int wakeup_pipe_out_;
168 // ... libevent wrapper for read end 185 // ... libevent wrapper for read end
169 event* wakeup_event_; 186 event* wakeup_event_;
170 187
171 ObserverList<IOObserver> io_observers_; 188 ObserverList<IOObserver> io_observers_;
189 EventSource* event_source_;
172 ThreadChecker watch_file_descriptor_caller_checker_; 190 ThreadChecker watch_file_descriptor_caller_checker_;
173 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent); 191 DISALLOW_COPY_AND_ASSIGN(MessagePumpLibevent);
174 }; 192 };
175 193
176 } // namespace base 194 } // namespace base
177 195
178 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_ 196 #endif // BASE_MESSAGE_LOOP_MESSAGE_PUMP_LIBEVENT_H_
OLDNEW
« no previous file with comments | « message_loop/message_loop.cc ('k') | message_loop/message_pump_libevent.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698