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