안드로이드 - Looper
Looper
키보드, 모션(터치) 등을 처리하는 기능.
..\Android\android-ndk-r13b\platforms\android-12\arch-x86\usr\include\android\looper.h
/**
* For callback-based event loops, this is the prototype of the function
* that is called when a file descriptor event occurs.
* It is given the file descriptor it is associated with,
* a bitmask of the poll events that were triggered (typically ALOOPER_EVENT_INPUT),
* and the data pointer that was originally supplied.
*
* Implementations should return 1 to continue receiving callbacks, or 0
* to have this file descriptor and callback unregistered from the looper.
*/
typedef int (*ALooper_callbackFunc)(int fd, int events, void* data);
/**
* Waits for events to be available, with optional timeout in milliseconds.
* Invokes callbacks for all file descriptors on which an event occurred.
*
* If the timeout is zero, returns immediately without blocking.
* If the timeout is negative, waits indefinitely until an event appears.
*
* Returns ALOOPER_POLL_WAKE if the poll was awoken using wake() before
* the timeout expired and no callbacks were invoked and no other file
* descriptors were ready.
*
* Returns ALOOPER_POLL_CALLBACK if one or more callbacks were invoked.
*
* Returns ALOOPER_POLL_TIMEOUT if there was no data before the given
* timeout expired.
*
* Returns ALOOPER_POLL_ERROR if an error occurred.
*
* Returns a value >= 0 containing an identifier if its file descriptor has data
* and it has no callback function (requiring the caller here to handle it).
* In this (and only this) case outFd, outEvents and outData will contain the poll
* events and data associated with the fd, otherwise they will be set to NULL.
*
* This method does not return until it has finished invoking the appropriate callbacks
* for all file descriptors that were signalled.
*/
int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData);
/**
* Like ALooper_pollOnce(), but performs all pending callbacks until all
* data has been consumed or a file descriptor is available with no callback.
* This function will never return ALOOPER_POLL_CALLBACK.
*/
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData);
// loop waiting for stuff to do.
//on_program_start();
while (1) {
// Read all pending events.
int ident;
int events;
struct android_poll_source* source;
// If not animating, we will block forever waiting for events.
// If animating, we loop until all events are read, then continue
// to draw the next frame of animation.
while ((ident=ALooper_pollAll(engine.animating ? 0 : -1, NULL, &events,
(void**)&source)) >= 0) {
// Process this event.
if (source != NULL) {
source->process(state, source);
}
// Check if we are exiting.
if (state->destroyRequested != 0) {
DEBUG_socket_printf("Engine thread destroy requested!\r\n");
//engine_term_display(&engine);
goto end;//return;
}
}
if (engine.animating)
{
engine_draw_frame(&engine);
}
}
'안드로이드' 카테고리의 다른 글
안드로이드 APK파일 디버깅 데이터 제거방법 (0) | 2017.02.18 |
---|---|
안드로이드 - NDK - ANativeWindow_Buffer (0) | 2017.02.18 |
안드로이드 - NDK 사용법 (0) | 2017.02.18 |
안드로이드 - assets 폴더 (0) | 2017.02.05 |
ant로 안드로이드 앱을 자동으로 빌드하자 (0) | 2017.02.04 |