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 "exit_reason.h"
17
18 #include "hilog_tag_wrapper.h"
19 #include "parcel_macro_base.h"
20 #include "string_ex.h"
21
22 namespace OHOS {
23 namespace AAFwk {
ExitReason(const Reason reason,const std::string & exitMsg)24 ExitReason::ExitReason(const Reason reason, const std::string &exitMsg)
25 {
26 this->reason = reason;
27 this->exitMsg = exitMsg;
28 }
29
ExitReason(const Reason & reason,int32_t subReason,const std::string & exitMsg)30 ExitReason::ExitReason(const Reason &reason, int32_t subReason, const std::string &exitMsg)
31 {
32 this->reason = reason;
33 this->subReason = subReason;
34 this->exitMsg = exitMsg;
35 }
36
ReadFromParcel(Parcel & parcel)37 bool ExitReason::ReadFromParcel(Parcel &parcel)
38 {
39 int32_t reasonData;
40 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonData);
41 reason = static_cast<Reason>(reasonData);
42 READ_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, reasonData);
43 subReason = reasonData;
44 exitMsg = Str16ToStr8(parcel.ReadString16());
45 return true;
46 }
47
Unmarshalling(Parcel & parcel)48 ExitReason *ExitReason::Unmarshalling(Parcel &parcel)
49 {
50 ExitReason *data = new (std::nothrow) ExitReason();
51 if (!data) {
52 TAG_LOGE(AAFwkTag::ABILITYMGR, "null data");
53 return nullptr;
54 }
55 if (!data->ReadFromParcel(parcel)) {
56 TAG_LOGE(AAFwkTag::ABILITYMGR, "read failed");
57 delete data;
58 data = nullptr;
59 }
60 return data;
61 }
62
Marshalling(Parcel & parcel) const63 bool ExitReason::Marshalling(Parcel &parcel) const
64 {
65 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, static_cast<int32_t>(reason));
66 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(Int32, parcel, subReason);
67 WRITE_PARCEL_AND_RETURN_FALSE_IF_FAIL(String16, parcel, Str8ToStr16(exitMsg));
68 return true;
69 }
70 } // namespace AppExecFwk
71 } // namespace OHOS
72