1 /* 2 * Copyright (c) 2023 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_POWER_MANAGER_SHUTDOWN_CLIENT_H 17 #define POWERMGR_POWER_MANAGER_SHUTDOWN_CLIENT_H 18 19 #include <singleton.h> 20 21 #include "ipower_mgr.h" 22 #include "ishutdown_client.h" 23 #include "itakeover_shutdown_callback.h" 24 #include "iasync_shutdown_callback.h" 25 #include "isync_shutdown_callback.h" 26 #include "power_errors.h" 27 28 namespace OHOS { 29 namespace PowerMgr { 30 /** 31 * Shutdown or reboot the client with related functions. 32 */ 33 class ShutdownClient final : public DelayedRefSingleton<ShutdownClient> { 34 DECLARE_DELAYED_REF_SINGLETON(ShutdownClient) 35 36 public: 37 DISALLOW_COPY_AND_MOVE(ShutdownClient); 38 39 /** 40 * Register a callback that takes over a shutdown or reboot. 41 * <p> 42 * Callbacks are executed in order of highest to lowest priority. 43 * 44 * @param callback Takes over the shutdown or reboot callbacks. 45 * @param priority Change the priority of execution. 46 */ 47 void RegisterShutdownCallback( 48 const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority = ShutdownPriority::DEFAULT); 49 50 /** 51 * Unregister callbacks to take over shutdown or reboot. 52 * 53 * @param callback Registered callback to take over shutdown or reboot. 54 */ 55 void UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback); 56 57 /** 58 * Register the asynchronous shutdown callback interface 59 * <p> 60 * Callbacks are executed in order of highest to lowest priority. 61 * 62 * @param callback Asynchronous shutdown or reboot callbacks. 63 * @param priority Change the priority of execution. 64 */ 65 void RegisterShutdownCallback( 66 const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority = ShutdownPriority::DEFAULT); 67 68 /** 69 * Unregister the asynchronous shutdown callback interface. 70 * 71 * @param callback Registered callback to asynchronous shutdown or reboot. 72 */ 73 void UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback); 74 75 /** 76 * Register the synchronous shutdown callback interface 77 * <p> 78 * Callbacks are executed in order of highest to lowest priority. 79 * 80 * @param callback Synchronous shutdown or reboot callbacks. 81 * @param priority Change the priority of execution. 82 */ 83 void RegisterShutdownCallback( 84 const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority = ShutdownPriority::DEFAULT); 85 86 /** 87 * Unregister the synchronous shutdown callback interface. 88 * 89 * @param callback Registered callback to synchronous shutdown or reboot. 90 */ 91 void UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback); 92 93 private: 94 ErrCode Connect(); 95 96 sptr<IPowerMgr> proxy_ {nullptr}; 97 }; 98 } // namespace PowerMgr 99 } // namespace OHOS 100 101 #endif // POWERMGR_POWER_MANAGER_SHUTDOWN_CLIENT_H 102