1 /* 2 * Copyright (c) 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 16 #ifndef CGROUP_SCHED_FRAMEWORK_UTILS_INCLUDE_RESSCHED_UTILS_H_ 17 #define CGROUP_SCHED_FRAMEWORK_UTILS_INCLUDE_RESSCHED_UTILS_H_ 18 19 #include <iostream> 20 #include "cgroup_adjuster.h" 21 #include "supervisor.h" 22 #include "sys/types.h" 23 #include "nlohmann/json.hpp" 24 25 namespace OHOS { 26 namespace ResourceSchedule { 27 using ReportDataFunc = void (*)(uint32_t resType, int64_t value, const nlohmann::json& payload); 28 using ReportArbitrationResultFunc = void (*)(Application &app, ProcessRecord &pr, AdjustSource source); 29 30 class ResSchedUtils { 31 public: 32 static ResSchedUtils& GetInstance(); 33 void ReportDataInProcess(uint32_t resType, int64_t value, const nlohmann::json& payload); 34 void ReportArbitrationResult(Application &app, ProcessRecord &pr, AdjustSource source); 35 36 private: ResSchedUtils()37 ResSchedUtils() 38 { 39 LoadUtils(); 40 LoadUtilsExtra(); 41 } ~ResSchedUtils()42 ~ResSchedUtils() 43 { 44 reportFunc_ = nullptr; 45 reportArbitrationResultFunc_ = nullptr; 46 } 47 void LoadUtils(); 48 void LoadUtilsExtra(); 49 50 ResSchedUtils(const ResSchedUtils&) = delete; 51 ResSchedUtils& operator=(const ResSchedUtils &) = delete; 52 ResSchedUtils(ResSchedUtils&&) = delete; 53 ResSchedUtils& operator=(ResSchedUtils&&) = delete; 54 55 ReportDataFunc reportFunc_ = nullptr; 56 ReportArbitrationResultFunc reportArbitrationResultFunc_ = nullptr; 57 }; 58 } // namespace ResourceSchedule 59 } // namespace OHOS 60 #endif // CGROUP_SCHED_FRAMEWORK_UTILS_INCLUDE_RESSCHED_UTILS_H_ 61