diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-09-13 23:17:30 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2010-09-14 01:59:45 -0700 |
commit | 4fe6c3e51be77e35f40872cdbca6c80f8f8b7ecb (patch) | |
tree | 5cbcfad147ad1bf26deb384e41d27f4e6bfcdb80 /core/jni/android_app_NativeActivity.cpp | |
parent | c891d2b3529b9cf24ef4781a585cd4784815e711 (diff) | |
download | frameworks_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 'core/jni/android_app_NativeActivity.cpp')
-rw-r--r-- | core/jni/android_app_NativeActivity.cpp | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/core/jni/android_app_NativeActivity.cpp b/core/jni/android_app_NativeActivity.cpp index 2517a8a..6aa77f6 100644 --- a/core/jni/android_app_NativeActivity.cpp +++ b/core/jni/android_app_NativeActivity.cpp @@ -28,7 +28,7 @@ #include <surfaceflinger/Surface.h> #include <ui/egl/android_natives.h> #include <ui/InputTransport.h> -#include <utils/PollLoop.h> +#include <utils/Looper.h> #include "JNIHelp.h" #include "android_os_MessageQueue.h" @@ -128,17 +128,17 @@ AInputQueue::~AInputQueue() { } void AInputQueue::attachLooper(ALooper* looper, int ident, - ALooper_callbackFunc* callback, void* data) { - mPollLoop = static_cast<android::PollLoop*>(looper); - mPollLoop->setLooperCallback(mConsumer.getChannel()->getReceivePipeFd(), - ident, POLLIN, callback, data); - mPollLoop->setLooperCallback(mDispatchKeyRead, - ident, POLLIN, callback, data); + ALooper_callbackFunc callback, void* data) { + mLooper = static_cast<android::Looper*>(looper); + mLooper->addFd(mConsumer.getChannel()->getReceivePipeFd(), + ident, ALOOPER_EVENT_INPUT, callback, data); + mLooper->addFd(mDispatchKeyRead, + ident, ALOOPER_EVENT_INPUT, callback, data); } void AInputQueue::detachLooper() { - mPollLoop->removeCallback(mConsumer.getChannel()->getReceivePipeFd()); - mPollLoop->removeCallback(mDispatchKeyRead); + mLooper->removeFd(mConsumer.getChannel()->getReceivePipeFd()); + mLooper->removeFd(mDispatchKeyRead); } int32_t AInputQueue::hasEvents() { @@ -440,8 +440,8 @@ struct NativeCode : public ANativeActivity { if (env != NULL && clazz != NULL) { env->DeleteGlobalRef(clazz); } - if (pollLoop != NULL && mainWorkRead >= 0) { - pollLoop->removeCallback(mainWorkRead); + if (looper != NULL && mainWorkRead >= 0) { + looper->removeFd(mainWorkRead); } if (nativeInputQueue != NULL) { nativeInputQueue->mWorkWrite = -1; @@ -509,7 +509,7 @@ struct NativeCode : public ANativeActivity { // These are used to wake up the main thread to process work. int mainWorkRead; int mainWorkWrite; - sp<PollLoop> pollLoop; + sp<Looper> looper; }; void android_NativeActivity_setWindowFormat( @@ -541,15 +541,15 @@ void android_NativeActivity_hideSoftInput( /* * Callback for handling native events on the application's main thread. */ -static bool mainWorkCallback(int fd, int events, void* data) { +static int mainWorkCallback(int fd, int events, void* data) { NativeCode* code = (NativeCode*)data; if ((events & POLLIN) == 0) { - return true; + return 1; } ActivityWork work; if (!read_work(code->mainWorkRead, &work)) { - return true; + return 1; } LOG_TRACE("mainWorkCallback: cmd=%d", work.cmd); @@ -593,7 +593,7 @@ static bool mainWorkCallback(int fd, int events, void* data) { break; } - return true; + return 1; } // ------------------------------------------------------------------------ @@ -621,9 +621,9 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQ return 0; } - code->pollLoop = android_os_MessageQueue_getPollLoop(env, messageQueue); - if (code->pollLoop == NULL) { - LOGW("Unable to retrieve MessageQueue's PollLoop"); + code->looper = android_os_MessageQueue_getLooper(env, messageQueue); + if (code->looper == NULL) { + LOGW("Unable to retrieve MessageQueue's Looper"); delete code; return 0; } @@ -642,7 +642,7 @@ loadNativeCode_native(JNIEnv* env, jobject clazz, jstring path, jobject messageQ result = fcntl(code->mainWorkWrite, F_SETFL, O_NONBLOCK); SLOGW_IF(result != 0, "Could not make main work write pipe " "non-blocking: %s", strerror(errno)); - code->pollLoop->setCallback(code->mainWorkRead, POLLIN, mainWorkCallback, code); + code->looper->addFd(code->mainWorkRead, 0, ALOOPER_EVENT_INPUT, mainWorkCallback, code); code->ANativeActivity::callbacks = &code->callbacks; if (env->GetJavaVM(&code->vm) < 0) { |