• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef OHOS_FORM_FWK_FORM_CACHE_MGR_H
16 #define OHOS_FORM_FWK_FORM_CACHE_MGR_H
17 
18 #include <map>
19 #include <mutex>
20 #include <singleton.h>
21 #include <string>
22 
23 namespace OHOS {
24 namespace AppExecFwk {
25 /**
26  * @class FormCacheMgr
27  * Form cache data manager.
28  */
29 class FormCacheMgr final : public DelayedRefSingleton<FormCacheMgr> {
30 DECLARE_DELAYED_REF_SINGLETON(FormCacheMgr)
31 public:
32     DISALLOW_COPY_AND_MOVE(FormCacheMgr);
33 
34     /**
35      * @brief Get form data.
36      * @param formId Form id.
37      * @param data Cache data.
38      * @return Returns true if this function is successfully called; returns false otherwise.
39      */
40     bool GetData(int64_t formId, std::string &data) const;
41 
42     /**
43      * @brief Add form data.
44      * @param formId Form id.
45      * @param data Cache data.
46      * @return Returns true if this function is successfully called; returns false otherwise.
47      */
48     bool AddData(int64_t formId, const std::string &data);
49 
50     /**
51      * @brief Delete form data.
52      * @param formId Form id.
53      * @return Returns true if this function is successfully called; returns false otherwise.
54      */
55     bool DeleteData(int64_t formId);
56 
57     /**
58      * @brief update form data.
59      * @param formId Form id.
60      * @param data Cache data.
61      * @return Returns true if this function is successfully called; returns false otherwise.
62      */
63     bool UpdateData(int64_t formId, const std::string &data);
64 
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(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 // OHOS_FORM_FWK_FORM_CACHE_MGR_H
79