Skip to content

Commit

Permalink
feat: rename symbol names for internal method channel name
Browse files Browse the repository at this point in the history
  • Loading branch information
peilinok committed Dec 2, 2024
1 parent 0f27549 commit 998b4e1
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 129 deletions.
Original file line number Diff line number Diff line change
@@ -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`.
Expand All @@ -21,133 +19,69 @@ class NativeIrisEventBinding {
lookup)
: _lookup = lookup;

int InitDartApiDL(
int RtmInitDartApiDL(
ffi.Pointer<ffi.Void> data,
) {
return _InitDartApiDL(
return _RtmInitDartApiDL(
data,
);
}

late final _InitDartApiDLPtr =
late final _RtmInitDartApiDLPtr =
_lookup<ffi.NativeFunction<ffi.IntPtr Function(ffi.Pointer<ffi.Void>)>>(
'InitDartApiDL');
late final _InitDartApiDL =
_InitDartApiDLPtr.asFunction<int Function(ffi.Pointer<ffi.Void>)>();
'RtmInitDartApiDL');
late final _RtmInitDartApiDL =
_RtmInitDartApiDLPtr.asFunction<int Function(ffi.Pointer<ffi.Void>)>();

void Dispose() {
return _Dispose();
void RtmDispose() {
return _RtmDispose();
}

late final _DisposePtr =
_lookup<ffi.NativeFunction<ffi.Void Function()>>('Dispose');
late final _Dispose = _DisposePtr.asFunction<void Function()>();
late final _RtmDisposePtr =
_lookup<ffi.NativeFunction<ffi.Void Function()>>('RtmDispose');
late final _RtmDispose = _RtmDisposePtr.asFunction<void Function()>();

void OnEvent(
void RtmOnEvent(
ffi.Pointer<EventParam> param,
) {
return _OnEvent(
return _RtmOnEvent(
param,
);
}

late final _OnEventPtr =
late final _RtmOnEventPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<EventParam>)>>(
'OnEvent');
late final _OnEvent =
_OnEventPtr.asFunction<void Function(ffi.Pointer<EventParam>)>();

void OnEventLegacy(
ffi.Pointer<ffi.Int8> event,
ffi.Pointer<ffi.Int8> data,
ffi.Pointer<ffi.Pointer<ffi.Void>> buffer,
ffi.Pointer<ffi.Uint32> length,
int buffer_count,
) {
return _OnEventLegacy(
event,
data,
buffer,
length,
buffer_count,
);
}

late final _OnEventLegacyPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>,
ffi.Pointer<ffi.Uint32>,
ffi.Uint32)>>('OnEventLegacy');
late final _OnEventLegacy = _OnEventLegacyPtr.asFunction<
void Function(ffi.Pointer<ffi.Int8>, ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>, ffi.Pointer<ffi.Uint32>, int)>();

void OnEventExLegacy(
ffi.Pointer<ffi.Int8> event,
ffi.Pointer<ffi.Int8> data,
ffi.Pointer<ffi.Int8> result,
ffi.Pointer<ffi.Pointer<ffi.Void>> buffer,
ffi.Pointer<ffi.Uint32> length,
int buffer_count,
) {
return _OnEventExLegacy(
event,
data,
result,
buffer,
length,
buffer_count,
);
}
'RtmOnEvent');
late final _RtmOnEvent =
_RtmOnEventPtr.asFunction<void Function(ffi.Pointer<EventParam>)>();

late final _OnEventExLegacyPtr = _lookup<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>,
ffi.Pointer<ffi.Uint32>,
ffi.Uint32)>>('OnEventExLegacy');
late final _OnEventExLegacy = _OnEventExLegacyPtr.asFunction<
void Function(
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>,
ffi.Pointer<ffi.Uint32>,
int)>();

void RegisterDartPort(
void RtmRegisterDartPort(
int send_port,
) {
return _RegisterDartPort(
return _RtmRegisterDartPort(
send_port,
);
}

late final _RegisterDartPortPtr =
late final _RtmRegisterDartPortPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'RegisterDartPort');
late final _RegisterDartPort =
_RegisterDartPortPtr.asFunction<void Function(int)>();
'RtmRegisterDartPort');
late final _RtmRegisterDartPort =
_RtmRegisterDartPortPtr.asFunction<void Function(int)>();

void UnregisterDartPort(
void RtmUnregisterDartPort(
int send_port,
) {
return _UnregisterDartPort(
return _RtmUnregisterDartPort(
send_port,
);
}

late final _UnregisterDartPortPtr =
late final _RtmUnregisterDartPortPtr =
_lookup<ffi.NativeFunction<ffi.Void Function(ffi.Int64)>>(
'UnregisterDartPort');
late final _UnregisterDartPort =
_UnregisterDartPortPtr.asFunction<void Function(int)>();
'RtmUnregisterDartPort');
late final _RtmUnregisterDartPort =
_RtmUnregisterDartPortPtr.asFunction<void Function(int)>();

late final addresses = _SymbolAddresses(this);
}
Expand All @@ -156,24 +90,7 @@ class _SymbolAddresses {
final NativeIrisEventBinding _library;
_SymbolAddresses(this._library);
ffi.Pointer<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<EventParam>)>>
get OnEvent => _library._OnEventPtr;
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>,
ffi.Pointer<ffi.Uint32>,
ffi.Uint32)>> get OnEventLegacy => _library._OnEventLegacyPtr;
ffi.Pointer<
ffi.NativeFunction<
ffi.Void Function(
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Int8>,
ffi.Pointer<ffi.Pointer<ffi.Void>>,
ffi.Pointer<ffi.Uint32>,
ffi.Uint32)>> get OnEventExLegacy => _library._OnEventExLegacyPtr;
get RtmOnEvent => _library._RtmOnEventPtr;
}

final class EventParam extends ffi.Struct {
Expand Down
12 changes: 6 additions & 6 deletions lib/src/method_channel/internal/platform/io/iris_event_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<ffi.NativeFunction<ffi.Void Function(ffi.Pointer<EventParam>)>>
get onEventPtr => _nativeIrisEventBinding.addresses.OnEvent;
get onEventPtr => _nativeIrisEventBinding.addresses.RtmOnEvent;
}
25 changes: 25 additions & 0 deletions scripts/ffi_gen/ffigen_config_method_channel.yaml
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions scripts/ffi_gen/run_ffi_gen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 5 additions & 5 deletions src/iris_event.cc
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ std::unique_ptr<DartMessageHandlerManager> 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<std::mutex> lock(message_handler_mutex_);
int ret = 0;
Expand All @@ -217,7 +217,7 @@ EXPORT intptr_t InitDartApiDL(void *data)
return ret;
}

EXPORT void Dispose()
EXPORT void RtmDispose()
{
std::lock_guard<std::mutex> lock(message_handler_mutex_);
--init_dart_api_times_;
Expand All @@ -227,7 +227,7 @@ EXPORT void Dispose()
}
}

EXPORT void OnEvent(EventParam *param)
EXPORT void RtmOnEvent(EventParam *param)
{
std::lock_guard<std::mutex> lock(message_handler_mutex_);
if (dartMessageHandlerManager_)
Expand All @@ -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<std::mutex> lock(message_handler_mutex_);
if (dartMessageHandlerManager_)
Expand All @@ -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<std::mutex> lock(message_handler_mutex_);
if (dartMessageHandlerManager_)
Expand Down
10 changes: 5 additions & 5 deletions src/iris_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 998b4e1

Please sign in to comment.