• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SCHED_CONTROLLER_INCLUDE_SCHED_CONTROLLER_H_
17 #define CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_SCHED_CONTROLLER_H_
18 
19 #include <set>
20 #include <sys/types.h>
21 #include <string>
22 #include "nlohmann/json.hpp"
23 #include "plugin.h"
24 #include "refbase.h"
25 #include "single_instance.h"
26 
27 namespace OHOS {
28 namespace ResourceSchedule {
29 class Supervisor;
30 class CgroupAdjuster;
31 class CgroupEventHandler;
32 
33 class SchedController : public Plugin {
34 DECLARE_SINGLE_INSTANCE(SchedController)
35 public:
36     void Init() override;
37     void Disable() override;
38 
39     int GetProcessGroup(pid_t pid);
40     void DispatchResource(const std::shared_ptr<ResData>& resData) override;
41     void DispatchOtherResource(uint32_t resType, int64_t value, const nlohmann::json& payload);
42     std::string GetBundleNameByUid(const int32_t uid);
43     void Dump(const std::vector<std::string>& args, std::string& result);
44     void DumpHelp(std::string& result);
45     void DumpProcessRunningLock(std::string &result);
46     void DumpProcessEventState(std::string &result);
47     void DumpProcessWindowInfo(std::string &result);
48 #ifdef POWER_MANAGER_ENABLE
49     void GetRunningLockState();
50 #endif
51 
GetCgroupEventHandler()52     const inline std::shared_ptr<CgroupEventHandler> GetCgroupEventHandler() const
53     {
54         return cgHandler_;
55     }
56 
GetSupervisor()57     const inline std::shared_ptr<Supervisor> GetSupervisor() const
58     {
59         return supervisor_;
60     }
61 
62 private:
63     std::shared_ptr<CgroupEventHandler> cgHandler_;
64     std::shared_ptr<Supervisor> supervisor_;
65 
66     std::set<uint32_t> resTypes;
67     std::unordered_map<uint32_t, std::function<void(std::shared_ptr<CgroupEventHandler>,
68         uint32_t, int64_t, const nlohmann::json&)>> dispatchResFuncMap_;
69 
70     void InitResTypes();
71     inline void InitCgroupHandler();
72     inline void InitCgroupAdjuster();
73     inline void InitSupervisor();
74     inline void InitAppStartupSceneRec();
75     inline void DeinitAppStartupSceneRec();
76     void InitDispatchResFuncMap();
77     void InitAddDispatchResFuncMap();
78 };
79 } // namespace ResourceSchedule
80 } // namespace OHOS
81 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_SCHED_CONTROLLER_H_
82