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
16#include "dscreen_hisysevent.h"
17
18#include "hisysevent.h"
19
20#include "dscreen_errcode.h"
21#include "dscreen_log.h"
22
23namespace OHOS {
24namespace DistributedHardware {
25void ReportSaFail(const std::string &eventName, int32_t errCode, int32_t saId, const std::string &errMsg)
26{
27    int32_t res = HiSysEventWrite(
28        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN,
29        eventName,
30        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
31        "ERRCODE", errCode,
32        "SAID", saId,
33        "MSG", errMsg);
34    if (res != DH_SUCCESS) {
35        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
36    }
37}
38
39void ReportRegisterFail(const std::string &eventName, int32_t errCode, const std::string &devId,
40    const std::string &dhId, const std::string &errMsg)
41{
42    int32_t res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN, eventName,
43                                  OHOS::HiviewDFX::HiSysEvent::EventType::FAULT, "ERRCODE", errCode,
44                                  "DEVID", devId, "DHID", dhId, "MSG", errMsg);
45    if (res != DH_SUCCESS) {
46        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
47    }
48}
49
50void ReportUnRegisterFail(const std::string &eventName, int32_t errCode, const std::string &devId,
51    const std::string &dhId, const std::string &errMsg)
52{
53    int32_t res = HiSysEventWrite(
54        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN,
55        eventName,
56        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
57        "ERRCODE", errCode,
58        "DEVID", devId,
59        "DHID", dhId,
60        "MSG", errMsg);
61    if (res != DH_SUCCESS) {
62        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
63    }
64}
65
66void ReportOptFail(const std::string &eventName, int32_t errCode, const std::string &errMsg)
67{
68    int32_t res = HiSysEventWrite(
69        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN,
70        eventName,
71        OHOS::HiviewDFX::HiSysEvent::EventType::FAULT,
72        "ERRCODE", errCode,
73        "MSG", errMsg);
74    if (res != DH_SUCCESS) {
75        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
76    }
77}
78
79void ReportSaEvent(const std::string &eventName, int32_t saId, const std::string &errMsg)
80{
81    int32_t res = HiSysEventWrite(
82        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN,
83        eventName,
84        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
85        "SAID", saId,
86        "MSG", errMsg);
87    if (res != DH_SUCCESS) {
88        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
89    }
90}
91
92void ReportRegisterScreenEvent(const std::string &eventName, const std::string &devId, const std::string &dhId,
93    const std::string &errMsg)
94{
95    int32_t res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN, eventName,
96                                  OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "DEVID", devId,
97                                  "DHID", dhId, "MSG", errMsg);
98    if (res != DH_SUCCESS) {
99        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
100    }
101}
102
103void ReportUnRegisterScreenEvent(const std::string &eventName, const std::string &devId, const std::string &dhId,
104    const std::string &errMsg)
105{
106    int32_t res = HiSysEventWrite(OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN, eventName,
107                                  OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR, "DEVID", devId, "DHID", dhId,
108                                  "MSG", errMsg);
109    if (res != DH_SUCCESS) {
110        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
111    }
112}
113
114void ReportScreenMirrorEvent(const std::string &eventName, const std::string &devId, const std::string &dhId,
115    const std::string &errMsg)
116{
117    int32_t res = HiSysEventWrite(
118        OHOS::HiviewDFX::HiSysEvent::Domain::DISTRIBUTED_SCREEN,
119        eventName,
120        OHOS::HiviewDFX::HiSysEvent::EventType::BEHAVIOR,
121        "DEVID", devId,
122        "DHID", dhId,
123        "MSG", errMsg);
124    if (res != DH_SUCCESS) {
125        DHLOGE("Write HiSysEvent error, res:%{public}" PRId32, res);
126    }
127}
128} // namespace DistributedHardware
129} // namespace OHOS
130