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
21namespace OHOS {
22namespace PowerMgr {
23ShutdownClient::ShutdownClient() {}
24ShutdownClient::~ShutdownClient() {}
25
26ErrCode ShutdownClient::Connect()
27{
28    proxy_ = ClientLifeCycle::GetProxy();
29    return proxy_ != nullptr ? ERR_OK : ERR_NO_INIT;
30}
31
32void ShutdownClient::RegisterShutdownCallback(
33    const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority)
34{
35    RETURN_IF(Connect() != ERR_OK);
36    proxy_->RegisterShutdownCallback(callback, priority);
37}
38
39void ShutdownClient::UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback)
40{
41    RETURN_IF(Connect() != ERR_OK);
42    proxy_->UnRegisterShutdownCallback(callback);
43}
44
45void ShutdownClient::RegisterShutdownCallback(
46    const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority)
47{
48    RETURN_IF(Connect() != ERR_OK);
49    proxy_->RegisterShutdownCallback(callback, priority);
50}
51
52void ShutdownClient::UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback)
53{
54    RETURN_IF(Connect() != ERR_OK);
55    proxy_->UnRegisterShutdownCallback(callback);
56}
57
58void ShutdownClient::RegisterShutdownCallback(
59    const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority)
60{
61    RETURN_IF(Connect() != ERR_OK);
62    proxy_->RegisterShutdownCallback(callback, priority);
63}
64
65void ShutdownClient::UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback)
66{
67    RETURN_IF(Connect() != ERR_OK);
68    proxy_->UnRegisterShutdownCallback(callback);
69}
70} // namespace PowerMgr
71} // namespace OHOS
72