1 /* 2 * Copyright (C) 2021-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 OHOS_P2P_GROUP_FORMED_STATE_H 17 #define OHOS_P2P_GROUP_FORMED_STATE_H 18 19 #include "state.h" 20 #include "p2p_define.h" 21 #include "p2p_macro.h" 22 #include "wifi_p2p_group_manager.h" 23 #include "wifi_p2p_device_manager.h" 24 25 namespace OHOS { 26 namespace Wifi { 27 class P2pStateMachine; 28 class GroupFormedState : public State { 29 FRIEND_GTEST(GroupFormedState); 30 31 public: 32 /** 33 * @Description Construct a new Group Formed State object 34 * @param None 35 * @return None 36 */ 37 GroupFormedState(P2pStateMachine &stateMachine, WifiP2pGroupManager &groupMgr, WifiP2pDeviceManager &deviceMgr); 38 39 /** 40 * @Description Destroy the Group Formed State object 41 * @param None 42 * @return None 43 */ 44 ~GroupFormedState() = default; 45 46 /** 47 * @Description - Called when entering state 48 * @param None 49 * @return None 50 */ 51 virtual void GoInState() override; 52 53 /** 54 * @Description - Called when exiting state 55 * @param None 56 * @return None 57 */ 58 virtual void GoOutState() override; 59 60 /** 61 * @Description - Message Processing Function 62 * @param msg - Message object pointer 63 * @return - bool true:success false:fail 64 */ 65 virtual bool ExecuteStateMsg(InternalMessagePtr msg) override; 66 67 private: 68 /** 69 * @Description Initialization 70 * @param None 71 * @return None 72 */ 73 virtual void Init(); 74 75 /** 76 * @Description Process the STA connect message received by the state machine 77 * @param msg - Message body sent by the state machine 78 * @return - bool true:handle false:not handle 79 */ 80 virtual bool ProcessConnectEvt(const InternalMessagePtr msg) const; 81 82 /** 83 * @Description Process the STA disconnect message received by the state machine 84 * @param msg - Message body sent by the state machine 85 * @return - bool true:handle false:not handle 86 */ 87 virtual bool ProcessDisconnectEvt(const InternalMessagePtr msg) const; 88 89 /** 90 * @Description Process the device lost message received by the state machine 91 * @param msg - Message body sent by the state machine 92 * @return - bool true:handle false:not handle 93 */ 94 virtual bool ProcessDeviceLostEvt(const InternalMessagePtr msg) const; 95 96 /** 97 * @Description Process the remove group command received by the state machine 98 * @param msg - Message body sent by the state machine 99 * @return - bool true:handle false:not handle 100 */ 101 virtual bool ProcessCmdRemoveGroup(const InternalMessagePtr msg) const; 102 103 /** 104 * @Description Process the delete group command received by the state machine 105 * @param msg - Message body sent by the state machine 106 * @return - bool true:handle false:not handle 107 */ 108 virtual bool ProcessCmdDeleteGroup(const InternalMessagePtr msg) const; 109 110 /** 111 * @Description Process the group removed message received by the state machine 112 * @param msg - Message body sent by the state machine 113 * @return - bool true:handle false:not handle 114 */ 115 virtual bool ProcessGroupRemovedEvt(const InternalMessagePtr msg) const; 116 117 /** 118 * @Description Process the connect command received by the state machine 119 * @param msg - Message body sent by the state machine 120 * @return - bool true:handle false:not handle 121 */ 122 virtual bool ProcessCmdConnect(const InternalMessagePtr msg) const; 123 124 /** 125 * @Description Process the provision discover message received by the state machine 126 * @param msg - Message body sent by the state machine 127 * @return - bool true:handle false:not handle 128 */ 129 virtual bool ProcessProvDiscEvt(const InternalMessagePtr msg) const; 130 131 /** 132 * @Description Process the group started message received by the state machine 133 * @param msg - Message body sent by the state machine 134 * @return - bool true:handle false:not handle 135 */ 136 virtual bool ProcessGroupStartedEvt(const InternalMessagePtr msg) const; 137 138 /** 139 * @Description Process the discover peer command received by the state machine 140 * @param msg - Message body sent by the state machine 141 * @return - bool true:handle false:not handle 142 */ 143 virtual bool ProcessCmdDiscoverPeer(const InternalMessagePtr msg) const; 144 145 /** 146 * @Description Process the discover services command received by the state machine 147 * @param msg - Message body sent by the state machine 148 * @return - bool true:handle false:not handle 149 */ 150 virtual bool ProcessCmdDiscServices(const InternalMessagePtr msg) const; 151 152 /** 153 * @Description Process the disable command received by the state machine 154 * @param msg - Message body sent by the state machine 155 * @return - bool true:handle false:not handle 156 */ 157 virtual bool ProcessCmdDisable(const InternalMessagePtr msg) const; 158 159 /** 160 * @Description Process the cancel connect command received by the state machine 161 * @param msg - Message body sent by the state machine 162 * @return - bool true:handle false:not handle 163 */ 164 virtual bool ProcessCmdCancelConnect(const InternalMessagePtr msg) const; 165 166 /** 167 * @Description Process the start listen command received by the state machine 168 * @param msg - Message body sent by the state machine 169 * @return - bool true:handle false:not handle 170 */ 171 virtual bool ProcessCmdStartListen(const InternalMessagePtr msg) const; 172 173 /** 174 * @Description Process the remove client command received by the state machine 175 * @param msg - Message body sent by the state machine 176 * @return - bool true:handle false:not handle 177 */ 178 virtual bool ProcessCmdRemoveGroupClient(const InternalMessagePtr msg) const; 179 180 /** 181 * @Description Process the start p2p channel switch 182 * @param msg - Message body sent by the state machine 183 * @return - bool true:handle false:not handle 184 */ 185 virtual bool ProcessCmdChSwitch(const InternalMessagePtr msg) const; 186 187 /** 188 * @Description Process the set p2p gc ip address 189 * @param msg - Message body sent by the state machine 190 * @return - bool true:handle false:not handle 191 */ 192 virtual bool ProcessCmdSetIpAddress(const InternalMessagePtr msg) const; 193 private: 194 P2pStateMachine &p2pStateMachine; 195 WifiP2pGroupManager &groupManager; 196 WifiP2pDeviceManager &deviceManager; 197 using ProcessFun = bool (GroupFormedState::*)(const InternalMessagePtr msg) const; 198 std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap; 199 }; 200 } // namespace Wifi 201 } // namespace OHOS 202 203 #endif /* OHOS_P2P_GROUP_FORMED_STATE_H */ 204