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,
48                                    const Message& message) {
49     if (mLooper == nullptr) {
50         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
51         return;
52     }
53 
54     return mLooper->sendMessage(handler, message);
55 }
56 
sendMessageAtTime(nsecs_t uptime,const sp<MessageHandler> & handler,const Message & message)57 void LooperWrapper::sendMessageAtTime(nsecs_t uptime,
58                                          const sp<MessageHandler>& handler,
59                                          const Message& message) {
60     if (mLooper == nullptr) {
61         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
62         return;
63     }
64 
65     return mLooper->sendMessageAtTime(uptime, handler, message);
66 }
67 
removeMessages(const sp<MessageHandler> & handler)68 void LooperWrapper::removeMessages(const sp<MessageHandler>& handler) {
69     if (mLooper == nullptr) {
70         LOG(WARNING) << __FUNCTION__ << ": Looper is invalid.";
71         return;
72     }
73 
74     return mLooper->removeMessages(handler);
75 }
76 
77 } // namespace implementation
78 } // namespace V1_1
79 } // namespace evs
80 } // namespace automotive
81 } // namespace android
82 
83