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_GROUP_NEGOTIATION_STATE_H 16 #define OHOS_P2P_GROUP_NEGOTIATION_STATE_H 17 18 #include "state.h" 19 #include "p2p_define.h" 20 #include "p2p_macro.h" 21 #include "wifi_p2p_device_manager.h" 22 #include "wifi_p2p_group_manager.h" 23 24 namespace OHOS { 25 namespace Wifi { 26 class P2pStateMachine; 27 class GroupNegotiationState : public State { 28 FRIEND_GTEST(GroupNegotiationState); 29 30 public: 31 /** 32 * @Description Construct a new Group Negotiation State object 33 * @param None 34 * @return None 35 */ 36 GroupNegotiationState(P2pStateMachine &stateMachine, WifiP2pGroupManager &groupMgr, 37 WifiP2pDeviceManager &deviceMgr); 38 39 /** 40 * @Description Destroy the Group Negotiation State object 41 * @param None 42 * @return None 43 */ 44 ~GroupNegotiationState() = 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 Process the negotiation success message received by the state machine 70 * @param msg - Message body sent by the state machine 71 * @return - bool true:handle false:not handle 72 */ 73 virtual bool ProcessNegotSucessEvt(InternalMessagePtr msg) const; 74 75 /** 76 * @Description Process the group formation success 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 ProcessGroupFormationSuccessEvt(InternalMessagePtr msg) const; 81 82 /** 83 * @Description Process the group started 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 ProcessGroupStartedEvt(InternalMessagePtr msg) const; 88 89 /** 90 * @Description Process the group formation fail 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 ProcessGroupFormationFailEvt(InternalMessagePtr msg) const; 95 96 /** 97 * @Description Process the negotiation fail message 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 ProcessNegotFailEvt(InternalMessagePtr msg) const; 102 103 /** 104 * @Description Process the invitation result message 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 ProcessInvitationResultEvt(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(InternalMessagePtr msg) const; 116 117 /** 118 * @Description Process remvoe group message 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 ProcessCmdRemoveGroup(InternalMessagePtr msg) const; 123 124 /** 125 * @Description Initialization 126 * @param None 127 * @return None 128 */ 129 virtual void Init(); 130 131 void DoDhcpInGroupStart(void) const; 132 private: 133 using ProcessFun = bool (GroupNegotiationState::*)(InternalMessagePtr msg) const; 134 std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap; 135 P2pStateMachine &p2pStateMachine; 136 WifiP2pGroupManager &groupManager; 137 WifiP2pDeviceManager &deviceManager; 138 }; 139 } // namespace Wifi 140 } // namespace OHOS 141 142 #endif /* OHOS_P2P_GROUP_NEGOTIATION_STATE_H */ 143