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 TIMER_BATCH_H 17 #define TIMER_BATCH_H 18 19 #include "timer_info.h" 20 namespace OHOS { 21 namespace MiscServices { 22 class Batch { 23 public: 24 Batch(); 25 explicit Batch(const TimerInfo &seed); 26 virtual ~Batch() = default; 27 std::chrono::steady_clock::time_point GetStart() const; 28 std::chrono::steady_clock::time_point GetEnd() const; 29 uint32_t GetFlags() const; 30 size_t Size() const; 31 std::shared_ptr<TimerInfo> Get(size_t index) const; 32 bool CanHold(std::chrono::steady_clock::time_point whenElapsed, 33 std::chrono::steady_clock::time_point maxWhen) const; 34 bool Add(const std::shared_ptr<TimerInfo> &alarm); 35 bool Remove(const TimerInfo &alarm); 36 bool Remove(std::function<bool(const TimerInfo &)> predicate); 37 bool HasPackage(const std::string &package_name); 38 bool HasWakeups() const; 39 40 private: 41 std::chrono::steady_clock::time_point start_; 42 std::chrono::steady_clock::time_point end_; 43 uint32_t flags_; 44 std::vector<std::shared_ptr<TimerInfo>> alarms_; 45 }; 46 } 47 } 48 #endif