From cbc91cd778ebfc17e7f16d383e839b4ea4695f5c Mon Sep 17 00:00:00 2001 From: anjiaqi Date: Tue, 22 Jul 2025 19:19:40 +0800 Subject: [PATCH] Overload in communication_netmanager_ext on 0702 Issue: https://gitee.com/openharmony/interface_sdk-js/issues/ICNPRN Signed-off-by: anjiaqi Change-Id: Iff10fb1f0a9c4362220b9ca53e1f5e12824c985f --- .../ani/sharing/ets/@ohos.net.sharing.d.ets | 129 +++++++++++++----- 1 file changed, 95 insertions(+), 34 deletions(-) diff --git a/frameworks/ets/ani/sharing/ets/@ohos.net.sharing.d.ets b/frameworks/ets/ani/sharing/ets/@ohos.net.sharing.d.ets index 4dbfc95a..b8d952d1 100644 --- a/frameworks/ets/ani/sharing/ets/@ohos.net.sharing.d.ets +++ b/frameworks/ets/ani/sharing/ets/@ohos.net.sharing.d.ets @@ -25,7 +25,7 @@ export default namespace sharing { export native function isSharingSupportedSync():boolean; - export function isSharingSupported(callback: AsyncCallback): void { + export function isSharingSupportedWithCallback(callback: AsyncCallback): void { let p1 = taskpool.execute((): boolean => { return isSharingSupportedSync(); }) @@ -36,7 +36,7 @@ export default namespace sharing { }); } - export function isSharingSupported(): Promise { + export function isSharingSupportedReturnsPromise(): Promise { return new Promise((resolve, reject) => { taskpool.execute((): boolean => { return isSharingSupportedSync(); @@ -48,9 +48,11 @@ export default namespace sharing { }); } + export overload isSharingSupported { isSharingSupportedWithCallback, isSharingSupportedReturnsPromise }; + export native function isSharingSync():boolean; - export function isSharing(callback: AsyncCallback): void { + export function isSharingWithCallback(callback: AsyncCallback): void { let p1 = taskpool.execute((): boolean => { return isSharingSync(); }) @@ -61,7 +63,7 @@ export default namespace sharing { }); } - export function isSharing(): Promise { + export function isSharingReturnsPromise(): Promise { return new Promise((resolve, reject) => { taskpool.execute((): boolean => { return isSharingSync(); @@ -73,9 +75,11 @@ export default namespace sharing { }); } + export overload isSharing { isSharingWithCallback, isSharingReturnsPromise }; + export native function startSharingSync(type: SharingIfaceType): void; - export function startSharing(type: SharingIfaceType, callback: AsyncCallback): void { + export function startSharingWithCallback(type: SharingIfaceType, callback: AsyncCallback): void { let p1 = taskpool.execute((): undefined => { return startSharingSync(type); }) @@ -86,7 +90,7 @@ export default namespace sharing { }); } - export function startSharing(type: SharingIfaceType): Promise { + export function startSharingReturnsPromise(type: SharingIfaceType): Promise { return new Promise((resolve, reject) => { taskpool.execute((): undefined => { return startSharingSync(type); @@ -98,9 +102,11 @@ export default namespace sharing { }); } + export overload startSharing { startSharingWithCallback, startSharingReturnsPromise }; + export native function stopSharingSync(type: SharingIfaceType): void; - export function stopSharing(type: SharingIfaceType, callback: AsyncCallback): void { + export function stopSharingWithCallback(type: SharingIfaceType, callback: AsyncCallback): void { let p1 = taskpool.execute((): undefined => { return stopSharingSync(type); }) @@ -111,7 +117,7 @@ export default namespace sharing { }); } - export function stopSharing(type: SharingIfaceType): Promise { + export function stopSharingReturnsPromise(type: SharingIfaceType): Promise { return new Promise((resolve, reject) => { taskpool.execute((): undefined => { return stopSharingSync(type); @@ -123,9 +129,11 @@ export default namespace sharing { }); } + export overload stopSharing { stopSharingWithCallback, stopSharingReturnsPromise }; + export native function getStatsRxBytesSync():long; - export function getStatsRxBytes(callback: AsyncCallback): void { + export function getStatsRxBytesWithCallback(callback: AsyncCallback): void { let p1 = taskpool.execute((): long => { return getStatsRxBytesSync(); }) @@ -136,7 +144,7 @@ export default namespace sharing { }); } - export function getStatsRxBytes(): Promise { + export function getStatsRxBytesReturnsPromise(): Promise { return new Promise((resolve, reject) => { taskpool.execute((): long => { return getStatsRxBytesSync(); @@ -148,9 +156,11 @@ export default namespace sharing { }); } + export overload getStatsRxBytes { getStatsRxBytesWithCallback, getStatsRxBytesReturnsPromise }; + export native function getStatsTxBytesSync():long; - function getStatsTxBytes(callback: AsyncCallback): void { + function getStatsTxBytesWithCallback(callback: AsyncCallback): void { let p1 = taskpool.execute((): long => { return getStatsTxBytesSync(); }) @@ -161,7 +171,7 @@ export default namespace sharing { }); } - function getStatsTxBytes(): Promise { + function getStatsTxBytesReturnsPromise(): Promise { return new Promise((resolve, reject) => { taskpool.execute((): long => { return getStatsTxBytesSync(); @@ -173,9 +183,11 @@ export default namespace sharing { }); } + export overload getStatsTxBytes { getStatsTxBytesWithCallback, getStatsTxBytesReturnsPromise }; + export native function getStatsTotalBytesSync():long; - export function getStatsTotalBytes(callback: AsyncCallback): void { + export function getStatsTotalBytesWithCallback(callback: AsyncCallback): void { let p1 = taskpool.execute((): long => { return getStatsTotalBytesSync(); }) @@ -186,7 +198,7 @@ export default namespace sharing { }); } - export function getStatsTotalBytes(): Promise { + export function getStatsTotalBytesReturnsPromise(): Promise { return new Promise((resolve, reject) => { taskpool.execute((): long => { return getStatsTxBytesSync(); @@ -198,9 +210,12 @@ export default namespace sharing { }); } + export overload getStatsTotalBytes { getStatsTotalBytesWithCallback, getStatsTotalBytesReturnsPromise }; + export native function getSharingIfacesSync(state: SharingIfaceState): Array; - export function getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback>): void { + export function getSharingIfacesWithCallback( + state: SharingIfaceState, callback: AsyncCallback>): void { let p1 = taskpool.execute((): Array => { return getSharingIfacesSync(state); }) @@ -211,7 +226,7 @@ export default namespace sharing { }); } - export function getSharingIfaces(state: SharingIfaceState): Promise> { + export function getSharingIfacesReturnsPromise(state: SharingIfaceState): Promise> { return new Promise>((resolve, reject) => { taskpool.execute((): Array => { return getSharingIfacesSync(state); @@ -223,9 +238,12 @@ export default namespace sharing { }); } + export overload getSharingIfaces { getSharingIfacesWithCallback, getSharingIfacesReturnsPromise }; + export native function getSharingStateSync(type: SharingIfaceType): SharingIfaceState; - export function getSharingState(type: SharingIfaceType, callback: AsyncCallback): void { + export function getSharingStateWithCallback( + type: SharingIfaceType, callback: AsyncCallback): void { let p1 = taskpool.execute((): SharingIfaceState => { return getSharingStateSync(type); }) @@ -236,7 +254,7 @@ export default namespace sharing { }); } - export function getSharingState(type: SharingIfaceType): Promise { + export function getSharingStateReturnsPromise(type: SharingIfaceType): Promise { return new Promise((resolve, reject) => { taskpool.execute((): SharingIfaceState => { return getSharingStateSync(type); @@ -248,9 +266,12 @@ export default namespace sharing { }); } + export overload getSharingState { getSharingStateWithCallback, getSharingStateReturnsPromise }; + export native function getSharableRegexesSync(type: SharingIfaceType): Array; - export function getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback>): void { + export function getSharableRegexesWtihCallback( + type: SharingIfaceType, callback: AsyncCallback>): void { let p1 = taskpool.execute((): Array => { return getSharableRegexesSync(type); }) @@ -261,7 +282,7 @@ export default namespace sharing { }); } - export function getSharableRegexes(type: SharingIfaceType): Promise> { + export function getSharableRegexesReturnsPromise(type: SharingIfaceType): Promise> { return new Promise>((resolve, reject) => { taskpool.execute((): Array => { return getSharableRegexesSync(type); @@ -273,26 +294,66 @@ export default namespace sharing { }); } - export function on(type: 'sharingStateChange' | 'interfaceSharingStateChange' | 'sharingUpstreamChange', callback: Object): void { - if (type == 'sharingStateChange') { - onSharingStateChange(callback as Callback); - } else if (type == 'interfaceSharingStateChange') { - onInterfaceSharingStateChange(callback as Callback) - } else if (type == 'sharingUpstreamChange') { - onSharingUpstreamChange(callback as Callback); + export overload getSharableRegexes { getSharableRegexesWtihCallback, getSharableRegexesReturnsPromise }; + + export function onSharingStateChangeWithCallback( + type: 'sharingStateChange', callback: Callback): void { + if (type != 'sharingStateChange') { + throw new Error('Invalid event type: ' + type); + } + onSharingStateChange(callback); + } + + export function onInterfaceSharingStateChangeWithCallback( + type: 'interfaceSharingStateChange', callback: Callback): void { + if (type != 'interfaceSharingStateChange') { + throw new Error('Invalid event type: ' + type); + } + onInterfaceSharingStateChange(callback); + } + + export function onSharingUpstreamChangeWithCallback( + type: 'sharingUpstreamChange', callback: Callback): void { + if (type != 'sharingUpstreamChange') { + throw new Error('Invalid event type: ' + type); + } + onSharingUpstreamChange(callback); + } + + export overload on { + onSharingStateChangeWithCallback, + onInterfaceSharingStateChangeWithCallback, + onSharingUpstreamChangeWithCallback }; + + export function offSharingStateChangeWithOptionalCallback( + type: 'sharingStateChange', callback?: Callback): void { + if (type != 'sharingStateChange') { + throw new Error('Invalid event type: ' + type); + } + offSharingStateChange(callback); + } + + export function offInterfaceSharingStateChangeWithOptionalCallback( + type: 'interfaceSharingStateChange', callback?: Callback): void { + if (type != 'interfaceSharingStateChange') { + throw new Error('Invalid event type: ' + type); } + offInterfaceSharingStateChange(callback); } - export function off(type: 'sharingStateChange' | 'interfaceSharingStateChange' | 'sharingUpstreamChange', callback?: Object): void { - if (type == 'sharingStateChange') { - offSharingStateChange(callback as Callback | undefined); - } else if (type == 'interfaceSharingStateChange') { - offInterfaceSharingStateChange(callback as Callback | undefined) - } else if (type == 'sharingUpstreamChange') { - offSharingUpstreamChange(callback as Callback | undefined); + export function offSharingUpstreamChangeWithOptionalCallback( + type: 'sharingUpstreamChange', callback?: Callback): void { + if (type != 'sharingUpstreamChange') { + throw new Error('Invalid event type: ' + type); } + offSharingUpstreamChange(callback); } + export overload off { + offSharingStateChangeWithOptionalCallback, + offInterfaceSharingStateChangeWithOptionalCallback, + offSharingUpstreamChangeWithOptionalCallback }; + export native function onSharingStateChange(callback: Callback): void; export native function offSharingStateChange(callback?: Callback): void; -- Gitee