Hello World!
Does someone know where the actual C/C++ implementation for the <android/looper.h> interface is?
I found that it *could* be in platform/frameworks/native/libs/utils/Looper.cpp but i'm not sure about it and by the way i cannot figure out how the C binding for it is.
Actually i'm trying to find out if a file descriptor previously submitted to an ALooper* via ALooper_addFd() is removed AND CLOSED when its ALooper_callbackFunc returns 0.
From <android/looper.h> (platform-18)
line 155: about
typedef int (*ALooper_callbackFunc)(int fd, int events, void* data);/*
* Implementations should return 1 to continue receiving callbacks, or 0
* to have this file descriptor and callback unregistered from the looper.
*/line 233: about int ALooper_removeFd(ALooper* looper, int fd);
/*
* When this method returns, it is safe to close the file descriptor since the looper
* will no longer have a reference to it. However, it is possible for the callback to
* already be running or for it to run one last time if the file descriptor was already
* signalled. Calling code is responsible for ensuring that this case is safely handled.
* For example, if the callback takes care of removing itself during its own execution either
* by returning 0 or by calling this method, then it can be guaranteed to not be invoked
* again at any later time unless registered anew.
*/
Still returning zero from a ALooper_callbackFunc this way: ( error checking and actual work removed for clarity )
static int loaderCallback( int fd , int events , void* any )
{
Args* args = (Args*)any;
ALooper* loop;
int check;
void* ret;
if( 1 != ( check = read( fd , &ret , 1 ) ) ) LOGE( "read( %d , 1 ) = %d, errno = %d: %s" , fd , check , errno , strerror( errno ) );
if( ( loop = ALooper_forThread() ) )
{
ALooper_removeFd( loop , args->pipe[0] );
}
else LOGE( "ALooper_forThread() == NULL, check ure threading soldier!" );
close( args->pipe[P_IN ] );
close( args->pipe[P_OUT] );
return 0;
}
causes my device ( ASUS TF101 @ 4.0.3 ) to CRASH and REBOOT immediately, while this way...
static int loaderCallback( int fd , int events , void* any )
{
Args* args = (Args*)any;
ALooper* loop;
int check;
void* ret;
if( 1 != ( check = read( fd , &ret , 1 ) ) ) LOGE( "read( %d , 1 ) =
%d, errno = %d: %s" , fd , check , errno , strerror( errno ) );
/*
if( ( loop = ALooper_forThread() ) )
{
ALooper_removeFd( loop , args->pipe[0] );
}
else LOGE( "ALooper_forThread() == NULL, check ure threading soldier!" );
close( args->pipe[P_IN ] );
*/
close( args->pipe[P_OUT] );
return 0;
}
...the code runs flawlessy. ( "args" is a 'casted to struct' pointer to "void* any", P_IN and P_OUT are 0 & 1 respectively and args->pipe[P_IN] == fd )
While I opened both file descriptors by myself i would like to assure that they will be both closed at some time after this routine returns ( I'm a kinda reentrant code maniac =P ).
Thanks for ure patience on reading this thing and for any help / advice about the topic!