1 /*
2  * Copyright (c) 2023 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_WIFI_P2P_MANAGER_H
17 #define OHOS_WIFI_P2P_MANAGER_H
18 
19 #ifdef FEATURE_P2P_SUPPORT
20 #include <mutex>
21 #include <functional>
22 #include "wifi_errcode.h"
23 #include "wifi_internal_msg.h"
24 #include "ip2p_service_callbacks.h"
25 
26 namespace OHOS {
27 namespace Wifi {
28 class WifiP2pManager {
29 public:
30     WifiP2pManager();
31     ~WifiP2pManager() = default;
32 
33     IP2pServiceCallbacks& GetP2pCallback(void);
34     ErrCode AutoStartP2pService();
35     ErrCode AutoStopP2pService();
36     void StopUnloadP2PSaTimer(void);
37     void StartUnloadP2PSaTimer(void);
38     void CloseP2pService(void);
39 
40 private:
41     void InitP2pCallback(void);
42     void DealP2pStateChanged(P2pState bState);
43     void DealP2pPeersChanged(const std::vector<WifiP2pDevice> &vPeers);
44     void DealP2pServiceChanged(const std::vector<WifiP2pServiceInfo> &vServices);
45     void DealP2pConnectionChanged(const WifiP2pLinkedInfo &info);
46     void DealP2pThisDeviceChanged(const WifiP2pDevice &info);
47     void DealP2pDiscoveryChanged(bool bState);
48     void DealP2pGroupsChanged(void);
49     void DealP2pActionResult(P2pActionCallback action, ErrCode code);
50     void DealConfigChanged(CfgType type, char* data, int dataLen);
51     void DealP2pGcJoinGroup(const GcInfo &info);
52     void DealP2pGcLeaveGroup(const GcInfo &info);
53     void IfaceDestoryCallback(std::string &destoryIfaceName, int createIfaceType);
54     void DealP2pPrivatePeersChanged(const std::string &privateInfo);
55 
56 private:
57     IP2pServiceCallbacks mP2pCallback;
58     uint32_t unloadP2PSaTimerId{0};
59     std::mutex unloadP2PSaTimerMutex;
60     std::string ifaceName{""};
61     std::mutex p2pEnableMutex;
62     std::condition_variable p2pEnableCond;
63 };
64 
65 }  // namespace Wifi
66 }  // namespace OHOS
67 #endif
68 #endif // OHOS_WIFI_P2P_MANAGER_H