1794c9f46Sopenharmony_ci/*
2794c9f46Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
3794c9f46Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4794c9f46Sopenharmony_ci * you may not use this file except in compliance with the License.
5794c9f46Sopenharmony_ci * You may obtain a copy of the License at
6794c9f46Sopenharmony_ci *
7794c9f46Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8794c9f46Sopenharmony_ci *
9794c9f46Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10794c9f46Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11794c9f46Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12794c9f46Sopenharmony_ci * See the License for the specific language governing permissions and
13794c9f46Sopenharmony_ci * limitations under the License.
14794c9f46Sopenharmony_ci */
15794c9f46Sopenharmony_ci#include "dh_utils_hisysevent.h"
16794c9f46Sopenharmony_ci
17794c9f46Sopenharmony_ci#include <unordered_map>
18794c9f46Sopenharmony_ci
19794c9f46Sopenharmony_ci#include "distributed_hardware_errno.h"
20794c9f46Sopenharmony_ci#include "distributed_hardware_log.h"
21794c9f46Sopenharmony_ci
22794c9f46Sopenharmony_cinamespace OHOS {
23794c9f46Sopenharmony_cinamespace DistributedHardware {
24794c9f46Sopenharmony_civoid HiSysEventWriteMsg(const std::string &status, const OHOS::HiviewDFX::HiSysEvent::EventType eventType,
25794c9f46Sopenharmony_ci    const std::string &msg)
26794c9f46Sopenharmony_ci{
27794c9f46Sopenharmony_ci    int32_t res = HiSysEventWrite(
28794c9f46Sopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_HARDWARE_FWK,
29794c9f46Sopenharmony_ci        status.c_str(),
30794c9f46Sopenharmony_ci        eventType,
31794c9f46Sopenharmony_ci        "MSG", msg.c_str());
32794c9f46Sopenharmony_ci    if (res != DH_FWK_SUCCESS) {
33794c9f46Sopenharmony_ci        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
34794c9f46Sopenharmony_ci    }
35794c9f46Sopenharmony_ci}
36794c9f46Sopenharmony_ci
37794c9f46Sopenharmony_civoid HiSysEventWriteErrCodeMsg(const std::string &status, const OHOS::HiviewDFX::HiSysEvent::EventType eventType,
38794c9f46Sopenharmony_ci    int32_t errCode, const std::string &msg)
39794c9f46Sopenharmony_ci{
40794c9f46Sopenharmony_ci    int32_t res = HiSysEventWrite(
41794c9f46Sopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_HARDWARE_FWK,
42794c9f46Sopenharmony_ci        status.c_str(),
43794c9f46Sopenharmony_ci        eventType,
44794c9f46Sopenharmony_ci        "ERR_CODE", errCode,
45794c9f46Sopenharmony_ci        "ERR_MSG", msg.c_str());
46794c9f46Sopenharmony_ci    if (res != DH_FWK_SUCCESS) {
47794c9f46Sopenharmony_ci        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
48794c9f46Sopenharmony_ci    }
49794c9f46Sopenharmony_ci}
50794c9f46Sopenharmony_ci
51794c9f46Sopenharmony_civoid HiSysEventWriteReleaseMsg(const std::string &status, const OHOS::HiviewDFX::HiSysEvent::EventType eventType,
52794c9f46Sopenharmony_ci    const DHType dhType, int32_t errCode, const std::string &msg)
53794c9f46Sopenharmony_ci{
54794c9f46Sopenharmony_ci    std::string dhTypeStr = "UNKNOWN";
55794c9f46Sopenharmony_ci    auto it = DHTypeStrMap.find(dhType);
56794c9f46Sopenharmony_ci    if (it != DHTypeStrMap.end()) {
57794c9f46Sopenharmony_ci        dhTypeStr = it->second;
58794c9f46Sopenharmony_ci    }
59794c9f46Sopenharmony_ci
60794c9f46Sopenharmony_ci    int32_t res = HiSysEventWrite(
61794c9f46Sopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_HARDWARE_FWK,
62794c9f46Sopenharmony_ci        status.c_str(),
63794c9f46Sopenharmony_ci        eventType,
64794c9f46Sopenharmony_ci        "DHTYPE", dhTypeStr.c_str(),
65794c9f46Sopenharmony_ci        "ERR_CODE", errCode,
66794c9f46Sopenharmony_ci        "ERR_MSG", msg.c_str());
67794c9f46Sopenharmony_ci    if (res != DH_FWK_SUCCESS) {
68794c9f46Sopenharmony_ci        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
69794c9f46Sopenharmony_ci    }
70794c9f46Sopenharmony_ci}
71794c9f46Sopenharmony_ci
72794c9f46Sopenharmony_civoid HiSysEventWriteCompOfflineMsg(const std::string &status, const OHOS::HiviewDFX::HiSysEvent::EventType eventType,
73794c9f46Sopenharmony_ci    const std::string &anonyNetworkId, const std::string &msg)
74794c9f46Sopenharmony_ci{
75794c9f46Sopenharmony_ci    int32_t res = HiSysEventWrite(
76794c9f46Sopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_HARDWARE_FWK,
77794c9f46Sopenharmony_ci        status.c_str(),
78794c9f46Sopenharmony_ci        eventType,
79794c9f46Sopenharmony_ci        "NETWORKID", anonyNetworkId.c_str(),
80794c9f46Sopenharmony_ci        "MSG", msg.c_str());
81794c9f46Sopenharmony_ci    if (res != DH_FWK_SUCCESS) {
82794c9f46Sopenharmony_ci        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
83794c9f46Sopenharmony_ci    }
84794c9f46Sopenharmony_ci}
85794c9f46Sopenharmony_ci
86794c9f46Sopenharmony_civoid HiSysEventWriteCompMgrFailedMsg(const std::string &status, const OHOS::HiviewDFX::HiSysEvent::EventType eventType,
87794c9f46Sopenharmony_ci    const std::string &anonyDHId, int32_t errCode, const std::string &msg)
88794c9f46Sopenharmony_ci{
89794c9f46Sopenharmony_ci    int32_t res = HiSysEventWrite(
90794c9f46Sopenharmony_ci        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_HARDWARE_FWK,
91794c9f46Sopenharmony_ci        status.c_str(),
92794c9f46Sopenharmony_ci        eventType,
93794c9f46Sopenharmony_ci        "DHID", anonyDHId.c_str(),
94794c9f46Sopenharmony_ci        "ERR_CODE", errCode,
95794c9f46Sopenharmony_ci        "ERR_MSG", msg.c_str());
96794c9f46Sopenharmony_ci    if (res != DH_FWK_SUCCESS) {
97794c9f46Sopenharmony_ci        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
98794c9f46Sopenharmony_ci    }
99794c9f46Sopenharmony_ci}
100794c9f46Sopenharmony_ci} // namespace DistributedHardware
101794c9f46Sopenharmony_ci} // namespace OHOS