1 /* 2 * Copyright (c) 2022 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 #ifndef LNN_HEARTBEAT_MEDIUM_MGR_H 17 #define LNN_HEARTBEAT_MEDIUM_MGR_H 18 19 #include <stdint.h> 20 21 #include "lnn_heartbeat_utils.h" 22 #include "softbus_common.h" 23 24 #ifdef __cplusplus 25 extern "C" { 26 #endif 27 28 typedef struct { 29 /** Heartbeat media type. For details, see {@link LnnHeartbeatType}. */ 30 LnnHeartbeatType type; 31 union { 32 /** Defines parameters of ble heartbeat. */ 33 struct BleParam { 34 /** minimum time between the start of two consecutive advertising events. */ 35 uint16_t advMinInterval; 36 /** maximum time between the start of two consecutive advertising events. */ 37 uint16_t advMaxInterval; 38 /** Interval between the start of two consecutive scan windows. */ 39 uint16_t scanInterval; 40 /** The duration in which the link layer scans on one channel. */ 41 uint16_t scanWindow; 42 } ble; 43 } info; 44 } LnnHeartbeatMediumParam; 45 46 typedef struct { 47 int32_t weight; 48 int32_t localMasterWeight; 49 } LnnHeartbeatWeight; 50 51 typedef struct { 52 void (*onRelay)(const char *udidHash, ConnectionAddrType type, LnnHeartbeatType hbType); 53 int32_t (*onReceive)(DeviceInfo *device, const LnnHeartbeatWeight *mediumWeight, LnnHeartbeatType hbType, 54 bool isOnlineDirectly, HbRespData *hbResp); 55 int32_t (*onRecvHigherWeight)(const char *udidHash, int32_t weight, ConnectionAddrType type, bool isReElect, 56 bool isPeerScreenOn); 57 void (*onRecvLpInfo)(const char *networkId, uint64_t nowTime); 58 } LnnHeartbeatMediumMgrCb; 59 60 typedef struct { 61 LnnHeartbeatType hbType; 62 bool wakeupFlag; 63 bool isRelay; 64 bool isSyncData; 65 bool isFirstBegin; 66 bool isNeedRestart; 67 bool hasScanRsp; 68 bool isFast; 69 } LnnHeartbeatSendBeginData; 70 71 typedef struct { 72 LnnHeartbeatType hbType; 73 bool wakeupFlag; 74 bool isRelay; 75 bool isLastEnd; 76 } LnnHeartbeatSendEndData; 77 78 typedef struct { 79 LnnHeartbeatType supportType; 80 int32_t (*init)(const LnnHeartbeatMediumMgrCb *callback); 81 int32_t (*onSendOneHbBegin)(const LnnHeartbeatSendBeginData *custData); 82 int32_t (*onSendOneHbEnd)(const LnnHeartbeatSendEndData *custData); 83 int32_t (*onSetMediumParam)(const LnnHeartbeatMediumParam *param); 84 int32_t (*onUpdateSendInfo)(LnnHeartbeatUpdateInfoType type); 85 int32_t (*onStopHbByType)(void); 86 void (*deinit)(void); 87 } LnnHeartbeatMediumMgr; 88 89 int32_t LnnHbMediumMgrSetParam(void *param); 90 int32_t LnnHbMediumMgrSendBegin(LnnHeartbeatSendBeginData *custData); 91 int32_t LnnHbMediumMgrSendEnd(LnnHeartbeatSendEndData *custData); 92 int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type); 93 int32_t LnnHbMediumMgrUpdateSendInfo(LnnHeartbeatUpdateInfoType type); 94 void LnnHbClearRecvList(void); 95 96 int32_t LnnHbMediumMgrInit(void); 97 void LnnHbMediumMgrDeinit(void); 98 99 int32_t LnnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr); 100 int32_t LnnUnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr); 101 102 void LnnDumpHbMgrRecvList(void); 103 void LnnDumpHbOnlineNodeList(void); 104 105 #ifdef __cplusplus 106 } 107 #endif 108 #endif /* LNN_HEARTBEAT_MEDIUM_MGR_H */ 109