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 #ifndef OHOS_FORM_FWK_FORM_PROVIDER_INFO_H 17 #define OHOS_FORM_FWK_FORM_PROVIDER_INFO_H 18 19 #include <cstdint> 20 #include <utility> 21 22 #include "form_ashmem.h" 23 #include "form_provider_data.h" 24 #include "nlohmann/json_fwd.hpp" 25 #include "parcel.h" 26 #include "refbase.h" 27 28 namespace OHOS { 29 namespace AppExecFwk { 30 /** 31 * @struct FormProviderInfo 32 * Defines form provider info. 33 */ 34 class FormProviderInfo : public Parcelable { 35 public: 36 FormProviderInfo() = default; 37 ~FormProviderInfo() = default; 38 39 /** 40 * @brief Set the form data. 41 * @param formProviderData The form data. 42 */ SetFormData(const FormProviderData & formProviderData)43 inline void SetFormData(const FormProviderData &formProviderData) 44 { 45 jsBindingData_ = formProviderData; 46 } 47 48 /** 49 * @brief Get the form data. 50 * @return the form data. 51 */ GetFormData()52 inline FormProviderData GetFormData() const 53 { 54 return jsBindingData_; 55 } 56 /** 57 * @brief Get the form data. 58 * @return the form data. 59 */ GetFormDataString()60 inline std::string GetFormDataString() const 61 { 62 return jsBindingData_.GetDataString(); 63 } 64 65 /** 66 * @brief Set the upgrade flg. 67 * @param upgradeFlg The upgrade flg. 68 */ SetUpgradeFlg(const bool upgradeFlg)69 inline void SetUpgradeFlg(const bool upgradeFlg) 70 { 71 upgradeFlg_ = upgradeFlg; 72 } 73 /** 74 * @brief Get the upgrade flg. 75 * @return the upgrade flg. 76 */ GetUpgradeFlg()77 inline bool GetUpgradeFlg() const 78 { 79 return upgradeFlg_; 80 } 81 82 /** 83 * @brief Set form date by string. 84 * @param dataString string json data. 85 */ 86 void SetFormDataString(std::string &dataString); 87 88 /** 89 * @brief Updates imageDataMap in this {@code FormProviderData} object. 90 * @param imageDataMap Indicates the imageDataMap to update. 91 */ 92 void SetImageDataMap(std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> imageDataMap); 93 94 /** 95 * @brief Obtains the imageDataMap stored in this {@code FormProviderData} object. 96 * @return Returns the map that contains shared image data. 97 */ 98 std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> GetImageDataMap() const; 99 100 /** 101 * @brief Merge new data to FormProviderData. 102 * @param addJsonData data to merge to FormProviderData 103 */ 104 void MergeData(nlohmann::json &addJsonData); 105 106 /** 107 * @brief Whether the form provider data needs to be cached 108 * @return Returns {@code true} if the data needs to be cached; returns {@code false} otherwise. 109 */ 110 bool NeedCache() const; 111 112 bool ReadFromParcel(Parcel &parcel); 113 virtual bool Marshalling(Parcel &parcel) const override; 114 static FormProviderInfo *Unmarshalling(Parcel &parcel); 115 private: 116 FormProviderData jsBindingData_; 117 bool upgradeFlg_; 118 }; 119 } // namespace AppExecFwk 120 } // namespace OHOS 121 #endif // OHOS_FORM_FWK_FORM_PROVIDER_INFO_H 122