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 #ifndef OHOS_P2P_ENABLED_STATE_H
16 #define OHOS_P2P_ENABLED_STATE_H
17 
18 #include "state.h"
19 #include "p2p_define.h"
20 #include "p2p_macro.h"
21 #include "wifi_p2p_group_manager.h"
22 #include "wifi_p2p_device_manager.h"
23 
24 namespace OHOS {
25 namespace Wifi {
26 class P2pStateMachine;
27 class P2pEnabledState : public State {
28     FRIEND_GTEST(P2pEnabledState);
29 
30 public:
31     /**
32      * @Description Construct a new P2pEnabledState object
33      * @param None
34      * @return None
35      */
36     P2pEnabledState(P2pStateMachine &stateMachine, WifiP2pGroupManager &groupMgr, WifiP2pDeviceManager &deviceMgr);
37 
38     /**
39      * @Description Destroy the P2pEnabledState object
40      * @param None
41      * @return None
42      */
43     ~P2pEnabledState() = default;
44 
45     /**
46      * @Description - Called when entering state
47      * @param None
48      * @return None
49      */
50     virtual void GoInState() override;
51 
52     /**
53      * @Description - Called when exiting state
54      * @param None
55      * @return None
56      */
57     virtual void GoOutState() override;
58 
59     /**
60      * @Description - Message Processing Function
61      * @param msg - Message object pointer
62      * @return - bool true:success   false:fail
63      */
64     virtual bool ExecuteStateMsg(InternalMessagePtr msg) override;
65 
66 private:
67     /**
68      * @Description - Initializing P2P Information
69      * @param None
70      * @return - bool true:success   false:fail
71      */
72     virtual bool P2pSettingsInitialization();
73 
74     /**
75      * @Description - Initializing P2P Configuration
76      * @param None
77      * @return - bool true:success   false:fail
78      */
79     virtual bool P2pConfigInitialization();
80 
81     /**
82      * @Description Initialization
83      * @param None
84      * @return None
85      */
86     virtual void Init();
87 
88     /**
89      * @Description InitProcessMsg
90      * @param None
91      * @return None
92      */
93     virtual void InitProcessMsg();
94 
95     /**
96      * @Description Process the disable command received by the state machine
97      * @param msg - Message body sent by the state machine
98      * @return - bool true:handle   false:not handle
99      */
100     virtual bool ProcessCmdDisable(InternalMessagePtr msg) const;
101 
102     /**
103      * @Description Process the start listen command received by the state machine
104      * @param msg - Message body sent by the state machine
105      * @return - bool true:handle   false:not handle
106      */
107     virtual bool ProcessCmdStartListen(InternalMessagePtr msg) const;
108 
109     /**
110      * @Description Process the stop listen command received by the state machine
111      * @param msg - Message body sent by the state machine
112      * @return - bool true:handle   false:not handle
113      */
114     virtual bool ProcessCmdStopListen(InternalMessagePtr msg) const;
115 
116     /**
117      * @Description Process the discover peer command received by the state machine
118      * @param msg - Message body sent by the state machine
119      * @return - bool true:handle   false:not handle
120      */
121     virtual bool ProcessCmdDiscPeer(InternalMessagePtr msg) const;
122 
123     /**
124      * @Description Process the stop discover peer command received by the state machine
125      * @param msg - Message body sent by the state machine
126      * @return - bool true:handle   false:not handle
127      */
128     virtual bool ProcessCmdStopDiscPeer(InternalMessagePtr msg) const;
129 
130     /**
131      * @Description Process the device found message received by the state machine
132      * @param msg - Message body sent by the state machine
133      * @return - bool true:handle   false:not handle
134      */
135     virtual bool ProcessDeviceFoundEvt(InternalMessagePtr msg) const;
136 
137     /**
138      * @Description Process the device found message received by the state machine
139      * @param msg - Message body sent by the state machine
140      * @return - bool true:handle   false:not handle
141      */
142     virtual bool ProcessPriDeviceFoundEvt(InternalMessagePtr msg) const;
143     /**
144      * @Description Process the device lost message received by the state machine
145      * @param msg - Message body sent by the state machine
146      * @return - bool true:handle   false:not handle
147      */
148     virtual bool ProcessDeviceLostEvt(InternalMessagePtr msg) const;
149 
150     /**
151      * @Description Process the find stopped message received by the state machine
152      * @param msg - Message body sent by the state machine
153      * @return - bool true:handle   false:not handle
154      */
155     virtual bool ProcessFindStoppedEvt(InternalMessagePtr msg) const;
156 
157     /**
158      * @Description Process the delete group command received by the state machine
159      * @param msg - Message body sent by the state machine
160      * @return - bool true:handle   false:not handle
161      */
162     virtual bool ProcessCmdDeleteGroup(InternalMessagePtr msg) const;
163 
164     /**
165      * @Description Process the add local service command received by the state machine
166      * @param msg - Message body sent by the state machine
167      * @return - bool true:handle   false:not handle
168      */
169     virtual bool ProcessCmdAddLocalService(InternalMessagePtr msg) const;
170 
171     /**
172      * @Description Process the delete local service command received by the state machine
173      * @param msg - Message body sent by the state machine
174      * @return - bool true:handle   false:not handle
175      */
176     virtual bool ProcessCmdDelLocalService(InternalMessagePtr msg) const;
177 
178     /**
179      * @Description Process the discover services command received by the state machine
180      * @param msg - Message body sent by the state machine
181      * @return - bool true:handle   false:not handle
182      */
183     virtual bool ProcessCmdDiscServices(InternalMessagePtr msg) const;
184 
185     /**
186      * @Description Process the stop discover services command received by the state machine
187      * @param msg - Message body sent by the state machine
188      * @return - bool true:handle   false:not handle
189      */
190     virtual bool ProcessCmdStopDiscServices(InternalMessagePtr msg) const;
191 
192     /**
193      * @Description Process the request service command received by the state machine
194      * @param msg - Message body sent by the state machine
195      * @return - bool true:handle   false:not handle
196      */
197     virtual bool ProcessCmdRequestService(InternalMessagePtr msg) const;
198 
199     /**
200      * @Description Process the service discover request message received by the state machine
201      * @param msg - Message body sent by the state machine
202      * @return - bool true:handle   false:not handle
203      */
204     virtual bool ProcessServiceDiscReqEvt(InternalMessagePtr msg) const;
205 
206     /**
207      * @Description Process the service discover response message received by the state machine
208      * @param msg - Message body sent by the state machine
209      * @return - bool true:handle   false:not handle
210      */
211     virtual bool ProcessServiceDiscRspEvt(InternalMessagePtr msg) const;
212 
213     /**
214      * @Description Process the exception timeout message received by the state machine.
215      * @param msg - Message body sent by the state machine
216      * @return true - handle
217      * @return false - not handle
218      */
219     virtual bool ProcessExceptionTimeOut(InternalMessagePtr msg) const;
220 
221     /**
222      * @Description Process the set device name command received by the state machine.
223      *
224      * @param msg - Message body sent by the state machine
225      * @return true - handle
226      * @return false - not handle
227      */
228     virtual bool ProcessCmdSetDeviceName(InternalMessagePtr msg) const;
229 
230     /**
231      * @Description Process the set WFD Info command received by the state machine.
232      *
233      * @param msg - Message body sent by the state machine
234      * @return true - handle
235      * @return false - not handle
236      */
237     virtual bool ProcessCmdSetWfdInfo(InternalMessagePtr msg) const;
238 
239     /**
240      * @Description Process the cancel connect command received by the state machine
241      * @param msg - Message body sent by the state machine
242      * @return - bool true:handle   false:not handle
243      */
244     virtual bool ProcessCmdCancelConnect(InternalMessagePtr msg) const;
245 
246     /**
247      * @Description Process the p2p connect failed command received by the state machine
248      * @param msg - Message body sent by the state machine
249      * @return - bool true:handle   false:not handle
250      */
251     virtual bool ProcessCmdConnectFailed(InternalMessagePtr msg) const;
252 
253     /**
254      * @Description Process the p2p discover device command received by the state machine
255      * @param msg - Message body sent by the state machine
256      * @return - bool true:handle   false:not handle
257      */
258     virtual bool ProcessCmdDiscoverPeers(InternalMessagePtr msg) const;
259 
260     /**
261      * @Description Process the p2p share link increase command received by the state machine
262      * @param msg - Message body sent by the state machine
263      * @return - bool true:handle   false:not handle
264      */
265     virtual bool ProcessCmdIncreaseSharedLink(InternalMessagePtr msg) const;
266 
267     /**
268      * @Description Process the p2p share link decrease command received by the state machine
269      * @param msg - Message body sent by the state machine
270      * @return - bool true:handle   false:not handle
271      */
272     virtual bool ProcessCmdDecreaseSharedLink(InternalMessagePtr msg) const;
273 
274     /**
275      * @Description Process the chr event received by the state machine
276      * @param msg - Message body sent by the state machine
277      * @return - bool true:handle   false:not handle
278      */
279     virtual bool ProcessChrReport(InternalMessagePtr msg) const;
280 private:
281     using ProcessFun = bool (P2pEnabledState::*)(InternalMessagePtr msg) const;
282     std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap;
283     P2pStateMachine &p2pStateMachine;
284     WifiP2pGroupManager &groupManager;
285     WifiP2pDeviceManager &deviceManager;
286 };
287 } // namespace Wifi
288 } // namespace OHOS
289 
290 #endif /* OHOS_P2P_ENABLED_STATE_H */
291