1686862fbSopenharmony_ci/*
2686862fbSopenharmony_ci * Copyright (c) 2023-2024 Huawei Device Co., Ltd.
3686862fbSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4686862fbSopenharmony_ci * you may not use this file except in compliance with the License.
5686862fbSopenharmony_ci * You may obtain a copy of the License at
6686862fbSopenharmony_ci *
7686862fbSopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8686862fbSopenharmony_ci *
9686862fbSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10686862fbSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11686862fbSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12686862fbSopenharmony_ci * See the License for the specific language governing permissions and
13686862fbSopenharmony_ci * limitations under the License.
14686862fbSopenharmony_ci */
15686862fbSopenharmony_ci
16686862fbSopenharmony_ci#include "dms_handler.h"
17686862fbSopenharmony_ci
18686862fbSopenharmony_ci#include "dtbschedmgr_log.h"
19686862fbSopenharmony_ci#include "single_instance.h"
20686862fbSopenharmony_ci
21686862fbSopenharmony_cinamespace OHOS {
22686862fbSopenharmony_cinamespace DistributedSchedule {
23686862fbSopenharmony_ciIMPLEMENT_SINGLE_INSTANCE(DmsHandler);
24686862fbSopenharmony_ci
25686862fbSopenharmony_cinamespace {
26686862fbSopenharmony_ciconst std::string TAG = "DmsHandle";
27686862fbSopenharmony_ci}
28686862fbSopenharmony_ci
29686862fbSopenharmony_ciint32_t DmsHandler::RegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener>& listener)
30686862fbSopenharmony_ci{
31686862fbSopenharmony_ci    HILOGI("RegisterListener type:%d", type);
32686862fbSopenharmony_ci    if (listener == nullptr) {
33686862fbSopenharmony_ci        HILOGE("RegisterListener is null.");
34686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
35686862fbSopenharmony_ci    }
36686862fbSopenharmony_ci    int32_t ret = DmsSaClient::GetInstance().AddDSchedEventListener(type, listener);
37686862fbSopenharmony_ci    if (ret != 0) {
38686862fbSopenharmony_ci        HILOGE("DmsSaClient AddListener fail");
39686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
40686862fbSopenharmony_ci    }
41686862fbSopenharmony_ci    return 0;
42686862fbSopenharmony_ci}
43686862fbSopenharmony_ci
44686862fbSopenharmony_ciint32_t DmsHandler::UnRegisterDSchedEventListener(const DSchedEventType& type, sptr<IDSchedEventListener> &listener)
45686862fbSopenharmony_ci{
46686862fbSopenharmony_ci    HILOGI("RegisterListener type:%d", type);
47686862fbSopenharmony_ci    if (listener == nullptr) {
48686862fbSopenharmony_ci        HILOGI("UnRegisterListener is null.");
49686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
50686862fbSopenharmony_ci    }
51686862fbSopenharmony_ci    int32_t ret = DmsSaClient::GetInstance().DelDSchedEventListener(type, listener);
52686862fbSopenharmony_ci    if (ret != 0) {
53686862fbSopenharmony_ci        HILOGE("DmsSaClient AddListener fail");
54686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
55686862fbSopenharmony_ci    }
56686862fbSopenharmony_ci    return 0;
57686862fbSopenharmony_ci}
58686862fbSopenharmony_ci
59686862fbSopenharmony_ciint32_t DmsHandler::GetContinueInfo(ContinueInfo &continueInfo)
60686862fbSopenharmony_ci{
61686862fbSopenharmony_ci    HILOGI("%{public}s called", __func__);
62686862fbSopenharmony_ci    int32_t ret = DmsSaClient::GetInstance().GetContinueInfo(continueInfo);
63686862fbSopenharmony_ci    if (ret != 0) {
64686862fbSopenharmony_ci        HILOGE("DmsSaClient GetContinueInfo fail");
65686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
66686862fbSopenharmony_ci    }
67686862fbSopenharmony_ci    return 0;
68686862fbSopenharmony_ci}
69686862fbSopenharmony_ci
70686862fbSopenharmony_ciint32_t DmsHandler::GetDSchedEventInfo(const DSchedEventType &type, std::vector<EventNotify> &events)
71686862fbSopenharmony_ci{
72686862fbSopenharmony_ci    HILOGI("%{public}s called", __func__);
73686862fbSopenharmony_ci    int32_t ret = DmsSaClient::GetInstance().GetDSchedEventInfo(type, events);
74686862fbSopenharmony_ci    if (ret != ERR_OK) {
75686862fbSopenharmony_ci        HILOGE("DmsSaClient GetDSchedEventInfo fail, ret %{public}d.", ret);
76686862fbSopenharmony_ci        return GET_REMOTE_DMS_FAIL;
77686862fbSopenharmony_ci    }
78686862fbSopenharmony_ci    return ERR_OK;
79686862fbSopenharmony_ci}
80686862fbSopenharmony_ci} // namespace DistributedSchedule
81686862fbSopenharmony_ci} // namespace OHOS