1 /* 2 * Copyright (c) 2021-2022 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 "screen_group_info.h" 17 18 namespace OHOS::Rosen { Marshalling(Parcel & parcel) const19bool ScreenGroupInfo::Marshalling(Parcel &parcel) const 20 { 21 bool res = ScreenInfo::Marshalling(parcel) && parcel.WriteUint32((uint32_t)combination_) && 22 parcel.WriteUInt64Vector(children_); 23 if (!res) { 24 return false; 25 } 26 size_t size = position_.size(); 27 if (!parcel.WriteUint32(size)) { 28 return false; 29 } 30 for (size_t i = 0; i < size; i++) { 31 if (!parcel.WriteInt32(position_[i].posX_) || !parcel.WriteInt32(position_[i].posY_)) { 32 return false; 33 } 34 } 35 return true; 36 } 37 Unmarshalling(Parcel & parcel)38ScreenGroupInfo* ScreenGroupInfo::Unmarshalling(Parcel &parcel) 39 { 40 ScreenGroupInfo* screenGroupInfo = new(std::nothrow) ScreenGroupInfo(); 41 if (screenGroupInfo == nullptr) { 42 return screenGroupInfo; 43 } 44 bool res = screenGroupInfo->InnerUnmarshalling(parcel); 45 if (res) { 46 return screenGroupInfo; 47 } 48 delete screenGroupInfo; 49 return nullptr; 50 } 51 InnerUnmarshalling(Parcel & parcel)52bool ScreenGroupInfo::InnerUnmarshalling(Parcel& parcel) 53 { 54 uint32_t combination; 55 if (!ScreenInfo::InnerUnmarshalling(parcel) || !parcel.ReadUint32(combination) || 56 !parcel.ReadUInt64Vector(&children_)) { 57 return false; 58 } 59 combination_ = (ScreenCombination) combination; 60 uint32_t size; 61 if (!parcel.ReadUint32(size)) { 62 return false; 63 } 64 for (size_t i = 0; i < size; i++) { 65 Point point; 66 if (parcel.ReadInt32(point.posX_) && parcel.ReadInt32(point.posY_)) { 67 position_.push_back(point); 68 } else { 69 return false; 70 } 71 } 72 return true; 73 } 74 } // namespace OHOS::Rosen