1c29fa5a6Sopenharmony_ci/*
2c29fa5a6Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3c29fa5a6Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4c29fa5a6Sopenharmony_ci * you may not use this file except in compliance with the License.
5c29fa5a6Sopenharmony_ci * You may obtain a copy of the License at
6c29fa5a6Sopenharmony_ci *
7c29fa5a6Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8c29fa5a6Sopenharmony_ci *
9c29fa5a6Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10c29fa5a6Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11c29fa5a6Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12c29fa5a6Sopenharmony_ci * See the License for the specific language governing permissions and
13c29fa5a6Sopenharmony_ci * limitations under the License.
14c29fa5a6Sopenharmony_ci */
15c29fa5a6Sopenharmony_ci
16c29fa5a6Sopenharmony_ci#include "intention_proxy.h"
17c29fa5a6Sopenharmony_ci
18c29fa5a6Sopenharmony_ci#include "iremote_object.h"
19c29fa5a6Sopenharmony_ci#include "message_option.h"
20c29fa5a6Sopenharmony_ci#include "message_parcel.h"
21c29fa5a6Sopenharmony_ci
22c29fa5a6Sopenharmony_ci#include "devicestatus_define.h"
23c29fa5a6Sopenharmony_ci#include "intention_identity.h"
24c29fa5a6Sopenharmony_ci
25c29fa5a6Sopenharmony_ci#undef LOG_TAG
26c29fa5a6Sopenharmony_ci#define LOG_TAG "IntentionProxy"
27c29fa5a6Sopenharmony_ci
28c29fa5a6Sopenharmony_cinamespace OHOS {
29c29fa5a6Sopenharmony_cinamespace Msdp {
30c29fa5a6Sopenharmony_cinamespace DeviceStatus {
31c29fa5a6Sopenharmony_ci
32c29fa5a6Sopenharmony_ciIntentionProxy::IntentionProxy(const sptr<IRemoteObject>& impl)
33c29fa5a6Sopenharmony_ci    : IRemoteProxy<IIntention>(impl)
34c29fa5a6Sopenharmony_ci{}
35c29fa5a6Sopenharmony_ci
36c29fa5a6Sopenharmony_ciint32_t IntentionProxy::Enable(Intention intention, MessageParcel &data, MessageParcel &reply)
37c29fa5a6Sopenharmony_ci{
38c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
39c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
40c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
41c29fa5a6Sopenharmony_ci    MessageOption option;
42c29fa5a6Sopenharmony_ci
43c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
44c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::ENABLE, static_cast<uint32_t>(intention), 0u),
45c29fa5a6Sopenharmony_ci        data, reply, option);
46c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
47c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
48c29fa5a6Sopenharmony_ci    }
49c29fa5a6Sopenharmony_ci    return ret;
50c29fa5a6Sopenharmony_ci}
51c29fa5a6Sopenharmony_ci
52c29fa5a6Sopenharmony_ciint32_t IntentionProxy::Disable(Intention intention, MessageParcel &data, MessageParcel &reply)
53c29fa5a6Sopenharmony_ci{
54c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
55c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
56c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
57c29fa5a6Sopenharmony_ci    MessageOption option;
58c29fa5a6Sopenharmony_ci
59c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
60c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::DISABLE, static_cast<uint32_t>(intention), 0u),
61c29fa5a6Sopenharmony_ci        data, reply, option);
62c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
63c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
64c29fa5a6Sopenharmony_ci    }
65c29fa5a6Sopenharmony_ci    return ret;
66c29fa5a6Sopenharmony_ci}
67c29fa5a6Sopenharmony_ci
68c29fa5a6Sopenharmony_ciint32_t IntentionProxy::Start(Intention intention, MessageParcel &data, MessageParcel &reply)
69c29fa5a6Sopenharmony_ci{
70c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
71c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
72c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
73c29fa5a6Sopenharmony_ci    MessageOption option;
74c29fa5a6Sopenharmony_ci
75c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
76c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::START, static_cast<uint32_t>(intention), 0u),
77c29fa5a6Sopenharmony_ci        data, reply, option);
78c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
79c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
80c29fa5a6Sopenharmony_ci    }
81c29fa5a6Sopenharmony_ci    return ret;
82c29fa5a6Sopenharmony_ci}
83c29fa5a6Sopenharmony_ci
84c29fa5a6Sopenharmony_ciint32_t IntentionProxy::Stop(Intention intention, MessageParcel &data, MessageParcel &reply)
85c29fa5a6Sopenharmony_ci{
86c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
87c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
88c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
89c29fa5a6Sopenharmony_ci    MessageOption option;
90c29fa5a6Sopenharmony_ci
91c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
92c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::STOP, static_cast<uint32_t>(intention), 0u),
93c29fa5a6Sopenharmony_ci        data, reply, option);
94c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
95c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
96c29fa5a6Sopenharmony_ci    }
97c29fa5a6Sopenharmony_ci    return ret;
98c29fa5a6Sopenharmony_ci}
99c29fa5a6Sopenharmony_ci
100c29fa5a6Sopenharmony_ciint32_t IntentionProxy::AddWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
101c29fa5a6Sopenharmony_ci{
102c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
103c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
104c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
105c29fa5a6Sopenharmony_ci    MessageOption option;
106c29fa5a6Sopenharmony_ci
107c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
108c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::ADD_WATCH, static_cast<uint32_t>(intention), id),
109c29fa5a6Sopenharmony_ci        data, reply, option);
110c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
111c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
112c29fa5a6Sopenharmony_ci    }
113c29fa5a6Sopenharmony_ci    return ret;
114c29fa5a6Sopenharmony_ci}
115c29fa5a6Sopenharmony_ci
116c29fa5a6Sopenharmony_ciint32_t IntentionProxy::RemoveWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
117c29fa5a6Sopenharmony_ci{
118c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
119c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
120c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
121c29fa5a6Sopenharmony_ci    MessageOption option;
122c29fa5a6Sopenharmony_ci
123c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
124c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::REMOVE_WATCH, static_cast<uint32_t>(intention), id),
125c29fa5a6Sopenharmony_ci        data, reply, option);
126c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
127c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
128c29fa5a6Sopenharmony_ci    }
129c29fa5a6Sopenharmony_ci    return ret;
130c29fa5a6Sopenharmony_ci}
131c29fa5a6Sopenharmony_ci
132c29fa5a6Sopenharmony_ciint32_t IntentionProxy::SetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
133c29fa5a6Sopenharmony_ci{
134c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
135c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
136c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
137c29fa5a6Sopenharmony_ci    MessageOption option;
138c29fa5a6Sopenharmony_ci
139c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
140c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::SET_PARAM, static_cast<uint32_t>(intention), id),
141c29fa5a6Sopenharmony_ci        data, reply, option);
142c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
143c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
144c29fa5a6Sopenharmony_ci    }
145c29fa5a6Sopenharmony_ci    return ret;
146c29fa5a6Sopenharmony_ci}
147c29fa5a6Sopenharmony_ci
148c29fa5a6Sopenharmony_ciint32_t IntentionProxy::GetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
149c29fa5a6Sopenharmony_ci{
150c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
151c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
152c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
153c29fa5a6Sopenharmony_ci    MessageOption option;
154c29fa5a6Sopenharmony_ci
155c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
156c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::GET_PARAM, static_cast<uint32_t>(intention), id),
157c29fa5a6Sopenharmony_ci        data, reply, option);
158c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
159c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
160c29fa5a6Sopenharmony_ci    }
161c29fa5a6Sopenharmony_ci    return ret;
162c29fa5a6Sopenharmony_ci}
163c29fa5a6Sopenharmony_ci
164c29fa5a6Sopenharmony_ciint32_t IntentionProxy::Control(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
165c29fa5a6Sopenharmony_ci{
166c29fa5a6Sopenharmony_ci    CALL_DEBUG_ENTER;
167c29fa5a6Sopenharmony_ci    sptr<IRemoteObject> remote = Remote();
168c29fa5a6Sopenharmony_ci    CHKPR(remote, RET_ERR);
169c29fa5a6Sopenharmony_ci    MessageOption option;
170c29fa5a6Sopenharmony_ci
171c29fa5a6Sopenharmony_ci    int32_t ret = remote->SendRequest(
172c29fa5a6Sopenharmony_ci        PARAMID(CommonAction::CONTROL, static_cast<uint32_t>(intention), id),
173c29fa5a6Sopenharmony_ci        data, reply, option);
174c29fa5a6Sopenharmony_ci    if (ret != RET_OK) {
175c29fa5a6Sopenharmony_ci        FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
176c29fa5a6Sopenharmony_ci    }
177c29fa5a6Sopenharmony_ci    return ret;
178c29fa5a6Sopenharmony_ci}
179c29fa5a6Sopenharmony_ci} // namespace DeviceStatus
180c29fa5a6Sopenharmony_ci} // namespace Msdp
181c29fa5a6Sopenharmony_ci} // namespace OHOS
182