From 0ac7cfa5aed6f02e5a8d8b3992aa427cbe661307 Mon Sep 17 00:00:00 2001 From: leo9001 Date: Mon, 7 Jul 2025 12:35:36 +0800 Subject: [PATCH] =?UTF-8?q?overload=E6=95=B4=E6=94=B9=20ets=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Issue: https://gitee.com/openharmony/sensors_miscdevice/issues/ICKRQB?from=project-issue Signed-off-by: leo9001 --- .../taihe/author/src/ohos.vibrator.impl.cpp | 8 +++++ frameworks/ets/taihe/idl/ohos.vibrator.taihe | 35 ++++++++++++++----- .../js/ani/vibrator/ets/@ohos.vibrator.ets | 12 ++++--- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp index 14268ad..c115a98 100644 --- a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp +++ b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp @@ -448,8 +448,16 @@ bool isSupportEffectSync(::taihe::string_view effectId) // Since these macros are auto-generate, lint will cause false positive. // NOLINTBEGIN TH_EXPORT_CPP_API_stopVibrationByModeSync(stopVibrationByModeSync); +TH_EXPORT_CPP_API_StopVibrationWithCallback_chinast_1(stopVibrationByModeSync); +TH_EXPORT_CPP_API_StopVibrationReturnsPromise_chinast_1(stopVibrationByModeSync); TH_EXPORT_CPP_API_startVibrationSync(startVibrationSync); +TH_EXPORT_CPP_API_StartVibrationWithCallback(startVibrationSync); +TH_EXPORT_CPP_API_StartVibrationReturnsPromise(startVibrationSync); TH_EXPORT_CPP_API_isHdHapticSupported(isHdHapticSupported); TH_EXPORT_CPP_API_stopVibrationSync(stopVibrationSync); +TH_EXPORT_CPP_API_StopVibrationWithCallback(stopVibrationSync); +TH_EXPORT_CPP_API_StopVibrationReturnsPromise(stopVibrationSync); TH_EXPORT_CPP_API_isSupportEffectSync(isSupportEffectSync); +TH_EXPORT_CPP_API_IsSupportEffectWithCallback(isSupportEffectSync); +TH_EXPORT_CPP_API_IsSupportEffectReturnsPromise(isSupportEffectSync); // NOLINTEND diff --git a/frameworks/ets/taihe/idl/ohos.vibrator.taihe b/frameworks/ets/taihe/idl/ohos.vibrator.taihe index bf4e15c..b5be289 100644 --- a/frameworks/ets/taihe/idl/ohos.vibrator.taihe +++ b/frameworks/ets/taihe/idl/ohos.vibrator.taihe @@ -624,9 +624,14 @@ struct HapticFileDescriptor { * @syscap SystemCapability.Sensors.MiscDevice * @since 9 */ -@gen_async("stopVibration") -@gen_promise("stopVibration") function stopVibrationByModeSync(stopMode: VibratorStopMode): void; +@static_overload("stopVibration") +@async +function StopVibrationWithCallback_chinast_1(stopMode: VibratorStopMode): void; +@static_overload("stopVibration") +@promise +function StopVibrationReturnsPromise_chinast_1(stopMode: VibratorStopMode): void; + /** * Trigger vibrator vibration. @@ -659,9 +664,13 @@ function stopVibrationByModeSync(stopMode: VibratorStopMode): void; * @atomicservice * @since 11 */ -@gen_async("startVibration") -@gen_promise("startVibration") function startVibrationSync(effect: VibrateEffect, attribute: VibrateAttribute): void; +@static_overload("startVibration") +@async +function StartVibrationWithCallback(effect: VibrateEffect, attribute: VibrateAttribute): void; +@static_overload("startVibration") +@promise +function StartVibrationReturnsPromise(effect: VibrateEffect, attribute: VibrateAttribute): void; /** * Whether the high-definition haptic is supported. @@ -683,9 +692,13 @@ function isHdHapticSupported(): bool; * @atomicservice * @since 12 */ -@gen_async("stopVibration") -@gen_promise("stopVibration") function stopVibrationSync(): void; +@static_overload("stopVibration") +@async +function StopVibrationWithCallback(): void; +@static_overload("stopVibration") +@promise +function StopVibrationReturnsPromise(): void; /** * Whether the preset vibration effect is supported. @@ -698,6 +711,10 @@ function stopVibrationSync(): void; * @syscap SystemCapability.Sensors.MiscDevice * @since 10 */ -@gen_async("isSupportEffect") -@gen_promise("isSupportEffect") -function isSupportEffectSync(effectId: String): bool; \ No newline at end of file +function isSupportEffectSync(effectId: String): bool; +@static_overload("isSupportEffect") +@async +function IsSupportEffectWithCallback(effectId: String): bool; +@static_overload("isSupportEffect") +@promise +function IsSupportEffectReturnsPromise(effectId: String): bool; \ No newline at end of file diff --git a/frameworks/js/ani/vibrator/ets/@ohos.vibrator.ets b/frameworks/js/ani/vibrator/ets/@ohos.vibrator.ets index 9c7c0ce..c8f3415 100644 --- a/frameworks/js/ani/vibrator/ets/@ohos.vibrator.ets +++ b/frameworks/js/ani/vibrator/ets/@ohos.vibrator.ets @@ -25,7 +25,7 @@ export default namespace vibrator { return 0; } - export function startVibration(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback): void { + export function startVibration_chinast_1(effect: VibrateEffect, attribute: VibrateAttribute, callback: AsyncCallback): void { let p1 = taskpool.execute(startVibrationIntSync, effect, attribute); p1.then((e: NullishType)=>{ console.log("in callback startVibration then.") @@ -39,7 +39,7 @@ export default namespace vibrator { }) } - export function startVibration(effect: VibrateEffect, attribute: VibrateAttribute): Promise { + export function startVibration_chinast_2(effect: VibrateEffect, attribute: VibrateAttribute): Promise { let p = new Promise((resolve: (v: undefined) => void, reject: (error: Error) => void) : void => { let p1 = taskpool.execute(startVibrationIntSync, effect, attribute); p1.then((e: NullishType) : void =>{ @@ -54,9 +54,11 @@ export default namespace vibrator { return p; } + overload startVibration { startVibration_chinast_1, startVibration_chinast_2 }; + export native function isSupportEffectInterally(effectId: string): boolean; - export function isSupportEffect(effectId: string, callback: AsyncCallback): void { + export function isSupportEffect_chinast_1(effectId: string, callback: AsyncCallback): void { let p1 = taskpool.execute(isSupportEffectInterally, effectId); p1.then((e: NullishType)=>{ let r = e as boolean; @@ -72,7 +74,7 @@ export default namespace vibrator { }); } - export function isSupportEffect(effectId: string): Promise { + export function isSupportEffect_chinast_2(effectId: string): Promise { let p = new Promise((resolve: (v: boolean) => void, reject: (error: Error) => void) : void => { let p1 = taskpool.execute(isSupportEffectInterally, effectId); p1.then((e: NullishType) : boolean=>{ @@ -88,6 +90,8 @@ export default namespace vibrator { return p; } + overload isSupportEffect { isSupportEffect_chinast_1, isSupportEffect_chinast_2 }; + export type Usage = 'unknown' | 'alarm' | 'ring' | 'notification' | 'communication' | 'touch' | 'media' | 'physicalFeedback' | 'simulateReality'; -- Gitee