15ccb8f90Sopenharmony_ci/*
25ccb8f90Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
35ccb8f90Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
45ccb8f90Sopenharmony_ci * you may not use this file except in compliance with the License.
55ccb8f90Sopenharmony_ci * You may obtain a copy of the License at
65ccb8f90Sopenharmony_ci *
75ccb8f90Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
85ccb8f90Sopenharmony_ci *
95ccb8f90Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
105ccb8f90Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
115ccb8f90Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
125ccb8f90Sopenharmony_ci * See the License for the specific language governing permissions and
135ccb8f90Sopenharmony_ci * limitations under the License.
145ccb8f90Sopenharmony_ci */
155ccb8f90Sopenharmony_ci
165ccb8f90Sopenharmony_ci#include "shutdown/shutdown_client.h"
175ccb8f90Sopenharmony_ci
185ccb8f90Sopenharmony_ci#include "client_lifecycle.h"
195ccb8f90Sopenharmony_ci#include "power_common.h"
205ccb8f90Sopenharmony_ci
215ccb8f90Sopenharmony_cinamespace OHOS {
225ccb8f90Sopenharmony_cinamespace PowerMgr {
235ccb8f90Sopenharmony_ciShutdownClient::ShutdownClient() {}
245ccb8f90Sopenharmony_ciShutdownClient::~ShutdownClient() {}
255ccb8f90Sopenharmony_ci
265ccb8f90Sopenharmony_ciErrCode ShutdownClient::Connect()
275ccb8f90Sopenharmony_ci{
285ccb8f90Sopenharmony_ci    proxy_ = ClientLifeCycle::GetProxy();
295ccb8f90Sopenharmony_ci    return proxy_ != nullptr ? ERR_OK : ERR_NO_INIT;
305ccb8f90Sopenharmony_ci}
315ccb8f90Sopenharmony_ci
325ccb8f90Sopenharmony_civoid ShutdownClient::RegisterShutdownCallback(
335ccb8f90Sopenharmony_ci    const sptr<ITakeOverShutdownCallback>& callback, ShutdownPriority priority)
345ccb8f90Sopenharmony_ci{
355ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
365ccb8f90Sopenharmony_ci    proxy_->RegisterShutdownCallback(callback, priority);
375ccb8f90Sopenharmony_ci}
385ccb8f90Sopenharmony_ci
395ccb8f90Sopenharmony_civoid ShutdownClient::UnRegisterShutdownCallback(const sptr<ITakeOverShutdownCallback>& callback)
405ccb8f90Sopenharmony_ci{
415ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
425ccb8f90Sopenharmony_ci    proxy_->UnRegisterShutdownCallback(callback);
435ccb8f90Sopenharmony_ci}
445ccb8f90Sopenharmony_ci
455ccb8f90Sopenharmony_civoid ShutdownClient::RegisterShutdownCallback(
465ccb8f90Sopenharmony_ci    const sptr<IAsyncShutdownCallback>& callback, ShutdownPriority priority)
475ccb8f90Sopenharmony_ci{
485ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
495ccb8f90Sopenharmony_ci    proxy_->RegisterShutdownCallback(callback, priority);
505ccb8f90Sopenharmony_ci}
515ccb8f90Sopenharmony_ci
525ccb8f90Sopenharmony_civoid ShutdownClient::UnRegisterShutdownCallback(const sptr<IAsyncShutdownCallback>& callback)
535ccb8f90Sopenharmony_ci{
545ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
555ccb8f90Sopenharmony_ci    proxy_->UnRegisterShutdownCallback(callback);
565ccb8f90Sopenharmony_ci}
575ccb8f90Sopenharmony_ci
585ccb8f90Sopenharmony_civoid ShutdownClient::RegisterShutdownCallback(
595ccb8f90Sopenharmony_ci    const sptr<ISyncShutdownCallback>& callback, ShutdownPriority priority)
605ccb8f90Sopenharmony_ci{
615ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
625ccb8f90Sopenharmony_ci    proxy_->RegisterShutdownCallback(callback, priority);
635ccb8f90Sopenharmony_ci}
645ccb8f90Sopenharmony_ci
655ccb8f90Sopenharmony_civoid ShutdownClient::UnRegisterShutdownCallback(const sptr<ISyncShutdownCallback>& callback)
665ccb8f90Sopenharmony_ci{
675ccb8f90Sopenharmony_ci    RETURN_IF(Connect() != ERR_OK);
685ccb8f90Sopenharmony_ci    proxy_->UnRegisterShutdownCallback(callback);
695ccb8f90Sopenharmony_ci}
705ccb8f90Sopenharmony_ci} // namespace PowerMgr
715ccb8f90Sopenharmony_ci} // namespace OHOS
72