• 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     void DispatchResourceExt(uint32_t resType, int64_t value, const nlohmann::json& payload);
41     bool CheckTidIsInPid(int32_t pid, int32_t tid);
42     void SubscribeResourceExt();
43     int32_t RssExeSendRequestSync(uint32_t resType, int64_t value,
44         const nlohmann::json& context, nlohmann::json& reply);
45     void RssExeSendRequestAsync(uint32_t resType, int64_t value, const nlohmann::json& context);
46 
47 private:
ResSchedUtils()48     ResSchedUtils()
49     {
50         LoadUtils();
51         LoadUtilsExtra();
52     }
~ResSchedUtils()53     ~ResSchedUtils()
54     {
55         reportFunc_ = nullptr;
56         reportArbitrationResultFunc_ = nullptr;
57         reportSysEventFunc_ = nullptr;
58         subscribeResourceExtFunc_ = nullptr;
59     }
60     void LoadUtils();
61     void LoadUtilsExtra();
62 
63     ResSchedUtils(const ResSchedUtils&) = delete;
64     ResSchedUtils& operator=(const ResSchedUtils &) = delete;
65     ResSchedUtils(ResSchedUtils&&) = delete;
66     ResSchedUtils& operator=(ResSchedUtils&&) = delete;
67 
68     ReportDataFunc reportFunc_ = nullptr;
69     ReportArbitrationResultFunc reportArbitrationResultFunc_ = nullptr;
70     ReportSysEventFunc reportSysEventFunc_ = nullptr;
71     DispatchResourceExtFunc dispatchResourceExtFunc_ = nullptr;
72     SubscribeResourceExtFunc subscribeResourceExtFunc_ = nullptr;
73 };
74 } // namespace ResourceSchedule
75 } // namespace OHOS
76 #endif // CGROUP_SCHED_FRAMEWORK_UTILS_INCLUDE_RESSCHED_UTILS_H_
77