• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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,
49         LnnHeartbeatType hbType, bool isOnlineDirectly, HbRespData *hbResp);
50     int32_t (*onRecvHigherWeight)(const char *udidHash, int32_t weight, ConnectionAddrType type, bool isReElect);
51 } LnnHeartbeatMediumMgrCb;
52 
53 typedef struct {
54     LnnHeartbeatType hbType;
55     bool wakeupFlag;
56     bool isRelay;
57     bool isSyncData;
58     bool isFirstBegin;
59 } LnnHeartbeatSendBeginData;
60 
61 typedef struct {
62     LnnHeartbeatType hbType;
63     bool wakeupFlag;
64     bool isRelay;
65     bool isLastEnd;
66 } LnnHeartbeatSendEndData;
67 
68 typedef struct {
69     LnnHeartbeatType supportType;
70     int32_t (*init)(const LnnHeartbeatMediumMgrCb *callback);
71     int32_t (*onSendOneHbBegin)(const LnnHeartbeatSendBeginData *custData);
72     int32_t (*onSendOneHbEnd)(const LnnHeartbeatSendEndData *custData);
73     int32_t (*onSetMediumParam)(const LnnHeartbeatMediumParam *param);
74     int32_t (*onUpdateSendInfo)(LnnHeartbeatUpdateInfoType type);
75     int32_t (*onStopHbByType)(void);
76     void (*deinit)(void);
77 } LnnHeartbeatMediumMgr;
78 
79 int32_t LnnHbMediumMgrSetParam(const LnnHeartbeatMediumParam *param);
80 int32_t LnnHbMediumMgrSendBegin(LnnHeartbeatSendBeginData *custData);
81 int32_t LnnHbMediumMgrSendEnd(LnnHeartbeatSendEndData *custData);
82 int32_t LnnHbMediumMgrStop(LnnHeartbeatType *type);
83 int32_t LnnHbMediumMgrUpdateSendInfo(LnnHeartbeatUpdateInfoType type);
84 void LnnHbClearRecvList(void);
85 
86 int32_t LnnHbMediumMgrInit(void);
87 void LnnHbMediumMgrDeinit(void);
88 
89 int32_t LnnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr);
90 int32_t LnnUnRegistHeartbeatMediumMgr(LnnHeartbeatMediumMgr *mgr);
91 
92 void LnnDumpHbMgrRecvList(void);
93 void LnnDumpHbOnlineNodeList(void);
94 
95 #ifdef __cplusplus
96 }
97 #endif
98 #endif /* LNN_HEARTBEAT_MEDIUM_MGR_H */
99