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 "lnn_bus_center_ipc.h"
17
18 #include <cstring>
19 #include <mutex>
20 #include <securec.h>
21 #include <vector>
22
23 #include "bus_center_client_proxy.h"
24 #include "bus_center_manager.h"
25 #include "lnn_connection_addr_utils.h"
26 #include "lnn_distributed_net_ledger.h"
27 #include "lnn_heartbeat_ctrl.h"
28 #include "lnn_ipc_utils.h"
29 #include "lnn_meta_node_ledger.h"
30 #include "lnn_time_sync_manager.h"
31 #include "softbus_def.h"
32 #include "softbus_errcode.h"
33 #include "softbus_log.h"
34 #include "softbus_permission.h"
35
36 struct JoinLnnRequestInfo {
37 char pkgName[PKG_NAME_SIZE_MAX];
38 ConnectionAddr addr;
39 };
40
41 struct LeaveLnnRequestInfo {
42 char pkgName[PKG_NAME_SIZE_MAX];
43 char networkId[NETWORK_ID_BUF_LEN];
44 };
45
46 static std::mutex g_lock;
47 static std::vector<JoinLnnRequestInfo *> g_joinLNNRequestInfo;
48 static std::vector<JoinLnnRequestInfo *> g_joinMetaNodeRequestInfo;
49 static std::vector<LeaveLnnRequestInfo *> g_leaveLNNRequestInfo;
50 static std::vector<LeaveLnnRequestInfo *> g_leaveMetaNodeRequestInfo;
51
52 static int32_t OnRefreshDeviceFound(const char *pkgName, const DeviceInfo *device,
53 const InnerDeviceInfoAddtions *addtions);
54
55 static IServerDiscInnerCallback g_discInnerCb = {
56 .OnServerDeviceFound = OnRefreshDeviceFound,
57 };
58
IsRepeatJoinLNNRequest(const char * pkgName,const ConnectionAddr * addr)59 static bool IsRepeatJoinLNNRequest(const char *pkgName, const ConnectionAddr *addr)
60 {
61 std::vector<JoinLnnRequestInfo *>::iterator iter;
62 for (iter = g_joinLNNRequestInfo.begin(); iter != g_joinLNNRequestInfo.end(); ++iter) {
63 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName)) != 0) {
64 continue;
65 }
66 if (LnnIsSameConnectionAddr(addr, &(*iter)->addr)) {
67 return true;
68 }
69 }
70 return false;
71 }
72
IsRepeatJoinMetaNodeRequest(const char * pkgName,const ConnectionAddr * addr)73 static bool IsRepeatJoinMetaNodeRequest(const char *pkgName, const ConnectionAddr *addr)
74 {
75 std::vector<JoinLnnRequestInfo *>::iterator iter;
76 for (iter = g_joinMetaNodeRequestInfo.begin(); iter != g_joinMetaNodeRequestInfo.end(); ++iter) {
77 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName)) != 0) {
78 continue;
79 }
80 if (LnnIsSameConnectionAddr(addr, &(*iter)->addr)) {
81 return true;
82 }
83 }
84 return false;
85 }
86
AddJoinLNNInfo(const char * pkgName,const ConnectionAddr * addr)87 static int32_t AddJoinLNNInfo(const char *pkgName, const ConnectionAddr *addr)
88 {
89 JoinLnnRequestInfo *info = new (std::nothrow) JoinLnnRequestInfo();
90 if (info == nullptr) {
91 return SOFTBUS_MEM_ERR;
92 }
93 if (strncpy_s(info->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) {
94 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail");
95 delete info;
96 return SOFTBUS_MEM_ERR;
97 }
98 info->addr = *addr;
99 g_joinLNNRequestInfo.push_back(info);
100 return SOFTBUS_OK;
101 }
102
AddJoinMetaNodeInfo(const char * pkgName,const ConnectionAddr * addr)103 static int32_t AddJoinMetaNodeInfo(const char *pkgName, const ConnectionAddr *addr)
104 {
105 JoinLnnRequestInfo *info = new (std::nothrow) JoinLnnRequestInfo();
106 if (info == nullptr) {
107 return SOFTBUS_MEM_ERR;
108 }
109 if (strncpy_s(info->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) {
110 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail");
111 delete info;
112 return SOFTBUS_MEM_ERR;
113 }
114 info->addr = *addr;
115 g_joinMetaNodeRequestInfo.push_back(info);
116 return SOFTBUS_OK;
117 }
118
IsRepeatLeaveLNNRequest(const char * pkgName,const char * networkId)119 static bool IsRepeatLeaveLNNRequest(const char *pkgName, const char *networkId)
120 {
121 std::vector<LeaveLnnRequestInfo *>::iterator iter;
122 for (iter = g_leaveLNNRequestInfo.begin(); iter != g_leaveLNNRequestInfo.end(); ++iter) {
123 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName)) != 0) {
124 continue;
125 }
126 if (strncmp(networkId, (*iter)->networkId, strlen(networkId)) == 0) {
127 return true;
128 }
129 }
130 return false;
131 }
132
IsRepeatLeaveMetaNodeRequest(const char * pkgName,const char * networkId)133 static bool IsRepeatLeaveMetaNodeRequest(const char *pkgName, const char *networkId)
134 {
135 std::vector<LeaveLnnRequestInfo *>::iterator iter;
136 for (iter = g_leaveMetaNodeRequestInfo.begin(); iter != g_leaveMetaNodeRequestInfo.end(); ++iter) {
137 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName)) != 0) {
138 continue;
139 }
140 if (strncmp(networkId, (*iter)->networkId, strlen(networkId)) == 0) {
141 return true;
142 }
143 }
144 return false;
145 }
146
AddLeaveLNNInfo(const char * pkgName,const char * networkId)147 static int32_t AddLeaveLNNInfo(const char *pkgName, const char *networkId)
148 {
149 LeaveLnnRequestInfo *info = new (std::nothrow) LeaveLnnRequestInfo();
150 if (info == nullptr) {
151 return SOFTBUS_MEM_ERR;
152 }
153 if (strncpy_s(info->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) {
154 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail");
155 delete info;
156 return SOFTBUS_MEM_ERR;
157 }
158 if (strncpy_s(info->networkId, NETWORK_ID_BUF_LEN, networkId, strlen(networkId)) != EOK) {
159 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy networkId fail");
160 delete info;
161 return SOFTBUS_MEM_ERR;
162 }
163 g_leaveLNNRequestInfo.push_back(info);
164 return SOFTBUS_OK;
165 }
166
AddLeaveMetaNodeInfo(const char * pkgName,const char * networkId)167 static int32_t AddLeaveMetaNodeInfo(const char *pkgName, const char *networkId)
168 {
169 LeaveLnnRequestInfo *info = new (std::nothrow) LeaveLnnRequestInfo();
170 if (info == nullptr) {
171 return SOFTBUS_MEM_ERR;
172 }
173 if (strncpy_s(info->pkgName, PKG_NAME_SIZE_MAX, pkgName, strlen(pkgName)) != EOK) {
174 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy pkgName fail");
175 delete info;
176 return SOFTBUS_MEM_ERR;
177 }
178 if (strncpy_s(info->networkId, NETWORK_ID_BUF_LEN, networkId, strlen(networkId)) != EOK) {
179 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy networkId fail");
180 delete info;
181 return SOFTBUS_MEM_ERR;
182 }
183 g_leaveMetaNodeRequestInfo.push_back(info);
184 return SOFTBUS_OK;
185 }
186
OnRefreshDeviceFound(const char * pkgName,const DeviceInfo * device,const InnerDeviceInfoAddtions * addtions)187 static int32_t OnRefreshDeviceFound(const char *pkgName, const DeviceInfo *device,
188 const InnerDeviceInfoAddtions *addtions)
189 {
190 DeviceInfo newDevice;
191 if (memcpy_s(&newDevice, sizeof(DeviceInfo), device, sizeof(DeviceInfo)) != EOK) {
192 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "copy new device info error");
193 return SOFTBUS_ERR;
194 }
195 LnnRefreshDeviceOnlineStateAndDevIdInfo(pkgName, &newDevice, addtions);
196 return ClientOnRefreshDeviceFound(pkgName, &newDevice, sizeof(DeviceInfo));
197 }
198
LnnIpcServerJoin(const char * pkgName,void * addr,uint32_t addrTypeLen)199 int32_t LnnIpcServerJoin(const char *pkgName, void *addr, uint32_t addrTypeLen)
200 {
201 ConnectionAddr *connAddr = reinterpret_cast<ConnectionAddr *>(addr);
202
203 (void)addrTypeLen;
204 if (pkgName == nullptr || connAddr == nullptr) {
205 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "parameters are nullptr!\n");
206 return SOFTBUS_INVALID_PARAM;
207 }
208 std::lock_guard<std::mutex> autoLock(g_lock);
209 if (IsRepeatJoinLNNRequest(pkgName, connAddr)) {
210 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "repeat join lnn request from: %s", pkgName);
211 return SOFTBUS_ALREADY_EXISTED;
212 }
213 int32_t ret = LnnServerJoin(connAddr);
214 if (ret == SOFTBUS_OK) {
215 ret = AddJoinLNNInfo(pkgName, connAddr);
216 }
217 return ret;
218 }
219
MetaNodeIpcServerJoin(const char * pkgName,void * addr,CustomData * customData,uint32_t addrTypeLen)220 int32_t MetaNodeIpcServerJoin(const char *pkgName, void *addr, CustomData *customData, uint32_t addrTypeLen)
221 {
222 ConnectionAddr *connAddr = reinterpret_cast<ConnectionAddr *>(addr);
223
224 (void)addrTypeLen;
225 if (pkgName == nullptr || connAddr == nullptr) {
226 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "parameters are nullptr!\n");
227 return SOFTBUS_INVALID_PARAM;
228 }
229 std::lock_guard<std::mutex> autoLock(g_lock);
230 if (IsRepeatJoinMetaNodeRequest(pkgName, connAddr)) {
231 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "repeat join lnn request from: %s", pkgName);
232 return SOFTBUS_ALREADY_EXISTED;
233 }
234 int32_t ret = MetaNodeServerJoin(connAddr, customData);
235 if (ret == SOFTBUS_OK) {
236 ret = AddJoinMetaNodeInfo(pkgName, connAddr);
237 }
238 return ret;
239 }
240
LnnIpcServerLeave(const char * pkgName,const char * networkId)241 int32_t LnnIpcServerLeave(const char *pkgName, const char *networkId)
242 {
243 if (pkgName == nullptr || networkId == nullptr) {
244 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "parameters are nullptr!\n");
245 return SOFTBUS_INVALID_PARAM;
246 }
247 std::lock_guard<std::mutex> autoLock(g_lock);
248 if (IsRepeatLeaveLNNRequest(pkgName, networkId)) {
249 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "repeat leave lnn request from: %s", pkgName);
250 return SOFTBUS_ALREADY_EXISTED;
251 }
252 int32_t ret = LnnServerLeave(networkId);
253 if (ret == SOFTBUS_OK) {
254 ret = AddLeaveLNNInfo(pkgName, networkId);
255 }
256 return ret;
257 }
258
MetaNodeIpcServerLeave(const char * pkgName,const char * networkId)259 int32_t MetaNodeIpcServerLeave(const char *pkgName, const char *networkId)
260 {
261 if (pkgName == nullptr || networkId == nullptr) {
262 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "parameters are nullptr!\n");
263 return SOFTBUS_INVALID_PARAM;
264 }
265 std::lock_guard<std::mutex> autoLock(g_lock);
266 if (IsRepeatLeaveMetaNodeRequest(pkgName, networkId)) {
267 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "repeat leave lnn request from: %s", pkgName);
268 return SOFTBUS_ALREADY_EXISTED;
269 }
270 int32_t ret = MetaNodeServerLeave(networkId);
271 if (ret == SOFTBUS_OK) {
272 ret = AddLeaveMetaNodeInfo(pkgName, networkId);
273 }
274 return ret;
275 }
276
LnnIpcGetAllOnlineNodeInfo(const char * pkgName,void ** info,uint32_t infoTypeLen,int * infoNum)277 int32_t LnnIpcGetAllOnlineNodeInfo(const char *pkgName, void **info, uint32_t infoTypeLen, int *infoNum)
278 {
279 if (infoTypeLen != sizeof(NodeBasicInfo)) {
280 SoftBusLog(SOFTBUS_LOG_LNN, SOFTBUS_LOG_ERROR, "infoTypeLen is invalid, infoTypeLen = %d", infoTypeLen);
281 return SOFTBUS_INVALID_PARAM;
282 }
283 return LnnGetAllOnlineNodeInfo(reinterpret_cast<NodeBasicInfo **>(info), infoNum);
284 }
285
LnnIpcGetLocalDeviceInfo(const char * pkgName,void * info,uint32_t infoTypeLen)286 int32_t LnnIpcGetLocalDeviceInfo(const char *pkgName, void *info, uint32_t infoTypeLen)
287 {
288 (void)infoTypeLen;
289 return LnnGetLocalDeviceInfo(reinterpret_cast<NodeBasicInfo *>(info));
290 }
291
LnnIpcGetNodeKeyInfo(const char * pkgName,const char * networkId,int key,unsigned char * buf,uint32_t len)292 int32_t LnnIpcGetNodeKeyInfo(const char *pkgName, const char *networkId, int key, unsigned char *buf, uint32_t len)
293 {
294 return LnnGetNodeKeyInfo(networkId, key, buf, len);
295 }
296
LnnIpcSetNodeDataChangeFlag(const char * pkgName,const char * networkId,uint16_t dataChangeFlag)297 int32_t LnnIpcSetNodeDataChangeFlag(const char *pkgName, const char *networkId, uint16_t dataChangeFlag)
298 {
299 (void)pkgName;
300 return LnnSetNodeDataChangeFlag(networkId, dataChangeFlag);
301 }
302
LnnIpcStartTimeSync(const char * pkgName,const char * targetNetworkId,int32_t accuracy,int32_t period)303 int32_t LnnIpcStartTimeSync(const char *pkgName, const char *targetNetworkId, int32_t accuracy, int32_t period)
304 {
305 return LnnStartTimeSync(pkgName, targetNetworkId, (TimeSyncAccuracy)accuracy, (TimeSyncPeriod)period);
306 }
307
LnnIpcStopTimeSync(const char * pkgName,const char * targetNetworkId)308 int32_t LnnIpcStopTimeSync(const char *pkgName, const char *targetNetworkId)
309 {
310 return LnnStopTimeSync(pkgName, targetNetworkId);
311 }
312
LnnIpcPublishLNN(const char * pkgName,const void * info,uint32_t infoTypeLen)313 int32_t LnnIpcPublishLNN(const char *pkgName, const void *info, uint32_t infoTypeLen)
314 {
315 (void)infoTypeLen;
316 PublishInfo pubInfo;
317 (void)memset_s(&pubInfo, sizeof(PublishInfo), 0, sizeof(PublishInfo));
318 ConvertVoidToPublishInfo(info, &pubInfo);
319 int32_t ret = LnnPublishService(pkgName, &pubInfo, false);
320 return ret;
321 }
322
LnnIpcStopPublishLNN(const char * pkgName,int32_t publishId)323 int32_t LnnIpcStopPublishLNN(const char *pkgName, int32_t publishId)
324 {
325 return LnnUnPublishService(pkgName, publishId, false);
326 }
327
LnnIpcRefreshLNN(const char * pkgName,const void * info,uint32_t infoTypeLen)328 int32_t LnnIpcRefreshLNN(const char *pkgName, const void *info, uint32_t infoTypeLen)
329 {
330 (void)infoTypeLen;
331 SubscribeInfo subInfo;
332 (void)memset_s(&subInfo, sizeof(SubscribeInfo), 0, sizeof(SubscribeInfo));
333 ConvertVoidToSubscribeInfo(info, &subInfo);
334 SetCallLnnStatus(false);
335 InnerCallback callback = {
336 .serverCb = g_discInnerCb,
337 };
338 int32_t ret = LnnStartDiscDevice(pkgName, &subInfo, &callback, false);
339 return ret;
340 }
341
LnnIpcStopRefreshLNN(const char * pkgName,int32_t refreshId)342 int32_t LnnIpcStopRefreshLNN(const char *pkgName, int32_t refreshId)
343 {
344 return LnnStopDiscDevice(pkgName, refreshId, false);
345 }
346
LnnIpcActiveMetaNode(const MetaNodeConfigInfo * info,char * metaNodeId)347 int32_t LnnIpcActiveMetaNode(const MetaNodeConfigInfo *info, char *metaNodeId)
348 {
349 return LnnActiveMetaNode(info, metaNodeId);
350 }
351
LnnIpcDeactiveMetaNode(const char * metaNodeId)352 int32_t LnnIpcDeactiveMetaNode(const char *metaNodeId)
353 {
354 return LnnDeactiveMetaNode(metaNodeId);
355 }
356
LnnIpcGetAllMetaNodeInfo(MetaNodeInfo * infos,int32_t * infoNum)357 int32_t LnnIpcGetAllMetaNodeInfo(MetaNodeInfo *infos, int32_t *infoNum)
358 {
359 return LnnGetAllMetaNodeInfo(infos, infoNum);
360 }
361
LnnIpcShiftLNNGear(const char * pkgName,const char * callerId,const char * targetNetworkId,const GearMode * mode)362 int32_t LnnIpcShiftLNNGear(const char *pkgName, const char *callerId, const char *targetNetworkId, const GearMode *mode)
363 {
364 return LnnShiftLNNGear(pkgName, callerId, targetNetworkId, mode);
365 }
366
LnnIpcNotifyJoinResult(void * addr,uint32_t addrTypeLen,const char * networkId,int32_t retCode)367 int32_t LnnIpcNotifyJoinResult(void *addr, uint32_t addrTypeLen, const char *networkId, int32_t retCode)
368 {
369 if (addr == nullptr) {
370 return SOFTBUS_INVALID_PARAM;
371 }
372 ConnectionAddr *connAddr = reinterpret_cast<ConnectionAddr *>(addr);
373 std::lock_guard<std::mutex> autoLock(g_lock);
374 std::vector<JoinLnnRequestInfo *>::iterator iter;
375 for (iter = g_joinLNNRequestInfo.begin(); iter != g_joinLNNRequestInfo.end();) {
376 if (!LnnIsSameConnectionAddr(connAddr, &(*iter)->addr)) {
377 ++iter;
378 continue;
379 }
380 ClientOnJoinLNNResult((*iter)->pkgName, addr, addrTypeLen, networkId, retCode);
381 delete *iter;
382 iter = g_joinLNNRequestInfo.erase(iter);
383 }
384 return SOFTBUS_OK;
385 }
386
MetaNodeIpcNotifyJoinResult(void * addr,uint32_t addrTypeLen,const char * networkId,int32_t retCode)387 int32_t MetaNodeIpcNotifyJoinResult(void *addr, uint32_t addrTypeLen, const char *networkId, int32_t retCode)
388 {
389 if (addr == nullptr) {
390 return SOFTBUS_INVALID_PARAM;
391 }
392 ConnectionAddr *connAddr = reinterpret_cast<ConnectionAddr *>(addr);
393 std::lock_guard<std::mutex> autoLock(g_lock);
394 std::vector<JoinLnnRequestInfo *>::iterator iter;
395 for (iter = g_joinMetaNodeRequestInfo.begin(); iter != g_joinMetaNodeRequestInfo.end();) {
396 if (!LnnIsSameConnectionAddr(connAddr, &(*iter)->addr)) {
397 ++iter;
398 continue;
399 }
400 ClientOnJoinMetaNodeResult((*iter)->pkgName, addr, addrTypeLen, networkId, retCode);
401 delete *iter;
402 iter = g_joinMetaNodeRequestInfo.erase(iter);
403 }
404 return SOFTBUS_OK;
405 }
406
LnnIpcNotifyLeaveResult(const char * networkId,int32_t retCode)407 int32_t LnnIpcNotifyLeaveResult(const char *networkId, int32_t retCode)
408 {
409 if (networkId == nullptr) {
410 return SOFTBUS_INVALID_PARAM;
411 }
412 std::lock_guard<std::mutex> autoLock(g_lock);
413 std::vector<LeaveLnnRequestInfo *>::iterator iter;
414 for (iter = g_leaveLNNRequestInfo.begin(); iter != g_leaveLNNRequestInfo.end();) {
415 if (strncmp(networkId, (*iter)->networkId, strlen(networkId))) {
416 ++iter;
417 continue;
418 }
419 ClientOnLeaveLNNResult((*iter)->pkgName, networkId, retCode);
420 delete *iter;
421 iter = g_leaveLNNRequestInfo.erase(iter);
422 }
423 return SOFTBUS_OK;
424 }
425
MetaNodeIpcNotifyLeaveResult(const char * networkId,int32_t retCode)426 int32_t MetaNodeIpcNotifyLeaveResult(const char *networkId, int32_t retCode)
427 {
428 if (networkId == nullptr) {
429 return SOFTBUS_INVALID_PARAM;
430 }
431 std::lock_guard<std::mutex> autoLock(g_lock);
432 std::vector<LeaveLnnRequestInfo *>::iterator iter;
433 for (iter = g_leaveMetaNodeRequestInfo.begin(); iter != g_leaveMetaNodeRequestInfo.end();) {
434 if (strncmp(networkId, (*iter)->networkId, strlen(networkId))) {
435 ++iter;
436 continue;
437 }
438 ClientOnLeaveMetaNodeResult((*iter)->pkgName, networkId, retCode);
439 delete *iter;
440 iter = g_leaveMetaNodeRequestInfo.erase(iter);
441 }
442 return SOFTBUS_OK;
443 }
444
LnnIpcNotifyOnlineState(bool isOnline,void * info,uint32_t infoTypeLen)445 int32_t LnnIpcNotifyOnlineState(bool isOnline, void *info, uint32_t infoTypeLen)
446 {
447 return ClinetOnNodeOnlineStateChanged(isOnline, info, infoTypeLen);
448 }
449
LnnIpcNotifyBasicInfoChanged(void * info,uint32_t infoTypeLen,int32_t type)450 int32_t LnnIpcNotifyBasicInfoChanged(void *info, uint32_t infoTypeLen, int32_t type)
451 {
452 return ClinetOnNodeBasicInfoChanged(info, infoTypeLen, type);
453 }
454
LnnIpcNotifyTimeSyncResult(const char * pkgName,const void * info,uint32_t infoTypeLen,int32_t retCode)455 int32_t LnnIpcNotifyTimeSyncResult(const char *pkgName, const void *info, uint32_t infoTypeLen, int32_t retCode)
456 {
457 return ClientOnTimeSyncResult(pkgName, info, infoTypeLen, retCode);
458 }
459
RemoveJoinRequestInfoByPkgName(const char * pkgName)460 static void RemoveJoinRequestInfoByPkgName(const char *pkgName)
461 {
462 std::lock_guard<std::mutex> autoLock(g_lock);
463 std::vector<JoinLnnRequestInfo *>::iterator iter;
464 for (iter = g_joinLNNRequestInfo.begin(); iter != g_joinLNNRequestInfo.end();) {
465 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName))) {
466 ++iter;
467 continue;
468 }
469 delete *iter;
470 iter = g_joinLNNRequestInfo.erase(iter);
471 }
472 }
473
RemoveLeaveRequestInfoByPkgName(const char * pkgName)474 static void RemoveLeaveRequestInfoByPkgName(const char *pkgName)
475 {
476 std::lock_guard<std::mutex> autoLock(g_lock);
477 std::vector<LeaveLnnRequestInfo *>::iterator iter;
478 for (iter = g_leaveLNNRequestInfo.begin(); iter != g_leaveLNNRequestInfo.end();) {
479 if (strncmp(pkgName, (*iter)->pkgName, strlen(pkgName))) {
480 ++iter;
481 continue;
482 }
483 delete *iter;
484 iter = g_leaveLNNRequestInfo.erase(iter);
485 }
486 }
487
BusCenterServerDeathCallback(const char * pkgName)488 void BusCenterServerDeathCallback(const char *pkgName)
489 {
490 if (pkgName == nullptr) {
491 return;
492 }
493 RemoveJoinRequestInfoByPkgName(pkgName);
494 RemoveLeaveRequestInfoByPkgName(pkgName);
495 }