From bfa53fe911a1941c32581f1c620edaba28c932b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B5=9A=E4=BA=88?= Date: Wed, 28 May 2025 21:27:42 +0800 Subject: [PATCH 1/3] modify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙浚予 --- wifi/bundle.json | 6 + wifi/frameworks/BUILD.gn | 2 + wifi/frameworks/ets/taihe/wifi/BUILD.gn | 80 +++ .../ets/taihe/wifi/idl/ohos.wifi.taihe | 16 + .../ets/taihe/wifi/src/ani_constructor.cpp | 29 + .../ets/taihe/wifi/src/ohos.wifi.impl.cpp | 23 + .../frameworks/ets/taihe/wifiManager/BUILD.gn | 83 +++ .../wifiManager/idl/ohos.wifiManager.taihe | 289 ++++++++++ .../taihe/wifiManager/src/ani_constructor.cpp | 28 + .../wifiManager/src/ohos.wifiManager.impl.cpp | 535 ++++++++++++++++++ .../wifiManager/src/wifi_callback_taihe.h | 314 ++++++++++ 11 files changed, 1405 insertions(+) create mode 100644 wifi/frameworks/ets/taihe/wifi/BUILD.gn create mode 100644 wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe create mode 100644 wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp create mode 100644 wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp create mode 100644 wifi/frameworks/ets/taihe/wifiManager/BUILD.gn create mode 100644 wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe create mode 100644 wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp create mode 100644 wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp create mode 100644 wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h diff --git a/wifi/bundle.json b/wifi/bundle.json index 9c3c4fd98..06725f778 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -172,6 +172,12 @@ "header_files": [] }, "name": "//foundation/communication/wifi/wifi/frameworks/cj:cj_wifi_ffi" + }, + { + "name": "//foundation/communication/wifi/wifi/frameworks/ets/taihe/wifi:copy_wifi" + }, + { + "name": "//foundation/communication/wifi/wifi/frameworks/ets/taihe/wifiManager:copy_wifiManager" } ], "test": [ diff --git a/wifi/frameworks/BUILD.gn b/wifi/frameworks/BUILD.gn index 3420689af..8c230722f 100644 --- a/wifi/frameworks/BUILD.gn +++ b/wifi/frameworks/BUILD.gn @@ -25,6 +25,8 @@ group("wifi_kits") { deps += [ "$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi", "$WIFI_ROOT_DIR/frameworks/ets/ani:wifi_ani", + "$WIFI_ROOT_DIR/frameworks/ets/taihe/wifi:wifi_framework_taihe", + "$WIFI_ROOT_DIR/frameworks/ets/taihe/wifiManager:wifiManager_framework_taihe", "$WIFI_ROOT_DIR/frameworks/js/napi:wifi", "$WIFI_ROOT_DIR/frameworks/js/napi:wifiext", "$WIFI_ROOT_DIR/frameworks/js/napi:wifimanager", diff --git a/wifi/frameworks/ets/taihe/wifi/BUILD.gn b/wifi/frameworks/ets/taihe/wifi/BUILD.gn new file mode 100644 index 000000000..7b8894c8c --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifi/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (C) 2025-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/communication/wifi/wifi/wifi.gni") # 导入taihe.gni + +copy_taihe_idl("copy_wifi") { + sources = [ + "./idl/ohos.wifi.taihe" + ] +} + +subsystem_name = "communication" +part_name = "wifi" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_wifi" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.wifi.ani.cpp", + "$taihe_generated_file_path/src/ohos.wifi.abi.c", + ] +} + +taihe_shared_library("wifi_taihe_native") { #调用taihe_shared_library模板编译so + sanitize = { + cfi = true # Enable/disable control flow integrity detection + boundary_sanitize = true # Enable boundary san detection + cfi_cross_dso = true # Cross-SO CFI Checks + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + sources += [ + "./src/ani_constructor.cpp", + "./src/ohos.wifi.impl.cpp", + ] + deps = [ + ":run_taihe", + "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" + ] +} + +generate_static_abc("wifi_framework_abc") { #调用generate_static_abc编译abc + base_url = "$taihe_generated_file_path" #base_url直接设置为taihe_generated_file_path + files = [ "$taihe_generated_file_path/@ohos.wifi.ets" ] #files传入生成的ets文件 + is_boot_abc = "True" + device_dst_file = "/system/framework/wifi_framework_abc.abc" + dependencies = [ ":run_taihe" ] #编译abc依赖太和工具链调用 +} + +ohos_prebuilt_etc("wifi_framework_etc") { #调用ohos_prebuilt_etc将abc拷贝到/system/framework下 + source = "$target_out_dir/wifi_framework_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":wifi_framework_abc" ] #拷贝abc依赖编译abc +} + +group("wifi_framework_taihe") { + deps = [ + ":wifi_framework_etc", + ":wifi_taihe_native" + ] #单独运行run_taihe目标即可只调用工具链并生成对应代码 +} \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe b/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe new file mode 100644 index 000000000..204e6e8a7 --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe @@ -0,0 +1,16 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.wifi", "wifi") \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp b/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp new file mode 100644 index 000000000..acf0e0380 --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.wifi.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::wifi::ANIRegister(env)) { + std::cerr << "Error from ohos::wifi::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp b/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp new file mode 100644 index 000000000..2ba156bce --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.wifi.proj.hpp" +#include "ohos.wifi.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +namespace { +// To be implemented. +} // namespace \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn b/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn new file mode 100644 index 000000000..e0f3f1d6f --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/BUILD.gn @@ -0,0 +1,83 @@ +# Copyright (C) 2025-2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/config/components/ets_frontend/ets2abc_config.gni") +import("//build/ohos.gni") +import("//build/ohos/taihe_idl/taihe.gni") +import("//foundation/communication/wifi/wifi/wifi.gni") # 导入taihe.gni + +copy_taihe_idl("copy_wifiManager") { + sources = [ + "./idl/ohos.wifiManager.taihe" + ] +} + +subsystem_name = "communication" +part_name = "wifi" +taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" + +ohos_taihe("run_taihe") { + taihe_generated_file_path = "$taihe_generated_file_path" + deps = [ ":copy_wifiManager" ] + outputs = [ + "$taihe_generated_file_path/src/ohos.wifiManager.ani.cpp", + "$taihe_generated_file_path/src/ohos.wifiManager.abi.c", + ] +} + +taihe_shared_library("wifiManager_taihe_native") { #调用taihe_shared_library模板编译so + sanitize = { + cfi = true # Enable/disable control flow integrity detection + boundary_sanitize = true # Enable boundary san detection + cfi_cross_dso = true # Cross-SO CFI Checks + debug = false + } + taihe_generated_file_path = "$taihe_generated_file_path" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + sources = get_target_outputs(":run_taihe") + sources += [ + "./src/ani_constructor.cpp", + "./src/ohos.wifiManager.impl.cpp", + ] + deps = [ + ":run_taihe", + "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" + ] + external_deps = [ + "c_utils:utils" + ] +} + +generate_static_abc("wifiManager_framework_abc") { #调用generate_static_abc编译abc + base_url = "$taihe_generated_file_path" #base_url直接设置为taihe_generated_file_path + files = [ "$taihe_generated_file_path/@ohos.wifiManager.ets" ] #files传入生成的ets文件 + is_boot_abc = "True" + device_dst_file = "/system/framework/wifimanager_framework_abc.abc" + dependencies = [ ":run_taihe" ] #编译abc依赖太和工具链调用 +} + +ohos_prebuilt_etc("wifiManager_framework_etc") { #调用ohos_prebuilt_etc将abc拷贝到/system/framework下 + source = "$target_out_dir/wifiManager_framework_abc.abc" + module_install_dir = "framework" + part_name = "$part_name" + subsystem_name = "$subsystem_name" + deps = [ ":wifiManager_framework_abc" ] #拷贝abc依赖编译abc +} + +group("wifiManager_framework_taihe") { + deps = [ + ":wifiManager_framework_etc", + ":wifiManager_taihe_native" + ] +} \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe new file mode 100644 index 000000000..3fdeac19d --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe @@ -0,0 +1,289 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +@!namespace("@ohos.wifiManager", "wifiManager") +@!sts_inject(""" +static { loadLibrary("wifiManager_taihe_native.z")} +""") +enum WifiSecurityType: i32 { + WIFI_SEC_TYPE_INVALID = 0, + WIFI_SEC_TYPE_OPEN = 1, + WIFI_SEC_TYPE_WEP = 2, + WIFI_SEC_TYPE_PSK = 3, + WIFI_SEC_TYPE_SAE = 4, + WIFI_SEC_TYPE_EAP = 5, + WIFI_SEC_TYPE_EAP_SUITE_B = 6, + WIFI_SEC_TYPE_OWE = 7, + WIFI_SEC_TYPE_WAPI_CERT = 8, + WIFI_SEC_TYPE_WAPI_PSK = 9 +} + +enum ConnState: i32 { + SCANNING = 0, + CONNECTING = 1, + AUTHENTICATING = 2, + OBTAINING_IPADDR = 3, + CONNECTED = 4, + DISCONNECTING = 5, + DISCONNECTED = 6, + UNKNOWN = 7 +} + +enum WifiCategory: i32 { + DEFAULT = 1, + WIFI6 = 2, + WIFI6_PLUS = 3, + WIFI7 = 4, + WIFI7_PLUS = 5 +} + +enum WifiDetailState: i32 { + UNKNOWN = -1, + INACTIVE = 0, + ACTIVATED = 1, + ACTIVATING = 2, + DEACTIVATING = 3, + SEMI_ACTIVATING = 4, + SEMI_ACTIVE = 5 +} + +enum P2pDeviceStatus: i32 { + CONNECTED = 0, + INVITED = 1, + FAILED = 2, + AVAILABLE = 3, + UNAVAILABLE = 4, +} + +enum P2pConnectState: i32 { + DISCONNECTED = 0, + CONNECTED = 1 +} + +struct WifiDeviceConfig { + ssid: String; + bssid: Optional; + preSharedKey: String; + securityType: WifiSecurityType; +} + +function MakeWifiDeviceConfig(ssid: String, bssid: Optional, preSharedKey: String, securityType: WifiSecurityType): WifiDeviceConfig; + +struct WifiScanInfo { + ssid: String; + bssid: String; + securityType: WifiSecurityType; + rssi: i32; + band: i32; + supportedWifiCategory: WifiCategory; +} + +function MakeWifiScanInfo(ssid: String, bssid: String, securityType: WifiSecurityType, rssi: i32, band: i32, supportedWifiCategory: WifiCategory): WifiScanInfo; + +struct WifiLinkedInfo { + ssid: String; + bssid: String; + rssi: i32; + band: i32; + macAddress: String; + connState: ConnState; + supportedWifiCategory: WifiCategory; +} + +function MakeWifiLinkedInfo(ssid: String, bssid: String, rssi: i32, band: i32, macAddress: String, connState: ConnState, supportedWifiCategory: WifiCategory): WifiLinkedInfo; + +struct IpInfo { + ipAddress: i32; +} + +function MakeIpInfo(ipAddress: i32): IpInfo; + +struct Ipv6Info { + linkIpv6Address: String; +} + +function MakeIpv6Info(linkIpv6Address: String): Ipv6Info; + +struct StationInfo { + macAddress: String; +} + +function MakeStationInfo(macAddress: String): StationInfo; + +struct HotspotConfig { + ssid: String; + securityType: WifiSecurityType; + band: i32; + preSharedKey: String; +} + +function MakeHotspotConfig(ssid: String, securityType: WifiSecurityType, band: i32, preSharedKey: String): HotspotConfig; + +struct WifiP2pLinkedInfo { + connectState: P2pConnectState; + isGroupOwner: bool; + groupOwnerAddr: String; +} + +enum DeviceAddressType: i32 { + RANDOM_DEVICE_ADDRESS = 0, + REAL_DEVICE_ADDRESS = 1, +} + +struct WifiP2pDevice { + deviceName: String; + deviceAddress: String; + deviceAddressType: DeviceAddressType; + primaryDeviceType: String; + deviceStatus: P2pDeviceStatus; + groupCapabilities: i32; +} + +// 函数 +function IsConnected(): bool; +function IsWifiActive(): bool; +function GetSignalLevel(rssi: f64, band: f64): f64; +function GetIpInfo(): IpInfo; +function GetIpv6Info(): Ipv6Info; +function IsOpenSoftApAllowed(): bool; +function GetScanInfoList(): Array; +function IsMeteredHotspot(): bool; +function GetWifiDetailState(): WifiDetailState; +function GetStations(): Array; +function EnableWifi(): void; +function DisableWifi(): void; +function EnableSemiWifi(): void; + +@!sts_inject(""" +export function on(type: string, cb: (arg_0: NullishType) => void) { + switch(type) { + case "wifiStateChange": return onWifiStateChange(cb); + case "wifiConnectionChange": return onWifiConnectionChange(cb); + case "wifiScanStateChange": return onWifiScanStateChange(cb); + case "wifiRssiChange": return onWifiRssiChange(cb); + case "streamChange": return onStreamChange(cb); + case "deviceConfigChange": return onDeviceConfigChange(cb); + case "hotspotStateChange": return onHotspotStateChange(cb); + case "hotspotStaJoin": return onHotspotStaJoin(cb); + case "hotspotStaLeave": return onHotspotStaLeave(cb); + case "p2pStateChange": return onP2pStateChange(cb); + case "p2pConnectionChange": return onP2pConnectionChange(cb); + case "p2pDeviceChange": return onP2pDeviceChange(cb); + case "p2pPeerDeviceChange": return onP2pPeerDeviceChange(cb); + case "p2pPersistentGroupChange": return onP2pPersistentGroupChange(cb); + case "p2pDiscoveryChange": return onP2pDiscoveryChange(cb); + default: throw new Error(`Unknown type: ${type}`); + } +} +export function off(type: string, cb?: (arg_0: NullishType) => void) { + switch(type) { + case "wifiStateChange": return offWifiStateChange(cb as (((data: double) => void) | undefined)); + case "wifiConnectionChange": return offWifiConnectionChange(cb as (((data: double) => void) | undefined)); + case "wifiScanStateChange": return offWifiScanStateChange(cb as (((data: double) => void) | undefined)); + case "wifiRssiChange": return offWifiRssiChange((cb as (((data: double) => void)|undefined))); + case "streamChange": return offStreamChange(cb as (((data: double) => void) | undefined)); + case "deviceConfigChange": return offDeviceConfigChange(cb as (((data: double) => void) | undefined)); + case "hotspotStateChange": return offHotspotStateChange(cb as (((data: double) => void) | undefined)); + case "hotspotStaJoin": return offHotspotStaJoin(cb as (((data: StationInfo) => void) | undefined)); + case "hotspotStaLeave": return offHotspotStaLeave(cb as (((data: StationInfo) => void) | undefined)); + case "p2pStateChange": return offP2pStateChange(cb as (((data: double) => void) | undefined)); + case "p2pConnectionChange": return offP2pConnectionChange(cb as (((data: WifiP2pLinkedInfo) => void) | undefined)); + case "p2pDeviceChange": return offP2pDeviceChange(cb as (((data: WifiP2pDevice) => void) | undefined)); + case "p2pPeerDeviceChange": return offP2pPeerDeviceChange(cb as (((data: Array) => void) | undefined)); + case "p2pPersistentGroupChange": return offP2pPersistentGroupChange(cb as ((() => void) | undefined)); + case "p2pDiscoveryChange": return offP2pDiscoveryChange(cb as (((data: double) => void) | undefined)); + default: throw new Error(`Unknown type: ${type}`); + } +} +""") + +// @on_off("wifiStateChange") +function OnWifiStateChange(callback: (data: f64) => void): void; +// @on_off("wifiStateChange") +function OffWifiStateChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("wifiConnectionChange") +function OnWifiConnectionChange(callback: (data: f64) => void): void; +// @on_off("wifiConnectionChange") +function OffWifiConnectionChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("wifiScanStateChange") +function OnWifiScanStateChange(callback: (data: f64) => void): void; +// @on_off("wifiScanStateChange") +function OffWifiScanStateChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("wifiRssiChange") +function OnWifiRssiChange(callback: (data: f64) => void): void; +// @on_off("wifiRssiChange") +function OffWifiRssiChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("streamChange") +function OnStreamChange(callback: (data: f64) => void): void; +// @on_off("streamChange") +function OffStreamChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("deviceConfigChange") +function OnDeviceConfigChange(callback: (data: f64) => void): void; +// @on_off("deviceConfigChange") +function OffDeviceConfigChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("hotspotStateChange") +function OnHotspotStateChange(callback: (data: f64) => void): void; +// @on_off("hotspotStateChange") +function OffHotspotStateChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("hotspotStaJoin") +function OnHotspotStaJoin(callback: (data: StationInfo) => void): void; +// @on_off("hotspotStaJoin") +function OffHotspotStaJoin(callback: Optional<(data: StationInfo) => void>): void; + +// @on_off("hotspotStaLeave") +function OnHotspotStaLeave(callback: (data: StationInfo) => void): void; +// @on_off("hotspotStaLeave") +function OffHotspotStaLeave(callback: Optional<(data: StationInfo) => void>): void; + +// @on_off("p2pStateChange") +function OnP2pStateChange(callback: (data: f64) => void): void; +// @on_off("p2pStateChange") +function OffP2pStateChange(callback: Optional<(data: f64) => void>): void; + +// @on_off("p2pConnectionChange") +function OnP2pConnectionChange(callback: (data: WifiP2pLinkedInfo) => void): void; +// @on_off("p2pConnectionChange") +function OffP2pConnectionChange(callback: Optional<(data: WifiP2pLinkedInfo) => void>): void; + +// @on_off("p2pDeviceChange") +function OnP2pDeviceChange(callback: (data: WifiP2pDevice) => void): void; +// @on_off("p2pDeviceChange") +function OffP2pDeviceChange(callback: Optional<(data: WifiP2pDevice) => void>): void; + +// @on_off("p2pPeerDeviceChange") +function OnP2pPeerDeviceChange(callback: (data: Array) => void): void; +// @on_off("p2pPeerDeviceChange") +function OffP2pPeerDeviceChange(callback:Optional<(data: Array) => void>): void; + +union UndefinedType { + @undefined undefined; +} + +// @on_off("p2pPersistentGroupChange") +function OnP2pPersistentGroupChange(callback: (data: UndefinedType) => void): void; +// @on_off("p2pPersistentGroupChange") +function OffP2pPersistentGroupChange(callback: Optional<(data: UndefinedType) => void>): void; + +// @on_off("p2pDiscoveryChange") +function OnP2pDiscoveryChange(callback: (data: f64) => void): void; +// @on_off("p2pDiscoveryChange") +function OffP2pDiscoveryChange(callback: Optional<(data: f64) => void>): void; \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp b/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp new file mode 100644 index 000000000..85f5275cf --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/src/ani_constructor.cpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "ohos.wifiManager.ani.hpp" +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + ani_env *env; + if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { + return ANI_ERROR; + } + if (ANI_OK != ohos::wifiManager::ANIRegister(env)) { + std::cerr << "Error from ohos::wifiManager::ANIRegister" << std::endl; + return ANI_ERROR; + } + *result = ANI_VERSION_1; + return ANI_OK; +} diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp new file mode 100644 index 000000000..538db2cca --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp @@ -0,0 +1,535 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "ohos.wifiManager.proj.hpp" +#include "ohos.wifiManager.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "wifi_callback_taihe.h" +using namespace OHOS::Wifi; + +static std::shared_ptr g_wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID); +std::shared_ptr g_wifiScanPtr = WifiScan::GetInstance(WIFI_SCAN_ABILITY_ID); +static std::shared_ptr g_wifiHotspotPtr = WifiHotspot::GetInstance(WIFI_HOTSPOT_ABILITY_ID); +std::shared_ptr g_wifiP2pPtr = WifiP2p::GetInstance(WIFI_P2P_ABILITY_ID); +namespace { + +::ohos::wifiManager::WifiDeviceConfig MakeWifiDeviceConfig(::taihe::string_view ssid, + ::taihe::optional_view<::taihe::string> bssid, ::taihe::string_view preSharedKey, + ::ohos::wifiManager::WifiSecurityType securityType) +{ + return {ssid, bssid, preSharedKey, securityType}; +} + +::ohos::wifiManager::WifiScanInfo MakeWifiScanInfo(::taihe::string_view ssid, ::taihe::string_view bssid, + ::ohos::wifiManager::WifiSecurityType securityType, int32_t rssi, int32_t band, + ::ohos::wifiManager::WifiCategory supportedWifiCategory) +{ + return {ssid, bssid, securityType, rssi, band, supportedWifiCategory}; +} + +::ohos::wifiManager::WifiScanInfo MakeTmpWifiScanInfo() +{ + return {"", "", ::ohos::wifiManager::WifiSecurityType::key_t::WIFI_SEC_TYPE_INVALID, 0, 0, + ::ohos::wifiManager::WifiCategory::key_t::DEFAULT}; +} + +::ohos::wifiManager::WifiLinkedInfo MakeWifiLinkedInfo(::taihe::string_view ssid, + ::taihe::string_view bssid, int32_t rssi, int32_t band, ::taihe::string_view macAddress, + ::ohos::wifiManager::ConnState connState, ::ohos::wifiManager::WifiCategory supportedWifiCategory) +{ + return {ssid, bssid, rssi, band, macAddress, connState, supportedWifiCategory}; +} + +::ohos::wifiManager::IpInfo MakeIpInfo(int32_t ipAddress) +{ + return {ipAddress}; +} + +::ohos::wifiManager::Ipv6Info MakeIpv6Info(::taihe::string_view linkIpv6Address) +{ + return {linkIpv6Address}; +} + +::ohos::wifiManager::StationInfo MakeStationInfo(::taihe::string_view macAddress) +{ + return {macAddress}; +} + +::ohos::wifiManager::StationInfo MakeTmpStationInfo() +{ + return {""}; +} + +::ohos::wifiManager::HotspotConfig MakeHotspotConfig(::taihe::string_view ssid, + ::ohos::wifiManager::WifiSecurityType securityType, int32_t band, ::taihe::string_view preSharedKey) +{ + return {ssid, securityType, band, preSharedKey}; +} + +bool IsConnected() +{ + bool isConnected = false; + ErrCode ret = g_wifiDevicePtr->IsConnected(isConnected); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("IsConnected return error"); + } + return static_cast(isConnected); +} + +bool IsWifiActive() +{ + bool activeStatus = false; + ErrCode ret = g_wifiDevicePtr->IsWifiActive(activeStatus); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("isWifiActive return error"); + } + return static_cast(activeStatus); +} + +double GetSignalLevel(double rssi, double band) +{ + int level = -1; + int tmpRssi = static_cast(rssi); + int tmpBand = static_cast(band); + ErrCode ret = g_wifiDevicePtr->GetSignalLevel(tmpRssi, tmpBand, level); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getSignalLevel return error"); + } + return static_cast(level); +} + +::ohos::wifiManager::IpInfo GetIpInfo() +{ + IpInfo ipInfo; + ErrCode ret = g_wifiDevicePtr->GetIpInfo(ipInfo); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getIpInfo return error"); + } + ::ohos::wifiManager::IpInfo result = MakeIpInfo(ipInfo.ipAddress); + return result; +} + +::ohos::wifiManager::Ipv6Info GetIpv6Info() +{ + IpV6Info ipInfo; + ErrCode ret = g_wifiDevicePtr->GetIpv6Info(ipInfo); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getIpv6Info return error"); + } + ::ohos::wifiManager::Ipv6Info result = MakeIpv6Info(ipInfo.linkIpV6Address); + return result; +} + +bool IsOpenSoftApAllowed() +{ + bool isSupported = false; + ErrCode ret = g_wifiHotspotPtr->IsOpenSoftApAllowed(isSupported); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("IsConnected return error"); + } + return static_cast(isSupported); +} + +void WifiScanInfoToTaihe(::ohos::wifiManager::WifiScanInfo &tmpInfo, WifiScanInfo scanInfo) +{ + tmpInfo.ssid = scanInfo.ssid; + tmpInfo.bssid = scanInfo.bssid; + tmpInfo.securityType = static_cast<::ohos::wifiManager::WifiSecurityType::key_t>(scanInfo.securityType); + tmpInfo.rssi = scanInfo.rssi; + tmpInfo.band = scanInfo.band; + tmpInfo.supportedWifiCategory = + static_cast<::ohos::wifiManager::WifiCategory::key_t>(scanInfo.supportedWifiCategory); +} + +::taihe::array<::ohos::wifiManager::WifiScanInfo> GetScanInfoList() +{ + bool compatible = false; + std::vector scanInfos; + ErrCode ret = g_wifiScanPtr->GetScanInfoList(scanInfos, compatible); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getScanInfoList return error"); + } + std::vector<::ohos::wifiManager::WifiScanInfo> result; + for (WifiScanInfo scanInfo : scanInfos) { + ::ohos::wifiManager::WifiScanInfo tmpInfo = MakeTmpWifiScanInfo(); + WifiScanInfoToTaihe(tmpInfo, scanInfo); + result.emplace_back(tmpInfo); + } + return ::taihe::array<::ohos::wifiManager::WifiScanInfo>(taihe::copy_data_t{}, result.data(), result.size()); +} + +bool IsMeteredHotspot() +{ + bool isMeteredHotspot = false; + ErrCode ret = g_wifiDevicePtr->IsMeteredHotspot(isMeteredHotspot); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("isMeteredHotspot return error"); + } + return static_cast(isMeteredHotspot); +} + +::ohos::wifiManager::WifiDetailState GetWifiDetailState() +{ + WifiDetailState state = WifiDetailState::STATE_UNKNOWN; + ErrCode ret = g_wifiDevicePtr->GetWifiDetailState(state); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("GetWifiDetailState return error"); + } + return static_cast<::ohos::wifiManager::WifiDetailState::key_t>(state); +} + +void StationInfoToTaihe(::ohos::wifiManager::StationInfo &tmpInfo, StationInfo stationInfo) +{ + tmpInfo.macAddress = stationInfo.bssid; +} + +::taihe::array<::ohos::wifiManager::StationInfo> GetStations() +{ + std::vector vecStationInfo; + ErrCode ret = g_wifiHotspotPtr->GetStationList(vecStationInfo); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("getStations return error"); + } + std::vector<::ohos::wifiManager::StationInfo> result; + for (StationInfo stationInfo : vecStationInfo) { + ::ohos::wifiManager::StationInfo tmpInfo = MakeTmpStationInfo(); + StationInfoToTaihe(tmpInfo, stationInfo); + result.emplace_back(tmpInfo); + } + return ::taihe::array<::ohos::wifiManager::StationInfo>(taihe::copy_data_t{}, result.data(), result.size()); +} + +void EnableWifi() +{ + ErrCode ret = g_wifiDevicePtr->EnableWifi(); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("enableWifi return error"); + } +} + +void DisableWifi() +{ + ErrCode ret = g_wifiDevicePtr->DisableWifi(); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("disableWifi return error"); + } +} + +void EnableSemiWifi() +{ + ErrCode ret = g_wifiDevicePtr->EnableSemiWifi(); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("enableSemiWifi return error"); + } +} +OHOS::sptr wifiDeviceCallback = + OHOS::sptr(new (std::nothrow) WifiIdlDeviceEventCallback()); + +OHOS::sptr wifiScanCallback = + OHOS::sptr(new (std::nothrow) WifiIdlScanEventCallback()); + +OHOS::sptr wifiHotspotCallback = + OHOS::sptr(new (std::nothrow) WifiIdlHotspotEventCallback()); + +OHOS::sptr wifiP2pCallback = + OHOS::sptr(new (std::nothrow) WifiIdlP2pEventCallback()); + +void OnWifiStateChange(::taihe::callback_view callback) +{ + wifiDeviceCallback->wifiStateChangedCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"wifiStateChange"}; + ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnWifiStateChange return error"); + } +} + +void OffWifiStateChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnWifiConnectionChange(::taihe::callback_view callback) +{ + wifiDeviceCallback->wifiConnectionChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"wifiConnectionChange"}; + ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnWifiConnectionChange return error"); + } +} + +void OffWifiConnectionChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnWifiScanStateChange(::taihe::callback_view callback) +{ + wifiScanCallback->wifiScanStateChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"wifiScanStateChange"}; + ErrCode ret = g_wifiScanPtr->RegisterCallBack(wifiScanCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnWifiScanStateChange return error"); + } +} + +void OffWifiScanStateChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnWifiRssiChange(::taihe::callback_view callback) +{ + wifiDeviceCallback->wifiRssiChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"wifiRssiChange"}; + ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnWifiRssiChange return error"); + } +} + +void OffWifiRssiChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnStreamChange(::taihe::callback_view callback) +{ + wifiDeviceCallback->wifiStreamChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"streamChange"}; + ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnWifiRssiChange return error"); + } +} + +void OffStreamChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnDeviceConfigChange(::taihe::callback_view callback) +{ + wifiDeviceCallback->wifiDeviceConfigChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"deviceConfigChange"}; + ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnDeviceConfigChange return error"); + } +} + +void OffDeviceConfigChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnHotspotStateChange(::taihe::callback_view callback) +{ + wifiHotspotCallback->wifiHotspotStateChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"hotspotStateChange"}; + ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnHotspotStateChange return error"); + } +} + +void OffHotspotStateChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnHotspotStaJoin(::taihe::callback_view callback) +{ + wifiHotspotCallback->wifiHotspotStaJoinCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"hotspotStaJoin"}; + ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnHotspotStaJoin return error"); + } +} + +void OffHotspotStaJoin( + ::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnHotspotStaLeave(::taihe::callback_view callback) +{ + wifiHotspotCallback->wifiHotspotStaLeaveCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"hotspotStaLeave"}; + ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnHotspotStaLeave return error"); + } +} + +void OffHotspotStaLeave( + ::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnP2pStateChange(::taihe::callback_view callback) +{ + wifiP2pCallback->wifiP2pStateChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"p2pStateChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pStateChange return error"); + } +} + +void OffP2pStateChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnP2pConnectionChange(::taihe::callback_view callback) +{ + wifiP2pCallback->wifiP2pConnectionChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"p2pConnectionChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pConnectionChange return error"); + } +} + +void OffP2pConnectionChange( + ::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnP2pDeviceChange(::taihe::callback_view callback) +{ + wifiP2pCallback->wifiP2pDeviceChangeCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"p2pDeviceChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pDeviceChange return error"); + } +} + +void OffP2pDeviceChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnP2pPeerDeviceChange(::taihe::callback_view)> callback) +{ + wifiP2pCallback->wifiP2pPeerDeviceChangeCallback_ = + ::taihe::optional<::taihe::callback)>>{std::in_place_t{}, callback}; + std::vector event = {"p2pPeerDeviceChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pPeerDeviceChange return error"); + } +} + +void OffP2pPeerDeviceChange(::taihe::optional_view<::taihe::callback)>> callback) +{ +} + +void OnP2pPersistentGroupChange(::taihe::callback_view callback) +{ + wifiP2pCallback->wifiP2pPersistentGroupChangeCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"p2pPersistentGroupChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pPersistentGroupChange return error"); + } +} + +void OffP2pPersistentGroupChange(::taihe::optional_view<::taihe::callback> callback) +{ +} + +void OnP2pDiscoveryChange(::taihe::callback_view callback) +{ + wifiP2pCallback->wifiP2pDiscoveryChangeCallback_ = + ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; + std::vector event = {"p2pDiscoveryChange"}; + ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); + if (ret != WIFI_OPT_SUCCESS) { + taihe::set_error("OnP2pDiscoveryChange return error"); + } +} + +void OffP2pDiscoveryChange(::taihe::optional_view<::taihe::callback> callback) +{ +} +} + +TH_EXPORT_CPP_API_MakeWifiDeviceConfig(MakeWifiDeviceConfig); +TH_EXPORT_CPP_API_MakeWifiScanInfo(MakeWifiScanInfo); +TH_EXPORT_CPP_API_MakeWifiLinkedInfo(MakeWifiLinkedInfo); +TH_EXPORT_CPP_API_MakeIpInfo(MakeIpInfo); +TH_EXPORT_CPP_API_MakeIpv6Info(MakeIpv6Info); +TH_EXPORT_CPP_API_MakeStationInfo(MakeStationInfo); +TH_EXPORT_CPP_API_MakeHotspotConfig(MakeHotspotConfig); +TH_EXPORT_CPP_API_IsConnected(IsConnected); +TH_EXPORT_CPP_API_IsWifiActive(IsWifiActive); +TH_EXPORT_CPP_API_GetSignalLevel(GetSignalLevel); +TH_EXPORT_CPP_API_GetIpInfo(GetIpInfo); +TH_EXPORT_CPP_API_GetIpv6Info(GetIpv6Info); +TH_EXPORT_CPP_API_IsOpenSoftApAllowed(IsOpenSoftApAllowed); +TH_EXPORT_CPP_API_GetScanInfoList(GetScanInfoList); +TH_EXPORT_CPP_API_IsMeteredHotspot(IsMeteredHotspot); +TH_EXPORT_CPP_API_GetWifiDetailState(GetWifiDetailState); +TH_EXPORT_CPP_API_GetStations(GetStations); +TH_EXPORT_CPP_API_EnableWifi(EnableWifi); +TH_EXPORT_CPP_API_DisableWifi(DisableWifi); +TH_EXPORT_CPP_API_EnableSemiWifi(EnableSemiWifi); +TH_EXPORT_CPP_API_OnWifiStateChange(OnWifiStateChange); +TH_EXPORT_CPP_API_OffWifiStateChange(OffWifiStateChange); +TH_EXPORT_CPP_API_OnWifiConnectionChange(OnWifiConnectionChange); +TH_EXPORT_CPP_API_OffWifiConnectionChange(OffWifiConnectionChange); +TH_EXPORT_CPP_API_OnWifiScanStateChange(OnWifiScanStateChange); +TH_EXPORT_CPP_API_OffWifiScanStateChange(OffWifiScanStateChange); +TH_EXPORT_CPP_API_OnWifiRssiChange(OnWifiRssiChange); +TH_EXPORT_CPP_API_OffWifiRssiChange(OffWifiRssiChange); +TH_EXPORT_CPP_API_OnStreamChange(OnStreamChange); +TH_EXPORT_CPP_API_OffStreamChange(OffStreamChange); +TH_EXPORT_CPP_API_OnDeviceConfigChange(OnDeviceConfigChange); +TH_EXPORT_CPP_API_OffDeviceConfigChange(OffDeviceConfigChange); +TH_EXPORT_CPP_API_OnHotspotStateChange(OnHotspotStateChange); +TH_EXPORT_CPP_API_OffHotspotStateChange(OffHotspotStateChange); +TH_EXPORT_CPP_API_OnHotspotStaJoin(OnHotspotStaJoin); +TH_EXPORT_CPP_API_OffHotspotStaJoin(OffHotspotStaJoin); +TH_EXPORT_CPP_API_OnHotspotStaLeave(OnHotspotStaLeave); +TH_EXPORT_CPP_API_OffHotspotStaLeave(OffHotspotStaLeave); +TH_EXPORT_CPP_API_OnP2pStateChange(OnP2pStateChange); +TH_EXPORT_CPP_API_OffP2pStateChange(OffP2pStateChange); +TH_EXPORT_CPP_API_OnP2pConnectionChange(OnP2pConnectionChange); +TH_EXPORT_CPP_API_OffP2pConnectionChange(OffP2pConnectionChange); +TH_EXPORT_CPP_API_OnP2pDeviceChange(OnP2pDeviceChange); +TH_EXPORT_CPP_API_OffP2pDeviceChange(OffP2pDeviceChange); +TH_EXPORT_CPP_API_OnP2pPeerDeviceChange(OnP2pPeerDeviceChange); +TH_EXPORT_CPP_API_OffP2pPeerDeviceChange(OffP2pPeerDeviceChange); +TH_EXPORT_CPP_API_OnP2pPersistentGroupChange(OnP2pPersistentGroupChange); +TH_EXPORT_CPP_API_OffP2pPersistentGroupChange(OffP2pPersistentGroupChange); +TH_EXPORT_CPP_API_OnP2pDiscoveryChange(OnP2pDiscoveryChange); +TH_EXPORT_CPP_API_OffP2pDiscoveryChange(OffP2pDiscoveryChange); \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h b/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h new file mode 100644 index 000000000..990646f11 --- /dev/null +++ b/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h @@ -0,0 +1,314 @@ +/* + * Copyright (C) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef OHOS_WIFI_CALLBACK_TAIHE_H +#define OHOS_WIFI_CALLBACK_TAIHE_H +#include "ohos.wifiManager.proj.hpp" +#include "ohos.wifiManager.impl.hpp" +#include "taihe/runtime.hpp" +#include "stdexcept" + +#include "wifi_device.h" +#include "wifi_device_impl.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_impl.h" +#include "wifi_scan.h" +#include "wifi_scan_impl.h" +#include "wifi_msg.h" +#include "wifi_p2p.h" +#include "wifi_p2p_impl.h" + +namespace OHOS { +namespace Wifi { +class WifiIdlDeviceEventCallback : public IWifiDeviceCallBack { +public: + WifiIdlDeviceEventCallback() + { + } + + virtual ~WifiIdlDeviceEventCallback() + { + } +public: + void OnWifiStateChanged(int state) override + { + double result = static_cast(state); + if (wifiStateChangedCallback_) { + (*wifiStateChangedCallback_)(result); + } + } + + void OnWifiConnectionChanged(int state, const WifiLinkedInfo &info) override + { + double result = static_cast(state); + if (wifiConnectionChangeCallback_) { + (*wifiConnectionChangeCallback_)(result); + } + } + + void OnWifiRssiChanged(int rssi) override + { + double result = static_cast(rssi); + if (wifiRssiChangeCallback_) { + (*wifiRssiChangeCallback_)(result); + } + } + + void OnWifiWpsStateChanged(int state, const std::string &pinCode) override + { + } + + void OnStreamChanged(int direction) override + { + double result = static_cast(direction); + if (wifiStreamChangeCallback_) { + (*wifiStreamChangeCallback_)(result); + } + } + + void OnDeviceConfigChanged(ConfigChange value) override + { + double result = static_cast(value); + if (wifiDeviceConfigChangeCallback_) { + (*wifiDeviceConfigChangeCallback_)(result); + } + } + + OHOS::sptr AsObject() override + { + return nullptr; + } + +public: + ::taihe::optional<::taihe::callback> wifiStateChangedCallback_; + ::taihe::optional<::taihe::callback> wifiConnectionChangeCallback_; + ::taihe::optional<::taihe::callback> wifiRssiChangeCallback_; + ::taihe::optional<::taihe::callback> wifiStreamChangeCallback_; + ::taihe::optional<::taihe::callback> wifiDeviceConfigChangeCallback_; +}; + +class WifiIdlScanEventCallback : public IWifiScanCallback { +public: + WifiIdlScanEventCallback() + { + } + + virtual ~WifiIdlScanEventCallback() + { + } + +public: + void OnWifiScanStateChanged(int state) override + { + double result = static_cast(state); + if (wifiScanStateChangeCallback_) { + (*wifiScanStateChangeCallback_)(result); + } + } + + OHOS::sptr AsObject() override + { + return nullptr; + } +public: + ::taihe::optional<::taihe::callback> wifiScanStateChangeCallback_; +}; + +class WifiIdlHotspotEventCallback : public IWifiHotspotCallback { +public: + WifiIdlHotspotEventCallback() + { + } + + virtual ~WifiIdlHotspotEventCallback() + { + } + +public: + void OnHotspotStateChanged(int state) override + { + double result = static_cast(state); + if (wifiHotspotStateChangeCallback_) { + (*wifiHotspotStateChangeCallback_)(result); + } + } + + void OnHotspotStaJoin(const StationInfo &info) override + { + // bssid -> macAddress + ::ohos::wifiManager::StationInfo result = {info.bssid}; + if (wifiHotspotStaJoinCallback_) { + (*wifiHotspotStaJoinCallback_)(result); + } + } + + void OnHotspotStaLeave(const StationInfo &info) override + { + // bssid -> macAddress + ::ohos::wifiManager::StationInfo result = {info.bssid}; + if (wifiHotspotStaLeaveCallback_) { + (*wifiHotspotStaLeaveCallback_)(result); + } + } + + OHOS::sptr AsObject() override + { + return nullptr; + } + +public: + ::taihe::optional<::taihe::callback> wifiHotspotStateChangeCallback_; + ::taihe::optional<::taihe::callback> + wifiHotspotStaJoinCallback_; + ::taihe::optional<::taihe::callback> + wifiHotspotStaLeaveCallback_; +}; + +class WifiIdlP2pEventCallback : public IWifiP2pCallback { +public: + WifiIdlP2pEventCallback() + { + } + + virtual ~WifiIdlP2pEventCallback() + { + } + +public: + void OnP2pStateChanged(int state) override + { + double result = static_cast(state); + if (wifiP2pStateChangeCallback_) { + (*wifiP2pStateChangeCallback_)(result); + } + } + + void OnP2pPersistentGroupsChanged(void) override + { + auto result = ::ohos::wifiManager::UndefinedType::make_undefined(); + if (wifiP2pPersistentGroupChangeCallback_) { + (*wifiP2pPersistentGroupChangeCallback_)(result); + } + } + + void OnP2pThisDeviceChanged(const WifiP2pDevice& device) override + { + ::taihe::string_view deviceName = static_cast<::taihe::string_view>(device.GetDeviceName()); + ::taihe::string_view deviceAddress = static_cast<::taihe::string_view>(device.GetDeviceAddress()); + ::ohos::wifiManager::DeviceAddressType deviceAddressType = + static_cast<::ohos::wifiManager::DeviceAddressType::key_t>(device.GetDeviceAddressType()); + ::taihe::string_view primaryDeviceType = static_cast<::taihe::string_view>(device.GetPrimaryDeviceType()); + ::ohos::wifiManager::P2pDeviceStatus deviceStatus = + static_cast<::ohos::wifiManager::P2pDeviceStatus::key_t>(device.GetP2pDeviceStatus()); + int groupCapabilities = static_cast(device.GetGroupCapabilitys()); + ::ohos::wifiManager::WifiP2pDevice result = {deviceName, deviceAddress, deviceAddressType, + primaryDeviceType, deviceStatus, groupCapabilities}; + if (wifiP2pDeviceChangeCallback_) { + (*wifiP2pDeviceChangeCallback_)(result); + } + } + + void OnP2pPeersChanged(const std::vector& devices) override + { + std::vector<::ohos::wifiManager::WifiP2pDevice> result; + for (WifiP2pDevice device : devices) { + ::taihe::string_view deviceName = static_cast<::taihe::string_view>(device.GetDeviceName()); + ::taihe::string_view deviceAddress = static_cast<::taihe::string_view>(device.GetDeviceAddress()); + ::ohos::wifiManager::DeviceAddressType deviceAddressType = + static_cast<::ohos::wifiManager::DeviceAddressType::key_t>(device.GetDeviceAddressType()); + ::taihe::string_view primaryDeviceType = + static_cast<::taihe::string_view>(device.GetPrimaryDeviceType()); + ::ohos::wifiManager::P2pDeviceStatus deviceStatus = + static_cast<::ohos::wifiManager::P2pDeviceStatus::key_t>(device.GetP2pDeviceStatus()); + int groupCapabilities = static_cast(device.GetGroupCapabilitys()); + ::ohos::wifiManager::WifiP2pDevice tmpDevice = {deviceName, deviceAddress, deviceAddressType, + primaryDeviceType, deviceStatus, groupCapabilities}; + result.emplace_back(tmpDevice); + } + ::taihe::array<::ohos::wifiManager::WifiP2pDevice> finalResult = + ::taihe::array<::ohos::wifiManager::WifiP2pDevice>(taihe::copy_data_t{}, result.data(), result.size()); + if (wifiP2pPeerDeviceChangeCallback_) { + (*wifiP2pPeerDeviceChangeCallback_)(finalResult); + } + } + + void OnP2pServicesChanged(const std::vector& srvInfo) override + { + } + + void OnP2pConnectionChanged(const WifiP2pLinkedInfo& info) override + { + ::ohos::wifiManager::P2pConnectState state = + static_cast<::ohos::wifiManager::P2pConnectState::key_t>(info.GetConnectState()); + ani_boolean isOwner = static_cast(info.IsGroupOwner()); + ::taihe::string_view ownerAddr = static_cast<::taihe::string_view>(info.GetGroupOwnerAddress()); + ::ohos::wifiManager::WifiP2pLinkedInfo result = {state, isOwner, ownerAddr}; + if (wifiP2pConnectionChangeCallback_) { + (*wifiP2pConnectionChangeCallback_)(result); + } + } + + void OnP2pDiscoveryChanged(bool isChange) override + { + double result = static_cast(isChange); + if (wifiP2pDiscoveryChangeCallback_) { + (*wifiP2pDiscoveryChangeCallback_)(result); + } + } + + void OnP2pActionResult(P2pActionCallback action, ErrCode code) override + { + } + + void OnConfigChanged(CfgType type, char* data, int dataLen) override + { + } + + void OnP2pGcJoinGroup(const OHOS::Wifi::GcInfo &info) override + { + } + + void OnP2pGcLeaveGroup(const OHOS::Wifi::GcInfo &info) override + { + } + + void OnP2pPrivatePeersChanged(const std::string &priWfdInfo) override + { + } + + void OnP2pChrErrCodeReport(const int errCode) override + { + } + + OHOS::sptr AsObject() override + { + return nullptr; + } + +public: + ::taihe::optional<::taihe::callback> wifiP2pStateChangeCallback_; + ::taihe::optional<::taihe::callback> + wifiP2pConnectionChangeCallback_; + ::taihe::optional<::taihe::callback> + wifiP2pDeviceChangeCallback_; + ::taihe::optional<::taihe::callback)>> + wifiP2pPeerDeviceChangeCallback_; + ::taihe::optional<::taihe::callback> + wifiP2pPersistentGroupChangeCallback_; + ::taihe::optional<::taihe::callback> wifiP2pDiscoveryChangeCallback_; +}; +} // namespace Wifi +} // namespace OHOS +#endif \ No newline at end of file -- Gitee From b82bc58cf43dcd26a654cb51cf5cb7922f4198b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B5=9A=E4=BA=88?= Date: Thu, 29 May 2025 15:52:55 +0800 Subject: [PATCH 2/3] modify MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙浚予 --- wifi/frameworks/ets/taihe/wifi/BUILD.gn | 80 ---- .../ets/taihe/wifi/idl/ohos.wifi.taihe | 16 - .../ets/taihe/wifi/src/ani_constructor.cpp | 29 -- .../ets/taihe/wifi/src/ohos.wifi.impl.cpp | 23 - .../wifiManager/idl/ohos.wifiManager.taihe | 132 +----- .../wifiManager/src/ohos.wifiManager.impl.cpp | 412 +----------------- .../wifiManager/src/wifi_callback_taihe.h | 314 ------------- 7 files changed, 11 insertions(+), 995 deletions(-) delete mode 100644 wifi/frameworks/ets/taihe/wifi/BUILD.gn delete mode 100644 wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe delete mode 100644 wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp delete mode 100644 wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp delete mode 100644 wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h diff --git a/wifi/frameworks/ets/taihe/wifi/BUILD.gn b/wifi/frameworks/ets/taihe/wifi/BUILD.gn deleted file mode 100644 index 7b8894c8c..000000000 --- a/wifi/frameworks/ets/taihe/wifi/BUILD.gn +++ /dev/null @@ -1,80 +0,0 @@ -# Copyright (C) 2025-2025 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -import("//build/config/components/ets_frontend/ets2abc_config.gni") -import("//build/ohos.gni") -import("//build/ohos/taihe_idl/taihe.gni") -import("//foundation/communication/wifi/wifi/wifi.gni") # 导入taihe.gni - -copy_taihe_idl("copy_wifi") { - sources = [ - "./idl/ohos.wifi.taihe" - ] -} - -subsystem_name = "communication" -part_name = "wifi" -taihe_generated_file_path = "$taihe_file_path/out/$subsystem_name/$part_name" - -ohos_taihe("run_taihe") { - taihe_generated_file_path = "$taihe_generated_file_path" - deps = [ ":copy_wifi" ] - outputs = [ - "$taihe_generated_file_path/src/ohos.wifi.ani.cpp", - "$taihe_generated_file_path/src/ohos.wifi.abi.c", - ] -} - -taihe_shared_library("wifi_taihe_native") { #调用taihe_shared_library模板编译so - sanitize = { - cfi = true # Enable/disable control flow integrity detection - boundary_sanitize = true # Enable boundary san detection - cfi_cross_dso = true # Cross-SO CFI Checks - debug = false - } - taihe_generated_file_path = "$taihe_generated_file_path" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - sources = get_target_outputs(":run_taihe") - sources += [ - "./src/ani_constructor.cpp", - "./src/ohos.wifi.impl.cpp", - ] - deps = [ - ":run_taihe", - "$WIFI_ROOT_DIR/frameworks/native:wifi_sdk" - ] -} - -generate_static_abc("wifi_framework_abc") { #调用generate_static_abc编译abc - base_url = "$taihe_generated_file_path" #base_url直接设置为taihe_generated_file_path - files = [ "$taihe_generated_file_path/@ohos.wifi.ets" ] #files传入生成的ets文件 - is_boot_abc = "True" - device_dst_file = "/system/framework/wifi_framework_abc.abc" - dependencies = [ ":run_taihe" ] #编译abc依赖太和工具链调用 -} - -ohos_prebuilt_etc("wifi_framework_etc") { #调用ohos_prebuilt_etc将abc拷贝到/system/framework下 - source = "$target_out_dir/wifi_framework_abc.abc" - module_install_dir = "framework" - part_name = "$part_name" - subsystem_name = "$subsystem_name" - deps = [ ":wifi_framework_abc" ] #拷贝abc依赖编译abc -} - -group("wifi_framework_taihe") { - deps = [ - ":wifi_framework_etc", - ":wifi_taihe_native" - ] #单独运行run_taihe目标即可只调用工具链并生成对应代码 -} \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe b/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe deleted file mode 100644 index 204e6e8a7..000000000 --- a/wifi/frameworks/ets/taihe/wifi/idl/ohos.wifi.taihe +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -@!namespace("@ohos.wifi", "wifi") \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp b/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp deleted file mode 100644 index acf0e0380..000000000 --- a/wifi/frameworks/ets/taihe/wifi/src/ani_constructor.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.wifi.ani.hpp" -ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) -{ - ani_env *env; - if (ANI_OK != vm->GetEnv(ANI_VERSION_1, &env)) { - return ANI_ERROR; - } - if (ANI_OK != ohos::wifi::ANIRegister(env)) { - std::cerr << "Error from ohos::wifi::ANIRegister" << std::endl; - return ANI_ERROR; - } - *result = ANI_VERSION_1; - return ANI_OK; -} diff --git a/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp b/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp deleted file mode 100644 index 2ba156bce..000000000 --- a/wifi/frameworks/ets/taihe/wifi/src/ohos.wifi.impl.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ohos.wifi.proj.hpp" -#include "ohos.wifi.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -namespace { -// To be implemented. -} // namespace \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe index 3fdeac19d..391ffa5a9 100644 --- a/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe +++ b/wifi/frameworks/ets/taihe/wifiManager/idl/ohos.wifiManager.taihe @@ -156,134 +156,4 @@ function IsConnected(): bool; function IsWifiActive(): bool; function GetSignalLevel(rssi: f64, band: f64): f64; function GetIpInfo(): IpInfo; -function GetIpv6Info(): Ipv6Info; -function IsOpenSoftApAllowed(): bool; -function GetScanInfoList(): Array; -function IsMeteredHotspot(): bool; -function GetWifiDetailState(): WifiDetailState; -function GetStations(): Array; -function EnableWifi(): void; -function DisableWifi(): void; -function EnableSemiWifi(): void; - -@!sts_inject(""" -export function on(type: string, cb: (arg_0: NullishType) => void) { - switch(type) { - case "wifiStateChange": return onWifiStateChange(cb); - case "wifiConnectionChange": return onWifiConnectionChange(cb); - case "wifiScanStateChange": return onWifiScanStateChange(cb); - case "wifiRssiChange": return onWifiRssiChange(cb); - case "streamChange": return onStreamChange(cb); - case "deviceConfigChange": return onDeviceConfigChange(cb); - case "hotspotStateChange": return onHotspotStateChange(cb); - case "hotspotStaJoin": return onHotspotStaJoin(cb); - case "hotspotStaLeave": return onHotspotStaLeave(cb); - case "p2pStateChange": return onP2pStateChange(cb); - case "p2pConnectionChange": return onP2pConnectionChange(cb); - case "p2pDeviceChange": return onP2pDeviceChange(cb); - case "p2pPeerDeviceChange": return onP2pPeerDeviceChange(cb); - case "p2pPersistentGroupChange": return onP2pPersistentGroupChange(cb); - case "p2pDiscoveryChange": return onP2pDiscoveryChange(cb); - default: throw new Error(`Unknown type: ${type}`); - } -} -export function off(type: string, cb?: (arg_0: NullishType) => void) { - switch(type) { - case "wifiStateChange": return offWifiStateChange(cb as (((data: double) => void) | undefined)); - case "wifiConnectionChange": return offWifiConnectionChange(cb as (((data: double) => void) | undefined)); - case "wifiScanStateChange": return offWifiScanStateChange(cb as (((data: double) => void) | undefined)); - case "wifiRssiChange": return offWifiRssiChange((cb as (((data: double) => void)|undefined))); - case "streamChange": return offStreamChange(cb as (((data: double) => void) | undefined)); - case "deviceConfigChange": return offDeviceConfigChange(cb as (((data: double) => void) | undefined)); - case "hotspotStateChange": return offHotspotStateChange(cb as (((data: double) => void) | undefined)); - case "hotspotStaJoin": return offHotspotStaJoin(cb as (((data: StationInfo) => void) | undefined)); - case "hotspotStaLeave": return offHotspotStaLeave(cb as (((data: StationInfo) => void) | undefined)); - case "p2pStateChange": return offP2pStateChange(cb as (((data: double) => void) | undefined)); - case "p2pConnectionChange": return offP2pConnectionChange(cb as (((data: WifiP2pLinkedInfo) => void) | undefined)); - case "p2pDeviceChange": return offP2pDeviceChange(cb as (((data: WifiP2pDevice) => void) | undefined)); - case "p2pPeerDeviceChange": return offP2pPeerDeviceChange(cb as (((data: Array) => void) | undefined)); - case "p2pPersistentGroupChange": return offP2pPersistentGroupChange(cb as ((() => void) | undefined)); - case "p2pDiscoveryChange": return offP2pDiscoveryChange(cb as (((data: double) => void) | undefined)); - default: throw new Error(`Unknown type: ${type}`); - } -} -""") - -// @on_off("wifiStateChange") -function OnWifiStateChange(callback: (data: f64) => void): void; -// @on_off("wifiStateChange") -function OffWifiStateChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("wifiConnectionChange") -function OnWifiConnectionChange(callback: (data: f64) => void): void; -// @on_off("wifiConnectionChange") -function OffWifiConnectionChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("wifiScanStateChange") -function OnWifiScanStateChange(callback: (data: f64) => void): void; -// @on_off("wifiScanStateChange") -function OffWifiScanStateChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("wifiRssiChange") -function OnWifiRssiChange(callback: (data: f64) => void): void; -// @on_off("wifiRssiChange") -function OffWifiRssiChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("streamChange") -function OnStreamChange(callback: (data: f64) => void): void; -// @on_off("streamChange") -function OffStreamChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("deviceConfigChange") -function OnDeviceConfigChange(callback: (data: f64) => void): void; -// @on_off("deviceConfigChange") -function OffDeviceConfigChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("hotspotStateChange") -function OnHotspotStateChange(callback: (data: f64) => void): void; -// @on_off("hotspotStateChange") -function OffHotspotStateChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("hotspotStaJoin") -function OnHotspotStaJoin(callback: (data: StationInfo) => void): void; -// @on_off("hotspotStaJoin") -function OffHotspotStaJoin(callback: Optional<(data: StationInfo) => void>): void; - -// @on_off("hotspotStaLeave") -function OnHotspotStaLeave(callback: (data: StationInfo) => void): void; -// @on_off("hotspotStaLeave") -function OffHotspotStaLeave(callback: Optional<(data: StationInfo) => void>): void; - -// @on_off("p2pStateChange") -function OnP2pStateChange(callback: (data: f64) => void): void; -// @on_off("p2pStateChange") -function OffP2pStateChange(callback: Optional<(data: f64) => void>): void; - -// @on_off("p2pConnectionChange") -function OnP2pConnectionChange(callback: (data: WifiP2pLinkedInfo) => void): void; -// @on_off("p2pConnectionChange") -function OffP2pConnectionChange(callback: Optional<(data: WifiP2pLinkedInfo) => void>): void; - -// @on_off("p2pDeviceChange") -function OnP2pDeviceChange(callback: (data: WifiP2pDevice) => void): void; -// @on_off("p2pDeviceChange") -function OffP2pDeviceChange(callback: Optional<(data: WifiP2pDevice) => void>): void; - -// @on_off("p2pPeerDeviceChange") -function OnP2pPeerDeviceChange(callback: (data: Array) => void): void; -// @on_off("p2pPeerDeviceChange") -function OffP2pPeerDeviceChange(callback:Optional<(data: Array) => void>): void; - -union UndefinedType { - @undefined undefined; -} - -// @on_off("p2pPersistentGroupChange") -function OnP2pPersistentGroupChange(callback: (data: UndefinedType) => void): void; -// @on_off("p2pPersistentGroupChange") -function OffP2pPersistentGroupChange(callback: Optional<(data: UndefinedType) => void>): void; - -// @on_off("p2pDiscoveryChange") -function OnP2pDiscoveryChange(callback: (data: f64) => void): void; -// @on_off("p2pDiscoveryChange") -function OffP2pDiscoveryChange(callback: Optional<(data: f64) => void>): void; \ No newline at end of file +function GetIpv6Info(): Ipv6Info; \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp index 538db2cca..411c9b8c5 100644 --- a/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp +++ b/wifi/frameworks/ets/taihe/wifiManager/src/ohos.wifiManager.impl.cpp @@ -18,7 +18,15 @@ #include "taihe/runtime.hpp" #include "stdexcept" -#include "wifi_callback_taihe.h" +#include "wifi_device.h" +#include "wifi_device_impl.h" +#include "wifi_hotspot.h" +#include "wifi_hotspot_impl.h" +#include "wifi_scan.h" +#include "wifi_scan_impl.h" +#include "wifi_msg.h" +#include "wifi_p2p.h" +#include "wifi_p2p_impl.h" using namespace OHOS::Wifi; static std::shared_ptr g_wifiDevicePtr = WifiDevice::GetInstance(WIFI_DEVICE_ABILITY_ID); @@ -132,404 +140,4 @@ double GetSignalLevel(double rssi, double band) } ::ohos::wifiManager::Ipv6Info result = MakeIpv6Info(ipInfo.linkIpV6Address); return result; -} - -bool IsOpenSoftApAllowed() -{ - bool isSupported = false; - ErrCode ret = g_wifiHotspotPtr->IsOpenSoftApAllowed(isSupported); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("IsConnected return error"); - } - return static_cast(isSupported); -} - -void WifiScanInfoToTaihe(::ohos::wifiManager::WifiScanInfo &tmpInfo, WifiScanInfo scanInfo) -{ - tmpInfo.ssid = scanInfo.ssid; - tmpInfo.bssid = scanInfo.bssid; - tmpInfo.securityType = static_cast<::ohos::wifiManager::WifiSecurityType::key_t>(scanInfo.securityType); - tmpInfo.rssi = scanInfo.rssi; - tmpInfo.band = scanInfo.band; - tmpInfo.supportedWifiCategory = - static_cast<::ohos::wifiManager::WifiCategory::key_t>(scanInfo.supportedWifiCategory); -} - -::taihe::array<::ohos::wifiManager::WifiScanInfo> GetScanInfoList() -{ - bool compatible = false; - std::vector scanInfos; - ErrCode ret = g_wifiScanPtr->GetScanInfoList(scanInfos, compatible); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("getScanInfoList return error"); - } - std::vector<::ohos::wifiManager::WifiScanInfo> result; - for (WifiScanInfo scanInfo : scanInfos) { - ::ohos::wifiManager::WifiScanInfo tmpInfo = MakeTmpWifiScanInfo(); - WifiScanInfoToTaihe(tmpInfo, scanInfo); - result.emplace_back(tmpInfo); - } - return ::taihe::array<::ohos::wifiManager::WifiScanInfo>(taihe::copy_data_t{}, result.data(), result.size()); -} - -bool IsMeteredHotspot() -{ - bool isMeteredHotspot = false; - ErrCode ret = g_wifiDevicePtr->IsMeteredHotspot(isMeteredHotspot); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("isMeteredHotspot return error"); - } - return static_cast(isMeteredHotspot); -} - -::ohos::wifiManager::WifiDetailState GetWifiDetailState() -{ - WifiDetailState state = WifiDetailState::STATE_UNKNOWN; - ErrCode ret = g_wifiDevicePtr->GetWifiDetailState(state); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("GetWifiDetailState return error"); - } - return static_cast<::ohos::wifiManager::WifiDetailState::key_t>(state); -} - -void StationInfoToTaihe(::ohos::wifiManager::StationInfo &tmpInfo, StationInfo stationInfo) -{ - tmpInfo.macAddress = stationInfo.bssid; -} - -::taihe::array<::ohos::wifiManager::StationInfo> GetStations() -{ - std::vector vecStationInfo; - ErrCode ret = g_wifiHotspotPtr->GetStationList(vecStationInfo); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("getStations return error"); - } - std::vector<::ohos::wifiManager::StationInfo> result; - for (StationInfo stationInfo : vecStationInfo) { - ::ohos::wifiManager::StationInfo tmpInfo = MakeTmpStationInfo(); - StationInfoToTaihe(tmpInfo, stationInfo); - result.emplace_back(tmpInfo); - } - return ::taihe::array<::ohos::wifiManager::StationInfo>(taihe::copy_data_t{}, result.data(), result.size()); -} - -void EnableWifi() -{ - ErrCode ret = g_wifiDevicePtr->EnableWifi(); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("enableWifi return error"); - } -} - -void DisableWifi() -{ - ErrCode ret = g_wifiDevicePtr->DisableWifi(); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("disableWifi return error"); - } -} - -void EnableSemiWifi() -{ - ErrCode ret = g_wifiDevicePtr->EnableSemiWifi(); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("enableSemiWifi return error"); - } -} -OHOS::sptr wifiDeviceCallback = - OHOS::sptr(new (std::nothrow) WifiIdlDeviceEventCallback()); - -OHOS::sptr wifiScanCallback = - OHOS::sptr(new (std::nothrow) WifiIdlScanEventCallback()); - -OHOS::sptr wifiHotspotCallback = - OHOS::sptr(new (std::nothrow) WifiIdlHotspotEventCallback()); - -OHOS::sptr wifiP2pCallback = - OHOS::sptr(new (std::nothrow) WifiIdlP2pEventCallback()); - -void OnWifiStateChange(::taihe::callback_view callback) -{ - wifiDeviceCallback->wifiStateChangedCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"wifiStateChange"}; - ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnWifiStateChange return error"); - } -} - -void OffWifiStateChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnWifiConnectionChange(::taihe::callback_view callback) -{ - wifiDeviceCallback->wifiConnectionChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"wifiConnectionChange"}; - ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnWifiConnectionChange return error"); - } -} - -void OffWifiConnectionChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnWifiScanStateChange(::taihe::callback_view callback) -{ - wifiScanCallback->wifiScanStateChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"wifiScanStateChange"}; - ErrCode ret = g_wifiScanPtr->RegisterCallBack(wifiScanCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnWifiScanStateChange return error"); - } -} - -void OffWifiScanStateChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnWifiRssiChange(::taihe::callback_view callback) -{ - wifiDeviceCallback->wifiRssiChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"wifiRssiChange"}; - ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnWifiRssiChange return error"); - } -} - -void OffWifiRssiChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnStreamChange(::taihe::callback_view callback) -{ - wifiDeviceCallback->wifiStreamChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"streamChange"}; - ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnWifiRssiChange return error"); - } -} - -void OffStreamChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnDeviceConfigChange(::taihe::callback_view callback) -{ - wifiDeviceCallback->wifiDeviceConfigChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"deviceConfigChange"}; - ErrCode ret = g_wifiDevicePtr->RegisterCallBack(wifiDeviceCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnDeviceConfigChange return error"); - } -} - -void OffDeviceConfigChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnHotspotStateChange(::taihe::callback_view callback) -{ - wifiHotspotCallback->wifiHotspotStateChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"hotspotStateChange"}; - ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnHotspotStateChange return error"); - } -} - -void OffHotspotStateChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnHotspotStaJoin(::taihe::callback_view callback) -{ - wifiHotspotCallback->wifiHotspotStaJoinCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"hotspotStaJoin"}; - ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnHotspotStaJoin return error"); - } -} - -void OffHotspotStaJoin( - ::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnHotspotStaLeave(::taihe::callback_view callback) -{ - wifiHotspotCallback->wifiHotspotStaLeaveCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"hotspotStaLeave"}; - ErrCode ret = g_wifiHotspotPtr->RegisterCallBack(wifiHotspotCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnHotspotStaLeave return error"); - } -} - -void OffHotspotStaLeave( - ::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnP2pStateChange(::taihe::callback_view callback) -{ - wifiP2pCallback->wifiP2pStateChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"p2pStateChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pStateChange return error"); - } -} - -void OffP2pStateChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnP2pConnectionChange(::taihe::callback_view callback) -{ - wifiP2pCallback->wifiP2pConnectionChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"p2pConnectionChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pConnectionChange return error"); - } -} - -void OffP2pConnectionChange( - ::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnP2pDeviceChange(::taihe::callback_view callback) -{ - wifiP2pCallback->wifiP2pDeviceChangeCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"p2pDeviceChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pDeviceChange return error"); - } -} - -void OffP2pDeviceChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnP2pPeerDeviceChange(::taihe::callback_view)> callback) -{ - wifiP2pCallback->wifiP2pPeerDeviceChangeCallback_ = - ::taihe::optional<::taihe::callback)>>{std::in_place_t{}, callback}; - std::vector event = {"p2pPeerDeviceChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pPeerDeviceChange return error"); - } -} - -void OffP2pPeerDeviceChange(::taihe::optional_view<::taihe::callback)>> callback) -{ -} - -void OnP2pPersistentGroupChange(::taihe::callback_view callback) -{ - wifiP2pCallback->wifiP2pPersistentGroupChangeCallback_ = ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"p2pPersistentGroupChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pPersistentGroupChange return error"); - } -} - -void OffP2pPersistentGroupChange(::taihe::optional_view<::taihe::callback> callback) -{ -} - -void OnP2pDiscoveryChange(::taihe::callback_view callback) -{ - wifiP2pCallback->wifiP2pDiscoveryChangeCallback_ = - ::taihe::optional<::taihe::callback>{std::in_place_t{}, callback}; - std::vector event = {"p2pDiscoveryChange"}; - ErrCode ret = g_wifiP2pPtr->RegisterCallBack(wifiP2pCallback, event); - if (ret != WIFI_OPT_SUCCESS) { - taihe::set_error("OnP2pDiscoveryChange return error"); - } -} - -void OffP2pDiscoveryChange(::taihe::optional_view<::taihe::callback> callback) -{ -} -} - -TH_EXPORT_CPP_API_MakeWifiDeviceConfig(MakeWifiDeviceConfig); -TH_EXPORT_CPP_API_MakeWifiScanInfo(MakeWifiScanInfo); -TH_EXPORT_CPP_API_MakeWifiLinkedInfo(MakeWifiLinkedInfo); -TH_EXPORT_CPP_API_MakeIpInfo(MakeIpInfo); -TH_EXPORT_CPP_API_MakeIpv6Info(MakeIpv6Info); -TH_EXPORT_CPP_API_MakeStationInfo(MakeStationInfo); -TH_EXPORT_CPP_API_MakeHotspotConfig(MakeHotspotConfig); -TH_EXPORT_CPP_API_IsConnected(IsConnected); -TH_EXPORT_CPP_API_IsWifiActive(IsWifiActive); -TH_EXPORT_CPP_API_GetSignalLevel(GetSignalLevel); -TH_EXPORT_CPP_API_GetIpInfo(GetIpInfo); -TH_EXPORT_CPP_API_GetIpv6Info(GetIpv6Info); -TH_EXPORT_CPP_API_IsOpenSoftApAllowed(IsOpenSoftApAllowed); -TH_EXPORT_CPP_API_GetScanInfoList(GetScanInfoList); -TH_EXPORT_CPP_API_IsMeteredHotspot(IsMeteredHotspot); -TH_EXPORT_CPP_API_GetWifiDetailState(GetWifiDetailState); -TH_EXPORT_CPP_API_GetStations(GetStations); -TH_EXPORT_CPP_API_EnableWifi(EnableWifi); -TH_EXPORT_CPP_API_DisableWifi(DisableWifi); -TH_EXPORT_CPP_API_EnableSemiWifi(EnableSemiWifi); -TH_EXPORT_CPP_API_OnWifiStateChange(OnWifiStateChange); -TH_EXPORT_CPP_API_OffWifiStateChange(OffWifiStateChange); -TH_EXPORT_CPP_API_OnWifiConnectionChange(OnWifiConnectionChange); -TH_EXPORT_CPP_API_OffWifiConnectionChange(OffWifiConnectionChange); -TH_EXPORT_CPP_API_OnWifiScanStateChange(OnWifiScanStateChange); -TH_EXPORT_CPP_API_OffWifiScanStateChange(OffWifiScanStateChange); -TH_EXPORT_CPP_API_OnWifiRssiChange(OnWifiRssiChange); -TH_EXPORT_CPP_API_OffWifiRssiChange(OffWifiRssiChange); -TH_EXPORT_CPP_API_OnStreamChange(OnStreamChange); -TH_EXPORT_CPP_API_OffStreamChange(OffStreamChange); -TH_EXPORT_CPP_API_OnDeviceConfigChange(OnDeviceConfigChange); -TH_EXPORT_CPP_API_OffDeviceConfigChange(OffDeviceConfigChange); -TH_EXPORT_CPP_API_OnHotspotStateChange(OnHotspotStateChange); -TH_EXPORT_CPP_API_OffHotspotStateChange(OffHotspotStateChange); -TH_EXPORT_CPP_API_OnHotspotStaJoin(OnHotspotStaJoin); -TH_EXPORT_CPP_API_OffHotspotStaJoin(OffHotspotStaJoin); -TH_EXPORT_CPP_API_OnHotspotStaLeave(OnHotspotStaLeave); -TH_EXPORT_CPP_API_OffHotspotStaLeave(OffHotspotStaLeave); -TH_EXPORT_CPP_API_OnP2pStateChange(OnP2pStateChange); -TH_EXPORT_CPP_API_OffP2pStateChange(OffP2pStateChange); -TH_EXPORT_CPP_API_OnP2pConnectionChange(OnP2pConnectionChange); -TH_EXPORT_CPP_API_OffP2pConnectionChange(OffP2pConnectionChange); -TH_EXPORT_CPP_API_OnP2pDeviceChange(OnP2pDeviceChange); -TH_EXPORT_CPP_API_OffP2pDeviceChange(OffP2pDeviceChange); -TH_EXPORT_CPP_API_OnP2pPeerDeviceChange(OnP2pPeerDeviceChange); -TH_EXPORT_CPP_API_OffP2pPeerDeviceChange(OffP2pPeerDeviceChange); -TH_EXPORT_CPP_API_OnP2pPersistentGroupChange(OnP2pPersistentGroupChange); -TH_EXPORT_CPP_API_OffP2pPersistentGroupChange(OffP2pPersistentGroupChange); -TH_EXPORT_CPP_API_OnP2pDiscoveryChange(OnP2pDiscoveryChange); -TH_EXPORT_CPP_API_OffP2pDiscoveryChange(OffP2pDiscoveryChange); \ No newline at end of file +} \ No newline at end of file diff --git a/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h b/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h deleted file mode 100644 index 990646f11..000000000 --- a/wifi/frameworks/ets/taihe/wifiManager/src/wifi_callback_taihe.h +++ /dev/null @@ -1,314 +0,0 @@ -/* - * Copyright (C) 2025 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef OHOS_WIFI_CALLBACK_TAIHE_H -#define OHOS_WIFI_CALLBACK_TAIHE_H -#include "ohos.wifiManager.proj.hpp" -#include "ohos.wifiManager.impl.hpp" -#include "taihe/runtime.hpp" -#include "stdexcept" - -#include "wifi_device.h" -#include "wifi_device_impl.h" -#include "wifi_hotspot.h" -#include "wifi_hotspot_impl.h" -#include "wifi_scan.h" -#include "wifi_scan_impl.h" -#include "wifi_msg.h" -#include "wifi_p2p.h" -#include "wifi_p2p_impl.h" - -namespace OHOS { -namespace Wifi { -class WifiIdlDeviceEventCallback : public IWifiDeviceCallBack { -public: - WifiIdlDeviceEventCallback() - { - } - - virtual ~WifiIdlDeviceEventCallback() - { - } -public: - void OnWifiStateChanged(int state) override - { - double result = static_cast(state); - if (wifiStateChangedCallback_) { - (*wifiStateChangedCallback_)(result); - } - } - - void OnWifiConnectionChanged(int state, const WifiLinkedInfo &info) override - { - double result = static_cast(state); - if (wifiConnectionChangeCallback_) { - (*wifiConnectionChangeCallback_)(result); - } - } - - void OnWifiRssiChanged(int rssi) override - { - double result = static_cast(rssi); - if (wifiRssiChangeCallback_) { - (*wifiRssiChangeCallback_)(result); - } - } - - void OnWifiWpsStateChanged(int state, const std::string &pinCode) override - { - } - - void OnStreamChanged(int direction) override - { - double result = static_cast(direction); - if (wifiStreamChangeCallback_) { - (*wifiStreamChangeCallback_)(result); - } - } - - void OnDeviceConfigChanged(ConfigChange value) override - { - double result = static_cast(value); - if (wifiDeviceConfigChangeCallback_) { - (*wifiDeviceConfigChangeCallback_)(result); - } - } - - OHOS::sptr AsObject() override - { - return nullptr; - } - -public: - ::taihe::optional<::taihe::callback> wifiStateChangedCallback_; - ::taihe::optional<::taihe::callback> wifiConnectionChangeCallback_; - ::taihe::optional<::taihe::callback> wifiRssiChangeCallback_; - ::taihe::optional<::taihe::callback> wifiStreamChangeCallback_; - ::taihe::optional<::taihe::callback> wifiDeviceConfigChangeCallback_; -}; - -class WifiIdlScanEventCallback : public IWifiScanCallback { -public: - WifiIdlScanEventCallback() - { - } - - virtual ~WifiIdlScanEventCallback() - { - } - -public: - void OnWifiScanStateChanged(int state) override - { - double result = static_cast(state); - if (wifiScanStateChangeCallback_) { - (*wifiScanStateChangeCallback_)(result); - } - } - - OHOS::sptr AsObject() override - { - return nullptr; - } -public: - ::taihe::optional<::taihe::callback> wifiScanStateChangeCallback_; -}; - -class WifiIdlHotspotEventCallback : public IWifiHotspotCallback { -public: - WifiIdlHotspotEventCallback() - { - } - - virtual ~WifiIdlHotspotEventCallback() - { - } - -public: - void OnHotspotStateChanged(int state) override - { - double result = static_cast(state); - if (wifiHotspotStateChangeCallback_) { - (*wifiHotspotStateChangeCallback_)(result); - } - } - - void OnHotspotStaJoin(const StationInfo &info) override - { - // bssid -> macAddress - ::ohos::wifiManager::StationInfo result = {info.bssid}; - if (wifiHotspotStaJoinCallback_) { - (*wifiHotspotStaJoinCallback_)(result); - } - } - - void OnHotspotStaLeave(const StationInfo &info) override - { - // bssid -> macAddress - ::ohos::wifiManager::StationInfo result = {info.bssid}; - if (wifiHotspotStaLeaveCallback_) { - (*wifiHotspotStaLeaveCallback_)(result); - } - } - - OHOS::sptr AsObject() override - { - return nullptr; - } - -public: - ::taihe::optional<::taihe::callback> wifiHotspotStateChangeCallback_; - ::taihe::optional<::taihe::callback> - wifiHotspotStaJoinCallback_; - ::taihe::optional<::taihe::callback> - wifiHotspotStaLeaveCallback_; -}; - -class WifiIdlP2pEventCallback : public IWifiP2pCallback { -public: - WifiIdlP2pEventCallback() - { - } - - virtual ~WifiIdlP2pEventCallback() - { - } - -public: - void OnP2pStateChanged(int state) override - { - double result = static_cast(state); - if (wifiP2pStateChangeCallback_) { - (*wifiP2pStateChangeCallback_)(result); - } - } - - void OnP2pPersistentGroupsChanged(void) override - { - auto result = ::ohos::wifiManager::UndefinedType::make_undefined(); - if (wifiP2pPersistentGroupChangeCallback_) { - (*wifiP2pPersistentGroupChangeCallback_)(result); - } - } - - void OnP2pThisDeviceChanged(const WifiP2pDevice& device) override - { - ::taihe::string_view deviceName = static_cast<::taihe::string_view>(device.GetDeviceName()); - ::taihe::string_view deviceAddress = static_cast<::taihe::string_view>(device.GetDeviceAddress()); - ::ohos::wifiManager::DeviceAddressType deviceAddressType = - static_cast<::ohos::wifiManager::DeviceAddressType::key_t>(device.GetDeviceAddressType()); - ::taihe::string_view primaryDeviceType = static_cast<::taihe::string_view>(device.GetPrimaryDeviceType()); - ::ohos::wifiManager::P2pDeviceStatus deviceStatus = - static_cast<::ohos::wifiManager::P2pDeviceStatus::key_t>(device.GetP2pDeviceStatus()); - int groupCapabilities = static_cast(device.GetGroupCapabilitys()); - ::ohos::wifiManager::WifiP2pDevice result = {deviceName, deviceAddress, deviceAddressType, - primaryDeviceType, deviceStatus, groupCapabilities}; - if (wifiP2pDeviceChangeCallback_) { - (*wifiP2pDeviceChangeCallback_)(result); - } - } - - void OnP2pPeersChanged(const std::vector& devices) override - { - std::vector<::ohos::wifiManager::WifiP2pDevice> result; - for (WifiP2pDevice device : devices) { - ::taihe::string_view deviceName = static_cast<::taihe::string_view>(device.GetDeviceName()); - ::taihe::string_view deviceAddress = static_cast<::taihe::string_view>(device.GetDeviceAddress()); - ::ohos::wifiManager::DeviceAddressType deviceAddressType = - static_cast<::ohos::wifiManager::DeviceAddressType::key_t>(device.GetDeviceAddressType()); - ::taihe::string_view primaryDeviceType = - static_cast<::taihe::string_view>(device.GetPrimaryDeviceType()); - ::ohos::wifiManager::P2pDeviceStatus deviceStatus = - static_cast<::ohos::wifiManager::P2pDeviceStatus::key_t>(device.GetP2pDeviceStatus()); - int groupCapabilities = static_cast(device.GetGroupCapabilitys()); - ::ohos::wifiManager::WifiP2pDevice tmpDevice = {deviceName, deviceAddress, deviceAddressType, - primaryDeviceType, deviceStatus, groupCapabilities}; - result.emplace_back(tmpDevice); - } - ::taihe::array<::ohos::wifiManager::WifiP2pDevice> finalResult = - ::taihe::array<::ohos::wifiManager::WifiP2pDevice>(taihe::copy_data_t{}, result.data(), result.size()); - if (wifiP2pPeerDeviceChangeCallback_) { - (*wifiP2pPeerDeviceChangeCallback_)(finalResult); - } - } - - void OnP2pServicesChanged(const std::vector& srvInfo) override - { - } - - void OnP2pConnectionChanged(const WifiP2pLinkedInfo& info) override - { - ::ohos::wifiManager::P2pConnectState state = - static_cast<::ohos::wifiManager::P2pConnectState::key_t>(info.GetConnectState()); - ani_boolean isOwner = static_cast(info.IsGroupOwner()); - ::taihe::string_view ownerAddr = static_cast<::taihe::string_view>(info.GetGroupOwnerAddress()); - ::ohos::wifiManager::WifiP2pLinkedInfo result = {state, isOwner, ownerAddr}; - if (wifiP2pConnectionChangeCallback_) { - (*wifiP2pConnectionChangeCallback_)(result); - } - } - - void OnP2pDiscoveryChanged(bool isChange) override - { - double result = static_cast(isChange); - if (wifiP2pDiscoveryChangeCallback_) { - (*wifiP2pDiscoveryChangeCallback_)(result); - } - } - - void OnP2pActionResult(P2pActionCallback action, ErrCode code) override - { - } - - void OnConfigChanged(CfgType type, char* data, int dataLen) override - { - } - - void OnP2pGcJoinGroup(const OHOS::Wifi::GcInfo &info) override - { - } - - void OnP2pGcLeaveGroup(const OHOS::Wifi::GcInfo &info) override - { - } - - void OnP2pPrivatePeersChanged(const std::string &priWfdInfo) override - { - } - - void OnP2pChrErrCodeReport(const int errCode) override - { - } - - OHOS::sptr AsObject() override - { - return nullptr; - } - -public: - ::taihe::optional<::taihe::callback> wifiP2pStateChangeCallback_; - ::taihe::optional<::taihe::callback> - wifiP2pConnectionChangeCallback_; - ::taihe::optional<::taihe::callback> - wifiP2pDeviceChangeCallback_; - ::taihe::optional<::taihe::callback)>> - wifiP2pPeerDeviceChangeCallback_; - ::taihe::optional<::taihe::callback> - wifiP2pPersistentGroupChangeCallback_; - ::taihe::optional<::taihe::callback> wifiP2pDiscoveryChangeCallback_; -}; -} // namespace Wifi -} // namespace OHOS -#endif \ No newline at end of file -- Gitee From 817e2e5ec6b6d251435769af41047571f128fabf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=B5=9A=E4=BA=88?= Date: Thu, 29 May 2025 15:54:35 +0800 Subject: [PATCH 3/3] test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙浚予 --- wifi/bundle.json | 3 --- wifi/frameworks/BUILD.gn | 1 - 2 files changed, 4 deletions(-) diff --git a/wifi/bundle.json b/wifi/bundle.json index 06725f778..5bdeeefc9 100644 --- a/wifi/bundle.json +++ b/wifi/bundle.json @@ -173,9 +173,6 @@ }, "name": "//foundation/communication/wifi/wifi/frameworks/cj:cj_wifi_ffi" }, - { - "name": "//foundation/communication/wifi/wifi/frameworks/ets/taihe/wifi:copy_wifi" - }, { "name": "//foundation/communication/wifi/wifi/frameworks/ets/taihe/wifiManager:copy_wifiManager" } diff --git a/wifi/frameworks/BUILD.gn b/wifi/frameworks/BUILD.gn index 8c230722f..a48078efd 100644 --- a/wifi/frameworks/BUILD.gn +++ b/wifi/frameworks/BUILD.gn @@ -25,7 +25,6 @@ group("wifi_kits") { deps += [ "$WIFI_ROOT_DIR/frameworks/cj:cj_wifi_ffi", "$WIFI_ROOT_DIR/frameworks/ets/ani:wifi_ani", - "$WIFI_ROOT_DIR/frameworks/ets/taihe/wifi:wifi_framework_taihe", "$WIFI_ROOT_DIR/frameworks/ets/taihe/wifiManager:wifiManager_framework_taihe", "$WIFI_ROOT_DIR/frameworks/js/napi:wifi", "$WIFI_ROOT_DIR/frameworks/js/napi:wifiext", -- Gitee