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