1 /*
2 * Copyright (c) 2025 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 FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_SYSTEM_POLICY_H
17 #define FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_SYSTEM_POLICY_H
18
19 #include <string>
20 #include "work_sched_constants.h"
21
22 namespace OHOS {
23 namespace WorkScheduler {
24 struct WorkSchedSystemPolicy {
25 std::string policyName = "NONE";
26 int32_t cpuUsage;
27 int32_t memAvailable;
28 // interfaces/inner_api/native/include/thermal_level_info.h
29 int32_t thermalLevel;
30 // interfaces/inner_api/native/include/power_mode_info.h
31 uint32_t powerMode;
32
33 inline std::string GetInfo() const;
34 inline void SetPolicyName(const std::string &policyName, int32_t allowRunningCount);
35 };
36
GetInfo()37 std::string WorkSchedSystemPolicy::GetInfo() const
38 {
39 return "policyName: " + policyName + ", cpuUsage: " + std::to_string(cpuUsage) +
40 ", memAvailable: " + std::to_string(memAvailable) + ", thermalLevel: " + std::to_string(thermalLevel) +
41 ", powerMode: " + std::to_string(powerMode);
42 }
43
SetPolicyName(const std::string & name,int32_t allowRunningCount)44 void WorkSchedSystemPolicy::SetPolicyName(const std::string &name, int32_t allowRunningCount)
45 {
46 if (allowRunningCount < MAX_RUNNING_COUNT) {
47 if (policyName == "NONE") {
48 policyName = name;
49 } else {
50 policyName.append("&").append(name);
51 }
52 }
53 }
54 } // namespace WorkScheduler
55 } // namespace OHOS
56 #endif // FOUNDATION_RESOURCESCHEDULE_WORKSCHEDULER_SYSTEM_POLICY_H