• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "shutdown/shutdown_client.h"
17 
18 #include "client_lifecycle.h"
19 #include "power_common.h"
20 
21 namespace OHOS {
22 namespace PowerMgr {
ShutdownClient()23 ShutdownClient::ShutdownClient() {}
~ShutdownClient()24 ShutdownClient::~ShutdownClient() {}
25 
Connect()26 ErrCode ShutdownClient::Connect()
27 {
28     proxy_ = ClientLifeCycle::GetProxy();
29     return proxy_ != nullptr ? ERR_OK : ERR_NO_INIT;
30 }
31 
RegisterShutdownCallback(const sptr<ITakeOverShutdownCallback> & callback,ShutdownPriority priority)32 void ShutdownClient::RegisterShutdownCallback(
33     const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority)
34 {
35     RETURN_IF(Connect() != ERR_OK);
36     int32_t priorityValue = static_cast<int32_t>(priority);
37     proxy_->RegisterShutdownCallbackIpc(callback, priorityValue);
38 }
39 
UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback> & callback)40 void ShutdownClient::UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback)
41 {
42     RETURN_IF(Connect() != ERR_OK);
43     proxy_->UnRegisterShutdownCallbackIpc(callback);
44 }
45 
RegisterShutdownCallback(const sptr<IAsyncShutdownCallback> & callback,ShutdownPriority priority)46 void ShutdownClient::RegisterShutdownCallback(
47     const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority)
48 {
49     RETURN_IF(Connect() != ERR_OK);
50     int32_t priorityValue = static_cast<int32_t>(priority);
51     proxy_->RegisterShutdownCallbackIpc(callback, priorityValue);
52 }
53 
UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback> & callback)54 void ShutdownClient::UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback)
55 {
56     RETURN_IF(Connect() != ERR_OK);
57     proxy_->UnRegisterShutdownCallbackIpc(callback);
58 }
59 
RegisterShutdownCallback(const sptr<ISyncShutdownCallback> & callback,ShutdownPriority priority)60 void ShutdownClient::RegisterShutdownCallback(
61     const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority)
62 {
63     RETURN_IF(Connect() != ERR_OK);
64     int32_t priorityValue = static_cast<int32_t>(priority);
65     proxy_->RegisterShutdownCallbackIpc(callback, priorityValue);
66 }
67 
UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback> & callback)68 void ShutdownClient::UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback)
69 {
70     RETURN_IF(Connect() != ERR_OK);
71     proxy_->UnRegisterShutdownCallbackIpc(callback);
72 }
73 } // namespace PowerMgr
74 } // namespace OHOS
75