summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Carlstrom2013-12-12 00:46:45 -0600
committerBrian Carlstrom2013-12-19 00:32:13 -0600
commit1693d7e48f976c2615100378c7e98d245e0213be (patch)
treec7d44f2b69021f0d96887a9e6b36fdade2bcf7d5 /libutils/Looper.cpp
parentd27498cbef862fccb857d7d8970418b893f550ca (diff)
downloadplatform-system-core-1693d7e48f976c2615100378c7e98d245e0213be.tar.gz
platform-system-core-1693d7e48f976c2615100378c7e98d245e0213be.tar.xz
platform-system-core-1693d7e48f976c2615100378c7e98d245e0213be.zip
Make libutils Looper independent of frameworks/native
Change-Id: I1dacca10a3cd7601abc3451b69ed761bf71c38fe
Diffstat (limited to 'libutils/Looper.cpp')
-rw-r--r--libutils/Looper.cpp40
1 files changed, 20 insertions, 20 deletions
diff --git a/libutils/Looper.cpp b/libutils/Looper.cpp
index c51df2d1a..9a2dd6cc4 100644
--- a/libutils/Looper.cpp
+++ b/libutils/Looper.cpp
@@ -43,7 +43,7 @@ void WeakMessageHandler::handleMessage(const Message& message) {
43 43
44// --- SimpleLooperCallback --- 44// --- SimpleLooperCallback ---
45 45
46SimpleLooperCallback::SimpleLooperCallback(ALooper_callbackFunc callback) : 46SimpleLooperCallback::SimpleLooperCallback(Looper_callbackFunc callback) :
47 mCallback(callback) { 47 mCallback(callback) {
48} 48}
49 49
@@ -139,7 +139,7 @@ sp<Looper> Looper::getForThread() {
139} 139}
140 140
141sp<Looper> Looper::prepare(int opts) { 141sp<Looper> Looper::prepare(int opts) {
142 bool allowNonCallbacks = opts & ALOOPER_PREPARE_ALLOW_NON_CALLBACKS; 142 bool allowNonCallbacks = opts & PREPARE_ALLOW_NON_CALLBACKS;
143 sp<Looper> looper = Looper::getForThread(); 143 sp<Looper> looper = Looper::getForThread();
144 if (looper == NULL) { 144 if (looper == NULL) {
145 looper = new Looper(allowNonCallbacks); 145 looper = new Looper(allowNonCallbacks);
@@ -147,7 +147,7 @@ sp<Looper> Looper::prepare(int opts) {
147 } 147 }
148 if (looper->getAllowNonCallbacks() != allowNonCallbacks) { 148 if (looper->getAllowNonCallbacks() != allowNonCallbacks) {
149 ALOGW("Looper already prepared for this thread with a different value for the " 149 ALOGW("Looper already prepared for this thread with a different value for the "
150 "ALOOPER_PREPARE_ALLOW_NON_CALLBACKS option."); 150 "LOOPER_PREPARE_ALLOW_NON_CALLBACKS option.");
151 } 151 }
152 return looper; 152 return looper;
153} 153}
@@ -212,7 +212,7 @@ int Looper::pollInner(int timeoutMillis) {
212 } 212 }
213 213
214 // Poll. 214 // Poll.
215 int result = ALOOPER_POLL_WAKE; 215 int result = POLL_WAKE;
216 mResponses.clear(); 216 mResponses.clear();
217 mResponseIndex = 0; 217 mResponseIndex = 0;
218 218
@@ -234,7 +234,7 @@ int Looper::pollInner(int timeoutMillis) {
234 goto Done; 234 goto Done;
235 } 235 }
236 ALOGW("Poll failed with an unexpected error, errno=%d", errno); 236 ALOGW("Poll failed with an unexpected error, errno=%d", errno);
237 result = ALOOPER_POLL_ERROR; 237 result = POLL_ERROR;
238 goto Done; 238 goto Done;
239 } 239 }
240 240
@@ -243,7 +243,7 @@ int Looper::pollInner(int timeoutMillis) {
243#if DEBUG_POLL_AND_WAKE 243#if DEBUG_POLL_AND_WAKE
244 ALOGD("%p ~ pollOnce - timeout", this); 244 ALOGD("%p ~ pollOnce - timeout", this);
245#endif 245#endif
246 result = ALOOPER_POLL_TIMEOUT; 246 result = POLL_TIMEOUT;
247 goto Done; 247 goto Done;
248 } 248 }
249 249
@@ -265,10 +265,10 @@ int Looper::pollInner(int timeoutMillis) {
265 ssize_t requestIndex = mRequests.indexOfKey(fd); 265 ssize_t requestIndex = mRequests.indexOfKey(fd);
266 if (requestIndex >= 0) { 266 if (requestIndex >= 0) {
267 int events = 0; 267 int events = 0;
268 if (epollEvents & EPOLLIN) events |= ALOOPER_EVENT_INPUT; 268 if (epollEvents & EPOLLIN) events |= EVENT_INPUT;
269 if (epollEvents & EPOLLOUT) events |= ALOOPER_EVENT_OUTPUT; 269 if (epollEvents & EPOLLOUT) events |= EVENT_OUTPUT;
270 if (epollEvents & EPOLLERR) events |= ALOOPER_EVENT_ERROR; 270 if (epollEvents & EPOLLERR) events |= EVENT_ERROR;
271 if (epollEvents & EPOLLHUP) events |= ALOOPER_EVENT_HANGUP; 271 if (epollEvents & EPOLLHUP) events |= EVENT_HANGUP;
272 pushResponse(events, mRequests.valueAt(requestIndex)); 272 pushResponse(events, mRequests.valueAt(requestIndex));
273 } else { 273 } else {
274 ALOGW("Ignoring unexpected epoll events 0x%x on fd %d that is " 274 ALOGW("Ignoring unexpected epoll events 0x%x on fd %d that is "
@@ -304,7 +304,7 @@ Done: ;
304 304
305 mLock.lock(); 305 mLock.lock();
306 mSendingMessage = false; 306 mSendingMessage = false;
307 result = ALOOPER_POLL_CALLBACK; 307 result = POLL_CALLBACK;
308 } else { 308 } else {
309 // The last message left at the head of the queue determines the next wakeup time. 309 // The last message left at the head of the queue determines the next wakeup time.
310 mNextMessageUptime = messageEnvelope.uptime; 310 mNextMessageUptime = messageEnvelope.uptime;
@@ -318,7 +318,7 @@ Done: ;
318 // Invoke all response callbacks. 318 // Invoke all response callbacks.
319 for (size_t i = 0; i < mResponses.size(); i++) { 319 for (size_t i = 0; i < mResponses.size(); i++) {
320 Response& response = mResponses.editItemAt(i); 320 Response& response = mResponses.editItemAt(i);
321 if (response.request.ident == ALOOPER_POLL_CALLBACK) { 321 if (response.request.ident == POLL_CALLBACK) {
322 int fd = response.request.fd; 322 int fd = response.request.fd;
323 int events = response.events; 323 int events = response.events;
324 void* data = response.request.data; 324 void* data = response.request.data;
@@ -333,7 +333,7 @@ Done: ;
333 // Clear the callback reference in the response structure promptly because we 333 // Clear the callback reference in the response structure promptly because we
334 // will not clear the response vector itself until the next poll. 334 // will not clear the response vector itself until the next poll.
335 response.request.callback.clear(); 335 response.request.callback.clear();
336 result = ALOOPER_POLL_CALLBACK; 336 result = POLL_CALLBACK;
337 } 337 }
338 } 338 }
339 return result; 339 return result;
@@ -344,7 +344,7 @@ int Looper::pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outDat
344 int result; 344 int result;
345 do { 345 do {
346 result = pollOnce(timeoutMillis, outFd, outEvents, outData); 346 result = pollOnce(timeoutMillis, outFd, outEvents, outData);
347 } while (result == ALOOPER_POLL_CALLBACK); 347 } while (result == POLL_CALLBACK);
348 return result; 348 return result;
349 } else { 349 } else {
350 nsecs_t endTime = systemTime(SYSTEM_TIME_MONOTONIC) 350 nsecs_t endTime = systemTime(SYSTEM_TIME_MONOTONIC)
@@ -352,14 +352,14 @@ int Looper::pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outDat
352 352
353 for (;;) { 353 for (;;) {
354 int result = pollOnce(timeoutMillis, outFd, outEvents, outData); 354 int result = pollOnce(timeoutMillis, outFd, outEvents, outData);
355 if (result != ALOOPER_POLL_CALLBACK) { 355 if (result != POLL_CALLBACK) {
356 return result; 356 return result;
357 } 357 }
358 358
359 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC); 359 nsecs_t now = systemTime(SYSTEM_TIME_MONOTONIC);
360 timeoutMillis = toMillisecondTimeoutDelay(now, endTime); 360 timeoutMillis = toMillisecondTimeoutDelay(now, endTime);
361 if (timeoutMillis == 0) { 361 if (timeoutMillis == 0) {
362 return ALOOPER_POLL_TIMEOUT; 362 return POLL_TIMEOUT;
363 } 363 }
364 } 364 }
365 } 365 }
@@ -401,7 +401,7 @@ void Looper::pushResponse(int events, const Request& request) {
401 mResponses.push(response); 401 mResponses.push(response);
402} 402}
403 403
404int Looper::addFd(int fd, int ident, int events, ALooper_callbackFunc callback, void* data) { 404int Looper::addFd(int fd, int ident, int events, Looper_callbackFunc callback, void* data) {
405 return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data); 405 return addFd(fd, ident, events, callback ? new SimpleLooperCallback(callback) : NULL, data);
406} 406}
407 407
@@ -422,12 +422,12 @@ int Looper::addFd(int fd, int ident, int events, const sp<LooperCallback>& callb
422 return -1; 422 return -1;
423 } 423 }
424 } else { 424 } else {
425 ident = ALOOPER_POLL_CALLBACK; 425 ident = POLL_CALLBACK;
426 } 426 }
427 427
428 int epollEvents = 0; 428 int epollEvents = 0;
429 if (events & ALOOPER_EVENT_INPUT) epollEvents |= EPOLLIN; 429 if (events & EVENT_INPUT) epollEvents |= EPOLLIN;
430 if (events & ALOOPER_EVENT_OUTPUT) epollEvents |= EPOLLOUT; 430 if (events & EVENT_OUTPUT) epollEvents |= EPOLLOUT;
431 431
432 { // acquire lock 432 { // acquire lock
433 AutoMutex _l(mLock); 433 AutoMutex _l(mLock);