• 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 
16 #ifndef FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TIMER_REFRESH_LIMITER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TIMER_REFRESH_LIMITER_H
18 
19 #include <map>
20 #include <mutex>
21 #include <vector>
22 #include "form_timer.h"
23 
24 namespace OHOS {
25 namespace AppExecFwk {
26 /**
27  * @class FormRefreshLimiter
28  * Form refresh limite manager.
29  */
30 class FormRefreshLimiter {
31 public:
32     /**
33      * @brief Add form limit info by formId.
34      * @param formId The form id.
35      * @return Returns true on success, false on failure.
36      */
37     bool AddItem(int64_t formId);
38     /**
39      * @brief Delete form limit info by formId.
40      * @param formId The form id.
41      */
42     void DeleteItem(int64_t formId);
43     /**
44      * @brief Reset limit info.
45      */
46     void ResetLimit();
47     /**
48      * @brief Refresh enable or not.
49      * @param formId The form id.
50      * @return Returns ERR_OK on success, others on failure.
51      */
52     bool IsEnableRefresh(int64_t formId);
53     /**
54      * @brief Get refresh count.
55      * @param formId The form id.
56      * @return refresh count.
57      */
58     int GetRefreshCount(int64_t formId) const;
59     /**
60      * @brief Increase refresh count.
61      * @param formId The form id.
62      */
63     void Increase(int64_t formId);
64     /**
65      * @brief Mark remind flag.
66      * @param formId The form id.
67      */
68     void MarkRemind(int64_t formId);
69     /**
70      * @brief Get remind list.
71      * @return remind list.
72      */
73     std::vector<int64_t> GetRemindList() const;
74     /**
75      * @brief Get remind list and reset limit.
76      * @return remind list.
77      */
78     std::vector<int64_t> GetRemindListAndResetLimit();
79     /**
80      * @brief Get item count.
81      * @return Item count.
82      */
83     int GetItemCount() const;
84 private:
85     mutable std::mutex limiterMutex_;
86     std::map<int64_t, LimitInfo> limiterMap_;
87 };
88 }  // namespace AppExecFwk
89 }  // namespace OHOS
90 
91 #endif // FOUNDATION_APPEXECFWK_SERVICES_FORMMGR_INCLUDE_FORM_TIMER_REFRESH_LIMITER_H