AtomicEngineFfi class

dart:ffi 绑定层:加载 libatomicengine 并暴露面向 Dart 的调用接口。

线程模型:

  • 所有 ffi 方法在 Dart 调用线程上执行,native 侧 AtomicEngine_Call 本身 只做任务分发即返回;
  • 异步 call 响应通过 native 侧 Dart_PostCObject_DL 投递到本 isolate 的 常驻 ReceivePort,以事件形式到达事件循环,从而避开 isolate 之间的内存 可见性问题,也不存在 per-call trampoline 的 use-after-free。

内存模型:

  • 每次 call 分配的 Pointer<Utf8> 参数在 native 同步返回后立即 free (native 侧已 dup / 拷贝,不持有指针);
  • call 响应经 token 路由到 Map<String, Completer>,complete 后移除;重复 投递的同一 token 查不到直接忽略,天然幂等;
  • query 返回的字符串指针由 native 侧 thread_local 缓冲管理,本类 通过 toDartString() 立即 copy,不 free。

Constructors

AtomicEngineFfi.load()
构造绑定并加载 libatomicengine。平台不支持时抛 UnsupportedError。
factory

Properties

hashCode → int
The hash code for this object.
no setterinherited
onEvent ↔ void Function(String eventName, String id, String jsonData)?
引擎 → Dart 被动事件分发回调。由上层(EngineBridge)设置。
getter/setter pair
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

call(Pointer<Void> handle, String apiName, String id, String jsonParam) → Future<EngineCallResult>
异步调用。返回 Future 在 native 通过 send_port 投递响应时 complete。
create() → Pointer<Void>
destroy(Pointer<Void> handle) → void
init(Pointer<Void> handle) → void
installEventHandler() → void
安装引擎 → Dart 的被动事件分发(port-based)。进程内幂等: 惰性执行 Dart_InitializeApiDL,注册事件 send_port 并 listen。 事件消息经 _onEventMessage 解析后回调 onEvent。
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
query(Pointer<Void> handle, String apiName, String id, String jsonParam) → String
同步查询。返回值已是 Dart 侧的 String(native 缓冲内容已 copy 走)。
shutdownCallChannel() → void
关闭 call 响应通道:以错误完成全部未决 completer、注销 send_port 并关闭 端口。由 EngineBridge.dispose 调用;本实例随单例一起释放、不再复用。
shutdownEventChannel() → void
关闭 OnCall 事件通道:注销事件 send_port、清空分发回调并关闭端口。 由 EngineBridge.dispose 在 Uninit 之前调用,让引擎在拆卸期间不再向 本 isolate 投递事件。
toString() → String
A string representation of this object.
inherited
uninit(Pointer<Void> handle) → void

Operators

operator ==(Object other) → bool
The equality operator.
inherited