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 16 #include "mission_stack_info.h" 17 18 #include "hilog_wrapper.h" 19 #include "nlohmann/json.hpp" 20 #include "string_ex.h" 21 22 namespace OHOS { 23 namespace AAFwk { ReadFromParcel(Parcel & parcel)24bool MissionStackInfo::ReadFromParcel(Parcel &parcel) 25 { 26 parcel.ReadInt32(id); 27 int32_t missionStackInfosSize = parcel.ReadInt32(); 28 for (int32_t i = 0; i < missionStackInfosSize; i++) { 29 std::unique_ptr<MissionRecordInfo> missionRecordInfo(parcel.ReadParcelable<MissionRecordInfo>()); 30 if (!missionRecordInfo) { 31 HILOG_ERROR("ReadParcelable<MissionRecordInfo> failed"); 32 return false; 33 } 34 missionRecords.emplace_back(*missionRecordInfo); 35 } 36 return true; 37 } 38 Unmarshalling(Parcel & parcel)39MissionStackInfo *MissionStackInfo::Unmarshalling(Parcel &parcel) 40 { 41 MissionStackInfo *info = new (std::nothrow) MissionStackInfo(); 42 if (info == nullptr) { 43 return nullptr; 44 } 45 46 if (!info->ReadFromParcel(parcel)) { 47 delete info; 48 info = nullptr; 49 } 50 return info; 51 } 52 Marshalling(Parcel & parcel) const53bool MissionStackInfo::Marshalling(Parcel &parcel) const 54 { 55 parcel.WriteInt32(id); 56 parcel.WriteInt32(missionRecords.size()); 57 for (auto &missionRecordInfo : missionRecords) { 58 parcel.WriteParcelable(&missionRecordInfo); 59 } 60 61 return true; 62 } 63 } // namespace AAFwk 64 } // namespace OHOS