• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 #include <condition_variable>
19 #include <mutex>
20 #include <string>
21 #include <thread>
22 
23 #include "infcc_host.h"
24 
25 namespace OHOS {
26 namespace NFC {
27 class NfcWatchDog final {
28 public:
29     NfcWatchDog(const std::string& threadName, int timeout, std::weak_ptr<NCI::INfccHost> nfccHost);
30     ~NfcWatchDog();
31     void Cancel();
32     void Run();
33 
34 private:
35     void MainLoop();
36 
37 private:
38     std::mutex mutex_ {};
39     std::condition_variable conditionVariable_ {};
40     std::string threadName_ {""};
41     int timeout_ {0};
42     volatile bool canceled_ {false};
43     std::unique_ptr<std::thread> thread_ {};
44 
45     std::weak_ptr<NCI::INfccHost> nfccHost_;
46 };
47 }  // namespace NFC
48 }  // namespace OHOS
49 #endif  // NFC_WATCH_DOG_H
50