1cf69771bSopenharmony_ci/*
2cf69771bSopenharmony_ci * Copyright (C) 2021 Huawei Device Co., Ltd.
3cf69771bSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4cf69771bSopenharmony_ci * you may not use this file except in compliance with the License.
5cf69771bSopenharmony_ci * You may obtain a copy of the License at
6cf69771bSopenharmony_ci *
7cf69771bSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8cf69771bSopenharmony_ci *
9cf69771bSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10cf69771bSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11cf69771bSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12cf69771bSopenharmony_ci * See the License for the specific language governing permissions and
13cf69771bSopenharmony_ci * limitations under the License.
14cf69771bSopenharmony_ci */
15cf69771bSopenharmony_ci
16cf69771bSopenharmony_ci#ifndef TIMER_BATCH_H
17cf69771bSopenharmony_ci#define TIMER_BATCH_H
18cf69771bSopenharmony_ci
19cf69771bSopenharmony_ci#include <cstdint>
20cf69771bSopenharmony_ci#include <vector>
21cf69771bSopenharmony_ci#include <chrono>
22cf69771bSopenharmony_ci#include <functional>
23cf69771bSopenharmony_ci#include "timer_info.h"
24cf69771bSopenharmony_ci#include "time_common.h"
25cf69771bSopenharmony_cinamespace OHOS {
26cf69771bSopenharmony_cinamespace MiscServices {
27cf69771bSopenharmony_ciclass Batch {
28cf69771bSopenharmony_cipublic:
29cf69771bSopenharmony_ci    Batch();
30cf69771bSopenharmony_ci    explicit Batch(const TimerInfo &seed);
31cf69771bSopenharmony_ci    virtual ~Batch() = default;
32cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point GetStart() const;
33cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point GetEnd() const;
34cf69771bSopenharmony_ci    uint32_t GetFlags() const;
35cf69771bSopenharmony_ci    size_t Size() const;
36cf69771bSopenharmony_ci    std::shared_ptr<TimerInfo> Get(size_t index) const;
37cf69771bSopenharmony_ci    bool CanHold(std::chrono::steady_clock::time_point whenElapsed,
38cf69771bSopenharmony_ci                 std::chrono::steady_clock::time_point maxWhen) const;
39cf69771bSopenharmony_ci    bool Add(const std::shared_ptr<TimerInfo> &alarm);
40cf69771bSopenharmony_ci    bool Remove(const TimerInfo &alarm);
41cf69771bSopenharmony_ci    bool Remove(std::function<bool(const TimerInfo &)> predicate);
42cf69771bSopenharmony_ci    bool HasPackage(const std::string &package_name);
43cf69771bSopenharmony_ci    bool HasWakeups() const;
44cf69771bSopenharmony_ci
45cf69771bSopenharmony_ciprivate:
46cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point start_;
47cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point end_;
48cf69771bSopenharmony_ci    uint32_t flags_;
49cf69771bSopenharmony_ci    std::vector<std::shared_ptr<TimerInfo>> alarms_;
50cf69771bSopenharmony_ci};
51cf69771bSopenharmony_ci}
52cf69771bSopenharmony_ci}
53cf69771bSopenharmony_ci#endif