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  * @class FormTimer
37  * form timer task.
38  */
39 class FormTimer {
40 public:
41     int64_t formId;
42     int32_t userId;
43     int64_t period;
44     int hour;
45     int min;
46     bool isUpdateAt;
47     int64_t refreshTime;
48     bool isEnable = true;
49     bool isCountTimer;
50     UpdateType type = UpdateType::TYPE_INTERVAL_CHANGE;
51 
FormTimer()52     FormTimer()
53     {
54         formId = -1;
55         userId = -1;
56         period = -1;
57         hour = -1;
58         min = -1;
59         isUpdateAt = false;
60         isCountTimer = false;
61         refreshTime = FormUtil::GetCurrentMillisecond();
62         type = UpdateType::TYPE_INTERVAL_CHANGE;
63     }
64 
65     FormTimer(int64_t id, bool countTimer, int32_t uId = 0)
66     {
67         formId = id;
68         userId = uId;
69         period = -1;
70         hour = -1;
71         min = -1;
72         isUpdateAt = false;
73         isCountTimer = countTimer;
74         refreshTime = FormUtil::GetCurrentMillisecond();
75         type = UpdateType::TYPE_INTERVAL_CHANGE;
76     }
77 
78     FormTimer(int64_t id, long repeatTime, int32_t uId = 0)
79     {
80         formId = id;
81         userId = uId;
82         period = repeatTime;
83         hour = -1;
84         min = -1;
85         isUpdateAt = false;
86         isCountTimer = true;
87         refreshTime = FormUtil::GetCurrentMillisecond();
88         type = UpdateType::TYPE_INTERVAL_CHANGE;
89     }
90 
91     FormTimer(int64_t id, int hourTime, int minTime, int32_t uId = 0)
92     {
93         formId = id;
94         userId = uId;
95         hour = hourTime;
96         min = minTime;
97         period = -1;
98         isUpdateAt = true;
99         isCountTimer = false;
100         refreshTime = FormUtil::GetCurrentMillisecond();
101         type = UpdateType::TYPE_INTERVAL_CHANGE;
102     }
103 
~FormTimer(void)104     ~FormTimer(void) {}
105 };
106 /**
107  * @class UpdateAtItem
108  * Update item at time.
109  */
110 class UpdateAtItem {
111 public:
112     long updateAtTime = -1;
113     FormTimer refreshTask;
114 };
115 /**
116  * @class DynamicRefreshItem
117  * Dynamic refresh item.
118  */
119 class DynamicRefreshItem {
120 public:
121     int64_t formId = 0L;
122     int64_t settedTime = INT64_MAX;
123     int32_t userId = -1;
124 
DynamicRefreshItem()125     DynamicRefreshItem() {}
126 
127     DynamicRefreshItem(int64_t id, int64_t time, int32_t uId = 0)
128     {
129         formId = id;
130         settedTime = time;
131         userId = uId;
132     }
133 
~DynamicRefreshItem(void)134     ~DynamicRefreshItem(void) {}
135 };
136 /**
137  * @struct LimitInfo
138  * Limit info about a form.
139  */
140 struct LimitInfo {
141     int refreshCount = 0;
142     bool isReported = false;
143     bool remindFlag = false;
144 };
145 
146 /**
147  * @struct FormTimerCfg
148  * Form timer config info.
149  */
150 struct FormTimerCfg {
151     bool enableUpdate = false;
152     int64_t updateDuration = 0L;
153     int updateAtHour = -1;
154     int updateAtMin = -1;
155 };
156 }  // namespace AppExecFwk
157 }  // namespace OHOS
158 #endif // OHOS_FORM_FWK_FORM_TIMER_H
159