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