• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 "distributed_camera_sink_proxy.h"
17 
18 #include "parcel.h"
19 
20 #include "anonymous_string.h"
21 #include "distributed_camera_errno.h"
22 #include "distributed_hardware_log.h"
23 
24 namespace OHOS {
25 namespace DistributedHardware {
InitSink(const std::string & params)26 int32_t DistributedCameraSinkProxy::InitSink(const std::string& params)
27 {
28     DHLOGI("DistributedCameraSinkProxy::InitSink");
29     if (params.empty() || params.size() > PARAM_MAX_SIZE) {
30         DHLOGE("DistributedCameraSinkProxy::InitSink params is invalid");
31         return DCAMERA_BAD_VALUE;
32     }
33     sptr<IRemoteObject> remote = Remote();
34     if (remote == nullptr) {
35         DHLOGE("DistributedCameraSinkProxy::InitSink remote service is null");
36         return DCAMERA_BAD_VALUE;
37     }
38 
39     MessageParcel data;
40     MessageParcel reply;
41     MessageOption option;
42     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
43         DHLOGE("DistributedCameraSinkProxy::InitSink write token failed");
44         return DCAMERA_BAD_VALUE;
45     }
46     if (!data.WriteString(params)) {
47         DHLOGE("DistributedCameraSinkProxy::InitSink write params failed");
48         return DCAMERA_BAD_VALUE;
49     }
50     remote->SendRequest(INIT_SINK, data, reply, option);
51     int32_t result = reply.ReadInt32();
52     return result;
53 }
54 
ReleaseSink()55 int32_t DistributedCameraSinkProxy::ReleaseSink()
56 {
57     DHLOGI("DistributedCameraSinkProxy::ReleaseSink");
58     sptr<IRemoteObject> remote = Remote();
59     if (remote == nullptr) {
60         DHLOGE("DistributedCameraSinkProxy::ReleaseSink remote service is null");
61         return DCAMERA_BAD_VALUE;
62     }
63 
64     MessageParcel data;
65     MessageParcel reply;
66     MessageOption option;
67     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
68         DHLOGE("DistributedCameraSinkProxy::ReleaseSink write token failed");
69         return DCAMERA_BAD_VALUE;
70     }
71     remote->SendRequest(RELEASE_SINK, data, reply, option);
72     int32_t result = reply.ReadInt32();
73     return result;
74 }
75 
SubscribeLocalHardware(const std::string & dhId,const std::string & parameters)76 int32_t DistributedCameraSinkProxy::SubscribeLocalHardware(const std::string& dhId, const std::string& parameters)
77 {
78     DHLOGI("DistributedCameraSinkProxy::SubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str());
79     if (parameters.empty() || parameters.size() > PARAM_MAX_SIZE || dhId.empty() ||
80         dhId.size() > DID_MAX_SIZE) {
81         DHLOGE("DistributedCameraSinkProxy::SubscribeLocalHardware params is invalid");
82         return DCAMERA_BAD_VALUE;
83     }
84     sptr<IRemoteObject> remote = Remote();
85     if (remote == nullptr) {
86         DHLOGE("DistributedCameraSinkProxy::SubscribeLocalHardware remote service is null");
87         return DCAMERA_BAD_VALUE;
88     }
89 
90     MessageParcel data;
91     MessageParcel reply;
92     MessageOption option;
93     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
94         DHLOGE("DistributedCameraSinkProxy::SubscribeLocalHardware write token failed");
95         return DCAMERA_BAD_VALUE;
96     }
97     if (!data.WriteString(dhId) || !data.WriteString(parameters)) {
98         DHLOGE("DistributedCameraSinkProxy::SubscribeLocalHardware write params failed");
99         return DCAMERA_BAD_VALUE;
100     }
101     remote->SendRequest(SUBSCRIBE_LOCAL_HARDWARE, data, reply, option);
102     int32_t result = reply.ReadInt32();
103     return result;
104 }
105 
UnsubscribeLocalHardware(const std::string & dhId)106 int32_t DistributedCameraSinkProxy::UnsubscribeLocalHardware(const std::string& dhId)
107 {
108     DHLOGI("DistributedCameraSinkProxy::UnsubscribeLocalHardware dhId: %s", GetAnonyString(dhId).c_str());
109     if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
110         DHLOGE("DistributedCameraSinkProxy::UnsubscribeLocalHardware params is invalid");
111         return DCAMERA_BAD_VALUE;
112     }
113     sptr<IRemoteObject> remote = Remote();
114     if (remote == nullptr) {
115         DHLOGE("DistributedCameraSinkProxy::UnsubscribeLocalHardware remote service is null");
116         return DCAMERA_BAD_VALUE;
117     }
118 
119     MessageParcel data;
120     MessageParcel reply;
121     MessageOption option;
122     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
123         DHLOGE("DistributedCameraSinkProxy::UnsubscribeLocalHardware write token failed");
124         return DCAMERA_BAD_VALUE;
125     }
126     if (!data.WriteString(dhId)) {
127         DHLOGE("DistributedCameraSinkProxy::UnsubscribeLocalHardware write params failed");
128         return DCAMERA_BAD_VALUE;
129     }
130     remote->SendRequest(UNSUBSCRIBE_LOCAL_HARDWARE, data, reply, option);
131     int32_t result = reply.ReadInt32();
132     return result;
133 }
134 
StopCapture(const std::string & dhId)135 int32_t DistributedCameraSinkProxy::StopCapture(const std::string& dhId)
136 {
137     DHLOGI("DistributedCameraSinkProxy::StopCapture dhId: %s", GetAnonyString(dhId).c_str());
138     if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
139         DHLOGE("DistributedCameraSinkProxy::StopCapture params is invalid");
140         return DCAMERA_BAD_VALUE;
141     }
142     sptr<IRemoteObject> remote = Remote();
143     if (remote == nullptr) {
144         DHLOGE("DistributedCameraSinkProxy::StopCapture remote service is null");
145         return DCAMERA_BAD_VALUE;
146     }
147 
148     MessageParcel data;
149     MessageParcel reply;
150     MessageOption option = { MessageOption::TF_ASYNC };
151     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
152         DHLOGE("DistributedCameraSinkProxy::StopCapture write token failed");
153         return DCAMERA_BAD_VALUE;
154     }
155     if (!data.WriteString(dhId)) {
156         DHLOGE("DistributedCameraSinkProxy::StopCapture write params failed");
157         return DCAMERA_BAD_VALUE;
158     }
159     remote->SendRequest(STOP_CAPTURE, data, reply, option);
160     int32_t result = reply.ReadInt32();
161     DHLOGI("DistributedCameraSinkProxy::StopCapture async dhId: %s", GetAnonyString(dhId).c_str());
162     return result;
163 }
164 
ChannelNeg(const std::string & dhId,std::string & channelInfo)165 int32_t DistributedCameraSinkProxy::ChannelNeg(const std::string& dhId, std::string& channelInfo)
166 {
167     DHLOGI("DistributedCameraSinkProxy::ChannelNeg dhId: %s", GetAnonyString(dhId).c_str());
168     if (dhId.empty() || dhId.size() > DID_MAX_SIZE || channelInfo.empty() ||
169         channelInfo.size() > PARAM_MAX_SIZE) {
170         DHLOGE("DistributedCameraSinkProxy::ChannelNeg params is invalid");
171         return DCAMERA_BAD_VALUE;
172     }
173     sptr<IRemoteObject> remote = Remote();
174     if (remote == nullptr) {
175         DHLOGE("DistributedCameraSinkProxy::ChannelNeg remote service is null");
176         return DCAMERA_BAD_VALUE;
177     }
178 
179     MessageParcel data;
180     MessageParcel reply;
181     MessageOption option;
182     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
183         DHLOGE("DistributedCameraSinkProxy::ChannelNeg write token failed");
184         return DCAMERA_BAD_VALUE;
185     }
186     if (!data.WriteString(dhId) || !data.WriteString(channelInfo)) {
187         DHLOGE("DistributedCameraSinkProxy::ChannelNeg write params failed");
188         return DCAMERA_BAD_VALUE;
189     }
190     remote->SendRequest(CHANNEL_NEG, data, reply, option);
191     int32_t result = reply.ReadInt32();
192     return result;
193 }
194 
GetCameraInfo(const std::string & dhId,std::string & cameraInfo)195 int32_t DistributedCameraSinkProxy::GetCameraInfo(const std::string& dhId, std::string& cameraInfo)
196 {
197     DHLOGI("DistributedCameraSinkProxy::GetCameraInfo dhId: %s", GetAnonyString(dhId).c_str());
198     if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
199         DHLOGE("DistributedCameraSinkProxy::GetCameraInfo parmas is invalid");
200         return DCAMERA_BAD_VALUE;
201     }
202     sptr<IRemoteObject> remote = Remote();
203     if (remote == nullptr) {
204         DHLOGE("DistributedCameraSinkProxy::GetCameraInfo remote service is null");
205         return DCAMERA_BAD_VALUE;
206     }
207 
208     MessageParcel data;
209     MessageParcel reply;
210     MessageOption option;
211     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
212         DHLOGE("DistributedCameraSinkProxy::GetCameraInfo write token failed");
213         return DCAMERA_BAD_VALUE;
214     }
215     if (!data.WriteString(dhId) || !data.WriteString(cameraInfo)) {
216         DHLOGE("DistributedCameraSinkProxy::GetCameraInfo write params failed");
217         return DCAMERA_BAD_VALUE;
218     }
219     remote->SendRequest(GET_CAMERA_INFO, data, reply, option);
220     int32_t result = reply.ReadInt32();
221     return result;
222 }
223 
OpenChannel(const std::string & dhId,std::string & openInfo)224 int32_t DistributedCameraSinkProxy::OpenChannel(const std::string& dhId, std::string& openInfo)
225 {
226     DHLOGI("DistributedCameraSinkProxy::OpenChannel dhId: %s", GetAnonyString(dhId).c_str());
227     if (dhId.empty() || dhId.size() > DID_MAX_SIZE || openInfo.empty() ||
228         openInfo.size() > PARAM_MAX_SIZE) {
229         DHLOGE("DistributedCameraSinkProxy::OpenChannel params is invalid");
230         return DCAMERA_BAD_VALUE;
231     }
232     sptr<IRemoteObject> remote = Remote();
233     if (remote == nullptr) {
234         DHLOGE("DistributedCameraSinkProxy::OpenChannel remote service is null");
235         return DCAMERA_BAD_VALUE;
236     }
237 
238     MessageParcel data;
239     MessageParcel reply;
240     MessageOption option;
241     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
242         DHLOGE("DistributedCameraSinkProxy::OpenChannel write token failed");
243         return DCAMERA_BAD_VALUE;
244     }
245     if (!data.WriteString(dhId) || !data.WriteString(openInfo)) {
246         DHLOGE("DistributedCameraSinkProxy::OpenChannel write params failed");
247         return DCAMERA_BAD_VALUE;
248     }
249     remote->SendRequest(OPEN_CHANNEL, data, reply, option);
250     int32_t result = reply.ReadInt32();
251     return result;
252 }
253 
CloseChannel(const std::string & dhId)254 int32_t DistributedCameraSinkProxy::CloseChannel(const std::string& dhId)
255 {
256     DHLOGI("DistributedCameraSinkProxy::CloseChannel dhId: %s", GetAnonyString(dhId).c_str());
257     if (dhId.empty() || dhId.size() > DID_MAX_SIZE) {
258         DHLOGE("DistributedCameraSinkProxy::CloseChannel params is invalid");
259         return DCAMERA_BAD_VALUE;
260     }
261     sptr<IRemoteObject> remote = Remote();
262     if (remote == nullptr) {
263         DHLOGE("DistributedCameraSinkProxy::CloseChannel remote service is null");
264         return DCAMERA_BAD_VALUE;
265     }
266 
267     MessageParcel data;
268     MessageParcel reply;
269     MessageOption option;
270     if (!data.WriteInterfaceToken(DistributedCameraSinkProxy::GetDescriptor())) {
271         DHLOGE("DistributedCameraSinkProxy::CloseChannel write token failed");
272         return DCAMERA_BAD_VALUE;
273     }
274     if (!data.WriteString(dhId)) {
275         DHLOGE("DistributedCameraSinkProxy::CloseChannel write params failed");
276         return DCAMERA_BAD_VALUE;
277     }
278     remote->SendRequest(CLOSE_CHANNEL, data, reply, option);
279     int32_t result = reply.ReadInt32();
280     return result;
281 }
282 } // namespace DistributedHardware
283 } // namespace OHOS