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