• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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"
23 namespace OHOS {
24 namespace HiviewDFX {
~FaultLogInfo()25 FaultLogInfo::~FaultLogInfo()
26 {
27     if (fd_ >= 0) {
28         close(fd_);
29         fd_ = -1;
30     }
31 }
32 
GetId() const33 uint32_t FaultLogInfo::GetId() const
34 {
35     return uid_;
36 }
37 
GetProcessId() const38 int32_t FaultLogInfo::GetProcessId() const
39 {
40     return pid_;
41 }
42 
GetRawFileDescriptor() const43 int32_t FaultLogInfo::GetRawFileDescriptor() const
44 {
45     return fd_;
46 }
47 
GetFaultType() const48 int32_t FaultLogInfo::GetFaultType() const
49 {
50     return type_;
51 }
52 
GetTimeStamp() const53 int64_t FaultLogInfo::GetTimeStamp() const
54 {
55     return ts_;
56 }
57 
GetModuleName() const58 std::string FaultLogInfo::GetModuleName() const
59 {
60     return module_;
61 }
62 
GetFaultReason() const63 std::string FaultLogInfo::GetFaultReason() const
64 {
65     return reason_;
66 }
67 
GetFaultSummary() const68 std::string FaultLogInfo::GetFaultSummary() const
69 {
70     return summary_;
71 }
72 
SetId(uint32_t id)73 void FaultLogInfo::SetId(uint32_t id)
74 {
75     uid_ = id;
76 }
77 
SetProcessId(int32_t pid)78 void FaultLogInfo::SetProcessId(int32_t pid)
79 {
80     pid_ = pid;
81 }
82 
SetFaultType(int32_t faultType)83 void FaultLogInfo::SetFaultType(int32_t faultType)
84 {
85     type_ = faultType;
86 }
87 
SetRawFileDescriptor(int32_t fd)88 void FaultLogInfo::SetRawFileDescriptor(int32_t fd)
89 {
90     fd_ = fd;
91 }
92 
SetTimeStamp(int64_t ts)93 void FaultLogInfo::SetTimeStamp(int64_t ts)
94 {
95     ts_ = ts;
96 }
97 
SetFaultReason(const std::string & reason)98 void FaultLogInfo::SetFaultReason(const std::string &reason)
99 {
100     reason_ = reason;
101 }
102 
SetModuleName(const std::string & module)103 void FaultLogInfo::SetModuleName(const std::string &module)
104 {
105     module_ = module;
106 }
107 
SetFaultSummary(const std::string & summary)108 void FaultLogInfo::SetFaultSummary(const std::string &summary)
109 {
110     summary_ = summary;
111 }
112 
GetStringFaultType() const113 std::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         default:
125             return "UnknownFaultType";
126     }
127 }
128 }  // namespace HiviewDFX
129 }  // namespace OHOS
130