• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 
16 #include "string_ex.h"
17 #include "report_data.h"
18 #include "xcollie_utils.h"
19 
20 namespace OHOS {
21 namespace HiviewDFX {
WriteContent(Parcel & parcel) const22 bool ReportData::WriteContent(Parcel &parcel) const
23 {
24     if (!parcel.WriteUint32(stuckTimeout)) {
25         XCOLLIE_LOGE("StuckTimeout [%{public}u] write uint32 failed.", stuckTimeout);
26         return false;
27     }
28 
29     if (token == nullptr) {
30         if (!parcel.WriteBool(false)) {
31             XCOLLIE_LOGE("Token falge [false] write bool failed.");
32             return false;
33         }
34     } else {
35         if (!parcel.WriteBool(true) || !(static_cast<MessageParcel*>(&parcel))->WriteRemoteObject(token)) {
36             XCOLLIE_LOGE("Token falge [true] write bool failed.");
37             return false;
38         }
39     }
40     return true;
41 }
42 
Marshalling(Parcel & parcel) const43 bool ReportData::Marshalling(Parcel &parcel) const
44 {
45     if (!parcel.WriteString(errorObject.name)) {
46         XCOLLIE_LOGE("Name [%{public}s] write string failed.", errorObject.name.c_str());
47         return false;
48     }
49 
50     if (!parcel.WriteString(errorObject.message)) {
51         XCOLLIE_LOGE("Message [%{public}s] write string failed.", errorObject.message.c_str());
52         return false;
53     }
54 
55     if (!parcel.WriteString(errorObject.stack)) {
56         XCOLLIE_LOGE("Stack [%{public}s] write string failed.", errorObject.stack.c_str());
57         return false;
58     }
59 
60     if (!parcel.WriteInt32(static_cast<int32_t>(faultType))) {
61         XCOLLIE_LOGE("FaultType [%{public}d] write int32 failed.", static_cast<int32_t>(faultType));
62         return false;
63     }
64 
65     if (!parcel.WriteString(timeoutMarkers)) {
66         XCOLLIE_LOGE("TimeoutMarkers [%{public}s] write string failed.", timeoutMarkers.c_str());
67         return false;
68     }
69 
70     if (!parcel.WriteBool(waitSaveState)) {
71         XCOLLIE_LOGE("WaitSaveState [%{public}s] write bool failed.", waitSaveState ? "true" : "false");
72         return false;
73     }
74 
75     if (!parcel.WriteBool(notifyApp)) {
76         XCOLLIE_LOGE("NotifyApp [%{public}s] write bool failed.", notifyApp ? "true" : "false");
77         return false;
78     }
79 
80     if (!parcel.WriteBool(forceExit)) {
81         XCOLLIE_LOGE("ForceExit [%{public}s] write bool failed.", forceExit ? "true" : "false");
82         return false;
83     }
84 
85     if (!parcel.WriteUint32(state)) {
86         XCOLLIE_LOGE("State [%{public}u] write uint32 failed.", state);
87         return false;
88     }
89 
90     if (!parcel.WriteInt32(eventId)) {
91         XCOLLIE_LOGE("EventId [%{public}u] write int32 failed.", eventId);
92         return false;
93     }
94 
95     if (!parcel.WriteInt32(tid)) {
96         XCOLLIE_LOGE("Tid [%{public}u] write int32 failed.", tid);
97         return false;
98     }
99 
100     return WriteContent(parcel);
101 }
102 } // end of HiviewDFX
103 } // end of OHOS
104