1 /**
2  * Copyright 2020 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 #include "LooperWrapper.h"
18 
19 #include <android-base/logging.h>
20 
21 namespace android {
22 namespace automotive {
23 namespace evs {
24 namespace V1_1 {
25 namespace implementation {
26 
27 using android::sp;
28 
wake()29 void LooperWrapper::wake() {
30     if (mLooper == nullptr) {
31         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
32         return;
33     }
34 
35     return mLooper->wake();
36 }
37 
pollAll(int timeoutMillis)38 int LooperWrapper::pollAll(int timeoutMillis) {
39     if (mLooper == nullptr) {
40         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
41         return 0;
42     }
43 
44     return mLooper->pollAll(timeoutMillis);
45 }
46 
sendMessage(const sp<MessageHandler> & handler,const Message & message)47 void LooperWrapper::sendMessage(const sp<MessageHandler>& handler, const Message& message) {
48     if (mLooper == nullptr) {
49         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
50         return;
51     }
52 
53     return mLooper->sendMessage(handler, message);
54 }
55 
sendMessageAtTime(nsecs_t uptime,const sp<MessageHandler> & handler,const Message & message)56 void LooperWrapper::sendMessageAtTime(nsecs_t uptime, const sp<MessageHandler>& handler,
57                                       const Message& message) {
58     if (mLooper == nullptr) {
59         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
60         return;
61     }
62 
63     return mLooper->sendMessageAtTime(uptime, handler, message);
64 }
65 
removeMessages(const sp<MessageHandler> & handler)66 void LooperWrapper::removeMessages(const sp<MessageHandler>& handler) {
67     if (mLooper == nullptr) {
68         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
69         return;
70     }
71 
72     return mLooper->removeMessages(handler);
73 }
74 
75 }  // namespace implementation
76 }  // namespace V1_1
77 }  // namespace evs
78 }  // namespace automotive
79 }  // namespace android
80