2023-07-25 14:26:29 +02:00
|
|
|
#include <stdbool.h>
|
2022-10-26 18:39:04 +02:00
|
|
|
#include <stddef.h>
|
2022-11-04 18:07:18 +01:00
|
|
|
#include <stdio.h>
|
2022-10-26 18:39:04 +02:00
|
|
|
|
2024-04-15 23:11:24 +02:00
|
|
|
#include "looper.h"
|
|
|
|
|
|
2023-06-06 18:36:06 +02:00
|
|
|
// dummy strong pointer class
|
|
|
|
|
struct sp {
|
|
|
|
|
ALooper *ptr;
|
|
|
|
|
/* the struct has to be larger then 16 bytes, because on aarch64 the
|
|
|
|
|
* calling convention for returning structs larger than 16 bytes is the
|
|
|
|
|
* same as the calling convention for returning large C++ objects */
|
|
|
|
|
char filler[16];
|
|
|
|
|
};
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-01-12 13:14:02 +01:00
|
|
|
/* --- */
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-06-06 18:36:06 +02:00
|
|
|
struct sp _ZN7android6Looper12getForThreadEv(void);
|
2023-01-12 13:14:02 +01:00
|
|
|
ALooper * ALooper_forThread(void)
|
|
|
|
|
{
|
2023-06-06 18:36:06 +02:00
|
|
|
return _ZN7android6Looper12getForThreadEv().ptr;
|
2023-01-12 13:14:02 +01:00
|
|
|
}
|
2022-11-24 18:42:18 +01:00
|
|
|
|
2023-06-06 18:36:06 +02:00
|
|
|
struct sp _ZN7android6Looper7prepareEi(int opts);
|
2023-01-12 13:14:02 +01:00
|
|
|
ALooper * ALooper_prepare(int opts)
|
|
|
|
|
{
|
2023-06-06 18:36:06 +02:00
|
|
|
return _ZN7android6Looper7prepareEi(opts).ptr;
|
2023-01-12 13:14:02 +01:00
|
|
|
}
|
2022-12-27 17:22:49 +01:00
|
|
|
|
|
|
|
|
void _ZNK7android7RefBase9incStrongEPKv(ALooper *this, void *unused);
|
|
|
|
|
void ALooper_acquire(ALooper* looper) {
|
|
|
|
|
_ZNK7android7RefBase9incStrongEPKv(looper, (void*)ALooper_acquire);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _ZNK7android7RefBase9decStrongEPKv(ALooper *this, void *unused);
|
|
|
|
|
void ALooper_release(ALooper* looper) {
|
|
|
|
|
_ZNK7android7RefBase9decStrongEPKv(looper, (void*)ALooper_acquire);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 14:26:29 +02:00
|
|
|
int _ZN7android6Looper7pollAllEiPiS1_PPv(ALooper *this, int timeoutMillis, int *outFd, int *outEvents, void **outData);
|
2022-10-26 18:39:04 +02:00
|
|
|
int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData)
|
|
|
|
|
{
|
2022-11-04 18:07:18 +01:00
|
|
|
ALooper *looper = ALooper_forThread();
|
|
|
|
|
if(!looper) {
|
|
|
|
|
fprintf(stderr, "ALooper_pollAll: ALooper_forThread returned NULL\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _ZN7android6Looper7pollAllEiPiS1_PPv(looper, timeoutMillis, outFd, outEvents, outData);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 14:26:29 +02:00
|
|
|
int _ZN7android6Looper8pollOnceEiPiS1_PPv(ALooper *this, int timeoutMillis, int *outFd, int *outEvents, void **outData);
|
|
|
|
|
int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData)
|
|
|
|
|
{
|
|
|
|
|
ALooper *looper = ALooper_forThread();
|
|
|
|
|
if(!looper) {
|
|
|
|
|
fprintf(stderr, "ALooper_pollAll: ALooper_forThread returned NULL\n");
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return _ZN7android6Looper8pollOnceEiPiS1_PPv(looper, timeoutMillis, outFd, outEvents, outData);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int _ZN7android6Looper5addFdEiiiPFiiiPvES1_(ALooper *this, int fd, int ident, int events, Looper_callbackFunc callback, void *data);
|
2022-11-04 18:07:18 +01:00
|
|
|
int ALooper_addFd(ALooper* looper, int fd, int ident, int events, Looper_callbackFunc callback, void* data)
|
|
|
|
|
{
|
|
|
|
|
return _ZN7android6Looper5addFdEiiiPFiiiPvES1_(looper, fd, ident, events, callback, data);
|
2022-10-26 18:39:04 +02:00
|
|
|
}
|
2023-07-25 14:26:29 +02:00
|
|
|
|
2022-12-27 17:22:49 +01:00
|
|
|
void _ZN7android6Looper4wakeEv(ALooper *this);
|
2023-07-25 14:26:29 +02:00
|
|
|
void ALooper_wake(ALooper *looper)
|
|
|
|
|
{
|
|
|
|
|
_ZN7android6Looper4wakeEv(looper);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-09 04:50:56 +01:00
|
|
|
int _ZN7android6Looper8removeFdEi(ALooper* this, int fd);
|
|
|
|
|
int ALooper_removeFd(ALooper* looper, int fd)
|
|
|
|
|
{
|
|
|
|
|
return _ZN7android6Looper8removeFdEi(looper, fd);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-25 14:26:29 +02:00
|
|
|
/* this is not part of the android API, but we use it internally */
|
|
|
|
|
|
|
|
|
|
bool _ZNK7android6Looper9isPollingEv(ALooper *this);
|
|
|
|
|
bool ALooper_isPolling(ALooper *looper)
|
|
|
|
|
{
|
|
|
|
|
return _ZNK7android6Looper9isPollingEv(looper);
|
2022-12-27 17:22:49 +01:00
|
|
|
}
|