notify networkId change

Signed-off-by: chenbotong <chenbotong1@huawei.com>
This commit is contained in:
chenbotong 2024-01-02 11:33:44 +08:00
parent 142a4b549c
commit ac03eb344c
3 changed files with 26 additions and 0 deletions

View File

@ -20,6 +20,7 @@
#include "anonymizer.h"
#include "auth_device_common_key.h"
#include "bus_center_event.h"
#include "bus_center_manager.h"
#include "lnn_cipherkey_manager.h"
#include "lnn_decision_db.h"
@ -92,6 +93,7 @@ static void LnnRestoreLocalDeviceInfo()
if (LnnUpdateLocalNetworkId(info.networkId) != SOFTBUS_OK) {
LNN_LOGE(LNN_LEDGER, "set networkId fail");
}
LnnNotifyNetworkIdChangeEvent(info.networkId);
}
AuthLoadDeviceKey();
if (LnnLoadRemoteDeviceInfo() != SOFTBUS_OK) {

View File

@ -50,6 +50,7 @@ typedef enum {
LNN_EVENT_NETWORK_STATE_CHANGED,
LNN_EVENT_SINGLE_NETWORK_OFFLINE,
LNN_EVENT_NODE_HB_REPEAT_CYCLE,
LNN_EVENT_NETWORKID_CHANGED,
LNN_EVENT_TYPE_MAX,
} LnnEventType;
@ -204,6 +205,11 @@ typedef struct {
const char *udid;
} LnnSingleNetworkOffLineEvent;
typedef struct {
LnnEventBasicInfo basic;
char networkId[NETWORK_ID_BUF_LEN];
} LnnNetworkIdChangedEvent;
typedef void (*LnnEventHandler)(const LnnEventBasicInfo *info);
int32_t LnnInitBusCenterEvent(void);
@ -244,6 +250,8 @@ void LnnNotifyNodeAddressChanged(const char *addr, const char *networkId, bool i
void LnnNotifyNetworkStateChanged(SoftBusNetworkState state);
void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basicInfo);
void LnnNotifyNetworkIdChangeEvent(const char *networkId);
void LnnNotifyHBRepeat(void);
#ifdef __cplusplus

View File

@ -119,6 +119,7 @@ static void HandleNetworkUpdateMessage(SoftBusMessage *msg)
return;
}
LnnSetLocalStrInfo(STRING_KEY_NETWORKID, networkId);
LnnNotifyNetworkIdChangeEvent(networkId);
LNN_LOGD(LNN_EVENT, "offline exceted 5min, process networkId update event");
}
@ -628,6 +629,21 @@ void LnnNotifySingleOffLineEvent(const ConnectionAddr *addr, NodeBasicInfo *basi
NotifyEvent((const LnnEventBasicInfo *)&event);
}
void LnnNotifyNetworkIdChangeEvent(const char *networkId)
{
if (networkId == NULL) {
LNN_LOGW(LNN_EVENT, "networkId is null");
return;
}
LnnNetworkIdChangedEvent eventInfo;
(void)memset_s(&eventInfo, sizeof(eventInfo), 0, sizeof(eventInfo));
eventInfo.basic.event = LNN_EVENT_NETWORKID_CHANGED;
if (strcpy_s(eventInfo.networkId, NETWORK_ID_BUF_LEN, networkId) != EOK) {
return;
}
NotifyEvent((LnnEventBasicInfo *)&eventInfo);
}
int32_t LnnInitBusCenterEvent(void)
{
int32_t i;