• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_record_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)24 bool MissionRecordInfo::ReadFromParcel(Parcel &parcel)
25 {
26     parcel.ReadInt32(id);
27     int32_t abilityRecordInfosSize = parcel.ReadInt32();
28     for (int32_t i = 0; i < abilityRecordInfosSize; i++) {
29         std::unique_ptr<AbilityRecordInfo> abilityRecordInfo(parcel.ReadParcelable<AbilityRecordInfo>());
30         if (!abilityRecordInfo) {
31             HILOG_ERROR("ReadParcelable<AbilityRecordInfo> failed");
32             return false;
33         }
34         abilityRecordInfos.emplace_back(*abilityRecordInfo);
35     }
36     return true;
37 }
38 
Unmarshalling(Parcel & parcel)39 MissionRecordInfo *MissionRecordInfo::Unmarshalling(Parcel &parcel)
40 {
41     MissionRecordInfo *info = new (std::nothrow) MissionRecordInfo();
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) const53 bool MissionRecordInfo::Marshalling(Parcel &parcel) const
54 {
55     parcel.WriteInt32(id);
56     parcel.WriteInt32(abilityRecordInfos.size());
57     for (auto &abilityRecordInfo : abilityRecordInfos) {
58         parcel.WriteParcelable(&abilityRecordInfo);
59     }
60 
61     return true;
62 }
63 
64 }  // namespace AAFwk
65 }  // namespace OHOS