• 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 <sys/types.h>
20 #include <string>
21 #include "hilog/log.h"
22 #include "nlohmann/json.hpp"
23 #include "refbase.h"
24 
25 namespace OHOS {
26 namespace ResourceSchedule {
27 class RmsApplicationStateObserver;
28 #ifdef CONFIG_BGTASK_MGR
29 class BackgroundTaskObserver;
30 #endif
31 class WindowStateObserver;
32 class WindowVisibilityObserver;
33 class WindowUpdateStateObserver;
34 class Supervisor;
35 class CgroupAdjuster;
36 class CgroupEventHandler;
37 
38 class SchedController {
39 public:
40     static SchedController& GetInstance();
41 
42     void Init();
43     void Deinit();
44     bool SubscribeAppState();
45     void UnsubscribeAppState();
46     bool SubscribeBackgroundTask();
47     void UnsubscribeBackgroundTask();
48     void SubscribeWindowState();
49     void UnsubscribeWindowState();
50     void UnregisterStateObservers();
51     int GetProcessGroup(pid_t pid);
52     void ReportAbilityStatus(int32_t saId, const std::string& deviceId, uint32_t status);
53     void DispatchResource(uint32_t resType, int64_t value, const nlohmann::json& payload);
54     std::string GetBundleNameByUid(const int32_t uid);
55 
GetCgroupEventHandler()56     const inline std::shared_ptr<CgroupEventHandler> GetCgroupEventHandler() const
57     {
58         return cgHandler_;
59     }
60 
GetSupervisor()61     const inline std::shared_ptr<Supervisor> GetSupervisor() const
62     {
63         return supervisor_;
64     }
65 
66 private:
67     SchedController() = default;
68     ~SchedController() = default;
69 
70     SchedController(const SchedController&) = delete;
71     SchedController& operator=(const SchedController &) = delete;
72     SchedController(SchedController&&) = delete;
73     SchedController& operator=(SchedController&&) = delete;
74 
75     std::shared_ptr<CgroupEventHandler> cgHandler_;
76     std::shared_ptr<Supervisor> supervisor_;
77     sptr<RmsApplicationStateObserver> appStateObserver_;
78 #ifdef CONFIG_BGTASK_MGR
79     std::shared_ptr<BackgroundTaskObserver> backgroundTaskObserver_;
80 #endif
81     sptr<WindowStateObserver> windowStateObserver_;
82     sptr<WindowVisibilityObserver> windowVisibilityObserver_;
83 
84     inline void InitCgroupHandler();
85     inline void InitCgroupAdjuster();
86     inline void InitSupervisor();
87 };
88 } // namespace ResourceSchedule
89 } // namespace OHOS
90 #endif // CGROUP_SCHED_FRAMEWORK_SCHED_CONTROLLER_INCLUDE_SCHED_CONTROLLER_H_
91