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_PROVISION_DISCOVERY_STATE_H
16 #define OHOS_P2P_PROVISION_DISCOVERY_STATE_H
17 
18 #include "state.h"
19 #include "p2p_define.h"
20 #include "wifi_p2p_group_manager.h"
21 #include "wifi_p2p_device_manager.h"
22 
23 namespace OHOS {
24 namespace Wifi {
25 class P2pStateMachine;
26 class ProvisionDiscoveryState : public State {
27     FRIEND_GTEST(ProvisionDiscoveryState);
28 
29 public:
30     /**
31      * @Description Construct a new Provision Discovery State object
32      * @param None
33      * @return None
34      */
35     ProvisionDiscoveryState(P2pStateMachine &stateMachine, WifiP2pGroupManager &setGroupMgr,
36         WifiP2pDeviceManager &setDeviceMgr);
37 
38     /**
39      * @Description Destroy the Provision Discovery State object
40      * @param None
41      * @return None
42      */
43     ~ProvisionDiscoveryState() = 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 Initialization
69      * @param None
70      * @return None
71      */
72     virtual void Init();
73 
74     /**
75      * @Description Process the discover peer command received by the state machine
76      * @param msg - Message body sent by the state machine
77      * @return - bool true:handle   false:not handle
78      */
79     virtual bool ProcessCmdDiscoverPeer(InternalMessagePtr msg) const;
80 
81     /**
82      * @Description Process the discover services command received by the state machine
83      * @param msg - Message body sent by the state machine
84      * @return - bool true:handle   false:not handle
85      */
86     virtual bool ProcessCmdDiscServices(InternalMessagePtr msg) const;
87 
88     /**
89      * @Description Process the start listen command received by the state machine
90      * @param msg - Message body sent by the state machine
91      * @return - bool true:handle   false:not handle
92      */
93     virtual bool ProcessCmdStartListen(InternalMessagePtr msg) const;
94 
95     /**
96      * @Description Process the provision discover pbc response message 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 ProcessProvDiscPbcRspEvt(InternalMessagePtr msg) const;
101 
102     /**
103      * @Description Process the provision discover enter pin message 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 ProcessProvDiscEnterPinEvt(InternalMessagePtr msg) const;
108 
109     /**
110      * @Description Process the provision discover show pin message 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 ProcessProvDiscShowPinEvt(InternalMessagePtr msg) const;
115 
116     /**
117      * @Description Process the provision discover failure message 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 ProcessProvDiscFailEvt(InternalMessagePtr msg) const;
122 
123     /**
124      * @Description Process the cancel connect message 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 ProcessCmdCancelConnect(InternalMessagePtr msg) const;
129 
130 private:
131     using ProcessFun = bool (ProvisionDiscoveryState::*)(InternalMessagePtr msg) const;
132     std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap;
133     P2pStateMachine &p2pStateMachine;
134     WifiP2pGroupManager &groupManager;
135     WifiP2pDeviceManager &deviceManager;
136 };
137 } // namespace Wifi
138 } // namespace OHOS
139 
140 #endif /* OHOS_P2P_PROVISION_DISCOVERY_STATE_H */
141