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 
16 #ifndef P2P_DESTROY_GROUP_STATE_H
17 #define P2P_DESTROY_GROUP_STATE_H
18 
19 #include "p2p_entity_state.h"
20 #include "timer.h"
21 
22 namespace OHOS::SoftBus {
23 class P2pDestroyGroupState : public P2pEntityState {
24 public:
25     static P2pDestroyGroupState *Instance();
GetName()26     std::string GetName() override { return "P2pDestroyGroupState"; }
27     void Enter(const std::shared_ptr<P2pOperation> &operation) override;
28     void Exit() override;
29 
30     int CreateGroup(const std::shared_ptr<P2pOperationWrapper<P2pCreateGroupParam>> &operation) override;
31     int Connect(const std::shared_ptr<P2pOperationWrapper<P2pConnectParam>> &operation) override;
32     int DestroyGroup(const std::shared_ptr<P2pOperationWrapper<P2pDestroyGroupParam>> &operation) override;
33     int RemoveLink(const std::shared_ptr<P2pOperationWrapper<P2pDestroyGroupParam>> &operation) override;
34 
35     void OnP2pStateChangeEvent(P2pState state) override;
36     void OnP2pConnectionChangeEvent(
37         const WifiP2pLinkedInfo &info, const std::shared_ptr<P2pAdapter::WifiDirectP2pGroupInfo> &groupInfo) override;
38     void OnTimeout();
39 
40 private:
41     static constexpr int DESTROY_GROUP_TIMEOUT_MS = 2000;
42     P2pDestroyGroupState();
43 
44     std::shared_ptr<P2pOperation> operation_;
45     OHOS::Utils::Timer timer_;
46 };
47 } // namespace OHOS::SoftBus
48 #endif