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_snapshot.h"
17 
18 namespace OHOS {
19 namespace AAFwk {
ReadFromParcel(Parcel & parcel)20 bool MissionSnapshot::ReadFromParcel(Parcel &parcel)
21 {
22 #ifdef SUPPORT_GRAPHICS
23     std::unique_ptr<AppExecFwk::ElementName> ability(parcel.ReadParcelable<AppExecFwk::ElementName>());
24     if (ability == nullptr) {
25         return false;
26     }
27     topAbility = *ability;
28     std::shared_ptr<Media::PixelMap> pixelMap(parcel.ReadParcelable<Media::PixelMap>());
29     if (pixelMap == nullptr) {
30         return false;
31     }
32     snapshot = pixelMap;
33 #endif
34     return true;
35 }
36 
Unmarshalling(Parcel & parcel)37 MissionSnapshot *MissionSnapshot::Unmarshalling(Parcel &parcel)
38 {
39     MissionSnapshot *info = new (std::nothrow) MissionSnapshot();
40 
41     if (!info->ReadFromParcel(parcel)) {
42         delete info;
43         info = nullptr;
44     }
45     return info;
46 }
47 
Marshalling(Parcel & parcel) const48 bool MissionSnapshot::Marshalling(Parcel &parcel) const
49 {
50     if (!parcel.WriteParcelable(&topAbility)) {
51         return false;
52     }
53 #ifdef SUPPORT_GRAPHICS
54     if (!parcel.WriteParcelable(snapshot.get())) {
55         return false;
56     }
57 #endif
58     return true;
59 }
60 }  // namespace AAFwk
61 }  // namespace OHOS
62