| 
									
										
										
										
											2021-06-28 22:56:15 +08:00
										 |  |  | /// bindings for `libdart_ffi`
 | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | import 'dart:ffi'; | 
					
						
							|  |  |  | import 'dart:io'; | 
					
						
							| 
									
										
										
										
											2024-11-13 11:10:15 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | // ignore: import_of_legacy_library_into_null_safe
 | 
					
						
							|  |  |  | import 'package:ffi/ffi.dart' as ffi; | 
					
						
							|  |  |  | import 'package:flutter/foundation.dart' as Foundation; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // ignore_for_file: unused_import, camel_case_types, non_constant_identifier_names
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final DynamicLibrary _dart_ffi_lib = _open(); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /// Reference to the Dynamic Library, it should be only used for low-level access
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final DynamicLibrary dl = _dart_ffi_lib; | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | DynamicLibrary _open() { | 
					
						
							| 
									
										
										
										
											2022-02-19 16:48:57 +08:00
										 |  |  |   if (Platform.environment.containsKey('FLUTTER_TEST')) { | 
					
						
							| 
									
										
										
										
											2022-02-20 08:35:52 +08:00
										 |  |  |     final prefix = "${Directory.current.path}/.sandbox"; | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  |     if (Platform.isLinux) | 
					
						
							|  |  |  |       return DynamicLibrary.open('${prefix}/libdart_ffi.so'); | 
					
						
							|  |  |  |     if (Platform.isAndroid) | 
					
						
							|  |  |  |       return DynamicLibrary.open('${prefix}/libdart_ffi.so'); | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  |     if (Platform.isMacOS) | 
					
						
							|  |  |  |       return DynamicLibrary.open('${prefix}/libdart_ffi.dylib'); | 
					
						
							| 
									
										
										
										
											2023-11-20 20:54:47 +08:00
										 |  |  |     if (Platform.isIOS) return DynamicLibrary.open('${prefix}/libdart_ffi.a'); | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  |     if (Platform.isWindows) | 
					
						
							|  |  |  |       return DynamicLibrary.open('${prefix}/dart_ffi.dll'); | 
					
						
							| 
									
										
										
										
											2022-02-19 16:48:57 +08:00
										 |  |  |   } else { | 
					
						
							|  |  |  |     if (Platform.isLinux) return DynamicLibrary.open('libdart_ffi.so'); | 
					
						
							|  |  |  |     if (Platform.isAndroid) return DynamicLibrary.open('libdart_ffi.so'); | 
					
						
							|  |  |  |     if (Platform.isMacOS) return DynamicLibrary.executable(); | 
					
						
							|  |  |  |     if (Platform.isIOS) return DynamicLibrary.executable(); | 
					
						
							|  |  |  |     if (Platform.isWindows) return DynamicLibrary.open('dart_ffi.dll'); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-20 08:35:52 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   throw UnsupportedError('This platform is not supported.'); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 10:27:08 +08:00
										 |  |  | /// C function `async_event`.
 | 
					
						
							|  |  |  | void async_event( | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  |   int port, | 
					
						
							|  |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   int len, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  |   _invoke_async(port, input, len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final _invoke_async_Dart _invoke_async = _dart_ffi_lib | 
					
						
							|  |  |  |     .lookupFunction<_invoke_async_C, _invoke_async_Dart>('async_event'); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | typedef _invoke_async_C = Void Function( | 
					
						
							|  |  |  |   Int64 port, | 
					
						
							|  |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   Uint64 len, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | typedef _invoke_async_Dart = void Function( | 
					
						
							|  |  |  |   int port, | 
					
						
							|  |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   int len, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-04 10:27:08 +08:00
										 |  |  | /// C function `sync_event`.
 | 
					
						
							|  |  |  | Pointer<Uint8> sync_event( | 
					
						
							| 
									
										
										
										
											2021-07-03 14:14:10 +08:00
										 |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   int len, | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2021-06-28 23:58:43 +08:00
										 |  |  |   return _invoke_sync(input, len); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final _invoke_sync_Dart _invoke_sync = _dart_ffi_lib | 
					
						
							|  |  |  |     .lookupFunction<_invoke_sync_C, _invoke_sync_Dart>('sync_event'); | 
					
						
							| 
									
										
										
										
											2021-06-28 23:58:43 +08:00
										 |  |  | typedef _invoke_sync_C = Pointer<Uint8> Function( | 
					
						
							| 
									
										
										
										
											2021-07-03 14:14:10 +08:00
										 |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   Uint64 len, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-06-28 23:58:43 +08:00
										 |  |  | typedef _invoke_sync_Dart = Pointer<Uint8> Function( | 
					
						
							| 
									
										
										
										
											2021-07-03 14:14:10 +08:00
										 |  |  |   Pointer<Uint8> input, | 
					
						
							|  |  |  |   int len, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-06-28 23:58:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | /// C function `init_sdk`.
 | 
					
						
							|  |  |  | int init_sdk( | 
					
						
							| 
									
										
										
										
											2024-02-04 05:50:23 +08:00
										 |  |  |   int port, | 
					
						
							| 
									
										
										
										
											2023-11-20 20:54:47 +08:00
										 |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | ) { | 
					
						
							| 
									
										
										
										
											2024-02-04 05:50:23 +08:00
										 |  |  |   return _init_sdk(port, data); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  | final _init_sdk_Dart _init_sdk = | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  |     _dart_ffi_lib.lookupFunction<_init_sdk_C, _init_sdk_Dart>('init_sdk'); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | typedef _init_sdk_C = Int64 Function( | 
					
						
							| 
									
										
										
										
											2024-02-04 05:50:23 +08:00
										 |  |  |   Int64 port, | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  |   Pointer<ffi.Utf8> path, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | typedef _init_sdk_Dart = int Function( | 
					
						
							| 
									
										
										
										
											2024-02-04 05:50:23 +08:00
										 |  |  |   int port, | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  |   Pointer<ffi.Utf8> path, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-21 15:43:05 +08:00
										 |  |  | /// C function `init_stream`.
 | 
					
						
							|  |  |  | int set_stream_port(int port) { | 
					
						
							|  |  |  |   return _set_stream_port(port); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final _set_stream_port_Dart _set_stream_port = | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  |     _dart_ffi_lib.lookupFunction<_set_stream_port_C, _set_stream_port_Dart>( | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  |         'set_stream_port'); | 
					
						
							| 
									
										
										
										
											2021-07-21 15:43:05 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | typedef _set_stream_port_C = Int32 Function( | 
					
						
							| 
									
										
										
										
											2021-11-15 18:15:09 +08:00
										 |  |  |   Int64 port, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-07-21 15:43:05 +08:00
										 |  |  | typedef _set_stream_port_Dart = int Function( | 
					
						
							| 
									
										
										
										
											2021-11-15 18:15:09 +08:00
										 |  |  |   int port, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2021-07-21 15:43:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-07 21:36:55 +08:00
										 |  |  | /// C function `set log stream port`.
 | 
					
						
							|  |  |  | int set_log_stream_port(int port) { | 
					
						
							|  |  |  |   return _set_log_stream_port(port); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final _set_log_stream_port_Dart _set_log_stream_port = _dart_ffi_lib | 
					
						
							|  |  |  |     .lookupFunction<_set_log_stream_port_C, _set_log_stream_port_Dart>( | 
					
						
							|  |  |  |         'set_log_stream_port'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef _set_log_stream_port_C = Int32 Function( | 
					
						
							|  |  |  |   Int64 port, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | typedef _set_log_stream_port_Dart = int Function( | 
					
						
							|  |  |  |   int port, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | /// C function `link_me_please`.
 | 
					
						
							|  |  |  | void link_me_please() { | 
					
						
							|  |  |  |   _link_me_please(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final _link_me_please_Dart _link_me_please = _dart_ffi_lib | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  |     .lookupFunction<_link_me_please_C, _link_me_please_Dart>('link_me_please'); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | typedef _link_me_please_C = Void Function(); | 
					
						
							|  |  |  | typedef _link_me_please_Dart = void Function(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /// Binding to `allo-isolate` crate
 | 
					
						
							|  |  |  | void store_dart_post_cobject( | 
					
						
							|  |  |  |   Pointer<NativeFunction<Int8 Function(Int64, Pointer<Dart_CObject>)>> ptr, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  |   _store_dart_post_cobject(ptr); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-15 23:34:56 +08:00
										 |  |  | final _store_dart_post_cobject_Dart _store_dart_post_cobject = _dart_ffi_lib | 
					
						
							| 
									
										
										
										
											2022-09-01 06:27:09 +02:00
										 |  |  |     .lookupFunction<_store_dart_post_cobject_C, _store_dart_post_cobject_Dart>( | 
					
						
							|  |  |  |         'store_dart_post_cobject'); | 
					
						
							| 
									
										
										
										
											2021-06-19 23:41:19 +08:00
										 |  |  | typedef _store_dart_post_cobject_C = Void Function( | 
					
						
							|  |  |  |   Pointer<NativeFunction<Int8 Function(Int64, Pointer<Dart_CObject>)>> ptr, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | typedef _store_dart_post_cobject_Dart = void Function( | 
					
						
							|  |  |  |   Pointer<NativeFunction<Int8 Function(Int64, Pointer<Dart_CObject>)>> ptr, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2023-02-07 22:09:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 15:27:12 +08:00
										 |  |  | void rust_log( | 
					
						
							| 
									
										
										
										
											2023-02-07 22:09:43 +08:00
										 |  |  |   int level, | 
					
						
							|  |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							|  |  |  | ) { | 
					
						
							| 
									
										
										
										
											2024-02-26 15:27:12 +08:00
										 |  |  |   _invoke_rust_log(level, data); | 
					
						
							| 
									
										
										
										
											2023-02-07 22:09:43 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-26 15:27:12 +08:00
										 |  |  | final _invoke_rust_log_Dart _invoke_rust_log = _dart_ffi_lib | 
					
						
							|  |  |  |     .lookupFunction<_invoke_rust_log_C, _invoke_rust_log_Dart>('rust_log'); | 
					
						
							|  |  |  | typedef _invoke_rust_log_C = Void Function( | 
					
						
							| 
									
										
										
										
											2023-02-07 22:09:43 +08:00
										 |  |  |   Int64 level, | 
					
						
							|  |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2024-02-26 15:27:12 +08:00
										 |  |  | typedef _invoke_rust_log_Dart = void Function( | 
					
						
							| 
									
										
										
										
											2023-02-07 22:09:43 +08:00
										 |  |  |   int level, | 
					
						
							|  |  |  |   Pointer<ffi.Utf8>, | 
					
						
							|  |  |  | ); | 
					
						
							| 
									
										
										
										
											2023-05-23 23:55:21 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | /// C function `set_env`.
 | 
					
						
							|  |  |  | void set_env( | 
					
						
							|  |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							|  |  |  | ) { | 
					
						
							|  |  |  |   _set_env(data); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | final _set_env_Dart _set_env = | 
					
						
							|  |  |  |     _dart_ffi_lib.lookupFunction<_set_env_C, _set_env_Dart>('set_env'); | 
					
						
							|  |  |  | typedef _set_env_C = Void Function( | 
					
						
							|  |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							|  |  |  | ); | 
					
						
							|  |  |  | typedef _set_env_Dart = void Function( | 
					
						
							|  |  |  |   Pointer<ffi.Utf8> data, | 
					
						
							|  |  |  | ); |