1 /* 2 * Copyright (c) 2023 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 SCHEDULE_TASK_H 17 #define SCHEDULE_TASK_H 18 19 #include <memory> 20 #include <string> 21 22 #include "startup_constant.h" 23 #include "update_define.h" 24 25 namespace OHOS { 26 namespace UpdateEngine { 27 class ScheduleTask final { 28 public: 29 TaskPriority priority = TaskPriority::LOW; 30 uint64_t minDelayTime = 0L; // 单位S 31 uint64_t maxDelayTime = 0L; // 单位S 32 int netType = 0; 33 int batteryLevel = 0; 34 bool deviceIdle = false; 35 std::string taskExtra; 36 StartupReason startupReason = StartupReason::UNKNOWN; 37 38 // 优先保证高优先级任务按时拉起 39 bool operator<(const ScheduleTask &other) const 40 { 41 if (minDelayTime != other.minDelayTime) { 42 // 最先执行,优先级更高 43 return minDelayTime < other.minDelayTime; 44 } 45 46 // 最大延时时间越小,越早触发,优先级更高 47 return maxDelayTime < other.maxDelayTime; 48 } 49 50 bool operator==(const ScheduleTask &other) const 51 { 52 return priority == other.priority && minDelayTime == other.minDelayTime && 53 maxDelayTime == other.maxDelayTime && netType == other.netType && 54 batteryLevel == other.batteryLevel && deviceIdle == other.deviceIdle && 55 taskExtra == other.taskExtra; 56 } 57 ToString()58 std::string ToString() const 59 { 60 return std::string("Task:[") 61 .append("priority:").append(std::to_string(CAST_INT(priority))).append(", ") 62 .append("minDelayTime:").append(std::to_string(minDelayTime)).append(", ") 63 .append("maxDelayTime:").append(std::to_string(maxDelayTime)).append(", ") 64 .append("netType:").append(std::to_string(netType)).append(", ") 65 .append("batteryLevel:").append(std::to_string(batteryLevel)).append(", ") 66 .append("deviceIdle:").append(std::to_string(CAST_INT(deviceIdle))).append(", ") 67 .append("taskExtra:").append(taskExtra) 68 .append("]"); 69 } 70 }; 71 } // namespace UpdateEngine 72 } // namespace OHOS 73 #endif // SCHEDULE_TASK_H