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