From 998b4e14fc6eb0df9378f2ebaf5fcb9a26bc54c2 Mon Sep 17 00:00:00 2001 From: sylar Date: Mon, 2 Dec 2024 14:12:46 +0800 Subject: [PATCH] feat: rename symbol names for internal method channel name --- .../bindings/native_iris_event_bindings.dart | 143 ++++-------------- .../internal/platform/io/iris_event_io.dart | 12 +- .../ffi_gen/ffigen_config_method_channel.yaml | 25 +++ scripts/ffi_gen/run_ffi_gen.sh | 1 + src/iris_event.cc | 10 +- src/iris_event.h | 10 +- 6 files changed, 72 insertions(+), 129 deletions(-) create mode 100644 scripts/ffi_gen/ffigen_config_method_channel.yaml diff --git a/lib/src/method_channel/internal/platform/io/bindings/native_iris_event_bindings.dart b/lib/src/method_channel/internal/platform/io/bindings/native_iris_event_bindings.dart index ba0b965..bacee31 100644 --- a/lib/src/method_channel/internal/platform/io/bindings/native_iris_event_bindings.dart +++ b/lib/src/method_channel/internal/platform/io/bindings/native_iris_event_bindings.dart @@ -1,5 +1,3 @@ -// ignore_for_file: camel_case_types, non_constant_identifier_names, public_member_api_docs, sort_constructors_first - // AUTO GENERATED FILE, DO NOT EDIT. // // Generated by `package:ffigen`. @@ -21,133 +19,69 @@ class NativeIrisEventBinding { lookup) : _lookup = lookup; - int InitDartApiDL( + int RtmInitDartApiDL( ffi.Pointer data, ) { - return _InitDartApiDL( + return _RtmInitDartApiDL( data, ); } - late final _InitDartApiDLPtr = + late final _RtmInitDartApiDLPtr = _lookup)>>( - 'InitDartApiDL'); - late final _InitDartApiDL = - _InitDartApiDLPtr.asFunction)>(); + 'RtmInitDartApiDL'); + late final _RtmInitDartApiDL = + _RtmInitDartApiDLPtr.asFunction)>(); - void Dispose() { - return _Dispose(); + void RtmDispose() { + return _RtmDispose(); } - late final _DisposePtr = - _lookup>('Dispose'); - late final _Dispose = _DisposePtr.asFunction(); + late final _RtmDisposePtr = + _lookup>('RtmDispose'); + late final _RtmDispose = _RtmDisposePtr.asFunction(); - void OnEvent( + void RtmOnEvent( ffi.Pointer param, ) { - return _OnEvent( + return _RtmOnEvent( param, ); } - late final _OnEventPtr = + late final _RtmOnEventPtr = _lookup)>>( - 'OnEvent'); - late final _OnEvent = - _OnEventPtr.asFunction)>(); - - void OnEventLegacy( - ffi.Pointer event, - ffi.Pointer data, - ffi.Pointer> buffer, - ffi.Pointer length, - int buffer_count, - ) { - return _OnEventLegacy( - event, - data, - buffer, - length, - buffer_count, - ); - } - - late final _OnEventLegacyPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ffi.Pointer, - ffi.Uint32)>>('OnEventLegacy'); - late final _OnEventLegacy = _OnEventLegacyPtr.asFunction< - void Function(ffi.Pointer, ffi.Pointer, - ffi.Pointer>, ffi.Pointer, int)>(); - - void OnEventExLegacy( - ffi.Pointer event, - ffi.Pointer data, - ffi.Pointer result, - ffi.Pointer> buffer, - ffi.Pointer length, - int buffer_count, - ) { - return _OnEventExLegacy( - event, - data, - result, - buffer, - length, - buffer_count, - ); - } + 'RtmOnEvent'); + late final _RtmOnEvent = + _RtmOnEventPtr.asFunction)>(); - late final _OnEventExLegacyPtr = _lookup< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ffi.Pointer, - ffi.Uint32)>>('OnEventExLegacy'); - late final _OnEventExLegacy = _OnEventExLegacyPtr.asFunction< - void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ffi.Pointer, - int)>(); - - void RegisterDartPort( + void RtmRegisterDartPort( int send_port, ) { - return _RegisterDartPort( + return _RtmRegisterDartPort( send_port, ); } - late final _RegisterDartPortPtr = + late final _RtmRegisterDartPortPtr = _lookup>( - 'RegisterDartPort'); - late final _RegisterDartPort = - _RegisterDartPortPtr.asFunction(); + 'RtmRegisterDartPort'); + late final _RtmRegisterDartPort = + _RtmRegisterDartPortPtr.asFunction(); - void UnregisterDartPort( + void RtmUnregisterDartPort( int send_port, ) { - return _UnregisterDartPort( + return _RtmUnregisterDartPort( send_port, ); } - late final _UnregisterDartPortPtr = + late final _RtmUnregisterDartPortPtr = _lookup>( - 'UnregisterDartPort'); - late final _UnregisterDartPort = - _UnregisterDartPortPtr.asFunction(); + 'RtmUnregisterDartPort'); + late final _RtmUnregisterDartPort = + _RtmUnregisterDartPortPtr.asFunction(); late final addresses = _SymbolAddresses(this); } @@ -156,24 +90,7 @@ class _SymbolAddresses { final NativeIrisEventBinding _library; _SymbolAddresses(this._library); ffi.Pointer)>> - get OnEvent => _library._OnEventPtr; - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ffi.Pointer, - ffi.Uint32)>> get OnEventLegacy => _library._OnEventLegacyPtr; - ffi.Pointer< - ffi.NativeFunction< - ffi.Void Function( - ffi.Pointer, - ffi.Pointer, - ffi.Pointer, - ffi.Pointer>, - ffi.Pointer, - ffi.Uint32)>> get OnEventExLegacy => _library._OnEventExLegacyPtr; + get RtmOnEvent => _library._RtmOnEventPtr; } final class EventParam extends ffi.Struct { diff --git a/lib/src/method_channel/internal/platform/io/iris_event_io.dart b/lib/src/method_channel/internal/platform/io/iris_event_io.dart index 4b9f151..0c83035 100644 --- a/lib/src/method_channel/internal/platform/io/iris_event_io.dart +++ b/lib/src/method_channel/internal/platform/io/iris_event_io.dart @@ -28,27 +28,27 @@ class IrisEventIO implements IrisEvent { late final NativeIrisEventBinding _nativeIrisEventBinding; - /// Initialize the [IrisEvent], which call `InitDartApiDL` directly + /// Initialize the [IrisEvent], which call `RtmInitDartApiDL` directly void initialize() { - _nativeIrisEventBinding.InitDartApiDL(ffi.NativeApi.initializeApiDLData); + _nativeIrisEventBinding.RtmInitDartApiDL(ffi.NativeApi.initializeApiDLData); } /// Register dart [SendPort] to send the message from native void registerEventHandler(SendPort sendPort) { - _nativeIrisEventBinding.RegisterDartPort(sendPort.nativePort); + _nativeIrisEventBinding.RtmRegisterDartPort(sendPort.nativePort); } /// Unregister dart [SendPort] which used to send the message from native void unregisterEventHandler(SendPort sendPort) { - _nativeIrisEventBinding.UnregisterDartPort(sendPort.nativePort); + _nativeIrisEventBinding.RtmUnregisterDartPort(sendPort.nativePort); } /// Clean up native resources void dispose() { - _nativeIrisEventBinding.Dispose(); + _nativeIrisEventBinding.RtmDispose(); } /// Get the onEvent function pointer from C ffi.Pointer)>> - get onEventPtr => _nativeIrisEventBinding.addresses.OnEvent; + get onEventPtr => _nativeIrisEventBinding.addresses.RtmOnEvent; } diff --git a/scripts/ffi_gen/ffigen_config_method_channel.yaml b/scripts/ffi_gen/ffigen_config_method_channel.yaml new file mode 100644 index 0000000..e4f5aeb --- /dev/null +++ b/scripts/ffi_gen/ffigen_config_method_channel.yaml @@ -0,0 +1,25 @@ +name: 'NativeIrisEventBinding' +description: 'Bindings to IrisEventHandler' + +output: 'lib/src/method_channel/internal/platform/io/bindings/native_iris_event_bindings.dart' + +headers: + entry-points: + - 'src/iris_event.h' + + include-directives: + - 'src/iris_event.h' + +llvm-path: + - '/opt/homebrew/opt/llvm@15' + +# Generating typedefs need set the sdk constraints to >=2.14, remove it +# if we can set our sdk constraints to >=2.14 +typedefs: + exclude: + - 'Dart_Port' + +functions: + symbol-address: + include: + - 'OnEvent' # Match function name. \ No newline at end of file diff --git a/scripts/ffi_gen/run_ffi_gen.sh b/scripts/ffi_gen/run_ffi_gen.sh index d77a53e..44ea832 100644 --- a/scripts/ffi_gen/run_ffi_gen.sh +++ b/scripts/ffi_gen/run_ffi_gen.sh @@ -19,6 +19,7 @@ pushd ${PROJECT_ROOT} flutter packages get flutter pub run ffigen --config=${MY_PATH}/ffigen_config.yaml +flutter pub run ffigen --config=${MY_PATH}/ffigen_config_method_channel.yaml popd diff --git a/src/iris_event.cc b/src/iris_event.cc index bb0f671..0a7d063 100644 --- a/src/iris_event.cc +++ b/src/iris_event.cc @@ -202,7 +202,7 @@ std::unique_ptr dartMessageHandlerManager_ = nullptr; int init_dart_api_times_ = 0; // Initialize `dart_api_dl.h` -EXPORT intptr_t InitDartApiDL(void *data) +EXPORT intptr_t RtmInitDartApiDL(void *data) { std::lock_guard lock(message_handler_mutex_); int ret = 0; @@ -217,7 +217,7 @@ EXPORT intptr_t InitDartApiDL(void *data) return ret; } -EXPORT void Dispose() +EXPORT void RtmDispose() { std::lock_guard lock(message_handler_mutex_); --init_dart_api_times_; @@ -227,7 +227,7 @@ EXPORT void Dispose() } } -EXPORT void OnEvent(EventParam *param) +EXPORT void RtmOnEvent(EventParam *param) { std::lock_guard lock(message_handler_mutex_); if (dartMessageHandlerManager_) @@ -236,7 +236,7 @@ EXPORT void OnEvent(EventParam *param) } } -EXPORT void RegisterDartPort(Dart_Port send_port) +EXPORT void RtmRegisterDartPort(Dart_Port send_port) { std::lock_guard lock(message_handler_mutex_); if (dartMessageHandlerManager_) @@ -245,7 +245,7 @@ EXPORT void RegisterDartPort(Dart_Port send_port) } } -EXPORT void UnregisterDartPort(Dart_Port send_port) +EXPORT void RtmUnregisterDartPort(Dart_Port send_port) { std::lock_guard lock(message_handler_mutex_); if (dartMessageHandlerManager_) diff --git a/src/iris_event.h b/src/iris_event.h index d7e7193..44eeef2 100644 --- a/src/iris_event.h +++ b/src/iris_event.h @@ -27,15 +27,15 @@ extern "C" } EventParam; // Initialize `dart_api_dl.h` - EXPORT intptr_t InitDartApiDL(void *data); + EXPORT intptr_t RtmInitDartApiDL(void *data); - EXPORT void Dispose(); + EXPORT void RtmDispose(); - EXPORT void OnEvent(EventParam *param); + EXPORT void RtmOnEvent(EventParam *param); - EXPORT void RegisterDartPort(Dart_Port send_port); + EXPORT void RtmRegisterDartPort(Dart_Port send_port); - EXPORT void UnregisterDartPort(Dart_Port send_port); + EXPORT void RtmUnregisterDartPort(Dart_Port send_port); #ifdef __cplusplus }