• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2024 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 using ReportSysEventFunc = void (*)(Application &app, ProcessRecord &pr, uint32_t resType, int32_t state);
30 using DispatchResourceExtFunc = void (*)(uint32_t resType, int64_t value, const nlohmann::json& payload);
31 using ReportAppStateFunc = void (*)(int32_t state, int32_t pid);
32 using SubscribeResourceExtFunc = void (*)();
33 class ResSchedUtils {
34 public:
35     static ResSchedUtils& GetInstance();
36     void ReportDataInProcess(uint32_t resType, int64_t value, const nlohmann::json& payload);
37     void ReportArbitrationResult(Application &app, ProcessRecord &pr, AdjustSource source);
38     void ReportSysEvent(Application &app, ProcessRecord &pr, uint32_t resType, int32_t state);
39     std::string GetProcessFilePath(int32_t uid, std::string bundleName, int32_t pid);
40     bool CheckTidIsInPid(int32_t pid, int32_t tid);
41     void DispatchResourceExt(uint32_t resType, int64_t value, const nlohmann::json& payload);
42     void ReportAppStateInProcess(int32_t state, int32_t pid);
43     void SubscribeResourceExt();
44 
45 private:
ResSchedUtils()46     ResSchedUtils()
47     {
48         LoadUtils();
49         LoadUtilsExtra();
50     }
~ResSchedUtils()51     ~ResSchedUtils()
52     {
53         reportFunc_ = nullptr;
54         reportArbitrationResultFunc_ = nullptr;
55         reportSysEventFunc_ = nullptr;
56         subscribeResourceExtFunc_ = nullptr;
57     }
58     void LoadUtils();
59     void LoadUtilsExtra();
60 
61     ResSchedUtils(const ResSchedUtils&) = delete;
62     ResSchedUtils& operator=(const ResSchedUtils &) = delete;
63     ResSchedUtils(ResSchedUtils&&) = delete;
64     ResSchedUtils& operator=(ResSchedUtils&&) = delete;
65 
66     ReportDataFunc reportFunc_ = nullptr;
67     ReportArbitrationResultFunc reportArbitrationResultFunc_ = nullptr;
68     ReportSysEventFunc reportSysEventFunc_ = nullptr;
69     DispatchResourceExtFunc dispatchResourceExtFunc_ = nullptr;
70     ReportAppStateFunc reportAppStateFunc_ = nullptr;
71     SubscribeResourceExtFunc subscribeResourceExtFunc_ = nullptr;
72 };
73 } // namespace ResourceSchedule
74 } // namespace OHOS
75 #endif // CGROUP_SCHED_FRAMEWORK_UTILS_INCLUDE_RESSCHED_UTILS_H_
76