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 "softbus_common.h" 22 #include "lnn_heartbeat_utils.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 void (*onRelay)(const char *udidHash, ConnectionAddrType type, LnnHeartbeatType hbType); 48 int32_t (*onReceive)(DeviceInfo *device, int32_t weight, int32_t localMasterWeight, LnnHeartbeatType hbType); 49 int32_t (*onRecvHigherWeight)(const char *udidHash, int32_t weight, ConnectionAddrType type, bool isReElect); 50 } LnnHeartbeatMediumMgrCb; 51 52 typedef struct { 53 LnnHeartbeatType hbType; 54 bool wakeupFlag; 55 bool isRelay; 56 } LnnHeartbeatCustSendData; 57 58 typedef struct { 59 LnnHeartbeatType supportType; 60 int32_t (*init)(const LnnHeartbeatMediumMgrCb *callback); 61 int32_t (*onSendOneHbBegin)(const LnnHeartbeatCustSendData *custData); 62 int32_t (*onSendOneHbEnd)(void); 63 int32_t (*onSetMediumParam)(const LnnHeartbeatMediumParam *param); 64 int32_t (*onUpdateSendInfo)(LnnHeartbeatUpdateInfoType type); 65 int32_t (*onStopHbByType)(void); 66 void (*deinit)(void); 67 } LnnHeartbeatMediumMgr; 68 69 int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param); 70 int32_t LnnHbMediumMgrSendBegin(LnnHeartbeatCustSendData *custData); 71 int32_t LnnHbMediumMgrSendEnd(LnnHeartbeatType *type); 72 int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type); 73 int32_t LnnHbMediumMgrUpdateSendInfo(LnnHeartbeatUpdateInfoType type); 74 75 int32_t LnnHbMediumMgrInit(void); 76 void LnnHbMediumMgrDeinit(void); 77 78 int32_t LnnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr); 79 int32_t LnnUnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr); 80 81 void LnnDumpHbMgrRecvList(void); 82 void LnnDumpHbOnlineNodeList(void); 83 84 #ifdef __cplusplus 85 } 86 #endif 87 #endif /* LNN_HEARTBEAT_MEDIUM_MGR_H */ 88