• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "form_ashmem.h"
25 
26 namespace OHOS {
27 namespace AppExecFwk {
28 /**
29  * @class FormCacheMgr
30  * Form cache data manager.
31  */
32 class FormCacheMgr final : public DelayedRefSingleton<FormCacheMgr> {
33 DECLARE_DELAYED_REF_SINGLETON(FormCacheMgr)
34 public:
35     DISALLOW_COPY_AND_MOVE(FormCacheMgr);
36 
37     /**
38      * @brief Get form data.
39      * @param formId Form id.
40      * @param data Cache data.
41      * @param imageMap Image map cache.
42      * @return Returns true if this function is successfully called; returns false otherwise.
43      */
44     bool GetData(const int64_t formId, std::string &data,
45         std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> &imageMap) const;
46 
47     /**
48      * @brief Add form data.
49      * @param formId Form id.
50      * @param data Cache data.
51      * @param imageMap Image map cache.
52      * @return Returns true if this function is successfully called; returns false otherwise.
53      */
54     bool AddData(const int64_t formId, const std::string &data,
55         const std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>> &imageMap);
56 
57     /**
58      * @brief Delete form data.
59      * @param formId Form id.
60      * @return Returns true if this function is successfully called; returns false otherwise.
61      */
62     bool DeleteData(const int64_t formId);
63 
64     /**
65      * @brief update form data.
66      * @param formId Form id.
67      * @param data Cache data.
68      * @return Returns true if this function is successfully called; returns false otherwise.
69      */
70     bool UpdateData(const int64_t formId, const std::string &data);
71     /**
72      * @brief Check if form data is exist or not.
73      * @param formId, Form id.
74      * @return Returns true if this function is successfully called; returns false otherwise.
75      */
76     bool IsExist(const int64_t formId) const;
77 private:
78     mutable std::mutex cacheMutex_;
79     std::map<int64_t, std::string> cacheData_;
80     std::map<int64_t, std::map<std::string, std::pair<sptr<FormAshmem>, int32_t>>> cacheImageMap_;
81 };
82 }  // namespace AppExecFwk
83 }  // namespace OHOS
84 
85 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_CACHE_MGR_H
86