1/*
2 * Copyright (c) 2022-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#include "hisysevent_util.h"
17
18#include "dinput_errcode.h"
19#include "dinput_log.h"
20#include "dinput_utils_tool.h"
21
22namespace OHOS {
23namespace DistributedHardware {
24namespace DistributedInput {
25IMPLEMENT_SINGLE_INSTANCE(HisyseventUtil);
26
27void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string msg)
28{
29    int32_t res = HiSysEventWrite(
30        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
31        status,
32        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
33        "MSG", msg);
34    if (res != DH_SUCCESS) {
35        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
36    }
37}
38
39void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string devId, std::string msg)
40{
41    int32_t res = HiSysEventWrite(
42        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
43        status,
44        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
45        "DEVID", GetAnonyString(devId),
46        "MSG", msg);
47    if (res != DH_SUCCESS) {
48        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
49    }
50}
51
52void HisyseventUtil::SysEventWriteBehavior(std::string status, std::string devId, std::string dhId, std::string msg)
53{
54    int32_t res = HiSysEventWrite(
55        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
56        status,
57        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
58        "DEVID", GetAnonyString(devId),
59        "DHID", GetAnonyString(dhId),
60        "MSG", msg);
61    if (res != DH_SUCCESS) {
62        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
63    }
64}
65
66void HisyseventUtil::SysEventWriteFault(std::string status, std::string msg)
67{
68    int32_t res = HiSysEventWrite(
69        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
70        status,
71        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
72        "MSG", msg);
73    if (res != DH_SUCCESS) {
74        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
75    }
76}
77
78void HisyseventUtil::SysEventWriteFault(std::string status, std::string devId, int32_t errorCode, std::string msg)
79{
80    int32_t res = HiSysEventWrite(
81        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
82        status,
83        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
84        "DEVID", GetAnonyString(devId),
85        "ERROR_CODE", errorCode,
86        "MSG", msg);
87    if (res != DH_SUCCESS) {
88        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
89    }
90}
91
92void HisyseventUtil::SysEventWriteFault(std::string status, std::string devId, std::string dhId, int32_t errorCode,
93    std::string msg)
94{
95    int32_t res = HiSysEventWrite(
96        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_INPUT,
97        status,
98        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
99        "DEVID", GetAnonyString(devId),
100        "DHID", GetAnonyString(dhId),
101        "ERROR_CODE", errorCode,
102        "MSG", msg);
103    if (res != DH_SUCCESS) {
104        DHLOGE("Write HiSysEvent error, res:%{public}d", res);
105    }
106}
107} // namespace DistributedInput
108} // namespace DistributedHardware
109} // namespace OHOS
110