diff options
Diffstat (limited to 'native/android')
-rw-r--r-- | native/android/input.cpp | 4 | ||||
-rw-r--r-- | native/android/looper.cpp | 75 | ||||
-rw-r--r-- | native/android/sensor.cpp | 6 |
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); } |