1 /*
2 * Copyright (c) 2023 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 "intention_proxy.h"
17
18 #include "iremote_object.h"
19 #include "message_option.h"
20 #include "message_parcel.h"
21
22 #include "devicestatus_define.h"
23 #include "intention_identity.h"
24
25 #undef LOG_TAG
26 #define LOG_TAG "IntentionProxy"
27
28 namespace OHOS {
29 namespace Msdp {
30 namespace DeviceStatus {
31
IntentionProxy(const sptr<IRemoteObject> & impl)32 IntentionProxy::IntentionProxy(const sptr<IRemoteObject>& impl)
33 : IRemoteProxy<IIntention>(impl)
34 {}
35
Enable(Intention intention,MessageParcel & data,MessageParcel & reply)36 int32_t IntentionProxy::Enable(Intention intention, MessageParcel &data, MessageParcel &reply)
37 {
38 CALL_DEBUG_ENTER;
39 sptr<IRemoteObject> remote = Remote();
40 CHKPR(remote, RET_ERR);
41 MessageOption option;
42
43 int32_t ret = remote->SendRequest(
44 PARAMID(CommonAction::ENABLE, static_cast<uint32_t>(intention), 0u),
45 data, reply, option);
46 if (ret != RET_OK) {
47 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
48 }
49 return ret;
50 }
51
Disable(Intention intention,MessageParcel & data,MessageParcel & reply)52 int32_t IntentionProxy::Disable(Intention intention, MessageParcel &data, MessageParcel &reply)
53 {
54 CALL_DEBUG_ENTER;
55 sptr<IRemoteObject> remote = Remote();
56 CHKPR(remote, RET_ERR);
57 MessageOption option;
58
59 int32_t ret = remote->SendRequest(
60 PARAMID(CommonAction::DISABLE, static_cast<uint32_t>(intention), 0u),
61 data, reply, option);
62 if (ret != RET_OK) {
63 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
64 }
65 return ret;
66 }
67
Start(Intention intention,MessageParcel & data,MessageParcel & reply)68 int32_t IntentionProxy::Start(Intention intention, MessageParcel &data, MessageParcel &reply)
69 {
70 CALL_DEBUG_ENTER;
71 sptr<IRemoteObject> remote = Remote();
72 CHKPR(remote, RET_ERR);
73 MessageOption option;
74
75 int32_t ret = remote->SendRequest(
76 PARAMID(CommonAction::START, static_cast<uint32_t>(intention), 0u),
77 data, reply, option);
78 if (ret != RET_OK) {
79 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
80 }
81 return ret;
82 }
83
Stop(Intention intention,MessageParcel & data,MessageParcel & reply)84 int32_t IntentionProxy::Stop(Intention intention, MessageParcel &data, MessageParcel &reply)
85 {
86 CALL_DEBUG_ENTER;
87 sptr<IRemoteObject> remote = Remote();
88 CHKPR(remote, RET_ERR);
89 MessageOption option;
90
91 int32_t ret = remote->SendRequest(
92 PARAMID(CommonAction::STOP, static_cast<uint32_t>(intention), 0u),
93 data, reply, option);
94 if (ret != RET_OK) {
95 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
96 }
97 return ret;
98 }
99
AddWatch(Intention intention,uint32_t id,MessageParcel & data,MessageParcel & reply)100 int32_t IntentionProxy::AddWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
101 {
102 CALL_DEBUG_ENTER;
103 sptr<IRemoteObject> remote = Remote();
104 CHKPR(remote, RET_ERR);
105 MessageOption option;
106
107 int32_t ret = remote->SendRequest(
108 PARAMID(CommonAction::ADD_WATCH, static_cast<uint32_t>(intention), id),
109 data, reply, option);
110 if (ret != RET_OK) {
111 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
112 }
113 return ret;
114 }
115
RemoveWatch(Intention intention,uint32_t id,MessageParcel & data,MessageParcel & reply)116 int32_t IntentionProxy::RemoveWatch(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
117 {
118 CALL_DEBUG_ENTER;
119 sptr<IRemoteObject> remote = Remote();
120 CHKPR(remote, RET_ERR);
121 MessageOption option;
122
123 int32_t ret = remote->SendRequest(
124 PARAMID(CommonAction::REMOVE_WATCH, static_cast<uint32_t>(intention), id),
125 data, reply, option);
126 if (ret != RET_OK) {
127 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
128 }
129 return ret;
130 }
131
SetParam(Intention intention,uint32_t id,MessageParcel & data,MessageParcel & reply)132 int32_t IntentionProxy::SetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
133 {
134 CALL_DEBUG_ENTER;
135 sptr<IRemoteObject> remote = Remote();
136 CHKPR(remote, RET_ERR);
137 MessageOption option;
138
139 int32_t ret = remote->SendRequest(
140 PARAMID(CommonAction::SET_PARAM, static_cast<uint32_t>(intention), id),
141 data, reply, option);
142 if (ret != RET_OK) {
143 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
144 }
145 return ret;
146 }
147
GetParam(Intention intention,uint32_t id,MessageParcel & data,MessageParcel & reply)148 int32_t IntentionProxy::GetParam(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
149 {
150 CALL_DEBUG_ENTER;
151 sptr<IRemoteObject> remote = Remote();
152 CHKPR(remote, RET_ERR);
153 MessageOption option;
154
155 int32_t ret = remote->SendRequest(
156 PARAMID(CommonAction::GET_PARAM, static_cast<uint32_t>(intention), id),
157 data, reply, option);
158 if (ret != RET_OK) {
159 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
160 }
161 return ret;
162 }
163
Control(Intention intention,uint32_t id,MessageParcel & data,MessageParcel & reply)164 int32_t IntentionProxy::Control(Intention intention, uint32_t id, MessageParcel &data, MessageParcel &reply)
165 {
166 CALL_DEBUG_ENTER;
167 sptr<IRemoteObject> remote = Remote();
168 CHKPR(remote, RET_ERR);
169 MessageOption option;
170
171 int32_t ret = remote->SendRequest(
172 PARAMID(CommonAction::CONTROL, static_cast<uint32_t>(intention), id),
173 data, reply, option);
174 if (ret != RET_OK) {
175 FI_HILOGE("SendRequest is failed, ret:%{public}d", ret);
176 }
177 return ret;
178 }
179 } // namespace DeviceStatus
180 } // namespace Msdp
181 } // namespace OHOS
182