summaryrefslogtreecommitdiffstats
path: root/native/android
diff options
context:
space:
mode:
authorJeff Brown <jeffbrown@google.com>2010-09-13 23:17:30 -0700
committerJeff Brown <jeffbrown@google.com>2010-09-14 01:59:45 -0700
commit4fe6c3e51be77e35f40872cdbca6c80f8f8b7ecb (patch)
tree5cbcfad147ad1bf26deb384e41d27f4e6bfcdb80 /native/android
parentc891d2b3529b9cf24ef4781a585cd4784815e711 (diff)
downloadframeworks_base-4fe6c3e51be77e35f40872cdbca6c80f8f8b7ecb.zip
frameworks_base-4fe6c3e51be77e35f40872cdbca6c80f8f8b7ecb.tar.gz
frameworks_base-4fe6c3e51be77e35f40872cdbca6c80f8f8b7ecb.tar.bz2
Replace epoll() with poll() and rename PollLoop to Looper.
As part of this change, consolidated and cleaned up the Looper API so that there are fewer distinctions between the NDK and non-NDK declarations (no need for two callback types, etc.). Removed the dependence on specific constants from sys/poll.h such as POLLIN. Instead looper.h defines events like LOOPER_EVENT_INPUT for the events that it supports. That should help make any future under-the-hood implementation changes easier. Fixed a couple of compiler warnings along the way. Change-Id: I449a7ec780bf061bdd325452f823673e2b39b6ae
Diffstat (limited to 'native/android')
-rw-r--r--native/android/input.cpp4
-rw-r--r--native/android/looper.cpp75
-rw-r--r--native/android/sensor.cpp6
3 files changed, 38 insertions, 47 deletions
diff --git a/native/android/input.cpp b/native/android/input.cpp
index 57f0072..c753aa5 100644
--- a/native/android/input.cpp
+++ b/native/android/input.cpp
@@ -20,7 +20,7 @@
#include <android/input.h>
#include <ui/Input.h>
#include <ui/InputTransport.h>
-#include <utils/PollLoop.h>
+#include <utils/Looper.h>
#include <utils/RefBase.h>
#include <utils/Vector.h>
@@ -250,7 +250,7 @@ float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t po
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
- int ident, ALooper_callbackFunc* callback, void* data) {
+ int ident, ALooper_callbackFunc callback, void* data) {
queue->attachLooper(looper, ident, callback, data);
}
diff --git a/native/android/looper.cpp b/native/android/looper.cpp
index 0aeed77..9f5cda9 100644
--- a/native/android/looper.cpp
+++ b/native/android/looper.cpp
@@ -18,65 +18,56 @@
#include <utils/Log.h>
#include <android/looper.h>
-#include <utils/PollLoop.h>
+#include <utils/Looper.h>
-using android::PollLoop;
+using android::Looper;
using android::sp;
ALooper* ALooper_forThread() {
- return PollLoop::getForThread().get();
+ return Looper::getForThread().get();
}
-ALooper* ALooper_prepare(int32_t opts) {
- bool allowFds = (opts&ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) != 0;
- sp<PollLoop> loop = PollLoop::getForThread();
- if (loop == NULL) {
- loop = new PollLoop(allowFds);
- PollLoop::setForThread(loop);
- }
- if (loop->getAllowNonCallbacks() != allowFds) {
- LOGW("ALooper_prepare again with different ALOOPER_PREPARE_ALLOW_NON_CALLBACKS");
- }
- return loop.get();
+ALooper* ALooper_prepare(int opts) {
+ return Looper::prepare(opts).get();
}
-int32_t ALooper_pollOnce(int timeoutMillis, int* outEvents, void** outData) {
- sp<PollLoop> loop = PollLoop::getForThread();
- if (loop == NULL) {
- LOGW("ALooper_pollOnce: No looper for this thread!");
- return -1;
- }
- return loop->pollOnce(timeoutMillis, outEvents, outData);
+void ALooper_acquire(ALooper* looper) {
+ static_cast<Looper*>(looper)->incStrong((void*)ALooper_acquire);
}
-int32_t ALooper_pollAll(int timeoutMillis, int* outEvents, void** outData) {
- sp<PollLoop> loop = PollLoop::getForThread();
- if (loop == NULL) {
- LOGW("ALooper_pollOnce: No looper for this thread!");
- return -1;
- }
-
- int32_t result;
- while ((result = loop->pollOnce(timeoutMillis, outEvents, outData)) == ALOOPER_POLL_CALLBACK) {
- ;
+void ALooper_release(ALooper* looper) {
+ static_cast<Looper*>(looper)->decStrong((void*)ALooper_acquire);
+}
+
+int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
+ sp<Looper> looper = Looper::getForThread();
+ if (looper == NULL) {
+ LOGE("ALooper_pollOnce: No looper for this thread!");
+ return ALOOPER_POLL_ERROR;
}
-
- return result;
+
+ return looper->pollOnce(timeoutMillis, outFd, outEvents, outData);
}
-void ALooper_acquire(ALooper* looper) {
- static_cast<PollLoop*>(looper)->incStrong((void*)ALooper_acquire);
+int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
+ sp<Looper> looper = Looper::getForThread();
+ if (looper == NULL) {
+ LOGE("ALooper_pollAll: No looper for this thread!");
+ return ALOOPER_POLL_ERROR;
+ }
+
+ return looper->pollAll(timeoutMillis, outFd, outEvents, outData);
}
-void ALooper_release(ALooper* looper) {
- static_cast<PollLoop*>(looper)->decStrong((void*)ALooper_acquire);
+void ALooper_wake(ALooper* looper) {
+ static_cast<Looper*>(looper)->wake();
}
-void ALooper_addFd(ALooper* looper, int fd, int ident, int events,
- ALooper_callbackFunc* callback, void* data) {
- static_cast<PollLoop*>(looper)->setLooperCallback(fd, ident, events, callback, data);
+int ALooper_addFd(ALooper* looper, int fd, int ident, int events,
+ ALooper_callbackFunc callback, void* data) {
+ return static_cast<Looper*>(looper)->addFd(fd, ident, events, callback, data);
}
-int32_t ALooper_removeFd(ALooper* looper, int fd) {
- return static_cast<PollLoop*>(looper)->removeCallback(fd) ? 1 : 0;
+int ALooper_removeFd(ALooper* looper, int fd) {
+ return static_cast<Looper*>(looper)->removeFd(fd);
}
diff --git a/native/android/sensor.cpp b/native/android/sensor.cpp
index cf7635d..76c6eda 100644
--- a/native/android/sensor.cpp
+++ b/native/android/sensor.cpp
@@ -21,7 +21,7 @@
#include <android/sensor.h>
#include <utils/RefBase.h>
-#include <utils/PollLoop.h>
+#include <utils/Looper.h>
#include <utils/Timers.h>
#include <gui/Sensor.h>
@@ -60,12 +60,12 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type
}
ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
- ALooper* looper, int ident, ALooper_callbackFunc* callback, void* data)
+ ALooper* looper, int ident, ALooper_callbackFunc callback, void* data)
{
sp<SensorEventQueue> queue =
static_cast<SensorManager*>(manager)->createEventQueue();
if (queue != 0) {
- ALooper_addFd(looper, queue->getFd(), ident, POLLIN, callback, data);
+ ALooper_addFd(looper, queue->getFd(), ident, ALOOPER_EVENT_INPUT, callback, data);
queue->looper = looper;
queue->incStrong(manager);
}