1 /** 2 * Copyright (c) 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 #ifndef CPP_WATCHDOG_SERVER_SRC_LOOPERWRAPPER_H_ 18 #define CPP_WATCHDOG_SERVER_SRC_LOOPERWRAPPER_H_ 19 20 #include <utils/Looper.h> 21 #include <utils/RefBase.h> 22 #include <utils/Timers.h> 23 24 namespace android { 25 namespace automotive { 26 namespace watchdog { 27 28 // LooperWrapper is a wrapper around the actual looper implementation so tests can stub this wrapper 29 // to deterministically poll the underlying looper. 30 // Refer to utils/Looper.h for the class and methods descriptions. 31 class LooperWrapper : public RefBase { 32 public: LooperWrapper()33 LooperWrapper() : mLooper(nullptr) {} ~LooperWrapper()34 virtual ~LooperWrapper() {} 35 setLooper(sp<Looper> looper)36 void setLooper(sp<Looper> looper) { mLooper = looper; } 37 void wake(); now()38 virtual nsecs_t now() { return systemTime(SYSTEM_TIME_MONOTONIC); } 39 virtual int pollAll(int timeoutMillis); 40 virtual void sendMessage(const android::sp<MessageHandler>& handler, const Message& message); 41 virtual void sendMessageAtTime(nsecs_t uptime, const android::sp<MessageHandler>& handler, 42 const Message& message); 43 virtual void removeMessages(const android::sp<MessageHandler>& handler); 44 virtual void removeMessages(const android::sp<MessageHandler>& handler, int what); 45 46 protected: 47 android::sp<Looper> mLooper; 48 }; 49 50 } // namespace watchdog 51 } // namespace automotive 52 } // namespace android 53 54 #endif // CPP_WATCHDOG_SERVER_SRC_LOOPERWRAPPER_H_ 55