• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_FSM_H
17 #define LNN_HEARTBEAT_FSM_H
18 
19 #include "lnn_heartbeat_medium_mgr.h"
20 #include "lnn_state_machine.h"
21 
22 #ifdef __cplusplus
23 extern "C" {
24 #endif
25 
26 #define PKG_NAME_SIZE_MAX 65
27 
28 typedef enum {
29     STATE_HB_INDEX_MIN = 0,
30     STATE_HB_NONE_INDEX = STATE_HB_INDEX_MIN,
31     STATE_HB_NORMAL_NODE_INDEX,
32     STATE_HB_MASTER_NODE_INDEX,
33     STATE_HB_INDEX_MAX,
34 } LnnHeartbeatState;
35 
36 typedef enum {
37     EVENT_HB_MIN = 0,
38     EVENT_HB_AS_MASTER_NODE,
39     EVENT_HB_AS_NORMAL_NODE,
40     EVENT_HB_IN_NONE_STATE,
41     EVENT_HB_PROCESS_SEND_ONCE,
42     EVENT_HB_SEND_ONE_BEGIN = 5,
43     EVENT_HB_SEND_ONE_END,
44     EVENT_HB_CHECK_DEV_STATUS,
45     EVENT_HB_START_PROCESS,
46     EVENT_HB_STOP_SPECIFIC,
47     EVENT_HB_SET_MEDIUM_PARAM = 10,
48     EVENT_HB_UPDATE_SEND_INFO,
49     EVENT_HB_SCREEN_OFF_CHECK_STATUS,
50     EVENT_HB_CHECK_SLE_DEV_STATUS,
51     EVENT_HB_MAX,
52 } LnnHeartbeatEventType;
53 
54 typedef struct {
55     char fsmName[HB_FSM_NAME_LEN];
56     uint16_t id;
57     LnnHeartbeatState state;
58     LnnHeartbeatStrategyType strategyType;
59     LnnHeartbeatType hbType;
60 
61     ListNode node;
62     FsmStateMachine fsm;
63 } LnnHeartbeatFsm;
64 
65 typedef struct {
66     bool wakeupFlag;
67     bool isRelay;
68     bool isMsdpRange;
69     LnnHeartbeatType hbType;
70     bool *isRemoved;
71 } LnnRemoveSendEndMsgPara;
72 
73 typedef struct {
74     bool hasNetworkId;
75     bool isWakeUp;
76     const char networkId[NETWORK_ID_BUF_LEN];
77     LnnHeartbeatType hbType;
78     ConnectionAddrType addrType;
79     uint64_t checkDelay;
80 } LnnCheckDevStatusMsgPara;
81 
82 typedef struct {
83     bool isRelay;
84     bool isSyncData;
85     bool isNeedRestart;
86     bool hasScanRsp;
87     bool isFirstBegin;
88     bool isFast;
89     bool isDirectBoardcast;
90     bool isMsdpRange;
91     char networkId[NETWORK_ID_BUF_LEN];
92     LnnHeartbeatType hbType;
93     LnnHeartbeatStrategyType strategyType;
94     int32_t duration;
95     uint64_t checkDelay;
96     char callerId[PKG_NAME_SIZE_MAX];
97 } LnnProcessSendOnceMsgPara;
98 
99 int32_t LnnStartHeartbeatFsm(LnnHeartbeatFsm *hbFsm);
100 int32_t LnnStopHeartbeatFsm(LnnHeartbeatFsm *hbFsm);
101 
102 int32_t LnnPostNextSendOnceMsgToHbFsm(
103     LnnHeartbeatFsm *hbFsm, const LnnProcessSendOnceMsgPara *para, uint64_t delayMillis);
104 int32_t LnnPostSendBeginMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatType type, bool wakeupFlag,
105     LnnProcessSendOnceMsgPara *msgPara, uint64_t delayMillis);
106 int32_t LnnPostSendEndMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatSendEndData *custData, uint64_t delayMillis);
107 int32_t LnnPostStartMsgToHbFsm(LnnHeartbeatFsm *hbFsm, uint64_t delayMillis);
108 int32_t LnnPostStopMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatType type);
109 int32_t LnnPostTransStateMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatEventType evtType);
110 int32_t LnnPostSetMediumParamMsgToHbFsm(LnnHeartbeatFsm *hbFsm, const LnnHeartbeatMediumParam *para);
111 int32_t LnnPostCheckDevStatusMsgToHbFsm(
112     LnnHeartbeatFsm *hbFsm, const LnnCheckDevStatusMsgPara *para, uint64_t delayMillis);
113 int32_t LnnPostUpdateSendInfoMsgToHbFsm(LnnHeartbeatFsm *hbFsm, LnnHeartbeatUpdateInfoType type);
114 int32_t LnnPostScreenOffCheckDevMsgToHbFsm(
115     LnnHeartbeatFsm *hbFsm, const LnnCheckDevStatusMsgPara *para, uint64_t delayMillis);
116 int32_t LnnPostSleCheckDevStatusMsgToHbFsm(
117     LnnHeartbeatFsm *hbFsm, const LnnCheckDevStatusMsgPara *para, uint64_t delayMillis);
118 
119 void LnnRemoveSendEndMsg(LnnHeartbeatFsm *hbFsm, LnnProcessSendOnceMsgPara *msg, bool wakeupFlag, bool *isRemoved);
120 void LnnRemoveCheckDevStatusMsg(LnnHeartbeatFsm *hbFsm, LnnCheckDevStatusMsgPara *msgPara);
121 void LnnRemoveScreenOffCheckStatusMsg(LnnHeartbeatFsm *hbFsm, LnnCheckDevStatusMsgPara *msgPara);
122 void LnnRemoveProcessSendOnceMsg(
123     LnnHeartbeatFsm *hbFsm, LnnHeartbeatType hbType, LnnHeartbeatStrategyType strategyType);
124 void LnnRemoveSleCheckStatusMsg(LnnHeartbeatFsm *hbFsm, LnnCheckDevStatusMsgPara *msgPara);
125 
126 LnnHeartbeatFsm *LnnCreateHeartbeatFsm(void);
127 void LnnDestroyHeartbeatFsm(LnnHeartbeatFsm *hbFsm);
128 
129 #ifdef __cplusplus
130 }
131 #endif
132 #endif /* LNN_HEARTBEAT_FSM_H */
133