1 /*
2  * Copyright (c) 2024 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 P2P_ENTITY_STATE_H
16 #define P2P_ENTITY_STATE_H
17 
18 #include "kits/c/wifi_p2p.h"
19 
20 #include "adapter/p2p_adapter.h"
21 #include "p2p_operation.h"
22 
23 namespace OHOS::SoftBus {
24 using P2pCreateGroupParam = P2pAdapter::CreateGroupParam;
25 using P2pConnectParam = P2pAdapter::ConnectParam;
26 using P2pDestroyGroupParam = P2pAdapter::DestroyGroupParam;
27 
28 class P2pEntity;
29 class P2pEntityState {
30 public:
31     P2pEntityState() = default;
32     virtual ~P2pEntityState() = default;
33 
34     virtual void Enter(const std::shared_ptr<P2pOperation> &operation) = 0;
35     virtual void Exit() = 0;
36     virtual std::string GetName() = 0;
37     virtual int CreateGroup(const std::shared_ptr<P2pOperationWrapper<P2pCreateGroupParam>> &operation) = 0;
38     virtual int Connect(const std::shared_ptr<P2pOperationWrapper<P2pConnectParam>> &operation) = 0;
39     virtual int DestroyGroup(const std::shared_ptr<P2pOperationWrapper<P2pDestroyGroupParam>> &operation) = 0;
40     virtual int RemoveLink(const std::shared_ptr<P2pOperationWrapper<P2pDestroyGroupParam>> &operation) = 0;
41 
42     virtual void OnP2pStateChangeEvent(P2pState state) = 0;
PreprocessP2pConnectionChangeEvent(const WifiP2pLinkedInfo & info,const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> & groupInfo)43     virtual void PreprocessP2pConnectionChangeEvent(
44         const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo) {};
45     virtual void OnP2pConnectionChangeEvent(
46         const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo) = 0;
47 
48 protected:
49     static constexpr int TIMER_TIMEOUT = 50;
50 
51     static void ChangeState(P2pEntityState *state, const std::shared_ptr<P2pOperation> &operation);
52 };
53 }
54 #endif
55