1 /*
2  * Copyright (c) 2021, 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 #ifndef CPP_TELEMETRY_CARTELEMETRYD_SRC_LOOPERWRAPPER_H_
18 #define CPP_TELEMETRY_CARTELEMETRYD_SRC_LOOPERWRAPPER_H_
19 
20 #include <utils/Looper.h>
21 
22 namespace android {
23 namespace automotive {
24 namespace telemetry {
25 
26 // LooperWrapper is a wrapper around the actual looper implementation so tests can stub this wrapper
27 // to deterministically poll the underlying looper.
28 // Refer to utils/Looper.h for the class and methods descriptions.
29 class LooperWrapper {
30 public:
LooperWrapper(android::sp<Looper> looper)31     explicit LooperWrapper(android::sp<Looper> looper) : mLooper(looper) {}
~LooperWrapper()32     virtual ~LooperWrapper() {}
33 
34     virtual int pollAll(int timeoutMillis);
35     virtual void sendMessageDelayed(nsecs_t uptime, const android::sp<MessageHandler>& handler,
36                                     const Message& message);
37     virtual void removeMessages(const android::sp<MessageHandler>& handler, int what);
38 
39 private:
40     android::sp<Looper> mLooper;
41 };
42 
43 }  // namespace telemetry
44 }  // namespace automotive
45 }  // namespace android
46 
47 #endif  // CPP_TELEMETRY_CARTELEMETRYD_SRC_LOOPERWRAPPER_H_
48