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 * 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#include "faultlog_info.h" 16 17#include <cstdint> 18#include <string> 19 20#include <unistd.h> 21 22#include "faultlogger_client.h" 23namespace OHOS { 24namespace HiviewDFX { 25FaultLogInfo::~FaultLogInfo() 26{ 27 if (fd_ >= 0) { 28 close(fd_); 29 fd_ = -1; 30 } 31} 32 33uint32_t FaultLogInfo::GetId() const 34{ 35 return uid_; 36} 37 38int32_t FaultLogInfo::GetProcessId() const 39{ 40 return pid_; 41} 42 43int32_t FaultLogInfo::GetRawFileDescriptor() const 44{ 45 return fd_; 46} 47 48int32_t FaultLogInfo::GetFaultType() const 49{ 50 return type_; 51} 52 53int64_t FaultLogInfo::GetTimeStamp() const 54{ 55 return ts_; 56} 57 58std::string FaultLogInfo::GetModuleName() const 59{ 60 return module_; 61} 62 63std::string FaultLogInfo::GetFaultReason() const 64{ 65 return reason_; 66} 67 68std::string FaultLogInfo::GetFaultSummary() const 69{ 70 return summary_; 71} 72 73void FaultLogInfo::SetId(uint32_t id) 74{ 75 uid_ = id; 76} 77 78void FaultLogInfo::SetProcessId(int32_t pid) 79{ 80 pid_ = pid; 81} 82 83void FaultLogInfo::SetFaultType(int32_t faultType) 84{ 85 type_ = faultType; 86} 87 88void FaultLogInfo::SetRawFileDescriptor(int32_t fd) 89{ 90 fd_ = fd; 91} 92 93void FaultLogInfo::SetTimeStamp(int64_t ts) 94{ 95 ts_ = ts; 96} 97 98void FaultLogInfo::SetFaultReason(const std::string &reason) 99{ 100 reason_ = reason; 101} 102 103void FaultLogInfo::SetModuleName(const std::string &module) 104{ 105 module_ = module; 106} 107 108void FaultLogInfo::SetFaultSummary(const std::string &summary) 109{ 110 summary_ = summary; 111} 112 113std::string FaultLogInfo::GetStringFaultType() const 114{ 115 switch (type_) { 116 case CPP_CRASH: 117 return "CppCrash"; 118 case JS_CRASH: 119 return "JsCrash"; 120 case APP_FREEZE: 121 return "AppFreeze"; 122 case SYS_FREEZE: 123 return "SysFreeze"; 124 case SYS_WARNING: 125 return "SysWarning"; 126 default: 127 return "UnknownFaultType"; 128 } 129} 130} // namespace HiviewDFX 131} // namespace OHOS 132