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