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