1 /*
2  * Copyright (c) 2021 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  * miscservices under the License is miscservices 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 #include "fault_reporter.h"
16 #include "hisysevent.h"
17 
18 namespace OHOS {
19 using namespace HiviewDFX;
20 namespace MiscServices {
21 constexpr const char *SERVICE_FAULT = "SERVICE_FAULT";
22 constexpr const char *RUNTIME_FAULT = "RUNTIME_FAULT";
23 constexpr const char *FAULT_TYPE = "FAULT_TYPE";
24 constexpr const char *MODULE_NAME = "MODULE_NAME";
25 constexpr const char *ERROR_TYPE = "ERROR_TYPE";
26 
ReportServiceFault(const FaultMsg & msg)27 ReportStatus FaultReporter::ReportServiceFault(const FaultMsg &msg)
28 {
29     int nRet = HiSysEventWrite(HiSysEvent::Domain::THEME, SERVICE_FAULT, HiSysEvent::EventType::FAULT, FAULT_TYPE,
30         static_cast<int>(msg.faultType), MODULE_NAME, msg.moduleName, ERROR_TYPE, static_cast<int>(msg.errorCode));
31     return nRet == 0 ? ReportStatus::SUCCESS : ReportStatus::ERROR;
32 }
33 
ReportRuntimeFault(const FaultMsg & msg)34 ReportStatus FaultReporter::ReportRuntimeFault(const FaultMsg &msg)
35 {
36     int nRet = HiSysEventWrite(HiSysEvent::Domain::THEME, RUNTIME_FAULT, HiSysEvent::EventType::FAULT, FAULT_TYPE,
37         static_cast<int>(msg.faultType), ERROR_TYPE, static_cast<int>(msg.errorCode));
38     return nRet == 0 ? ReportStatus::SUCCESS : ReportStatus::ERROR;
39 }
40 } // namespace MiscServices
41 } // namespace OHOS
42