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 "form_provider_info.h"
17
18 namespace OHOS {
19 namespace AppExecFwk {
ReadFromParcel(Parcel & parcel)20 bool FormProviderInfo::ReadFromParcel(Parcel &parcel)
21 {
22 std::unique_ptr<FormProviderData> bindingData(parcel.ReadParcelable<FormProviderData>());
23 jsBindingData_ = *bindingData;
24 return true;
25 }
26
Unmarshalling(Parcel & parcel)27 FormProviderInfo *FormProviderInfo::Unmarshalling(Parcel &parcel)
28 {
29 std::unique_ptr<FormProviderInfo> formProviderInfo = std::make_unique<FormProviderInfo>();
30 if (formProviderInfo && !formProviderInfo->ReadFromParcel(parcel)) {
31 formProviderInfo = nullptr;
32 }
33 return formProviderInfo.release();
34 }
35
Marshalling(Parcel & parcel) const36 bool FormProviderInfo::Marshalling(Parcel &parcel) const
37 {
38 if (!parcel.WriteParcelable(&jsBindingData_)) {
39 return false;
40 }
41 return true;
42 }
SetFormDataString(std::string & dataString)43 void FormProviderInfo::SetFormDataString(std::string &dataString)
44 {
45 jsBindingData_.SetDataString(dataString);
46 }
47 /**
48 * @brief Updates imageDataMap in this {@code FormProviderData} object.
49 * @param imageDataMap Indicates the imageDataMap to update.
50 */
SetImageDataMap(std::map<std::string,std::pair<sptr<FormAshmem>,int32_t>> imageDataMap)51 void FormProviderInfo::SetImageDataMap(std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> imageDataMap)
52 {
53 jsBindingData_.SetImageDataMap(imageDataMap);
54 }
55
56 /**
57 * @brief Obtains the imageDataMap stored in this {@code FormProviderData} object.
58 * @return Returns the map that contains shared image data.
59 */
GetImageDataMap() const60 std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> FormProviderInfo::GetImageDataMap() const
61 {
62 return jsBindingData_.GetImageDataMap();
63 }
64 /**
65 * @brief Merge new data to FormProviderData.
66 * @param addJsonData data to merge to FormProviderData
67 */
MergeData(nlohmann::json & addJsonData)68 void FormProviderInfo::MergeData(nlohmann::json &addJsonData)
69 {
70 jsBindingData_.MergeData(addJsonData);
71 }
72
NeedCache() const73 bool FormProviderInfo::NeedCache() const
74 {
75 return jsBindingData_.NeedCache();
76 }
77 } // namespace AppExecFwk
78 } // namespace OHOS
79