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_INFO_H
17cf69771bSopenharmony_ci#define TIMER_INFO_H
18cf69771bSopenharmony_ci
19cf69771bSopenharmony_ci#include <cstdint>
20cf69771bSopenharmony_ci#include <string>
21cf69771bSopenharmony_ci
22cf69771bSopenharmony_ci#include "timer_manager_interface.h"
23cf69771bSopenharmony_ci
24cf69771bSopenharmony_cinamespace OHOS {
25cf69771bSopenharmony_cinamespace MiscServices {
26cf69771bSopenharmony_cistatic const uint32_t HALF_SECEND = 2;
27cf69771bSopenharmony_ci
28cf69771bSopenharmony_ciclass TimerInfo {
29cf69771bSopenharmony_cipublic:
30cf69771bSopenharmony_ci    const uint64_t id;
31cf69771bSopenharmony_ci    const int type;
32cf69771bSopenharmony_ci    const std::chrono::milliseconds origWhen;
33cf69771bSopenharmony_ci    const bool wakeup;
34cf69771bSopenharmony_ci    const std::function<int32_t (const uint64_t)> callback;
35cf69771bSopenharmony_ci    const std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent;
36cf69771bSopenharmony_ci    const uint32_t flags;
37cf69771bSopenharmony_ci    const int uid;
38cf69771bSopenharmony_ci    const int pid;
39cf69771bSopenharmony_ci
40cf69771bSopenharmony_ci    std::chrono::milliseconds when;
41cf69771bSopenharmony_ci    std::chrono::milliseconds windowLength;
42cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point originWhenElapsed;
43cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point originMaxWhenElapsed;
44cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point whenElapsed;
45cf69771bSopenharmony_ci    std::chrono::steady_clock::time_point maxWhenElapsed;
46cf69771bSopenharmony_ci    std::chrono::milliseconds repeatInterval;
47cf69771bSopenharmony_ci    std::chrono::milliseconds offset;
48cf69771bSopenharmony_ci    std::string bundleName;
49cf69771bSopenharmony_ci
50cf69771bSopenharmony_ci    TimerInfo(uint64_t id, int type,
51cf69771bSopenharmony_ci        std::chrono::milliseconds when,
52cf69771bSopenharmony_ci        std::chrono::steady_clock::time_point whenElapsed,
53cf69771bSopenharmony_ci        std::chrono::milliseconds windowLength,
54cf69771bSopenharmony_ci        std::chrono::steady_clock::time_point maxWhen,
55cf69771bSopenharmony_ci        std::chrono::milliseconds interval,
56cf69771bSopenharmony_ci        std::function<int32_t (const uint64_t)> callback,
57cf69771bSopenharmony_ci        std::shared_ptr<OHOS::AbilityRuntime::WantAgent::WantAgent> wantAgent,
58cf69771bSopenharmony_ci        uint32_t flags,
59cf69771bSopenharmony_ci        int uid,
60cf69771bSopenharmony_ci        int pid,
61cf69771bSopenharmony_ci        const std::string &bundleName);
62cf69771bSopenharmony_ci    virtual ~TimerInfo() = default;
63cf69771bSopenharmony_ci    bool operator==(const TimerInfo &other) const;
64cf69771bSopenharmony_ci    bool Matches(const std::string &packageName) const;
65cf69771bSopenharmony_ci    bool UpdateWhenElapsedFromNow(std::chrono::steady_clock::time_point now, std::chrono::nanoseconds offset);
66cf69771bSopenharmony_ci    bool AdjustTimer(const std::chrono::steady_clock::time_point &now, const uint32_t interval);
67cf69771bSopenharmony_ci    bool RestoreAdjustTimer();
68cf69771bSopenharmony_ci};
69cf69771bSopenharmony_ci} // MiscService
70cf69771bSopenharmony_ci} // OHOS
71cf69771bSopenharmony_ci#endif