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 "softbus_client_stub.h"
17
18 #include "client_bus_center_manager.h"
19 #include "client_disc_manager.h"
20 #include "client_trans_channel_callback.h"
21 #include "ipc_skeleton.h"
22 #include "ipc_types.h"
23 #include "message_parcel.h"
24 #include "securec.h"
25 #include "softbus_def.h"
26 #include "softbus_errcode.h"
27 #include "softbus_ipc_def.h"
28 #include "softbus_log.h"
29
30 namespace OHOS {
SoftBusClientStub()31 SoftBusClientStub::SoftBusClientStub()
32 {
33 memberFuncMap_[CLIENT_DISCOVERY_DEVICE_FOUND] =
34 &SoftBusClientStub::OnDeviceFoundInner;
35 memberFuncMap_[CLIENT_DISCOVERY_SUCC] =
36 &SoftBusClientStub::OnDiscoverySuccessInner;
37 memberFuncMap_[CLIENT_DISCOVERY_FAIL] =
38 &SoftBusClientStub::OnDiscoverFailedInner;
39 memberFuncMap_[CLIENT_PUBLISH_SUCC] =
40 &SoftBusClientStub::OnPublishSuccessInner;
41 memberFuncMap_[CLIENT_PUBLISH_FAIL] =
42 &SoftBusClientStub::OnPublishFailInner;
43 memberFuncMap_[CLIENT_ON_CHANNEL_OPENED] =
44 &SoftBusClientStub::OnChannelOpenedInner;
45 memberFuncMap_[CLIENT_ON_CHANNEL_OPENFAILED] =
46 &SoftBusClientStub::OnChannelOpenFailedInner;
47 memberFuncMap_[CLIENT_ON_CHANNEL_LINKDOWN] =
48 &SoftBusClientStub::OnChannelLinkDownInner;
49 memberFuncMap_[CLIENT_ON_CHANNEL_CLOSED] =
50 &SoftBusClientStub::OnChannelClosedInner;
51 memberFuncMap_[CLIENT_ON_CHANNEL_MSGRECEIVED] =
52 &SoftBusClientStub::OnChannelMsgReceivedInner;
53 memberFuncMap_[CLIENT_ON_CHANNEL_QOSEVENT] =
54 &SoftBusClientStub::OnChannelQosEventInner;
55 memberFuncMap_[CLIENT_ON_JOIN_RESULT] =
56 &SoftBusClientStub::OnJoinLNNResultInner;
57 memberFuncMap_[CLIENT_ON_LEAVE_RESULT] =
58 &SoftBusClientStub::OnLeaveLNNResultInner;
59 memberFuncMap_[CLIENT_ON_NODE_ONLINE_STATE_CHANGED] =
60 &SoftBusClientStub::OnNodeOnlineStateChangedInner;
61 memberFuncMap_[CLIENT_ON_NODE_BASIC_INFO_CHANGED] =
62 &SoftBusClientStub::OnNodeBasicInfoChangedInner;
63 memberFuncMap_[CLIENT_ON_TIME_SYNC_RESULT] =
64 &SoftBusClientStub::OnTimeSyncResultInner;
65 memberFuncMap_[CLIENT_ON_PUBLISH_LNN_RESULT] =
66 &SoftBusClientStub::OnPublishLNNResultInner;
67 memberFuncMap_[CLIENT_ON_REFRESH_LNN_RESULT] =
68 &SoftBusClientStub::OnRefreshLNNResultInner;
69 memberFuncMap_[CLIENT_ON_REFRESH_DEVICE_FOUND] =
70 &SoftBusClientStub::OnRefreshDeviceFoundInner;
71 }
72
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)73 int32_t SoftBusClientStub::OnRemoteRequest(uint32_t code,
74 MessageParcel &data, MessageParcel &reply, MessageOption &option)
75 {
76 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "SoftBusClientStub::OnReceived, code = %{public}u", code);
77 if (data.ReadInterfaceToken() != GetDescriptor()) {
78 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "SoftBusClientStub: ReadInterfaceToken faild!");
79 return SOFTBUS_ERR;
80 }
81 auto itFunc = memberFuncMap_.find(code);
82 if (itFunc != memberFuncMap_.end()) {
83 auto memberFunc = itFunc->second;
84 if (memberFunc != nullptr) {
85 return (this->*memberFunc)(data, reply);
86 }
87 }
88 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_INFO, "SoftBusClientStub: default case, need check.");
89 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
90 }
91
OnDeviceFoundInner(MessageParcel & data,MessageParcel & reply)92 int32_t SoftBusClientStub::OnDeviceFoundInner(MessageParcel &data, MessageParcel &reply)
93 {
94 const unsigned char *info = data.ReadBuffer(sizeof(DeviceInfo));
95 if (info == NULL) {
96 return SOFTBUS_ERR;
97 }
98 DeviceInfo deviceInfo;
99 if (memcpy_s(&deviceInfo, sizeof(DeviceInfo), info, sizeof(DeviceInfo)) != EOK) {
100 return SOFTBUS_ERR;
101 }
102 OnDeviceFound(&deviceInfo);
103 return SOFTBUS_OK;
104 }
105
OnDiscoverFailedInner(MessageParcel & data,MessageParcel & reply)106 int32_t SoftBusClientStub::OnDiscoverFailedInner(MessageParcel &data, MessageParcel &reply)
107 {
108 int subscribeId = data.ReadInt32();
109 int failReason = data.ReadInt32();
110 OnDiscoverFailed(subscribeId, failReason);
111 return SOFTBUS_OK;
112 }
113
OnDiscoverySuccessInner(MessageParcel & data,MessageParcel & reply)114 int32_t SoftBusClientStub::OnDiscoverySuccessInner(MessageParcel &data, MessageParcel &reply)
115 {
116 int subscribeId = data.ReadInt32();
117 OnDiscoverySuccess(subscribeId);
118 return SOFTBUS_OK;
119 }
120
OnPublishSuccessInner(MessageParcel & data,MessageParcel & reply)121 int32_t SoftBusClientStub::OnPublishSuccessInner(MessageParcel &data, MessageParcel &reply)
122 {
123 int publishId = data.ReadInt32();
124 OnPublishSuccess(publishId);
125 return SOFTBUS_OK;
126 }
127
OnPublishFailInner(MessageParcel & data,MessageParcel & reply)128 int32_t SoftBusClientStub::OnPublishFailInner(MessageParcel &data, MessageParcel &reply)
129 {
130 int publishId = data.ReadInt32();
131 int failReason = data.ReadInt32();
132 OnPublishFail(publishId, failReason);
133 return SOFTBUS_OK;
134 }
135
OnDeviceFound(const DeviceInfo * device)136 void SoftBusClientStub::OnDeviceFound(const DeviceInfo *device)
137 {
138 DiscClientOnDeviceFound(device);
139 }
140
OnDiscoverFailed(int subscribeId,int failReason)141 void SoftBusClientStub::OnDiscoverFailed(int subscribeId, int failReason)
142 {
143 DiscClientOnDiscoverFailed(subscribeId, (DiscoveryFailReason)failReason);
144 }
145
OnDiscoverySuccess(int subscribeId)146 void SoftBusClientStub::OnDiscoverySuccess(int subscribeId)
147 {
148 DiscClientOnDiscoverySuccess(subscribeId);
149 }
150
OnPublishSuccess(int publishId)151 void SoftBusClientStub::OnPublishSuccess(int publishId)
152 {
153 DiscClientOnPublishSuccess(publishId);
154 }
155
OnPublishFail(int publishId,int reason)156 void SoftBusClientStub::OnPublishFail(int publishId, int reason)
157 {
158 DiscClientOnPublishFail(publishId, (PublishFailReason)reason);
159 }
160
OnChannelOpened(const char * sessionName,const ChannelInfo * info)161 int32_t SoftBusClientStub::OnChannelOpened(const char *sessionName, const ChannelInfo *info)
162 {
163 return TransOnChannelOpened(sessionName, info);
164 }
165
OnChannelOpenFailed(int32_t channelId,int32_t channelType)166 int32_t SoftBusClientStub::OnChannelOpenFailed(int32_t channelId, int32_t channelType)
167 {
168 return TransOnChannelOpenFailed(channelId, channelType);
169 }
170
OnChannelLinkDown(const char * networkId,int32_t routeType)171 int32_t SoftBusClientStub::OnChannelLinkDown(const char *networkId, int32_t routeType)
172 {
173 return TransOnChannelLinkDown(networkId, routeType);
174 }
175
OnChannelClosed(int32_t channelId,int32_t channelType)176 int32_t SoftBusClientStub::OnChannelClosed(int32_t channelId, int32_t channelType)
177 {
178 return TransOnChannelClosed(channelId, channelType);
179 }
180
OnChannelMsgReceived(int32_t channelId,int32_t channelType,const void * data,uint32_t len,int32_t type)181 int32_t SoftBusClientStub::OnChannelMsgReceived(int32_t channelId, int32_t channelType, const void *data,
182 uint32_t len, int32_t type)
183 {
184 return TransOnChannelMsgReceived(channelId, channelType, data, len, static_cast<SessionPktType>(type));
185 }
186
OnChannelQosEvent(int32_t channelId,int32_t channelType,int32_t eventId,int32_t tvCount,const QosTv * tvList)187 int32_t SoftBusClientStub::OnChannelQosEvent(int32_t channelId, int32_t channelType, int32_t eventId,
188 int32_t tvCount, const QosTv *tvList)
189 {
190 return TransOnChannelQosEvent(channelId, channelType, eventId, tvCount, tvList);
191 }
192
OnChannelOpenedInner(MessageParcel & data,MessageParcel & reply)193 int32_t SoftBusClientStub::OnChannelOpenedInner(MessageParcel &data, MessageParcel &reply)
194 {
195 const char *sessionName = data.ReadCString();
196 if (sessionName == nullptr) {
197 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read sessionName failed!");
198 return SOFTBUS_ERR;
199 }
200
201 ChannelInfo channel = {0};
202 if (!data.ReadInt32(channel.channelId)) {
203 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
204 return SOFTBUS_ERR;
205 }
206 if (!data.ReadInt32(channel.channelType)) {
207 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
208 return SOFTBUS_ERR;
209 }
210 if (channel.channelType == CHANNEL_TYPE_TCP_DIRECT) {
211 channel.fd = data.ReadFileDescriptor();
212 }
213 if (!data.ReadBool(channel.isServer)) {
214 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
215 return SOFTBUS_ERR;
216 }
217 if (!data.ReadBool(channel.isEnabled)) {
218 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
219 return SOFTBUS_ERR;
220 }
221 if (!data.ReadInt32(channel.peerUid)) {
222 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
223 return SOFTBUS_ERR;
224 }
225 if (!data.ReadInt32(channel.peerPid)) {
226 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read retCode failed!");
227 return SOFTBUS_ERR;
228 }
229 channel.groupId = (char *)data.ReadCString();
230 if (channel.groupId == nullptr) {
231 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
232 return SOFTBUS_ERR;
233 }
234 if (!data.ReadUint32(channel.keyLen)) {
235 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner len failed!");
236 return SOFTBUS_ERR;
237 }
238 channel.sessionKey = (char *)data.ReadRawData(channel.keyLen);
239 if (channel.sessionKey == nullptr) {
240 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
241 return SOFTBUS_ERR;
242 }
243 channel.peerSessionName = (char *)data.ReadCString();
244 if (channel.peerSessionName == nullptr) {
245 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
246 return SOFTBUS_ERR;
247 }
248 channel.peerDeviceId = (char *)data.ReadCString();
249 if (channel.peerDeviceId == nullptr) {
250 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read addr failed!");
251 return SOFTBUS_ERR;
252 }
253 if (channel.channelType == CHANNEL_TYPE_UDP) {
254 data.ReadInt32(channel.businessType);
255 channel.myIp = (char *)data.ReadCString();
256 if (!channel.isServer) {
257 data.ReadInt32(channel.peerPort);
258 channel.peerIp = (char *)data.ReadCString();
259 }
260 }
261 data.ReadInt32(channel.routeType);
262
263 int ret = OnChannelOpened(sessionName, &channel);
264 bool res = reply.WriteInt32(ret);
265 if (!res) {
266 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner write reply failed!");
267 return SOFTBUS_ERR;
268 }
269 return SOFTBUS_OK;
270 }
271
OnChannelOpenFailedInner(MessageParcel & data,MessageParcel & reply)272 int32_t SoftBusClientStub::OnChannelOpenFailedInner(MessageParcel &data, MessageParcel &reply)
273 {
274 int32_t channelId;
275 if (!data.ReadInt32(channelId)) {
276 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel id failed!");
277 return SOFTBUS_ERR;
278 }
279
280 int32_t channelType;
281 if (!data.ReadInt32(channelType)) {
282 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel type failed!");
283 return SOFTBUS_ERR;
284 }
285
286 int ret = OnChannelOpenFailed(channelId, channelType);
287 bool res = reply.WriteInt32(ret);
288 if (!res) {
289 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner write reply failed!");
290 return SOFTBUS_ERR;
291 }
292 return SOFTBUS_OK;
293 }
294
OnChannelLinkDownInner(MessageParcel & data,MessageParcel & reply)295 int32_t SoftBusClientStub::OnChannelLinkDownInner(MessageParcel &data, MessageParcel &reply)
296 {
297 const char *networkId = data.ReadCString();
298 if (networkId == nullptr) {
299 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner read networkId failed!");
300 return SOFTBUS_ERR;
301 }
302 int32_t routeType;
303 if (!data.ReadInt32(routeType)) {
304 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner read routeType failed!");
305 return SOFTBUS_ERR;
306 }
307 int32_t retReply = OnChannelLinkDown(networkId, routeType);
308 if (!reply.WriteInt32(retReply)) {
309 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelLinkDownInner write reply failed!");
310 return SOFTBUS_ERR;
311 }
312 return SOFTBUS_OK;
313 }
314
OnChannelClosedInner(MessageParcel & data,MessageParcel & reply)315 int32_t SoftBusClientStub::OnChannelClosedInner(MessageParcel &data, MessageParcel &reply)
316 {
317 int32_t channelId;
318 if (!data.ReadInt32(channelId)) {
319 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelClosedInner read channel id failed!");
320 return SOFTBUS_ERR;
321 }
322
323 int32_t channelType;
324 if (!data.ReadInt32(channelType)) {
325 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenFailedInner read channel type failed!");
326 return SOFTBUS_ERR;
327 }
328
329 int ret = OnChannelClosed(channelId, channelType);
330 bool res = reply.WriteInt32(ret);
331 if (!res) {
332 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelClosedInner write reply failed!");
333 return SOFTBUS_ERR;
334 }
335 return SOFTBUS_OK;
336 }
337
OnChannelMsgReceivedInner(MessageParcel & data,MessageParcel & reply)338 int32_t SoftBusClientStub::OnChannelMsgReceivedInner(MessageParcel &data, MessageParcel &reply)
339 {
340 int32_t channelId;
341 if (!data.ReadInt32(channelId)) {
342 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read channel id failed!");
343 return SOFTBUS_ERR;
344 }
345 int32_t channelType;
346 if (!data.ReadInt32(channelType)) {
347 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read channel type failed!");
348 return SOFTBUS_ERR;
349 }
350 uint32_t len;
351 if (!data.ReadUint32(len)) {
352 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read data len failed!");
353 return SOFTBUS_ERR;
354 }
355 char *dataInfo = (char *)data.ReadRawData(len);
356 if (dataInfo == nullptr) {
357 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelOpenedInner read dataInfo failed!");
358 return SOFTBUS_ERR;
359 }
360 int32_t type;
361 if (!data.ReadInt32(type)) {
362 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner read type failed!");
363 return SOFTBUS_ERR;
364 }
365 int ret = OnChannelMsgReceived(channelId, channelType, dataInfo, len, type);
366 bool res = reply.WriteInt32(ret);
367 if (!res) {
368 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelMsgReceivedInner write reply failed!");
369 return SOFTBUS_ERR;
370 }
371 return SOFTBUS_OK;
372 }
373
OnChannelQosEventInner(MessageParcel & data,MessageParcel & reply)374 int32_t SoftBusClientStub::OnChannelQosEventInner(MessageParcel &data, MessageParcel &reply)
375 {
376 SoftBusLog(SOFTBUS_LOG_TRAN, SOFTBUS_LOG_INFO, "OnChannelQosEventInner");
377 int32_t channelId;
378 if (!data.ReadInt32(channelId)) {
379 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read channel id failed!");
380 return SOFTBUS_ERR;
381 }
382 int32_t channelType;
383 if (!data.ReadInt32(channelType)) {
384 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read channel type failed!");
385 return SOFTBUS_ERR;
386 }
387 int32_t eventId;
388 if (!data.ReadInt32(eventId)) {
389 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read eventId failed!");
390 return SOFTBUS_ERR;
391 }
392 int32_t tvCount;
393 if (!data.ReadInt32(tvCount) || tvCount <= 0) {
394 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read tv count:%d failed!", tvCount);
395 return SOFTBUS_ERR;
396 }
397 QosTv *tvList = (QosTv *)data.ReadRawData(sizeof(QosTv) * tvCount);
398 if (tvList == nullptr) {
399 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner read tv list failed!");
400 return SOFTBUS_ERR;
401 }
402 int ret = OnChannelQosEvent(channelId, channelType, eventId, tvCount, tvList);
403 bool res = reply.WriteInt32(ret);
404 if (!res) {
405 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnChannelQosEventInner write reply failed!");
406 return SOFTBUS_ERR;
407 }
408 return SOFTBUS_OK;
409 }
410
OnJoinLNNResultInner(MessageParcel & data,MessageParcel & reply)411 int32_t SoftBusClientStub::OnJoinLNNResultInner(MessageParcel &data, MessageParcel &reply)
412 {
413 uint32_t addrTypeLen;
414 if (!data.ReadUint32(addrTypeLen) || addrTypeLen != sizeof(ConnectionAddr)) {
415 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
416 "OnJoinLNNResultInner read addr type length:%d failed!", addrTypeLen);
417 return SOFTBUS_ERR;
418 }
419 void *addr = (void *)data.ReadRawData(addrTypeLen);
420 if (addr == nullptr) {
421 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read addr failed!");
422 return SOFTBUS_ERR;
423 }
424 int32_t retCode;
425 if (!data.ReadInt32(retCode)) {
426 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read retCode failed!");
427 return SOFTBUS_ERR;
428 }
429 const char *networkId = nullptr;
430 if (retCode == 0) {
431 networkId = data.ReadCString();
432 if (networkId == nullptr) {
433 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner read networkId failed!");
434 return SOFTBUS_ERR;
435 }
436 }
437 int32_t retReply = OnJoinLNNResult(addr, addrTypeLen, networkId, retCode);
438 if (!reply.WriteInt32(retReply)) {
439 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnJoinLNNResultInner write reply failed!");
440 return SOFTBUS_ERR;
441 }
442 return SOFTBUS_OK;
443 }
444
OnLeaveLNNResultInner(MessageParcel & data,MessageParcel & reply)445 int32_t SoftBusClientStub::OnLeaveLNNResultInner(MessageParcel &data, MessageParcel &reply)
446 {
447 const char *networkId = data.ReadCString();
448 if (networkId == nullptr) {
449 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner read networkId failed!");
450 return SOFTBUS_ERR;
451 }
452 int32_t retCode;
453 if (!data.ReadInt32(retCode)) {
454 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner read retCode failed!");
455 return SOFTBUS_ERR;
456 }
457 int32_t retReply = OnLeaveLNNResult(networkId, retCode);
458 if (!reply.WriteInt32(retReply)) {
459 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnLeaveLNNResultInner write reply failed!");
460 return SOFTBUS_ERR;
461 }
462 return SOFTBUS_OK;
463 }
464
OnNodeOnlineStateChangedInner(MessageParcel & data,MessageParcel & reply)465 int32_t SoftBusClientStub::OnNodeOnlineStateChangedInner(MessageParcel &data, MessageParcel &reply)
466 {
467 bool isOnline = false;
468 if (!data.ReadBool(isOnline)) {
469 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner read online state failed!");
470 return SOFTBUS_ERR;
471 }
472 uint32_t infoTypeLen;
473 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(NodeBasicInfo)) {
474 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
475 "OnNodeOnlineStateChangedInner read info type length:%d failed!", infoTypeLen);
476 return SOFTBUS_ERR;
477 }
478 void *info = (void *)data.ReadRawData(infoTypeLen);
479 if (info == nullptr) {
480 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner read basic info failed!");
481 return SOFTBUS_ERR;
482 }
483 int32_t retReply = OnNodeOnlineStateChanged(isOnline, info, infoTypeLen);
484 if (!reply.WriteInt32(retReply)) {
485 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeOnlineStateChangedInner write reply failed!");
486 return SOFTBUS_ERR;
487 }
488 return SOFTBUS_OK;
489 }
490
OnNodeBasicInfoChangedInner(MessageParcel & data,MessageParcel & reply)491 int32_t SoftBusClientStub::OnNodeBasicInfoChangedInner(MessageParcel &data, MessageParcel &reply)
492 {
493 int32_t type;
494 if (!data.ReadInt32(type)) {
495 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner read type failed!");
496 return SOFTBUS_ERR;
497 }
498 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner type %d", type);
499 uint32_t infoTypeLen;
500 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(NodeBasicInfo)) {
501 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
502 "OnNodeBasicInfoChangedInner read info type length:%d failed!", infoTypeLen);
503 return SOFTBUS_ERR;
504 }
505 void *info = (void *)data.ReadRawData(infoTypeLen);
506 if (info == nullptr) {
507 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner read basic info failed!");
508 return SOFTBUS_ERR;
509 }
510 int32_t retReply = OnNodeBasicInfoChanged(info, infoTypeLen, type);
511 if (!reply.WriteInt32(retReply)) {
512 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnNodeBasicInfoChangedInner write reply failed!");
513 return SOFTBUS_ERR;
514 }
515 return SOFTBUS_OK;
516 }
517
OnTimeSyncResultInner(MessageParcel & data,MessageParcel & reply)518 int32_t SoftBusClientStub::OnTimeSyncResultInner(MessageParcel &data, MessageParcel &reply)
519 {
520 uint32_t infoTypeLen;
521 if (!data.ReadUint32(infoTypeLen) || infoTypeLen != sizeof(TimeSyncResultInfo)) {
522 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
523 "OnTimeSyncResultInner read info length:%d failed!", infoTypeLen);
524 return SOFTBUS_ERR;
525 }
526 void *info = (void *)data.ReadRawData(infoTypeLen);
527 if (info == nullptr) {
528 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner read info failed!");
529 return SOFTBUS_ERR;
530 }
531 int32_t retCode;
532 if (!data.ReadInt32(retCode)) {
533 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner read retCode failed!");
534 return SOFTBUS_ERR;
535 }
536
537 int32_t retReply = OnTimeSyncResult(info, infoTypeLen, retCode);
538 if (!reply.WriteInt32(retReply)) {
539 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnTimeSyncResultInner write reply failed!");
540 return SOFTBUS_ERR;
541 }
542 return SOFTBUS_OK;
543 }
544
OnPublishLNNResultInner(MessageParcel & data,MessageParcel & reply)545 int32_t SoftBusClientStub::OnPublishLNNResultInner(MessageParcel &data, MessageParcel &reply)
546 {
547 int32_t publishId;
548 if (!data.ReadInt32(publishId)) {
549 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnPublishLNNResultInner read publishId failed!");
550 return SOFTBUS_ERR;
551 }
552 int32_t reason;
553 if (!data.ReadInt32(reason)) {
554 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnPublishLNNResultInner read reason failed!");
555 return SOFTBUS_ERR;
556 }
557
558 OnPublishLNNResult(publishId, reason);
559 return SOFTBUS_OK;
560 }
561
OnRefreshLNNResultInner(MessageParcel & data,MessageParcel & reply)562 int32_t SoftBusClientStub::OnRefreshLNNResultInner(MessageParcel &data, MessageParcel &reply)
563 {
564 int32_t refreshId;
565 if (!data.ReadInt32(refreshId)) {
566 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshLNNResultInner read publishId failed!");
567 return SOFTBUS_ERR;
568 }
569 int32_t reason;
570 if (!data.ReadInt32(reason)) {
571 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshLNNResultInner read reason failed!");
572 return SOFTBUS_ERR;
573 }
574
575 OnRefreshLNNResult(refreshId, reason);
576 return SOFTBUS_OK;
577 }
578
OnRefreshDeviceFoundInner(MessageParcel & data,MessageParcel & reply)579 int32_t SoftBusClientStub::OnRefreshDeviceFoundInner(MessageParcel &data, MessageParcel &reply)
580 {
581 uint32_t deviceLen;
582 if (!data.ReadUint32(deviceLen) || deviceLen != sizeof(DeviceInfo)) {
583 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR,
584 "OnRefreshDeviceFoundInner read info length:%d failed!", deviceLen);
585 return SOFTBUS_ERR;
586 }
587 void *device = (void *)data.ReadRawData(deviceLen);
588 if (device == nullptr) {
589 SoftBusLog(SOFTBUS_LOG_COMM, SOFTBUS_LOG_ERROR, "OnRefreshDeviceFoundInner read info failed!");
590 return SOFTBUS_ERR;
591 }
592 OnRefreshDeviceFound(device, deviceLen);
593 return SOFTBUS_OK;
594 }
595
OnJoinLNNResult(void * addr,uint32_t addrTypeLen,const char * networkId,int retCode)596 int32_t SoftBusClientStub::OnJoinLNNResult(void *addr, uint32_t addrTypeLen, const char *networkId, int retCode)
597 {
598 (void)addrTypeLen;
599 return LnnOnJoinResult(addr, networkId, retCode);
600 }
601
OnLeaveLNNResult(const char * networkId,int retCode)602 int32_t SoftBusClientStub::OnLeaveLNNResult(const char *networkId, int retCode)
603 {
604 return LnnOnLeaveResult(networkId, retCode);
605 }
606
OnNodeOnlineStateChanged(bool isOnline,void * info,uint32_t infoTypeLen)607 int32_t SoftBusClientStub::OnNodeOnlineStateChanged(bool isOnline, void *info, uint32_t infoTypeLen)
608 {
609 (void)infoTypeLen;
610 return LnnOnNodeOnlineStateChanged(isOnline, info);
611 }
612
OnNodeBasicInfoChanged(void * info,uint32_t infoTypeLen,int32_t type)613 int32_t SoftBusClientStub::OnNodeBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t type)
614 {
615 (void)infoTypeLen;
616 return LnnOnNodeBasicInfoChanged(info, type);
617 }
618
OnTimeSyncResult(const void * info,uint32_t infoTypeLen,int32_t retCode)619 int32_t SoftBusClientStub::OnTimeSyncResult(const void *info, uint32_t infoTypeLen, int32_t retCode)
620 {
621 (void)infoTypeLen;
622 return LnnOnTimeSyncResult(info, retCode);
623 }
624
OnPublishLNNResult(int32_t publishId,int32_t reason)625 void SoftBusClientStub::OnPublishLNNResult(int32_t publishId, int32_t reason)
626 {
627 LnnOnPublishLNNResult(publishId, reason);
628 }
629
OnRefreshLNNResult(int32_t refreshId,int32_t reason)630 void SoftBusClientStub::OnRefreshLNNResult(int32_t refreshId, int32_t reason)
631 {
632 LnnOnRefreshLNNResult(refreshId, reason);
633 }
634
OnRefreshDeviceFound(const void * device,uint32_t deviceLen)635 void SoftBusClientStub::OnRefreshDeviceFound(const void *device, uint32_t deviceLen)
636 {
637 (void)deviceLen;
638 LnnOnRefreshDeviceFound(device);
639 }
640 } // namespace OHOS
641