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