blob: 9f5cda9a9e986f8469532d32118f2e1c30f1393c [file] [log] [blame]
Dianne Hackborn68267412010-07-02 18:52:01 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define LOG_TAG "ALooper"
18#include <utils/Log.h>
19
20#include <android/looper.h>
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070021#include <utils/Looper.h>
Dianne Hackborn68267412010-07-02 18:52:01 -070022
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070023using android::Looper;
Dianne Hackborn68267412010-07-02 18:52:01 -070024using android::sp;
25
26ALooper* ALooper_forThread() {
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070027 return Looper::getForThread().get();
Dianne Hackborn68267412010-07-02 18:52:01 -070028}
29
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070030ALooper* ALooper_prepare(int opts) {
31 return Looper::prepare(opts).get();
Dianne Hackborn68267412010-07-02 18:52:01 -070032}
33
34void ALooper_acquire(ALooper* looper) {
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070035 static_cast<Looper*>(looper)->incStrong((void*)ALooper_acquire);
Dianne Hackborn68267412010-07-02 18:52:01 -070036}
37
38void ALooper_release(ALooper* looper) {
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070039 static_cast<Looper*>(looper)->decStrong((void*)ALooper_acquire);
Dianne Hackborn68267412010-07-02 18:52:01 -070040}
41
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070042int ALooper_pollOnce(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
43 sp<Looper> looper = Looper::getForThread();
44 if (looper == NULL) {
45 LOGE("ALooper_pollOnce: No looper for this thread!");
46 return ALOOPER_POLL_ERROR;
47 }
48
49 return looper->pollOnce(timeoutMillis, outFd, outEvents, outData);
Dianne Hackborn68267412010-07-02 18:52:01 -070050}
51
Jeff Brown4fe6c3e2010-09-13 23:17:30 -070052int ALooper_pollAll(int timeoutMillis, int* outFd, int* outEvents, void** outData) {
53 sp<Looper> looper = Looper::getForThread();
54 if (looper == NULL) {
55 LOGE("ALooper_pollAll: No looper for this thread!");
56 return ALOOPER_POLL_ERROR;
57 }
58
59 return looper->pollAll(timeoutMillis, outFd, outEvents, outData);
60}
61
62void ALooper_wake(ALooper* looper) {
63 static_cast<Looper*>(looper)->wake();
64}
65
66int ALooper_addFd(ALooper* looper, int fd, int ident, int events,
67 ALooper_callbackFunc callback, void* data) {
68 return static_cast<Looper*>(looper)->addFd(fd, ident, events, callback, data);
69}
70
71int ALooper_removeFd(ALooper* looper, int fd) {
72 return static_cast<Looper*>(looper)->removeFd(fd);
Dianne Hackborn68267412010-07-02 18:52:01 -070073}