• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H
17 #define POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H
18 
19 #include <memory>
20 #include <mutex>
21 
22 #include <singleton.h>
23 
24 #include "hdi_service_status_listener.h"
25 #include "powerms_event_handler.h"
26 #include "suspend/irunning_lock_hub.h"
27 #include "suspend/isuspend_controller.h"
28 #include "power_hdi_callback.h"
29 #include "v1_0/ipower_interface.h"
30 
31 namespace OHOS {
32 namespace PowerMgr {
33 class SystemSuspendController : public DelayedRefSingleton<SystemSuspendController> {
34 public:
35     void Suspend(const std::function<void()>& onSuspend, const std::function<void()>& onWakeup, bool force);
36     void Wakeup();
37     void AcquireRunningLock(const std::string& name);
38     void ReleaseRunningLock(const std::string& name);
39     void Dump(std::string& info);
40     void RegisterHdiStatusListener(const std::shared_ptr<PowermsEventHandler>& handler);
41     void RegisterPowerHdiCallback();
42     void UnRegisterPowerHdiCallback();
43 
44 private:
45     DECLARE_DELAYED_REF_SINGLETON(SystemSuspendController);
46 
47     inline static constexpr const char* WAKEUP_HOLDER = "OHOSPowerMgr.WakeupHolder";
48     class PowerHdfCallback : public OHOS::HDI::Power::V1_0::IPowerHdiCallback {
49     public:
50         PowerHdfCallback() = default;
51         ~PowerHdfCallback() = default;
52         int32_t OnSuspend() override;
53         int32_t OnWakeup() override;
54         void SetListener(std::function<void()>& suspend, std::function<void()>& wakeup);
55     private:
56         std::function<void()> onSuspend_;
57         std::function<void()> onWakeup_;
58     };
59     std::mutex mutex_;
60     std::shared_ptr<Suspend::ISuspendController> sc_;
61     sptr<OHOS::HDI::Power::V1_0::IPowerInterface> powerInterface_ { nullptr };
62     sptr<OHOS::HDI::ServiceManager::V1_0::IServiceManager> hdiServiceMgr_ { nullptr };
63     sptr<HdiServiceStatusListener::IServStatListener> hdiServStatListener_ { nullptr };
64 };
65 } // namespace PowerMgr
66 } // namespace OHOS
67 #endif // POWERMGR_SYSTEM_SUSPEND_CONTROLLER_H
68