• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_OPERATING_STATE_H
17 #define OHOS_P2P_GROUP_OPERATING_STATE_H
18 
19 #include "state.h"
20 #include "p2p_define.h"
21 #include "wifi_p2p_group_manager.h"
22 #include "wifi_p2p_device_manager.h"
23 #include "ienhance_service.h"
24 
25 namespace OHOS {
26 namespace Wifi {
27 class P2pStateMachine;
28 class P2pGroupOperatingState : public State {
29     FRIEND_GTEST(P2pGroupOperatingState);
30 
31 public:
32     /* *
33      * @Description Construct a new P2pGroupOperatingState object
34      * @param None
35      * @return None
36      */
37     P2pGroupOperatingState(P2pStateMachine &stateMachine, WifiP2pGroupManager &groupMgr,
38         WifiP2pDeviceManager &deviceMgr);
39 
40     /**
41      * @Description Destroy the P2pGroupOperatingState object
42      * @param None
43      * @return None
44      */
45     ~P2pGroupOperatingState() = default;
46 
47     /**
48      * @Description - Called when entering state
49      * @param None
50      * @return None
51      */
52     virtual void GoInState() override;
53 
54     /**
55      * @Description - Called when exiting state
56      * @param None
57      * @return None
58      */
59     virtual void GoOutState() override;
60 
61     /**
62      * @Description - Message Processing Function
63      * @param msg - Message object pointer
64      * @return - bool true:success   false:fail
65      */
66     virtual bool ExecuteStateMsg(InternalMessagePtr msg) override;
67 
68     /**
69      * @Description Set EnhanceService to p2p service
70      *
71      * @param enhanceService IEnhanceService object
72      * @return success: WIFI_OPT_SUCCESS, failed: WIFI_OPT_FAILED
73      */
74     virtual void SetEnhanceService(IEnhanceService* enhanceService);
75 
76 private:
77     /**
78      * @Description Initialization
79      * @param None
80      * @return None
81      */
82     virtual void Init();
83 
84     /**
85      * @Description Process the create group command received by the state machine
86      * @param msg - Message body sent by the state machine
87      * @return - bool true:handle   false:not handle
88      */
89     virtual bool ProcessCmdCreateGroup(const InternalMessagePtr msg) const;
90 
91     /**
92      * @Description Process the group started message received by the state machine
93      * @param msg - Message body sent by the state machine
94      * @return - bool true:handle   false:not handle
95      */
96     virtual bool ProcessGroupStartedEvt(const InternalMessagePtr msg) const;
97 
98     /**
99      * @Description Process the create group timeout message received by the state machine
100      * @param msg - Message body sent by the state machine
101      * @return - bool true:handle   false:not handle
102      */
103     virtual bool ProcessCreateGroupTimeOut(const InternalMessagePtr msg) const;
104 
105     /**
106      * @Description Process the group removed message received by the state machine
107      * @param msg - Message body sent by the state machine
108      * @return - bool true:handle   false:not handle
109      */
110     virtual bool ProcessGroupRemovedEvt(const InternalMessagePtr msg) const;
111 
112     /**
113      * @Description Process the disable command received by the state machine
114      * @param msg - Message body sent by the state machine
115      * @return - bool true:handle   false:not handle
116      */
117     virtual bool ProcessCmdDisable(const InternalMessagePtr msg) const;
118 
119     /**
120      * @Description Process the remove group command received by the state machine
121      * @param msg - Message body sent by the state machine
122      * @return - bool true:handle   false:not handle
123      */
124     virtual bool ProcessCmdRemoveGroup(const InternalMessagePtr msg) const;
125 
126     /**
127      * @Description Process the delete group command received by the state machine
128      * @param msg - Message body sent by the state machine
129      * @return - bool true:handle   false:not handle
130      */
131     virtual bool ProcessCmdDeleteGroup(const InternalMessagePtr msg) const;
132 
133     /**
134      * @Description Process the hid2d create group command received by the state machine
135      * @param msg - Message body sent by the state machine
136      * @return - bool true:handle   false:not handle
137      */
138     virtual bool ProcessCmdHid2dCreateGroup(const InternalMessagePtr msg) const;
139 
140 private:
141     using ProcessFun = bool (P2pGroupOperatingState::*)(const InternalMessagePtr msg) const;
142     std::map<P2P_STATE_MACHINE_CMD, ProcessFun> mProcessFunMap;
143     P2pStateMachine &p2pStateMachine;
144     WifiP2pGroupManager &groupManager;
145     WifiP2pDeviceManager &deviceManager;
146     IEnhanceService *enhanceService_ = nullptr;
147 };
148 } // namespace Wifi
149 } // namespace OHOS
150 
151 #endif /* OHOS_P2P_GROUP_OPERATING_STATE_H */
152