Merge "Modify native ALooper to take an explicit ident." into gingerbread
This commit is contained in:
committed by
Android (Google) Code Review
commit
2d3739d479
@ -127,12 +127,13 @@ AInputQueue::~AInputQueue() {
|
|||||||
close(mDispatchKeyWrite);
|
close(mDispatchKeyWrite);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AInputQueue::attachLooper(ALooper* looper, ALooper_callbackFunc* callback, void* data) {
|
void AInputQueue::attachLooper(ALooper* looper, int ident,
|
||||||
|
ALooper_callbackFunc* callback, void* data) {
|
||||||
mPollLoop = static_cast<android::PollLoop*>(looper);
|
mPollLoop = static_cast<android::PollLoop*>(looper);
|
||||||
mPollLoop->setLooperCallback(mConsumer.getChannel()->getReceivePipeFd(),
|
mPollLoop->setLooperCallback(mConsumer.getChannel()->getReceivePipeFd(),
|
||||||
POLLIN, callback, data);
|
ident, POLLIN, callback, data);
|
||||||
mPollLoop->setLooperCallback(mDispatchKeyRead,
|
mPollLoop->setLooperCallback(mDispatchKeyRead,
|
||||||
POLLIN, callback, data);
|
ident, POLLIN, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AInputQueue::detachLooper() {
|
void AInputQueue::detachLooper() {
|
||||||
|
@ -69,7 +69,7 @@ public:
|
|||||||
/* Destroys the consumer and releases its input channel. */
|
/* Destroys the consumer and releases its input channel. */
|
||||||
~AInputQueue();
|
~AInputQueue();
|
||||||
|
|
||||||
void attachLooper(ALooper* looper, ALooper_callbackFunc* callback, void* data);
|
void attachLooper(ALooper* looper, int ident, ALooper_callbackFunc* callback, void* data);
|
||||||
|
|
||||||
void detachLooper();
|
void detachLooper();
|
||||||
|
|
||||||
|
@ -111,12 +111,18 @@ public:
|
|||||||
* This method can be called on any thread.
|
* This method can be called on any thread.
|
||||||
* This method may block briefly if it needs to wake the poll loop.
|
* This method may block briefly if it needs to wake the poll loop.
|
||||||
*/
|
*/
|
||||||
void setCallback(int fd, int events, Callback callback, void* data = NULL);
|
void setCallback(int fd, int ident, int events, Callback callback, void* data = NULL);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convenience for above setCallback when ident is not used. In this case
|
||||||
|
* the ident is set to POLL_CALLBACK.
|
||||||
|
*/
|
||||||
|
void setCallback(int fd, int events, Callback callback, void* data = NULL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Like setCallback(), but for the NDK callback function.
|
* Like setCallback(), but for the NDK callback function.
|
||||||
*/
|
*/
|
||||||
void setLooperCallback(int fd, int events, ALooper_callbackFunc* callback,
|
void setLooperCallback(int fd, int ident, int events, ALooper_callbackFunc* callback,
|
||||||
void* data);
|
void* data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,11 +159,13 @@ private:
|
|||||||
struct RequestedCallback {
|
struct RequestedCallback {
|
||||||
Callback callback;
|
Callback callback;
|
||||||
ALooper_callbackFunc* looperCallback;
|
ALooper_callbackFunc* looperCallback;
|
||||||
|
int ident;
|
||||||
void* data;
|
void* data;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct PendingCallback {
|
struct PendingCallback {
|
||||||
int fd;
|
int fd;
|
||||||
|
int ident;
|
||||||
int events;
|
int events;
|
||||||
Callback callback;
|
Callback callback;
|
||||||
ALooper_callbackFunc* looperCallback;
|
ALooper_callbackFunc* looperCallback;
|
||||||
@ -185,7 +193,7 @@ private:
|
|||||||
void openWakePipe();
|
void openWakePipe();
|
||||||
void closeWakePipe();
|
void closeWakePipe();
|
||||||
|
|
||||||
void setCallbackCommon(int fd, int events, Callback callback,
|
void setCallbackCommon(int fd, int ident, int events, Callback callback,
|
||||||
ALooper_callbackFunc* looperCallback, void* data);
|
ALooper_callbackFunc* looperCallback, void* data);
|
||||||
ssize_t getRequestIndexLocked(int fd);
|
ssize_t getRequestIndexLocked(int fd);
|
||||||
void wakeAndLock();
|
void wakeAndLock();
|
||||||
|
@ -86,7 +86,7 @@ sp<PollLoop> SensorEventQueue::getPollLoop() const
|
|||||||
Mutex::Autolock _l(mLock);
|
Mutex::Autolock _l(mLock);
|
||||||
if (mPollLoop == 0) {
|
if (mPollLoop == 0) {
|
||||||
mPollLoop = new PollLoop(true);
|
mPollLoop = new PollLoop(true);
|
||||||
mPollLoop->setCallback(getFd(), POLLIN, NULL, NULL);
|
mPollLoop->setCallback(getFd(), getFd(), POLLIN, NULL, NULL);
|
||||||
}
|
}
|
||||||
return mPollLoop;
|
return mPollLoop;
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,7 @@ void PollLoop::openWakePipe() {
|
|||||||
RequestedCallback requestedCallback;
|
RequestedCallback requestedCallback;
|
||||||
requestedCallback.callback = NULL;
|
requestedCallback.callback = NULL;
|
||||||
requestedCallback.looperCallback = NULL;
|
requestedCallback.looperCallback = NULL;
|
||||||
|
requestedCallback.ident = 0;
|
||||||
requestedCallback.data = NULL;
|
requestedCallback.data = NULL;
|
||||||
mRequestedCallbacks.insertAt(requestedCallback, 0);
|
mRequestedCallbacks.insertAt(requestedCallback, 0);
|
||||||
}
|
}
|
||||||
@ -116,7 +117,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) {
|
|||||||
mPendingFdsPos++;
|
mPendingFdsPos++;
|
||||||
if (outEvents != NULL) *outEvents = pending.events;
|
if (outEvents != NULL) *outEvents = pending.events;
|
||||||
if (outData != NULL) *outData = pending.data;
|
if (outData != NULL) *outData = pending.data;
|
||||||
return pending.fd;
|
return pending.ident;
|
||||||
}
|
}
|
||||||
|
|
||||||
mLock.lock();
|
mLock.lock();
|
||||||
@ -182,6 +183,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) {
|
|||||||
const RequestedCallback& requestedCallback = mRequestedCallbacks.itemAt(i);
|
const RequestedCallback& requestedCallback = mRequestedCallbacks.itemAt(i);
|
||||||
PendingCallback pending;
|
PendingCallback pending;
|
||||||
pending.fd = requestedFd.fd;
|
pending.fd = requestedFd.fd;
|
||||||
|
pending.ident = requestedCallback.ident;
|
||||||
pending.events = revents;
|
pending.events = revents;
|
||||||
pending.callback = requestedCallback.callback;
|
pending.callback = requestedCallback.callback;
|
||||||
pending.looperCallback = requestedCallback.looperCallback;
|
pending.looperCallback = requestedCallback.looperCallback;
|
||||||
@ -191,7 +193,7 @@ int32_t PollLoop::pollOnce(int timeoutMillis, int* outEvents, void** outData) {
|
|||||||
mPendingCallbacks.push(pending);
|
mPendingCallbacks.push(pending);
|
||||||
} else if (pending.fd != mWakeReadPipeFd) {
|
} else if (pending.fd != mWakeReadPipeFd) {
|
||||||
if (result == POLL_CALLBACK) {
|
if (result == POLL_CALLBACK) {
|
||||||
result = pending.fd;
|
result = pending.ident;
|
||||||
if (outEvents != NULL) *outEvents = pending.events;
|
if (outEvents != NULL) *outEvents = pending.events;
|
||||||
if (outData != NULL) *outData = pending.data;
|
if (outData != NULL) *outData = pending.data;
|
||||||
} else {
|
} else {
|
||||||
@ -268,16 +270,20 @@ bool PollLoop::getAllowNonCallbacks() const {
|
|||||||
return mAllowNonCallbacks;
|
return mAllowNonCallbacks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PollLoop::setCallback(int fd, int ident, int events, Callback callback, void* data) {
|
||||||
|
setCallbackCommon(fd, ident, events, callback, NULL, data);
|
||||||
|
}
|
||||||
|
|
||||||
void PollLoop::setCallback(int fd, int events, Callback callback, void* data) {
|
void PollLoop::setCallback(int fd, int events, Callback callback, void* data) {
|
||||||
setCallbackCommon(fd, events, callback, NULL, data);
|
setCallbackCommon(fd, POLL_CALLBACK, events, callback, NULL, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PollLoop::setLooperCallback(int fd, int events, ALooper_callbackFunc* callback,
|
void PollLoop::setLooperCallback(int fd, int ident, int events, ALooper_callbackFunc* callback,
|
||||||
void* data) {
|
void* data) {
|
||||||
setCallbackCommon(fd, events, NULL, callback, data);
|
setCallbackCommon(fd, ident, events, NULL, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PollLoop::setCallbackCommon(int fd, int events, Callback callback,
|
void PollLoop::setCallbackCommon(int fd, int ident, int events, Callback callback,
|
||||||
ALooper_callbackFunc* looperCallback, void* data) {
|
ALooper_callbackFunc* looperCallback, void* data) {
|
||||||
|
|
||||||
#if DEBUG_CALLBACKS
|
#if DEBUG_CALLBACKS
|
||||||
@ -305,6 +311,7 @@ void PollLoop::setCallbackCommon(int fd, int events, Callback callback,
|
|||||||
RequestedCallback requestedCallback;
|
RequestedCallback requestedCallback;
|
||||||
requestedCallback.callback = callback;
|
requestedCallback.callback = callback;
|
||||||
requestedCallback.looperCallback = looperCallback;
|
requestedCallback.looperCallback = looperCallback;
|
||||||
|
requestedCallback.ident = ident;
|
||||||
requestedCallback.data = data;
|
requestedCallback.data = data;
|
||||||
|
|
||||||
ssize_t index = getRequestIndexLocked(fd);
|
ssize_t index = getRequestIndexLocked(fd);
|
||||||
|
@ -246,8 +246,8 @@ float AMotionEvent_getHistoricalOrientation(AInputEvent* motion_event, size_t po
|
|||||||
|
|
||||||
|
|
||||||
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
|
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
|
||||||
ALooper_callbackFunc* callback, void* data) {
|
int ident, ALooper_callbackFunc* callback, void* data) {
|
||||||
queue->attachLooper(looper, callback, data);
|
queue->attachLooper(looper, ident, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AInputQueue_detachLooper(AInputQueue* queue) {
|
void AInputQueue_detachLooper(AInputQueue* queue) {
|
||||||
|
@ -72,9 +72,9 @@ void ALooper_release(ALooper* looper) {
|
|||||||
static_cast<PollLoop*>(looper)->decStrong((void*)ALooper_acquire);
|
static_cast<PollLoop*>(looper)->decStrong((void*)ALooper_acquire);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ALooper_addFd(ALooper* looper, int fd, int events,
|
void ALooper_addFd(ALooper* looper, int fd, int ident, int events,
|
||||||
ALooper_callbackFunc* callback, void* data) {
|
ALooper_callbackFunc* callback, void* data) {
|
||||||
static_cast<PollLoop*>(looper)->setLooperCallback(fd, events, callback, data);
|
static_cast<PollLoop*>(looper)->setLooperCallback(fd, ident, events, callback, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t ALooper_removeFd(ALooper* looper, int fd) {
|
int32_t ALooper_removeFd(ALooper* looper, int fd) {
|
||||||
|
@ -60,12 +60,12 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type
|
|||||||
}
|
}
|
||||||
|
|
||||||
ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
|
ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
|
||||||
ALooper* looper, ALooper_callbackFunc* callback, void* data)
|
ALooper* looper, int ident, ALooper_callbackFunc* callback, void* data)
|
||||||
{
|
{
|
||||||
sp<SensorEventQueue> queue =
|
sp<SensorEventQueue> queue =
|
||||||
static_cast<SensorManager*>(manager)->createEventQueue();
|
static_cast<SensorManager*>(manager)->createEventQueue();
|
||||||
if (queue != 0) {
|
if (queue != 0) {
|
||||||
ALooper_addFd(looper, queue->getFd(), POLLIN, callback, data);
|
ALooper_addFd(looper, queue->getFd(), ident, POLLIN, callback, data);
|
||||||
queue->looper = looper;
|
queue->looper = looper;
|
||||||
queue->incStrong(manager);
|
queue->incStrong(manager);
|
||||||
}
|
}
|
||||||
|
@ -623,10 +623,10 @@ typedef struct AInputQueue AInputQueue;
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Add this input queue to a looper for processing. See
|
* Add this input queue to a looper for processing. See
|
||||||
* ALooper_addFd() for information on the callback and data params.
|
* ALooper_addFd() for information on the ident, callback, and data params.
|
||||||
*/
|
*/
|
||||||
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
|
void AInputQueue_attachLooper(AInputQueue* queue, ALooper* looper,
|
||||||
ALooper_callbackFunc* callback, void* data);
|
int ident, ALooper_callbackFunc* callback, void* data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Remove the input queue from the looper it is currently attached to.
|
* Remove the input queue from the looper it is currently attached to.
|
||||||
|
@ -111,7 +111,7 @@ enum {
|
|||||||
*
|
*
|
||||||
* Returns ALOPER_POLL_ERROR if an error occurred.
|
* Returns ALOPER_POLL_ERROR if an error occurred.
|
||||||
*
|
*
|
||||||
* Returns a value >= 0 containing a file descriptor if it has data
|
* 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).
|
* and it has no callback function (requiring the caller here to handle it).
|
||||||
* In this (and only this) case outEvents and outData will contain the poll
|
* In this (and only this) case outEvents and outData will contain the poll
|
||||||
* events and data associated with the fd.
|
* events and data associated with the fd.
|
||||||
@ -145,10 +145,12 @@ void ALooper_release(ALooper* looper);
|
|||||||
* descriptor was previously added, it is replaced.
|
* descriptor was previously added, it is replaced.
|
||||||
*
|
*
|
||||||
* "fd" is the file descriptor to be added.
|
* "fd" is the file descriptor to be added.
|
||||||
|
* "ident" is an identifier for this event, which is returned from
|
||||||
|
* ALooper_pollOnce(). Must be >= 0, or ALOOPER_POLL_CALLBACK if
|
||||||
|
* providing a non-NULL callback.
|
||||||
* "events" are the poll events to wake up on. Typically this is POLLIN.
|
* "events" are the poll events to wake up on. Typically this is POLLIN.
|
||||||
* "callback" is the function to call when there is an event on the file
|
* "callback" is the function to call when there is an event on the file
|
||||||
* descriptor.
|
* descriptor.
|
||||||
* "id" is an identifier to associated with this file descriptor, or 0.
|
|
||||||
* "data" is a private data pointer to supply to the callback.
|
* "data" is a private data pointer to supply to the callback.
|
||||||
*
|
*
|
||||||
* There are two main uses of this function:
|
* There are two main uses of this function:
|
||||||
@ -156,13 +158,13 @@ void ALooper_release(ALooper* looper);
|
|||||||
* (1) If "callback" is non-NULL, then
|
* (1) If "callback" is non-NULL, then
|
||||||
* this function will be called when there is data on the file descriptor. It
|
* this function will be called when there is data on the file descriptor. It
|
||||||
* should execute any events it has pending, appropriately reading from the
|
* should execute any events it has pending, appropriately reading from the
|
||||||
* file descriptor.
|
* file descriptor. The 'ident' is ignored in this case.
|
||||||
*
|
*
|
||||||
* (2) If "callback" is NULL, the fd will be returned by ALooper_pollOnce
|
* (2) If "callback" is NULL, the 'ident' will be returned by ALooper_pollOnce
|
||||||
* when it has data available, requiring the caller to take care of processing
|
* when its file descriptor has data available, requiring the caller to take
|
||||||
* it.
|
* care of processing it.
|
||||||
*/
|
*/
|
||||||
void ALooper_addFd(ALooper* looper, int fd, int events,
|
void ALooper_addFd(ALooper* looper, int fd, int ident, int events,
|
||||||
ALooper_callbackFunc* callback, void* data);
|
ALooper_callbackFunc* callback, void* data);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,7 +166,7 @@ ASensor const* ASensorManager_getDefaultSensor(ASensorManager* manager, int type
|
|||||||
* Creates a new sensor event queue and associate it with a looper.
|
* Creates a new sensor event queue and associate it with a looper.
|
||||||
*/
|
*/
|
||||||
ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
|
ASensorEventQueue* ASensorManager_createEventQueue(ASensorManager* manager,
|
||||||
ALooper* looper, ALooper_callbackFunc* callback, void* data);
|
ALooper* looper, int ident, ALooper_callbackFunc* callback, void* data);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Destroys the event queue and free all resources associated to it.
|
* Destroys the event queue and free all resources associated to it.
|
||||||
|
Reference in New Issue
Block a user