1 /*
2  * Copyright (c) 2021-2023 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 #ifndef HIVIEW_FAULTLOG_INFO_H
16 #define HIVIEW_FAULTLOG_INFO_H
17 #include <cstdint>
18 #include <string>
19 namespace OHOS {
20 namespace HiviewDFX {
21 class FaultLogInfo {
22 public:
23     ~FaultLogInfo();
24 
25     /**
26      * @brief get user id
27      *
28      * @return user id
29     */
30     uint32_t GetId() const;
31 
32     /**
33      * @brief get process id
34      *
35      * @return process id
36     */
37     int32_t GetProcessId() const;
38 
39     /**
40      * @brief get file descriptor
41      * the fd is managed by fault log info obj it will be closed in destructor
42      *
43      * @return file descriptor
44     */
45     int32_t GetRawFileDescriptor() const;
46 
47     /**
48      * @brief get type of fault
49      *
50      * @return type of fault(int32_t)
51     */
52     int32_t GetFaultType() const;
53 
54     /**
55      * @brief get timestamp when fault happened
56      *
57      * @return timestamp
58     */
59     int64_t GetTimeStamp() const;
60 
61     /**
62      * @brief get type of fault
63      *
64      * @return fault type(string)
65     */
66     std::string GetStringFaultType() const;
67 
68     /**
69      * @brief get the reason for fault
70      *
71      * @return the reason for fault
72     */
73     std::string GetFaultReason() const;
74 
75     /**
76      * @brief get the name of module which occurred fault
77      *
78      * @return the name of module
79     */
80     std::string GetModuleName() const;
81 
82     /**
83      * @brief get the summary of fault information
84      *
85      * @return summary of fault information
86     */
87     std::string GetFaultSummary() const;
88 
89     /**
90      * @brief set user id
91      *
92      * @param id user id
93     */
94     void SetId(uint32_t id);
95 
96     /**
97      * @brief set process id
98      *
99      * @param pid process id
100     */
101     void SetProcessId(int32_t pid);
102 
103     /**
104      * @brief set timestamp when fault happened
105      *
106      * @param ts timestamp
107     */
108     void SetTimeStamp(int64_t ts);
109 
110     /**
111      * @brief set type of fault
112      *
113      * @param faultType type of fault
114     */
115     void SetFaultType(int32_t faultType);
116 
117     /**
118      * @brief set the reason for fault
119      *
120      * @param reason the reason for fault
121     */
122     void SetFaultReason(const std::string &reason);
123 
124     /**
125      * @brief set the name of module which occurred fault
126      *
127      * @param module the name of module
128     */
129     void SetModuleName(const std::string &module);
130 
131     /**
132      * @brief set the summary of fault information
133      *
134      * @param summary summary of fault information
135     */
136     void SetFaultSummary(const std::string &summary);
137 
138     /**
139      * @brief set file descriptor
140      * the fd is managed by fault log info obj it will be closed in destructor
141      *
142      * @param fd file descriptor
143     */
144     void SetRawFileDescriptor(int32_t fd);
145 
146 private:
147     int32_t pid_ {-1};
148     uint32_t uid_ {-1};
149     int32_t type_ {0};
150     int32_t fd_ {-1};
151     int64_t ts_ {0};
152     std::string reason_;
153     std::string module_;
154     std::string summary_;
155 };
156 }  // namespace HiviewDFX
157 }  // namespace OHOS
158 #endif  // HIVIEW_FAULTLOG_INFO_H