• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #ifndef HDF_UHDF_UTILS_INCLUDE_HDF_XCOLLIE_H
17 #define HDF_UHDF_UTILS_INCLUDE_HDF_XCOLLIE_H
18 
19 #include <string>
20 #ifdef HDFHICOLLIE_ENABLE
21 #include "xcollie/xcollie.h"
22 #else
23 #include "singleton.h"
24 #endif
25 
26 namespace OHOS {
27 constexpr uint32_t HDF_XCOLLIE_FLAG_LOG = 1; // generate log file
28 constexpr uint32_t HDF_XCOLLIE_FLAG_RECOVERY = 2; // die when timeout
29 constexpr uint32_t DEFAULT_TIMEOUT_SECONDS = 10;
30 #ifdef HDFHICOLLIE_ENABLE
31 class HdfXCollie {
32     HdfXCollie(const std::string& tag, uint32_t timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
33         std::function<void(void *)> func = nullptr, void* arg = nullptr, uint32_t flag = HDF_XCOLLIE_FLAG_LOG);
34     ~HdfXCollie();
35 
36     void CancelHdfXCollie();
37 
38 private:
39     int32_t id_;
40     std::string tag_;
41     bool isCanceled_;
42 };
43 
44 #else
45 class HdfXCollie {
46 public:
47     HdfXCollie(const std::string& tag, uint32_t timeoutSeconds = DEFAULT_TIMEOUT_SECONDS,
48         std::function<void(void *)> func = nullptr, void* arg = nullptr, uint32_t flag = HDF_XCOLLIE_FLAG_LOG);
49     ~HdfXCollie();
50 };
51 #endif
52 }
53 #endif // HDF_UHDF_UTILS_INCLUDE_HDF_XCOLLIE_H