1/*
2 * Copyright (c) 2024 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 "stationary_client.h"
17
18#include "default_params.h"
19#include "devicestatus_define.h"
20#include "stationary_params.h"
21
22#undef LOG_TAG
23#define LOG_TAG "StationaryClient"
24
25namespace OHOS {
26namespace Msdp {
27namespace DeviceStatus {
28
29int32_t StationaryClient::SubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
30    ReportLatencyNs latency, sptr<IRemoteDevStaCallback> callback)
31{
32    SubscribeStationaryParam param { type, event, latency, callback };
33    DefaultReply reply {};
34    FI_HILOGI("SubscribeStationary(type:%{public}d,event:%{public}d,latency:%{public}d)", type, event, latency);
35    int32_t ret = tunnel.AddWatch(Intention::STATIONARY, StationaryRequestID::SUBSCRIBE_STATIONARY, param, reply);
36    if (ret != RET_OK) {
37        FI_HILOGE("SubscribeStationary fail, error:%{public}d", ret);
38    }
39    return ret;
40}
41
42int32_t StationaryClient::UnsubscribeCallback(ITunnelClient &tunnel, Type type, ActivityEvent event,
43    sptr<IRemoteDevStaCallback> callback)
44{
45    UnsubscribeStationaryParam param { type, event, ReportLatencyNs::Latency_INVALID, callback };
46    DefaultReply reply {};
47    FI_HILOGI("UnsubscribeStationary(type:%{public}d,event:%{public}d)", type, event);
48    int32_t ret = tunnel.RemoveWatch(Intention::STATIONARY, StationaryRequestID::UNSUBSCRIBE_STATIONARY, param, reply);
49    if (ret != RET_OK) {
50        FI_HILOGE("UnsubscribeStationary fail, error:%{public}d", ret);
51    }
52    return ret;
53}
54
55Data StationaryClient::GetDeviceStatusData(ITunnelClient &tunnel, Type type)
56{
57    GetStaionaryDataParam param { type };
58    GetStaionaryDataReply reply {};
59    FI_HILOGI("GetDeviceStatusData(type:%{public}d)", type);
60    int32_t ret = tunnel.GetParam(Intention::STATIONARY, StationaryRequestID::GET_STATIONARY_DATA, param, reply);
61    if (ret != RET_OK) {
62        FI_HILOGE("GetStationaryData fail, error:%{public}d", ret);
63    }
64    return reply.data_;
65}
66} // namespace DeviceStatus
67} // namespace Msdp
68} // namespace OHOS
69