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 "hisysevent.h"
16 #include "fault_reporter.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 = HiSysEvent::Write(HiSysEvent::Domain::THEME, SERVICE_FAULT, HiSysEvent::EventType::FAULT,
30 FAULT_TYPE, static_cast<int>(msg.faultType), MODULE_NAME, msg.moduleName, ERROR_TYPE,
31 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 = HiSysEvent::Write(HiSysEvent::Domain::THEME, RUNTIME_FAULT, HiSysEvent::EventType::FAULT,
38 FAULT_TYPE, 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