1 /* 2 * Copyright (c) 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 BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_FLOW_CONTROL_H 17 #define BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_FLOW_CONTROL_H 18 19 #include <chrono> 20 #include <list> 21 22 namespace OHOS { 23 namespace Notification { 24 class DistributedFlowControl { 25 public: 26 DistributedFlowControl(int kvManagerSecondMaxinum = KVMANAGER_MAXINUM_PER_SECOND, 27 int kvManagerMinuteMaxinum = KVMANAGER_MAXINUM_PER_MINUTE, 28 int kvStoreSecondMaxinum = KVSTORE_MAXINUM_PER_SECOND, 29 int kvStoreMinuteMaxinum = KVSTORE_MAXINUM_PER_MINUTE); 30 bool KvManagerFlowControl(void); 31 bool KvStoreFlowControl(void); 32 void KvManagerFlowControlClear(void); 33 void KvStoreFlowControlClear(void); 34 35 protected: 36 static const int KVMANAGER_MAXINUM_PER_SECOND = 50; 37 static const int KVMANAGER_MAXINUM_PER_MINUTE = 500; 38 static const int KVSTORE_MAXINUM_PER_SECOND = 1000; 39 static const int KVSTORE_MAXINUM_PER_MINUTE = 10000; 40 41 private: 42 int kvManagerSecondMaxinum_; 43 int kvManagerMinuteMaxinum_; 44 int kvStoreSecondMaxinum_; 45 int kvStoreMinuteMaxinum_; 46 std::list<std::chrono::system_clock::time_point> kvDataManagerTimestampList_; 47 std::list<std::chrono::system_clock::time_point> kvStoreTimestampList_; 48 }; 49 } // namespace Notification 50 } // namespace OHOS 51 52 #endif /* BASE_NOTIFICATION_ANS_STANDARD_SERVICES_DISTRIBUTED_INCLUDE_DISTRIBUTED_FLOW_CONTROL_H */