1 /*
2 * Copyright (C) 2025 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 #include "ohos.wifiManager.proj.hpp"
17 #include "ohos.wifiManager.impl.hpp"
18 #include "taihe/runtime.hpp"
19 #include "stdexcept"
20
21 #include "define.h"
22 #include "wifi_callback_taihe.h"
23 #include "wifi_errorcode_taihe.h"
24 using namespace OHOS::Wifi;
25 DEFINE_WIFILOG_LABEL("WifiManagerTaihe");
26 static std::shared_ptr<WifiDevice> g_wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID);
27 std::shared_ptr<WifiScan> g_wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID);
28 static std::shared_ptr<WifiHotspot> g_wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID);
29 std::shared_ptr<WifiP2p> g_wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID);
30 namespace {
MakeTmpWifiScanInfo(WifiScanInfo scanInfo)31 ::ohos::wifiManager::WifiScanInfo MakeTmpWifiScanInfo(WifiScanInfo scanInfo)
32 {
33 return {scanInfo.ssid, scanInfo.bssid,
34 static_cast<::ohos::wifiManager::WifiSecurityType::key_t>(scanInfo.securityType),
35 scanInfo.rssi, scanInfo.band,
36 static_cast<::ohos::wifiManager::WifiCategory::key_t>(scanInfo.supportedWifiCategory)};
37 }
38
MakeWifiLinkedInfo(WifiLinkedInfo linkedInfo)39 ::ohos::wifiManager::WifiLinkedInfo MakeWifiLinkedInfo(WifiLinkedInfo linkedInfo)
40 {
41 ::ohos::wifiManager::ConnState connState =
42 static_cast<::ohos::wifiManager::ConnState::key_t>(linkedInfo.connState);
43 ::ohos::wifiManager::WifiCategory supportedWifiCategory =
44 static_cast<::ohos::wifiManager::WifiCategory::key_t>(linkedInfo.supportedWifiCategory);
45 return {linkedInfo.ssid, linkedInfo.bssid, linkedInfo.rssi, linkedInfo.band,
46 linkedInfo.macAddress, connState, supportedWifiCategory};
47 }
48
MakeIpInfo(int32_t ipAddress)49 ::ohos::wifiManager::IpInfo MakeIpInfo(int32_t ipAddress)
50 {
51 return {ipAddress};
52 }
53
MakeIpv6Info(::taihe::string_view linkIpv6Address)54 ::ohos::wifiManager::Ipv6Info MakeIpv6Info(::taihe::string_view linkIpv6Address)
55 {
56 return {linkIpv6Address};
57 }
58
MakeTmpStationInfo()59 ::ohos::wifiManager::StationInfo MakeTmpStationInfo()
60 {
61 return {""};
62 }
63
IsConnected()64 bool IsConnected()
65 {
66 bool isConnected = false;
67 if (g_wifiDevicePtr == nullptr) {
68 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
69 return static_cast<ani_boolean>(isConnected);
70 }
71 ErrCode ret = g_wifiDevicePtr->IsConnected(isConnected);
72 if (ret != WIFI_OPT_SUCCESS) {
73 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
74 }
75 return static_cast<ani_boolean>(isConnected);
76 }
77
IsWifiActive()78 bool IsWifiActive()
79 {
80 bool activeStatus = false;
81 if (g_wifiDevicePtr == nullptr) {
82 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
83 return static_cast<ani_boolean>(activeStatus);
84 }
85 ErrCode ret = g_wifiDevicePtr->IsWifiActive(activeStatus);
86 if (ret != WIFI_OPT_SUCCESS) {
87 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
88 }
89 return static_cast<ani_boolean>(activeStatus);
90 }
91
GetLinkedInfoSync()92 ::ohos::wifiManager::WifiLinkedInfo GetLinkedInfoSync()
93 {
94 WifiLinkedInfo linkedInfo;
95 if (g_wifiDevicePtr == nullptr) {
96 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
97 ::ohos::wifiManager::WifiLinkedInfo errorResult = MakeWifiLinkedInfo(linkedInfo);
98 return errorResult;
99 }
100 ErrCode ret = g_wifiDevicePtr->GetLinkedInfo(linkedInfo);
101 if (ret != WIFI_OPT_SUCCESS) {
102 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
103 }
104 return MakeWifiLinkedInfo(linkedInfo);
105 }
106
GetSignalLevel(double rssi,double band)107 double GetSignalLevel(double rssi, double band)
108 {
109 int level = -1;
110 int tmpRssi = static_cast<int>(rssi);
111 int tmpBand = static_cast<int>(band);
112 if (g_wifiDevicePtr == nullptr) {
113 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
114 return 0.0;
115 }
116 ErrCode ret = g_wifiDevicePtr->GetSignalLevel(tmpRssi, tmpBand, level);
117 if (ret != WIFI_OPT_SUCCESS) {
118 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
119 }
120 return static_cast<ani_int>(level);
121 }
122
GetIpInfo()123 ::ohos::wifiManager::IpInfo GetIpInfo()
124 {
125 IpInfo ipInfo;
126 if (g_wifiDevicePtr == nullptr) {
127 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
128 ::ohos::wifiManager::IpInfo errorResult = MakeIpInfo(ipInfo.ipAddress);
129 return errorResult;
130 }
131 ErrCode ret = g_wifiDevicePtr->GetIpInfo(ipInfo);
132 if (ret != WIFI_OPT_SUCCESS) {
133 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
134 }
135 ::ohos::wifiManager::IpInfo result = MakeIpInfo(ipInfo.ipAddress);
136 return result;
137 }
138
GetIpv6Info()139 ::ohos::wifiManager::Ipv6Info GetIpv6Info()
140 {
141 IpV6Info ipInfo;
142 if (g_wifiDevicePtr == nullptr) {
143 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
144 ::ohos::wifiManager::Ipv6Info errorResult = MakeIpv6Info(ipInfo.linkIpV6Address);
145 return errorResult;
146 }
147 ErrCode ret = g_wifiDevicePtr->GetIpv6Info(ipInfo);
148 if (ret != WIFI_OPT_SUCCESS) {
149 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
150 }
151 ::ohos::wifiManager::Ipv6Info result = MakeIpv6Info(ipInfo.linkIpV6Address);
152 return result;
153 }
154
IsOpenSoftApAllowed()155 bool IsOpenSoftApAllowed()
156 {
157 bool isSupported = false;
158 if (g_wifiHotspotPtr == nullptr) {
159 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_CORE);
160 return static_cast<ani_boolean>(isSupported);
161 }
162 ErrCode ret = g_wifiHotspotPtr->IsOpenSoftApAllowed(isSupported);
163 if (ret != WIFI_OPT_SUCCESS) {
164 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_AP_CORE);
165 }
166 return static_cast<ani_boolean>(isSupported);
167 }
168
GetScanInfoList()169 ::taihe::array<::ohos::wifiManager::WifiScanInfo> GetScanInfoList()
170 {
171 bool compatible = false;
172 std::vector<WifiScanInfo> scanInfos;
173 std::vector<::ohos::wifiManager::WifiScanInfo> result;
174 if (g_wifiScanPtr == nullptr) {
175 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
176 return ::taihe::array<::ohos::wifiManager::WifiScanInfo>(
177 taihe::copy_data_t{}, result.data(), result.size());
178 }
179 ErrCode ret = g_wifiScanPtr->GetScanInfoList(scanInfos, compatible);
180 if (ret != WIFI_OPT_SUCCESS) {
181 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
182 }
183 WIFI_LOGI("GetScanInfoList, size: %{public}zu", scanInfos.size());
184 for (WifiScanInfo scanInfo : scanInfos) {
185 ::ohos::wifiManager::WifiScanInfo tmpInfo = MakeTmpWifiScanInfo(scanInfo);
186 result.emplace_back(tmpInfo);
187 }
188 return ::taihe::array<::ohos::wifiManager::WifiScanInfo>(taihe::copy_data_t{}, result.data(), result.size());
189 }
190
IsMeteredHotspot()191 bool IsMeteredHotspot()
192 {
193 bool isMeteredHotspot = false;
194 if (g_wifiDevicePtr == nullptr) {
195 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
196 return static_cast<ani_boolean>(isMeteredHotspot);
197 }
198 ErrCode ret = g_wifiDevicePtr->IsMeteredHotspot(isMeteredHotspot);
199 if (ret != WIFI_OPT_SUCCESS) {
200 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
201 }
202 return static_cast<ani_boolean>(isMeteredHotspot);
203 }
204
GetWifiDetailState()205 ::ohos::wifiManager::WifiDetailState GetWifiDetailState()
206 {
207 WifiDetailState state = WifiDetailState::STATE_UNKNOWN;
208 if (g_wifiDevicePtr == nullptr) {
209 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
210 return static_cast<::ohos::wifiManager::WifiDetailState::key_t>(state);
211 }
212 ErrCode ret = g_wifiDevicePtr->GetWifiDetailState(state);
213 if (ret != WIFI_OPT_SUCCESS) {
214 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
215 }
216 return static_cast<::ohos::wifiManager::WifiDetailState::key_t>(state);
217 }
218
StationInfoToTaihe(::ohos::wifiManager::StationInfo & tmpInfo,StationInfo stationInfo)219 void StationInfoToTaihe(::ohos::wifiManager::StationInfo &tmpInfo, StationInfo stationInfo)
220 {
221 tmpInfo.macAddress = stationInfo.bssid;
222 }
223
GetStations()224 ::taihe::array<::ohos::wifiManager::StationInfo> GetStations()
225 {
226 std::vector<StationInfo> vecStationInfo;
227 std::vector<::ohos::wifiManager::StationInfo> result;
228 if (g_wifiHotspotPtr == nullptr) {
229 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_CORE);
230 return ::taihe::array<::ohos::wifiManager::StationInfo>(
231 taihe::copy_data_t{}, result.data(), result.size());
232 }
233 ErrCode ret = g_wifiHotspotPtr->GetStationList(vecStationInfo);
234 if (ret != WIFI_OPT_SUCCESS) {
235 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_AP_CORE);
236 }
237 WIFI_LOGI("Get station list size: %{public}zu", vecStationInfo.size());
238 for (StationInfo stationInfo : vecStationInfo) {
239 ::ohos::wifiManager::StationInfo tmpInfo = MakeTmpStationInfo();
240 StationInfoToTaihe(tmpInfo, stationInfo);
241 result.emplace_back(tmpInfo);
242 }
243 return ::taihe::array<::ohos::wifiManager::StationInfo>(taihe::copy_data_t{}, result.data(), result.size());
244 }
245
EnableWifi()246 void EnableWifi()
247 {
248 if (g_wifiDevicePtr == nullptr) {
249 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
250 return;
251 }
252 ErrCode ret = g_wifiDevicePtr->EnableWifi();
253 if (ret != WIFI_OPT_SUCCESS) {
254 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
255 }
256 }
257
DisableWifi()258 void DisableWifi()
259 {
260 if (g_wifiDevicePtr == nullptr) {
261 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
262 return;
263 }
264 ErrCode ret = g_wifiDevicePtr->DisableWifi();
265 if (ret != WIFI_OPT_SUCCESS) {
266 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
267 }
268 }
269
EnableSemiWifi()270 void EnableSemiWifi()
271 {
272 if (g_wifiDevicePtr == nullptr) {
273 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
274 return;
275 }
276 ErrCode ret = g_wifiDevicePtr->EnableSemiWifi();
277 if (ret != WIFI_OPT_SUCCESS) {
278 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
279 }
280 }
281
282 OHOS::sptr<WifiIdlDeviceEventCallback> wifiDeviceCallback =
283 OHOS::sptr<WifiIdlDeviceEventCallback>(new (std::nothrow) WifiIdlDeviceEventCallback());
284
285 OHOS::sptr<WifiIdlScanEventCallback> wifiScanCallback =
286 OHOS::sptr<WifiIdlScanEventCallback>(new (std::nothrow) WifiIdlScanEventCallback());
287
288 OHOS::sptr<WifiIdlHotspotEventCallback> wifiHotspotCallback =
289 OHOS::sptr<WifiIdlHotspotEventCallback>(new (std::nothrow) WifiIdlHotspotEventCallback());
290
291 OHOS::sptr<WifiIdlP2pEventCallback> wifiP2pCallback =
292 OHOS::sptr<WifiIdlP2pEventCallback>(new (std::nothrow) WifiIdlP2pEventCallback());
293
OnWifiStateChange(::taihe::callback_view<void (double)> callback)294 void OnWifiStateChange(::taihe::callback_view<void(double)> callback)
295 {
296 std::unique_lock<std::shared_mutex> guard(g_wifiStateChangeLock);
297 auto wifiStateChangedCallback =
298 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
299 std::vector<std::string> event = {"wifiStateChange"};
300 if (g_wifiDevicePtr == nullptr) {
301 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
302 return;
303 }
304 if (g_wifiStateChangeVec.size() > REGISTERINFO_MAX_NUM) {
305 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
306 return;
307 }
308 ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event);
309 if (ret != WIFI_OPT_SUCCESS) {
310 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
311 }
312 g_wifiStateChangeVec.emplace_back(wifiStateChangedCallback);
313 }
314
OffWifiStateChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)315 void OffWifiStateChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
316 {
317 std::unique_lock<std::shared_mutex> guard(g_wifiStateChangeLock);
318 if (g_wifiStateChangeVec.empty()) {
319 WIFI_LOGE("Unregister type not registered!");
320 return;
321 }
322 if (callback != nullptr) {
323 for (int i = static_cast<int>(g_wifiStateChangeVec.size()) - 1; i >= 0; --i) {
324 if (g_wifiStateChangeVec[i] == callback) {
325 g_wifiStateChangeVec.erase(g_wifiStateChangeVec.begin() + i);
326 }
327 }
328 } else {
329 WIFI_LOGW("Unregister all relevant subscribe for: wifiStateChange");
330 g_wifiStateChangeVec.clear();
331 }
332 }
333
OnWifiConnectionChange(::taihe::callback_view<void (double)> callback)334 void OnWifiConnectionChange(::taihe::callback_view<void(double)> callback)
335 {
336 std::unique_lock<std::shared_mutex> guard(g_wifiConnectionChangeLock);
337 auto wifiConnectionChangeCallback =
338 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
339 std::vector<std::string> event = {"wifiConnectionChange"};
340 if (g_wifiDevicePtr == nullptr) {
341 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
342 return;
343 }
344 if (g_wifiConnectionChangeVec.size() > REGISTERINFO_MAX_NUM) {
345 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
346 return;
347 }
348 ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event);
349 if (ret != WIFI_OPT_SUCCESS) {
350 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
351 return;
352 }
353 g_wifiConnectionChangeVec.emplace_back(wifiConnectionChangeCallback);
354 }
355
OffWifiConnectionChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)356 void OffWifiConnectionChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
357 {
358 std::unique_lock<std::shared_mutex> guard(g_wifiConnectionChangeLock);
359 if (g_wifiConnectionChangeVec.empty()) {
360 WIFI_LOGE("Unregister type not registered!");
361 return;
362 }
363 if (callback != nullptr) {
364 for (int i = static_cast<int>(g_wifiConnectionChangeVec.size()) - 1; i >= 0; --i) {
365 if (g_wifiConnectionChangeVec[i] == callback) {
366 g_wifiConnectionChangeVec.erase(g_wifiConnectionChangeVec.begin() + i);
367 }
368 }
369 } else {
370 WIFI_LOGW("Unregister all relevant subscribe for: wifiConnectionChange");
371 g_wifiConnectionChangeVec.clear();
372 }
373 }
374
OnWifiScanStateChange(::taihe::callback_view<void (double)> callback)375 void OnWifiScanStateChange(::taihe::callback_view<void(double)> callback)
376 {
377 std::unique_lock<std::shared_mutex> guard(g_wifiScanStateChangeLock);
378 auto wifiScanStateChangeCallback =
379 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
380 std::vector<std::string> event = {"wifiScanStateChange"};
381 if (g_wifiScanPtr == nullptr) {
382 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
383 return;
384 }
385 if (g_wifiScanStateChangeVec.size() > REGISTERINFO_MAX_NUM) {
386 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
387 return;
388 }
389 ErrCode ret = g_wifiScanPtr->RegisterCallBack(wifiScanCallback, event);
390 if (ret != WIFI_OPT_SUCCESS) {
391 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
392 return;
393 }
394 g_wifiScanStateChangeVec.emplace_back(wifiScanStateChangeCallback);
395 }
396
OffWifiScanStateChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)397 void OffWifiScanStateChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
398 {
399 std::unique_lock<std::shared_mutex> guard(g_wifiScanStateChangeLock);
400 if (g_wifiScanStateChangeVec.empty()) {
401 WIFI_LOGE("Unregister type not registered!");
402 return;
403 }
404 if (callback != nullptr) {
405 for (int i = static_cast<int>(g_wifiScanStateChangeVec.size()) - 1; i >= 0; --i) {
406 if (g_wifiScanStateChangeVec[i] == callback) {
407 g_wifiScanStateChangeVec.erase(g_wifiScanStateChangeVec.begin() + i);
408 }
409 }
410 } else {
411 WIFI_LOGW("Unregister all relevant subscribe for: wifiScanStateChange");
412 g_wifiScanStateChangeVec.clear();
413 }
414 }
415
OnWifiRssiChange(::taihe::callback_view<void (double)> callback)416 void OnWifiRssiChange(::taihe::callback_view<void(double)> callback)
417 {
418 std::unique_lock<std::shared_mutex> guard(g_wifiRssiChangeLock);
419 auto wifiRssiChangeCallback =
420 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
421 std::vector<std::string> event = {"wifiRssiChange"};
422 if (g_wifiDevicePtr == nullptr) {
423 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
424 return;
425 }
426 if (g_wifiRssiChangeVec.size() > REGISTERINFO_MAX_NUM) {
427 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
428 return;
429 }
430 ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event);
431 if (ret != WIFI_OPT_SUCCESS) {
432 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
433 return;
434 }
435 g_wifiRssiChangeVec.emplace_back(wifiRssiChangeCallback);
436 }
437
OffWifiRssiChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)438 void OffWifiRssiChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
439 {
440 std::unique_lock<std::shared_mutex> guard(g_wifiRssiChangeLock);
441 if (g_wifiRssiChangeVec.empty()) {
442 WIFI_LOGE("Unregister type not registered!");
443 return;
444 }
445 if (callback != nullptr) {
446 for (int i = static_cast<int>(g_wifiRssiChangeVec.size()) - 1; i >= 0; --i) {
447 if (g_wifiRssiChangeVec[i] == callback) {
448 g_wifiRssiChangeVec.erase(g_wifiRssiChangeVec.begin() + i);
449 }
450 }
451 } else {
452 WIFI_LOGW("Unregister all relevant subscribe for: wifiRssiChange");
453 g_wifiRssiChangeVec.clear();
454 }
455 }
456
OnStreamChange(::taihe::callback_view<void (double)> callback)457 void OnStreamChange(::taihe::callback_view<void(double)> callback)
458 {
459 std::unique_lock<std::shared_mutex> guard(g_wifiStreamChangeLock);
460 auto wifiRssiChangeCallback =
461 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
462 std::vector<std::string> event = {"streamChange"};
463 if (g_wifiDevicePtr == nullptr) {
464 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
465 return;
466 }
467 if (g_wifiStreamChangeVec.size() > REGISTERINFO_MAX_NUM) {
468 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
469 return;
470 }
471 ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event);
472 if (ret != WIFI_OPT_SUCCESS) {
473 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
474 return;
475 }
476 g_wifiStreamChangeVec.emplace_back(wifiRssiChangeCallback);
477 }
478
OffStreamChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)479 void OffStreamChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
480 {
481 std::unique_lock<std::shared_mutex> guard(g_wifiStreamChangeLock);
482 if (g_wifiStreamChangeVec.empty()) {
483 WIFI_LOGE("Unregister type not registered!");
484 return;
485 }
486 if (callback != nullptr) {
487 for (int i = static_cast<int>(g_wifiStreamChangeVec.size()) - 1; i >= 0; --i) {
488 if (g_wifiStreamChangeVec[i] == callback) {
489 g_wifiStreamChangeVec.erase(g_wifiStreamChangeVec.begin() + i);
490 }
491 }
492 } else {
493 WIFI_LOGW("Unregister all relevant subscribe for: streamChange");
494 g_wifiStreamChangeVec.clear();
495 }
496 }
497
OnDeviceConfigChange(::taihe::callback_view<void (double)> callback)498 void OnDeviceConfigChange(::taihe::callback_view<void(double)> callback)
499 {
500 std::unique_lock<std::shared_mutex> guard(g_wifiDeviceConfigChangeLock);
501 auto wifiDeviceConfigChangeCallback =
502 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
503 std::vector<std::string> event = {"deviceConfigChange"};
504 if (g_wifiDevicePtr == nullptr) {
505 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_STA);
506 return;
507 }
508 if (g_wifiDeviceConfigChangeVec.size() > REGISTERINFO_MAX_NUM) {
509 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
510 return;
511 }
512 ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event);
513 if (ret != WIFI_OPT_SUCCESS) {
514 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_STA);
515 return;
516 }
517 g_wifiDeviceConfigChangeVec.emplace_back(wifiDeviceConfigChangeCallback);
518 }
519
OffDeviceConfigChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)520 void OffDeviceConfigChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
521 {
522 std::unique_lock<std::shared_mutex> guard(g_wifiDeviceConfigChangeLock);
523 if (g_wifiDeviceConfigChangeVec.empty()) {
524 WIFI_LOGE("Unregister type not registered!");
525 return;
526 }
527 if (callback != nullptr) {
528 for (int i = static_cast<int>(g_wifiDeviceConfigChangeVec.size()) - 1; i >= 0; --i) {
529 if (g_wifiDeviceConfigChangeVec[i] == callback) {
530 g_wifiDeviceConfigChangeVec.erase(g_wifiDeviceConfigChangeVec.begin() + i);
531 }
532 }
533 } else {
534 WIFI_LOGW("Unregister all relevant subscribe for: deviceConfigChange");
535 g_wifiDeviceConfigChangeVec.clear();
536 }
537 }
538
OnHotspotStateChange(::taihe::callback_view<void (double)> callback)539 void OnHotspotStateChange(::taihe::callback_view<void(double)> callback)
540 {
541 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStateChangeLock);
542 auto wifiHotspotStateChangeCallback =
543 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
544 std::vector<std::string> event = {"hotspotStateChange"};
545 if (g_wifiHotspotPtr == nullptr) {
546 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_CORE);
547 return;
548 }
549 if (g_wifiHotspotStateChangeVec.size() > REGISTERINFO_MAX_NUM) {
550 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
551 return;
552 }
553 ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event);
554 if (ret != WIFI_OPT_SUCCESS) {
555 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_AP_CORE);
556 return;
557 }
558 g_wifiHotspotStateChangeVec.emplace_back(wifiHotspotStateChangeCallback);
559 }
560
OffHotspotStateChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)561 void OffHotspotStateChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
562 {
563 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStateChangeLock);
564 if (g_wifiHotspotStateChangeVec.empty()) {
565 WIFI_LOGE("Unregister type not registered!");
566 return;
567 }
568 if (callback != nullptr) {
569 for (int i = static_cast<int>(g_wifiHotspotStateChangeVec.size()) - 1; i >= 0; --i) {
570 if (g_wifiHotspotStateChangeVec[i] == callback) {
571 g_wifiHotspotStateChangeVec.erase(g_wifiHotspotStateChangeVec.begin() + i);
572 }
573 }
574 } else {
575 WIFI_LOGW("Unregister all relevant subscribe for: hotspotStateChange");
576 g_wifiHotspotStateChangeVec.clear();
577 }
578 }
579
OnHotspotStaJoin(::taihe::callback_view<void (::ohos::wifiManager::StationInfo const &)> callback)580 void OnHotspotStaJoin(::taihe::callback_view<void(::ohos::wifiManager::StationInfo const&)> callback)
581 {
582 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStaJoinLock);
583 auto wifiHotspotStaJoinCallback = ::taihe::optional<::taihe::callback<void(
584 ::ohos::wifiManager::StationInfo const&)>>{std::in_place_t{}, callback};
585 std::vector<std::string> event = {"hotspotStaJoin"};
586 if (g_wifiHotspotPtr == nullptr) {
587 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_CORE);
588 return;
589 }
590 if (g_wifiHotspotStaJoinVec.size() > REGISTERINFO_MAX_NUM) {
591 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
592 return;
593 }
594 ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event);
595 if (ret != WIFI_OPT_SUCCESS) {
596 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_AP_CORE);
597 return;
598 }
599 g_wifiHotspotStaJoinVec.emplace_back(wifiHotspotStaJoinCallback);
600 }
601
OffHotspotStaJoin(::taihe::optional_view<::taihe::callback<void (::ohos::wifiManager::StationInfo const &)>> callback)602 void OffHotspotStaJoin(
603 ::taihe::optional_view<::taihe::callback<void(::ohos::wifiManager::StationInfo const&)>> callback)
604 {
605 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStaJoinLock);
606 if (g_wifiHotspotStaJoinVec.empty()) {
607 WIFI_LOGE("Unregister type not registered!");
608 return;
609 }
610 if (callback != nullptr) {
611 for (int i = static_cast<int>(g_wifiHotspotStaJoinVec.size()) - 1; i >= 0; --i) {
612 if (g_wifiHotspotStaJoinVec[i] == callback) {
613 g_wifiHotspotStaJoinVec.erase(g_wifiHotspotStaJoinVec.begin() + i);
614 }
615 }
616 } else {
617 WIFI_LOGW("Unregister all relevant subscribe for: hotspotStaJoin");
618 g_wifiHotspotStaJoinVec.clear();
619 }
620 }
621
OnHotspotStaLeave(::taihe::callback_view<void (::ohos::wifiManager::StationInfo const &)> callback)622 void OnHotspotStaLeave(::taihe::callback_view<void(::ohos::wifiManager::StationInfo const&)> callback)
623 {
624 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStaLeaveLock);
625 auto wifiHotspotStaLeaveCallback = ::taihe::optional<::taihe::callback<void(
626 ::ohos::wifiManager::StationInfo const&)>>{std::in_place_t{}, callback};
627 std::vector<std::string> event = {"hotspotStaLeave"};
628 if (g_wifiHotspotPtr == nullptr) {
629 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_AP_CORE);
630 return;
631 }
632 if (g_wifiHotspotStaLeaveVec.size() > REGISTERINFO_MAX_NUM) {
633 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
634 return;
635 }
636 ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event);
637 if (ret != WIFI_OPT_SUCCESS) {
638 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_AP_CORE);
639 return;
640 }
641 g_wifiHotspotStaLeaveVec.emplace_back(wifiHotspotStaLeaveCallback);
642 }
643
OffHotspotStaLeave(::taihe::optional_view<::taihe::callback<void (::ohos::wifiManager::StationInfo const &)>> callback)644 void OffHotspotStaLeave(
645 ::taihe::optional_view<::taihe::callback<void(::ohos::wifiManager::StationInfo const&)>> callback)
646 {
647 std::unique_lock<std::shared_mutex> guard(g_wifiHotspotStaLeaveLock);
648 if (g_wifiHotspotStaLeaveVec.empty()) {
649 WIFI_LOGE("Unregister type not registered!");
650 return;
651 }
652 if (callback != nullptr) {
653 for (int i = static_cast<int>(g_wifiHotspotStaLeaveVec.size()) - 1; i >= 0; --i) {
654 if (g_wifiHotspotStaLeaveVec[i] == callback) {
655 g_wifiHotspotStaLeaveVec.erase(g_wifiHotspotStaLeaveVec.begin() + i);
656 }
657 }
658 } else {
659 WIFI_LOGW("Unregister all relevant subscribe for: hotspotStaLeave");
660 g_wifiHotspotStaLeaveVec.clear();
661 }
662 }
663
OnP2pStateChange(::taihe::callback_view<void (double)> callback)664 void OnP2pStateChange(::taihe::callback_view<void(double)> callback)
665 {
666 std::unique_lock<std::shared_mutex> guard(g_wifiP2pStateChangeLock);
667 auto wifiP2pStateChangeCallback =
668 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
669 std::vector<std::string> event = {"p2pStateChange"};
670 if (g_wifiP2pPtr == nullptr) {
671 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
672 return;
673 }
674 if (g_wifiP2pStateChangeVec.size() > REGISTERINFO_MAX_NUM) {
675 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
676 return;
677 }
678 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
679 if (ret != WIFI_OPT_SUCCESS) {
680 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
681 return;
682 }
683 g_wifiP2pStateChangeVec.emplace_back(wifiP2pStateChangeCallback);
684 }
685
OffP2pStateChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)686 void OffP2pStateChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
687 {
688 std::unique_lock<std::shared_mutex> guard(g_wifiP2pStateChangeLock);
689 if (g_wifiP2pStateChangeVec.empty()) {
690 WIFI_LOGE("Unregister type not registered!");
691 return;
692 }
693 if (callback != nullptr) {
694 for (int i = static_cast<int>(g_wifiP2pStateChangeVec.size()) - 1; i >= 0; --i) {
695 if (g_wifiP2pStateChangeVec[i] == callback) {
696 g_wifiP2pStateChangeVec.erase(g_wifiP2pStateChangeVec.begin() + i);
697 }
698 }
699 } else {
700 WIFI_LOGW("Unregister all relevant subscribe for: p2pStateChange");
701 g_wifiP2pStateChangeVec.clear();
702 }
703 }
704
OnP2pConnectionChange(::taihe::callback_view<void (::ohos::wifiManager::WifiP2pLinkedInfo const &)> callback)705 void OnP2pConnectionChange(::taihe::callback_view<void(::ohos::wifiManager::WifiP2pLinkedInfo const&)> callback)
706 {
707 std::unique_lock<std::shared_mutex> guard(g_wifiP2pConnectionChangeLock);
708 auto wifiP2pConnectionChangeCallback = ::taihe::optional<::taihe::callback<void(
709 ::ohos::wifiManager::WifiP2pLinkedInfo const&)>>{std::in_place_t{}, callback};
710 std::vector<std::string> event = {"p2pConnectionChange"};
711 if (g_wifiP2pPtr == nullptr) {
712 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
713 return;
714 }
715 if (g_wifiP2pConnectionChangeVec.size() > REGISTERINFO_MAX_NUM) {
716 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
717 return;
718 }
719 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
720 if (ret != WIFI_OPT_SUCCESS) {
721 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
722 return;
723 }
724 g_wifiP2pConnectionChangeVec.emplace_back(wifiP2pConnectionChangeCallback);
725 }
726
OffP2pConnectionChange(::taihe::optional_view<::taihe::callback<void (::ohos::wifiManager::WifiP2pLinkedInfo const &)>> callback)727 void OffP2pConnectionChange(
728 ::taihe::optional_view<::taihe::callback<void(::ohos::wifiManager::WifiP2pLinkedInfo const&)>> callback)
729 {
730 std::unique_lock<std::shared_mutex> guard(g_wifiP2pConnectionChangeLock);
731 if (g_wifiP2pConnectionChangeVec.empty()) {
732 WIFI_LOGE("Unregister type not registered!");
733 return;
734 }
735 if (callback != nullptr) {
736 for (int i = static_cast<int>(g_wifiP2pConnectionChangeVec.size()) - 1; i >= 0; --i) {
737 if (g_wifiP2pConnectionChangeVec[i] == callback) {
738 g_wifiP2pConnectionChangeVec.erase(g_wifiP2pConnectionChangeVec.begin() + i);
739 }
740 }
741 } else {
742 WIFI_LOGW("Unregister all relevant subscribe for: p2pConnectionChange");
743 g_wifiP2pConnectionChangeVec.clear();
744 }
745 }
746
OnP2pDeviceChange(::taihe::callback_view<void (::ohos::wifiManager::WifiP2pDevice const &)> callback)747 void OnP2pDeviceChange(::taihe::callback_view<void(::ohos::wifiManager::WifiP2pDevice const&)> callback)
748 {
749 std::unique_lock<std::shared_mutex> guard(g_wifiP2pDeviceChangeLock);
750 auto wifiP2pDeviceChangeCallback = ::taihe::optional<::taihe::callback<void(
751 ::ohos::wifiManager::WifiP2pDevice const&)>>{std::in_place_t{}, callback};
752 std::vector<std::string> event = {"p2pDeviceChange"};
753 if (g_wifiP2pPtr == nullptr) {
754 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
755 return;
756 }
757 if (g_wifiP2pDeviceChangeVec.size() > REGISTERINFO_MAX_NUM) {
758 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
759 return;
760 }
761 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
762 if (ret != WIFI_OPT_SUCCESS) {
763 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
764 return;
765 }
766 g_wifiP2pDeviceChangeVec.emplace_back(wifiP2pDeviceChangeCallback);
767 }
768
OffP2pDeviceChange(::taihe::optional_view<::taihe::callback<void (::ohos::wifiManager::WifiP2pDevice const &)>> callback)769 void OffP2pDeviceChange(::taihe::optional_view<::taihe::callback<void(
770 ::ohos::wifiManager::WifiP2pDevice const&)>> callback)
771 {
772 std::unique_lock<std::shared_mutex> guard(g_wifiP2pDeviceChangeLock);
773 if (g_wifiP2pDeviceChangeVec.empty()) {
774 WIFI_LOGE("Unregister type not registered!");
775 return;
776 }
777 if (callback != nullptr) {
778 for (int i = static_cast<int>(g_wifiP2pDeviceChangeVec.size()) - 1; i >= 0; --i) {
779 if (g_wifiP2pDeviceChangeVec[i] == callback) {
780 g_wifiP2pDeviceChangeVec.erase(g_wifiP2pDeviceChangeVec.begin() + i);
781 }
782 }
783 } else {
784 WIFI_LOGW("Unregister all relevant subscribe for: p2pDeviceChange");
785 g_wifiP2pDeviceChangeVec.clear();
786 }
787 }
788
OnP2pPeerDeviceChange(::taihe::callback_view<void (::taihe::array_view<::ohos::wifiManager::WifiP2pDevice>)> callback)789 void OnP2pPeerDeviceChange(::taihe::callback_view<void(
790 ::taihe::array_view<::ohos::wifiManager::WifiP2pDevice>)> callback)
791 {
792 std::unique_lock<std::shared_mutex> guard(g_wifiP2pPeerDeviceChangeLock);
793 auto wifiP2pPeerDeviceChangeCallback =
794 ::taihe::optional<::taihe::callback<void(
795 ::taihe::array_view<::ohos::wifiManager::WifiP2pDevice>)>>{std::in_place_t{}, callback};
796 std::vector<std::string> event = {"p2pPeerDeviceChange"};
797 if (g_wifiP2pPtr == nullptr) {
798 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
799 return;
800 }
801 if (g_wifiP2pPeerDeviceChangeVec.size() > REGISTERINFO_MAX_NUM) {
802 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
803 return;
804 }
805 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
806 if (ret != WIFI_OPT_SUCCESS) {
807 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
808 return;
809 }
810 g_wifiP2pPeerDeviceChangeVec.emplace_back(wifiP2pPeerDeviceChangeCallback);
811 }
812
OffP2pPeerDeviceChange(::taihe::optional_view<::taihe::callback<void (::taihe::array_view<::ohos::wifiManager::WifiP2pDevice>)>> callback)813 void OffP2pPeerDeviceChange(::taihe::optional_view<::taihe::callback<void(
814 ::taihe::array_view<::ohos::wifiManager::WifiP2pDevice>)>> callback)
815 {
816 std::unique_lock<std::shared_mutex> guard(g_wifiP2pPeerDeviceChangeLock);
817 if (g_wifiP2pPeerDeviceChangeVec.empty()) {
818 WIFI_LOGE("Unregister type not registered!");
819 return;
820 }
821 if (callback != nullptr) {
822 for (int i = static_cast<int>(g_wifiP2pPeerDeviceChangeVec.size()) - 1; i >= 0; --i) {
823 if (g_wifiP2pPeerDeviceChangeVec[i] == callback) {
824 g_wifiP2pPeerDeviceChangeVec.erase(g_wifiP2pPeerDeviceChangeVec.begin() + i);
825 }
826 }
827 } else {
828 WIFI_LOGW("Unregister all relevant subscribe for: p2pPeerDeviceChange");
829 g_wifiP2pPeerDeviceChangeVec.clear();
830 }
831 }
832
OnP2pPersistentGroupChange(::taihe::callback_view<void (::ohos::wifiManager::UndefinedType const &)> callback)833 void OnP2pPersistentGroupChange(::taihe::callback_view<void(::ohos::wifiManager::UndefinedType const&)> callback)
834 {
835 std::unique_lock<std::shared_mutex> guard(g_wifiP2pPersistentGroupChangeLock);
836 auto wifiP2pPersistentGroupChangeCallback = ::taihe::optional<::taihe::callback<void(
837 ::ohos::wifiManager::UndefinedType const&)>>{std::in_place_t{}, callback};
838 std::vector<std::string> event = {"p2pPersistentGroupChange"};
839 if (g_wifiP2pPtr == nullptr) {
840 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
841 return;
842 }
843 if (g_wifiP2pPersistentGroupChangeVec.size() > REGISTERINFO_MAX_NUM) {
844 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
845 return;
846 }
847 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
848 if (ret != WIFI_OPT_SUCCESS) {
849 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
850 return;
851 }
852 g_wifiP2pPersistentGroupChangeVec.emplace_back(wifiP2pPersistentGroupChangeCallback);
853 }
854
OffP2pPersistentGroupChange(::taihe::optional_view<::taihe::callback<void (::ohos::wifiManager::UndefinedType const &)>> callback)855 void OffP2pPersistentGroupChange(::taihe::optional_view<::taihe::callback<void(
856 ::ohos::wifiManager::UndefinedType const&)>> callback)
857 {
858 std::unique_lock<std::shared_mutex> guard(g_wifiP2pPersistentGroupChangeLock);
859 if (g_wifiP2pPersistentGroupChangeVec.empty()) {
860 WIFI_LOGE("Unregister type not registered!");
861 return;
862 }
863 if (callback != nullptr) {
864 for (int i = static_cast<int>(g_wifiP2pPersistentGroupChangeVec.size()) - 1; i >= 0; --i) {
865 if (g_wifiP2pPersistentGroupChangeVec[i] == callback) {
866 g_wifiP2pPersistentGroupChangeVec.erase(g_wifiP2pPersistentGroupChangeVec.begin() + i);
867 }
868 }
869 } else {
870 WIFI_LOGW("Unregister all relevant subscribe for: p2pPersistentGroupChange");
871 g_wifiP2pPersistentGroupChangeVec.clear();
872 }
873 }
874
OnP2pDiscoveryChange(::taihe::callback_view<void (double)> callback)875 void OnP2pDiscoveryChange(::taihe::callback_view<void(double)> callback)
876 {
877 std::unique_lock<std::shared_mutex> guard(g_wifiP2pDiscoveryChangeLock);
878 auto wifiP2pDiscoveryChangeCallback =
879 ::taihe::optional<::taihe::callback<void(double)>>{std::in_place_t{}, callback};
880 std::vector<std::string> event = {"p2pDiscoveryChange"};
881 if (g_wifiP2pPtr == nullptr) {
882 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, WIFI_OPT_FAILED, SYSCAP_WIFI_P2P);
883 return;
884 }
885 if (g_wifiP2pDiscoveryChangeVec.size() > REGISTERINFO_MAX_NUM) {
886 WIFI_LOGE("RegisterInfo Exceeding the maximum value!");
887 return;
888 }
889 ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event);
890 if (ret != WIFI_OPT_SUCCESS) {
891 WifiIdlErrorCode::TaiheSetBusinessError(__FUNCTION__, ret, SYSCAP_WIFI_P2P);
892 return;
893 }
894 g_wifiP2pDiscoveryChangeVec.emplace_back(wifiP2pDiscoveryChangeCallback);
895 }
896
OffP2pDiscoveryChange(::taihe::optional_view<::taihe::callback<void (double)>> callback)897 void OffP2pDiscoveryChange(::taihe::optional_view<::taihe::callback<void(double)>> callback)
898 {
899 std::unique_lock<std::shared_mutex> guard(g_wifiP2pDiscoveryChangeLock);
900 if (g_wifiP2pDiscoveryChangeVec.empty()) {
901 WIFI_LOGE("Unregister type not registered!");
902 return;
903 }
904 if (callback != nullptr) {
905 for (int i = static_cast<int>(g_wifiP2pDiscoveryChangeVec.size()) - 1; i >= 0; --i) {
906 if (g_wifiP2pDiscoveryChangeVec[i] == callback) {
907 g_wifiP2pDiscoveryChangeVec.erase(g_wifiP2pDiscoveryChangeVec.begin() + i);
908 }
909 }
910 } else {
911 WIFI_LOGW("Unregister all relevant subscribe for: p2pDiscoveryChange");
912 g_wifiP2pDiscoveryChangeVec.clear();
913 }
914 }
915 }
916
917 TH_EXPORT_CPP_API_IsConnected(IsConnected);
918 TH_EXPORT_CPP_API_IsWifiActive(IsWifiActive);
919 TH_EXPORT_CPP_API_GetLinkedInfoSync(GetLinkedInfoSync);
920 TH_EXPORT_CPP_API_GetSignalLevel(GetSignalLevel);
921 TH_EXPORT_CPP_API_GetIpInfo(GetIpInfo);
922 TH_EXPORT_CPP_API_GetIpv6Info(GetIpv6Info);
923 TH_EXPORT_CPP_API_IsOpenSoftApAllowed(IsOpenSoftApAllowed);
924 TH_EXPORT_CPP_API_GetScanInfoList(GetScanInfoList);
925 TH_EXPORT_CPP_API_IsMeteredHotspot(IsMeteredHotspot);
926 TH_EXPORT_CPP_API_GetWifiDetailState(GetWifiDetailState);
927 TH_EXPORT_CPP_API_GetStations(GetStations);
928 TH_EXPORT_CPP_API_EnableWifi(EnableWifi);
929 TH_EXPORT_CPP_API_DisableWifi(DisableWifi);
930 TH_EXPORT_CPP_API_EnableSemiWifi(EnableSemiWifi);
931 TH_EXPORT_CPP_API_OnWifiStateChange(OnWifiStateChange);
932 TH_EXPORT_CPP_API_OffWifiStateChange(OffWifiStateChange);
933 TH_EXPORT_CPP_API_OnWifiConnectionChange(OnWifiConnectionChange);
934 TH_EXPORT_CPP_API_OffWifiConnectionChange(OffWifiConnectionChange);
935 TH_EXPORT_CPP_API_OnWifiScanStateChange(OnWifiScanStateChange);
936 TH_EXPORT_CPP_API_OffWifiScanStateChange(OffWifiScanStateChange);
937 TH_EXPORT_CPP_API_OnWifiRssiChange(OnWifiRssiChange);
938 TH_EXPORT_CPP_API_OffWifiRssiChange(OffWifiRssiChange);
939 TH_EXPORT_CPP_API_OnStreamChange(OnStreamChange);
940 TH_EXPORT_CPP_API_OffStreamChange(OffStreamChange);
941 TH_EXPORT_CPP_API_OnDeviceConfigChange(OnDeviceConfigChange);
942 TH_EXPORT_CPP_API_OffDeviceConfigChange(OffDeviceConfigChange);
943 TH_EXPORT_CPP_API_OnHotspotStateChange(OnHotspotStateChange);
944 TH_EXPORT_CPP_API_OffHotspotStateChange(OffHotspotStateChange);
945 TH_EXPORT_CPP_API_OnHotspotStaJoin(OnHotspotStaJoin);
946 TH_EXPORT_CPP_API_OffHotspotStaJoin(OffHotspotStaJoin);
947 TH_EXPORT_CPP_API_OnHotspotStaLeave(OnHotspotStaLeave);
948 TH_EXPORT_CPP_API_OffHotspotStaLeave(OffHotspotStaLeave);
949 TH_EXPORT_CPP_API_OnP2pStateChange(OnP2pStateChange);
950 TH_EXPORT_CPP_API_OffP2pStateChange(OffP2pStateChange);
951 TH_EXPORT_CPP_API_OnP2pConnectionChange(OnP2pConnectionChange);
952 TH_EXPORT_CPP_API_OffP2pConnectionChange(OffP2pConnectionChange);
953 TH_EXPORT_CPP_API_OnP2pDeviceChange(OnP2pDeviceChange);
954 TH_EXPORT_CPP_API_OffP2pDeviceChange(OffP2pDeviceChange);
955 TH_EXPORT_CPP_API_OnP2pPeerDeviceChange(OnP2pPeerDeviceChange);
956 TH_EXPORT_CPP_API_OffP2pPeerDeviceChange(OffP2pPeerDeviceChange);
957 TH_EXPORT_CPP_API_OnP2pPersistentGroupChange(OnP2pPersistentGroupChange);
958 TH_EXPORT_CPP_API_OffP2pPersistentGroupChange(OffP2pPersistentGroupChange);
959 TH_EXPORT_CPP_API_OnP2pDiscoveryChange(OnP2pDiscoveryChange);
960 TH_EXPORT_CPP_API_OffP2pDiscoveryChange(OffP2pDiscoveryChange);