• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 #ifndef OHOS_FORM_FWK_FORM_TIMER_H
16 #define OHOS_FORM_FWK_FORM_TIMER_H
17 
18 #include "form_constants.h"
19 #include "form_util.h"
20 
21 namespace OHOS {
22 namespace AppExecFwk {
23 /**
24  * @enum UpdateType
25  * Update type.
26  */
27 enum UpdateType {
28     TYPE_INTERVAL_CHANGE,
29     TYPE_ATTIME_CHANGE,
30     TYPE_INTERVAL_TO_ATTIME,
31     TYPE_ATTIME_TO_INTERVAL,
32     TYPE_INTERVAL_ONCE,
33     TYPE_NO_CHANGE,
34 };
35 
36 /**
37  * @enum RefreshType
38  * Refresh type.
39  */
40 enum RefreshType {
41     TYPE_NO_TIMER,
42     TYPE_INTERVAL,
43     TYPE_UPDATETIMES,
44     TYPE_UPDATENEXTTIME,
45     TYPE_VISIABLE,
46 };
47 
48 /**
49  * @class FormTimer
50  * form timer task.
51  */
52 class FormTimer {
53 public:
54     int64_t formId;
55     int32_t userId;
56     int64_t period;
57     int hour;
58     int min;
59     bool isUpdateAt;
60     int64_t refreshTime;
61     bool isEnable = true;
62     bool isCountTimer;
63     UpdateType type = UpdateType::TYPE_INTERVAL_CHANGE;
64     RefreshType refreshType = RefreshType::TYPE_NO_TIMER;
65     bool needUpdateAlarm = true;
66 
FormTimer()67     FormTimer()
68     {
69         formId = -1;
70         userId = -1;
71         period = -1;
72         hour = -1;
73         min = -1;
74         isUpdateAt = false;
75         isCountTimer = false;
76         refreshTime = FormUtil::GetCurrentMillisecond();
77         type = UpdateType::TYPE_INTERVAL_CHANGE;
78         refreshType = RefreshType::TYPE_NO_TIMER;
79     }
80 
81     FormTimer(int64_t id, bool countTimer, int32_t uId = 0)
82     {
83         formId = id;
84         userId = uId;
85         period = -1;
86         hour = -1;
87         min = -1;
88         isUpdateAt = false;
89         isCountTimer = countTimer;
90         refreshTime = FormUtil::GetCurrentMillisecond();
91         type = UpdateType::TYPE_INTERVAL_CHANGE;
92         refreshType = RefreshType::TYPE_NO_TIMER;
93     }
94 
95     FormTimer(int64_t id, long repeatTime, int32_t uId = 0)
96     {
97         formId = id;
98         userId = uId;
99         period = repeatTime;
100         hour = -1;
101         min = -1;
102         isUpdateAt = false;
103         isCountTimer = true;
104         refreshTime = FormUtil::GetCurrentMillisecond();
105         type = UpdateType::TYPE_INTERVAL_CHANGE;
106         refreshType = RefreshType::TYPE_NO_TIMER;
107     }
108 
109     FormTimer(int64_t id, int hourTime, int minTime, int32_t uId = 0)
110     {
111         formId = id;
112         userId = uId;
113         hour = hourTime;
114         min = minTime;
115         period = -1;
116         isUpdateAt = true;
117         isCountTimer = false;
118         refreshTime = FormUtil::GetCurrentMillisecond();
119         type = UpdateType::TYPE_INTERVAL_CHANGE;
120         refreshType = RefreshType::TYPE_NO_TIMER;
121     }
122 
~FormTimer(void)123     ~FormTimer(void) {}
124 };
125 /**
126  * @class UpdateAtItem
127  * Update item at time.
128  */
129 class UpdateAtItem {
130 public:
131     long updateAtTime = -1;
132     FormTimer refreshTask;
133 };
134 /**
135  * @class DynamicRefreshItem
136  * Dynamic refresh item.
137  */
138 class DynamicRefreshItem {
139 public:
140     int64_t formId = 0L;
141     int64_t settedTime = INT64_MAX;
142     int32_t userId = -1;
143 
DynamicRefreshItem()144     DynamicRefreshItem() {}
145 
146     DynamicRefreshItem(int64_t id, int64_t time, int32_t uId = 0)
147     {
148         formId = id;
149         settedTime = time;
150         userId = uId;
151     }
152 
~DynamicRefreshItem(void)153     ~DynamicRefreshItem(void) {}
154 };
155 /**
156  * @struct LimitInfo
157  * Limit info about a form.
158  */
159 struct LimitInfo {
160     int refreshCount = 0;
161     bool isReported = false;
162     bool remindFlag = false;
163 };
164 
165 /**
166  * @struct FormTimerCfg
167  * Form timer config info.
168  */
169 struct FormTimerCfg {
170     bool enableUpdate = false;
171     int64_t updateDuration = 0L;
172     int updateAtHour = -1;
173     int updateAtMin = -1;
174     std::vector<std::vector<int>> updateAtTimes;
175 };
176 }  // namespace AppExecFwk
177 }  // namespace OHOS
178 #endif // OHOS_FORM_FWK_FORM_TIMER_H
179