• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)23 bool 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     formUsageState = static_cast<FormUsageState>(parcel.ReadInt32());
34     return true;
35 }
36 
Marshalling(Parcel & parcel) const37 bool FormInstance::Marshalling(Parcel &parcel) const
38 {
39     // write formId
40     if (!parcel.WriteInt64(formId)) {
41         return false;
42     }
43 
44     // write formHostName
45     if (!parcel.WriteString16(Str8ToStr16(formHostName))) {
46         return false;
47     }
48 
49     // write formVisiblity
50     if (!parcel.WriteInt32(static_cast<int32_t>(formVisiblity))) {
51         return false;
52     }
53 
54     // write specification
55     if (!parcel.WriteInt32(specification)) {
56         return false;
57     }
58 
59     // write bundleName
60     if (!parcel.WriteString16(Str8ToStr16(bundleName))) {
61         return false;
62     }
63 
64     // write moduleName
65     if (!parcel.WriteString16(Str8ToStr16(moduleName))) {
66         return false;
67     }
68 
69     // write abilityName
70     if (!parcel.WriteString16(Str8ToStr16(abilityName))) {
71         return false;
72     }
73 
74     // write formName
75     if (!parcel.WriteString16(Str8ToStr16(formName))) {
76         return false;
77     }
78 
79     // write formUsageState
80     if (!parcel.WriteInt32(static_cast<int32_t>(formUsageState))) {
81         return false;
82     }
83     return true;
84 }
85 
Unmarshalling(Parcel & parcel)86 FormInstance* FormInstance::Unmarshalling(Parcel &parcel)
87 {
88     std::unique_ptr<FormInstance> object = std::make_unique<FormInstance>();
89     if (object && !object->ReadFromParcel(parcel)) {
90         object = nullptr;
91         return nullptr;
92     }
93     return object.release();
94 }
95 } // namespace AppExecFwk
96 } // namespace OHOS
97