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 #ifndef FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_CACHE_MGR_H 16 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_CACHE_MGR_H 17 18 #include <map> 19 #include <memory> 20 #include <mutex> 21 #include <singleton.h> 22 #include <string> 23 24 namespace OHOS { 25 namespace AppExecFwk { 26 /** 27 * @class FormCacheMgr 28 * Form cache data manager. 29 */ 30 class FormCacheMgr final : public DelayedRefSingleton<FormCacheMgr> { 31 DECLARE_DELAYED_REF_SINGLETON(FormCacheMgr) 32 public: 33 DISALLOW_COPY_AND_MOVE(FormCacheMgr); 34 35 /** 36 * @brief Get form data. 37 * @param formId Form id. 38 * @param data Cache data. 39 * @return Returns true if this function is successfully called; returns false otherwise. 40 */ 41 bool GetData(const int64_t formId, std::string &data) const; 42 43 /** 44 * @brief Add form data. 45 * @param formId Form id. 46 * @param data Cache data. 47 * @return Returns true if this function is successfully called; returns false otherwise. 48 */ 49 bool AddData(const int64_t formId, const std::string &data); 50 51 /** 52 * @brief Delete form data. 53 * @param formId Form id. 54 * @return Returns true if this function is successfully called; returns false otherwise. 55 */ 56 bool DeleteData(const int64_t formId); 57 58 /** 59 * @brief update form data. 60 * @param formId Form id. 61 * @param data Cache data. 62 * @return Returns true if this function is successfully called; returns false otherwise. 63 */ 64 bool UpdateData(const int64_t formId, const std::string &data); 65 /** 66 * @brief Check if form data is exist or not. 67 * @param formId, Form id. 68 * @return Returns true if this function is successfully called; returns false otherwise. 69 */ 70 bool IsExist(const int64_t formId) const; 71 private: 72 mutable std::mutex cacheMutex_; 73 std::map<int64_t, std::string> cacheData_; 74 }; 75 } // namespace AppExecFwk 76 } // namespace OHOS 77 78 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_CACHE_MGR_H 79