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