1 /*
2 * Copyright (c) 2025 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 DATASHARESERVICE_HIVIEW_FAULT_ADAPTER_H
17 #define DATASHARESERVICE_HIVIEW_FAULT_ADAPTER_H
18 
19 #include <chrono>
20 #include <cinttypes>
21 #include <string>
22 #include "accesstoken_kit.h"
23 #include "hisysevent_c.h"
24 namespace OHOS {
25 namespace DataShare {
26 struct DataShareFaultInfo {
27     std::string faultType;
28     std::string bundleName;
29     std::string moduleName;
30     std::string storeName;
31     std::string businessType;
32     int32_t errorCode;
33     std::string appendix;
34 };
35 
36 struct RdbTimeCostInfo {
37     std::chrono::time_point<std::chrono::steady_clock> start = std::chrono::steady_clock::now();
38     std::string bundleName;
39     std::string moduleName;
40     std::string storeName;
41     std::string businessType;
42     int32_t errorCode = 0;
43     uint64_t callingTokenId;
44 
RdbTimeCostInfoRdbTimeCostInfo45     explicit RdbTimeCostInfo(const std::string &bundleName, const std::string &moduleName,
46         const std::string &storeName, const std::string &businessType,
47         uint64_t tokenId) : bundleName(bundleName), moduleName(moduleName),
48         storeName(storeName), businessType(businessType), callingTokenId(tokenId)
49     {}
50     ~RdbTimeCostInfo();
51 };
52 
53 
54 class HiViewFaultAdapter {
55 public:
56     static void ReportDataFault(const DataShareFaultInfo &faultInfo);
57     static std::pair<std::string, int> GetCallingName(uint32_t callingTokenid);
58 };
59 
60 inline const char* TIME_OUT = "TIME_OUT";
61 inline const char* RESULTSET_FULL = "RESULTSET_FULL";
62 inline const char* CURD_FAILED = "CURD_FAILED";
63 inline const std::chrono::milliseconds TIME_OUT_MS = std::chrono::milliseconds(300);
64 }
65 }
66 #endif