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_WIFI_P2P_H 17 #define OHOS_WIFI_P2P_H 18 19 #include "wifi_errcode.h" 20 #include "wifi_p2p_msg.h" 21 #include "i_wifi_p2p_callback.h" 22 23 namespace OHOS { 24 namespace Wifi { 25 class WifiP2p { 26 public: 27 static std::unique_ptr<WifiP2p> CreateWifiP2p(int system_ability_id); 28 static std::unique_ptr<WifiP2p> GetInstance(int system_ability_id); 29 30 virtual ~WifiP2p(); 31 32 /** 33 * @Description Enabling the P2P Mode. 34 * 35 * @return ErrCode - operation result 36 */ 37 virtual ErrCode EnableP2p(void) = 0; 38 39 /** 40 * @Description Disable the P2P mode. 41 * 42 * @return ErrCode - operation result 43 */ 44 virtual ErrCode DisableP2p(void) = 0; 45 46 /** 47 * @Description Start Wi-Fi P2P device search. 48 * 49 * @return ErrCode - operation result 50 */ 51 virtual ErrCode DiscoverDevices(void) = 0; 52 53 /** 54 * @Description Stop Wi-Fi P2P device search. 55 * 56 * @return ErrCode - operation result 57 */ 58 virtual ErrCode StopDiscoverDevices(void) = 0; 59 60 /** 61 * @Description Start the search for the Wi-Fi P2P service. 62 * 63 * @return ErrCode - operation result 64 */ 65 virtual ErrCode DiscoverServices(void) = 0; 66 67 /** 68 * @Description Stop the search for the Wi-Fi P2P service. 69 * 70 * @return ErrCode - operation result 71 */ 72 virtual ErrCode StopDiscoverServices(void) = 0; 73 74 /** 75 * @Description request the P2P service. 76 * 77 * @param device - WifiP2pDevice object 78 * @param request - WifiP2pServiceRequest object 79 * @return ErrCode - operation result 80 */ 81 virtual ErrCode RequestService(const WifiP2pDevice &device, const WifiP2pServiceRequest &request) = 0; 82 83 /** 84 * @Description Register the local P2P service. 85 * 86 * @param srvInfo - WifiP2pServiceInfo object 87 * @return ErrCode - operation result 88 */ 89 virtual ErrCode PutLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 90 91 /** 92 * @Description Delete the local P2P service. 93 * 94 * @param srvInfo - WifiP2pServiceInfo object 95 * @return ErrCode - operation result 96 */ 97 virtual ErrCode DeleteLocalP2pService(const WifiP2pServiceInfo &srvInfo) = 0; 98 99 /** 100 * @Description Enable Wi-Fi P2P listening. 101 * 102 * @param period - period 103 * @param interval - interval 104 * @return ErrCode - operation result 105 */ 106 virtual ErrCode StartP2pListen(int period, int interval) = 0; 107 108 /** 109 * @Description Disable Wi-Fi P2P listening. 110 * 111 * @return ErrCode - operation result 112 */ 113 virtual ErrCode StopP2pListen(void) = 0; 114 115 /** 116 * @Description Creating a P2P Group. 117 * 118 * @param config - WifiP2pConfig object 119 * @return ErrCode - operation result 120 */ 121 virtual ErrCode CreateGroup(const WifiP2pConfig &config) = 0; 122 123 /** 124 * @Description Remove a P2P Group. 125 * 126 * @return ErrCode - operation result 127 */ 128 virtual ErrCode RemoveGroup(void) = 0; 129 130 /** 131 * @Description Delete a p2p Group. 132 * 133 * @param group - WifiP2pGroupInfo object 134 * @return ErrCode - operation result 135 */ 136 virtual ErrCode DeleteGroup(const WifiP2pGroupInfo &group) = 0; 137 138 /** 139 * @Description P2P connection. 140 * 141 * @param config - WifiP2pConfig object 142 * @return ErrCode - operation result 143 */ 144 virtual ErrCode P2pConnect(const WifiP2pConfig &config) = 0; 145 146 /** 147 * @Description Canceling a P2P connection. 148 * 149 * @return ErrCode - operation result 150 */ 151 virtual ErrCode P2pCancelConnect(void) = 0; 152 153 /** 154 * @Description Querying Wi-Fi P2P Connection Information. 155 * 156 * @param linkedInfo - Get the WifiP2pLinkedInfo msg 157 * @return ErrCode - operation result 158 */ 159 virtual ErrCode QueryP2pLinkedInfo(WifiP2pLinkedInfo &linkedInfo) = 0; 160 161 /** 162 * @Description Get the Current Group object. 163 * 164 * @param group - the WifiP2pGroupInfo object 165 * @return ErrCode - operation result 166 */ 167 virtual ErrCode GetCurrentGroup(WifiP2pGroupInfo &group) = 0; 168 169 /** 170 * @Description Obtains the P2P switch status. 171 * 172 * @param status - the P2P switch status 173 * @return ErrCode - operation result 174 */ 175 virtual ErrCode GetP2pEnableStatus(int &status) = 0; 176 177 /** 178 * @Description Obtains the P2P discovery status. 179 * 180 * @param status - the P2P discovery status 181 * @return ErrCode - operation result 182 */ 183 virtual ErrCode GetP2pDiscoverStatus(int &status) = 0; 184 185 /** 186 * @Description Obtains the P2P connection status. 187 * 188 * @param status - the P2P connection status 189 * @return ErrCode - operation result 190 */ 191 virtual ErrCode GetP2pConnectedStatus(int &status) = 0; 192 193 /** 194 * @Description Query the local device information. 195 * 196 * @param devives - Get result of WifiP2pDevice 197 * @return ErrCode - operation result 198 */ 199 virtual ErrCode QueryP2pLocalDevice(WifiP2pDevice &device) = 0; 200 201 /** 202 * @Description Query the information about the found devices. 203 * 204 * @param devices - Get result vector of WifiP2pDevice 205 * @return ErrCode - operation result 206 */ 207 virtual ErrCode QueryP2pDevices(std::vector<WifiP2pDevice> &devices) = 0; 208 209 /** 210 * @Description Query the information about the found groups. 211 * 212 * @param groups - Get result vector of WifiP2pGroupInfo 213 * @return ErrCode - operation result 214 */ 215 virtual ErrCode QueryP2pGroups(std::vector<WifiP2pGroupInfo> &groups) = 0; 216 217 /** 218 * @Description Query the service information. 219 * 220 * @param services - Get result vector of Device 221 * @return ErrCode - operation result 222 */ 223 virtual ErrCode QueryP2pServices(std::vector<WifiP2pServiceInfo> &services) = 0; 224 225 /** 226 * @Description Register callback function. 227 * 228 * @param callback - IWifiP2pCallback object 229 * @return ErrCode - operation result 230 */ 231 virtual ErrCode RegisterCallBack(const sptr<IWifiP2pCallback> &callback) = 0; 232 233 /** 234 * @Description Get supported features 235 * 236 * @param features - return supported features 237 * @return ErrCode - operation result 238 */ 239 virtual ErrCode GetSupportedFeatures(long &features) = 0; 240 241 /** 242 * @Description Check if supported input feature 243 * 244 * @param feature - input feature 245 * @return bool - true if supported, false if unsupported 246 */ 247 virtual bool IsFeatureSupported(long feature) = 0; 248 249 /** 250 * @Description set the device name 251 * 252 * @param deviceName - device name 253 * @return ErrCode - operation result 254 */ 255 virtual ErrCode SetP2pDeviceName(const std::string &deviceName) = 0; 256 257 /** 258 * @Description set p2p wifi display info 259 * 260 * @param wfdInfo - wifi display info 261 * @return ErrCode - operation result 262 */ 263 virtual ErrCode SetP2pWfdInfo(const WifiP2pWfdInfo &wfdInfo) = 0; 264 }; 265 } // namespace Wifi 266 } // namespace OHOS 267 #endif