1 /* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef NFC_WATCH_DOG_H 16 #define NFC_WATCH_DOG_H 17 #include <condition_variable> 18 #include <mutex> 19 #include <string> 20 #include <thread> 21 #include "inci_nfcc_interface.h" 22 23 namespace OHOS { 24 namespace NFC { 25 class NfcWatchDog final { 26 public: 27 NfcWatchDog(const std::string& threadName, int timeout, std::weak_ptr<NCI::INciNfccInterface> nfccProxy); 28 ~NfcWatchDog(); 29 void Cancel(); 30 void Run(); 31 32 private: 33 void MainLoop(); 34 35 private: 36 std::mutex mutex_ {}; 37 std::condition_variable conditionVariable_ {}; 38 std::string threadName_ {""}; 39 int timeout_ {0}; 40 volatile bool canceled_ {false}; 41 std::unique_ptr<std::thread> thread_ {}; 42 43 std::weak_ptr<NCI::INciNfccInterface> nciNfccProxy_; 44 }; 45 } // namespace NFC 46 } // namespace OHOS 47 #endif // NFC_WATCH_DOG_H 48