1 /* 2 * Copyright (c) 2023 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 "form_instance.h" 17 #include "fms_log_wrapper.h" 18 #include "message_parcel.h" 19 #include "string_ex.h" 20 21 namespace OHOS { 22 namespace AppExecFwk { ReadFromParcel(Parcel & parcel)23bool FormInstance::ReadFromParcel(Parcel &parcel) 24 { 25 formId = parcel.ReadInt64(); 26 formHostName = Str16ToStr8(parcel.ReadString16()); 27 formVisiblity = static_cast<FormVisibilityType>(parcel.ReadInt32()); 28 specification = parcel.ReadInt32(); 29 bundleName = Str16ToStr8(parcel.ReadString16()); 30 moduleName = Str16ToStr8(parcel.ReadString16()); 31 abilityName = Str16ToStr8(parcel.ReadString16()); 32 formName = Str16ToStr8(parcel.ReadString16()); 33 return true; 34 } 35 Marshalling(Parcel & parcel) const36bool FormInstance::Marshalling(Parcel &parcel) const 37 { 38 // write formId 39 if (!parcel.WriteInt64(formId)) { 40 return false; 41 } 42 43 // write formHostName 44 if (!parcel.WriteString16(Str8ToStr16(formHostName))) { 45 return false; 46 } 47 48 // write formVisiblity 49 if (!parcel.WriteInt32(static_cast<int32_t>(formVisiblity))) { 50 return false; 51 } 52 53 // write specification 54 if (!parcel.WriteInt32(specification)) { 55 return false; 56 } 57 58 // write bundleName 59 if (!parcel.WriteString16(Str8ToStr16(bundleName))) { 60 return false; 61 } 62 63 // write moduleName 64 if (!parcel.WriteString16(Str8ToStr16(moduleName))) { 65 return false; 66 } 67 68 // write abilityName 69 if (!parcel.WriteString16(Str8ToStr16(abilityName))) { 70 return false; 71 } 72 73 // write formName 74 if (!parcel.WriteString16(Str8ToStr16(formName))) { 75 return false; 76 } 77 return true; 78 } 79 Unmarshalling(Parcel & parcel)80FormInstance* FormInstance::Unmarshalling(Parcel &parcel) 81 { 82 std::unique_ptr<FormInstance> object = std::make_unique<FormInstance>(); 83 if (object && !object->ReadFromParcel(parcel)) { 84 object = nullptr; 85 return nullptr; 86 } 87 return object.release(); 88 } 89 } // namespace AppExecFwk 90 } // namespace OHOS 91