ffi work
This commit is contained in:
@@ -1,31 +1,92 @@
|
||||
import 'dart:async';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:veilid/bridge_generated.dart';
|
||||
import 'package:oxidized/oxidized.dart';
|
||||
|
||||
const base = 'veilid_flutter';
|
||||
final path = Platform.isWindows
|
||||
? '$base.dll'
|
||||
: Platform.isMacOS
|
||||
? 'lib$base.dylib'
|
||||
: 'lib$base.so';
|
||||
late final dylib = Platform.isIOS ? DynamicLibrary.process() : DynamicLibrary.open(path);
|
||||
late final veilidApi = VeilidFlutterImpl(dylib);
|
||||
import 'veilid_stub.dart'
|
||||
if (dart.library.io) 'veilid_ffi.dart'
|
||||
if (dart.library.js) 'veilid_js.dart';
|
||||
|
||||
class Veilid {
|
||||
//////////////////////////////////////////////////////////
|
||||
|
||||
static VeilidFlutterImpl get api {
|
||||
if (veilidApi == null) {
|
||||
throw PlatformException(
|
||||
code: 'Library missing',
|
||||
details: 'veilid_flutter library could not be loaded dynamically',
|
||||
);
|
||||
}
|
||||
return veilidApi;
|
||||
enum AttachmentState {
|
||||
Detached,
|
||||
Attaching,
|
||||
AttachedWeak,
|
||||
AttachedGood,
|
||||
AttachedStrong,
|
||||
FullyAttached,
|
||||
OverAttached,
|
||||
Detaching,
|
||||
}
|
||||
|
||||
enum VeilidLogLevel {
|
||||
Error,
|
||||
Warn,
|
||||
Info,
|
||||
Debug,
|
||||
Trace,
|
||||
}
|
||||
|
||||
// VeilidVersion
|
||||
|
||||
class VeilidVersion {
|
||||
final int major;
|
||||
final int minor;
|
||||
final int patch;
|
||||
|
||||
VeilidVersion({
|
||||
required this.major,
|
||||
required this.minor,
|
||||
required this.patch,
|
||||
});
|
||||
}
|
||||
|
||||
// VeilidUpdate
|
||||
|
||||
abstract class VeilidUpdate {
|
||||
VeilidUpdateKind get kind;
|
||||
}
|
||||
|
||||
class VeilidUpdateLog implements VeilidUpdate {
|
||||
final VeilidLogLevel logLevel;
|
||||
final String message;
|
||||
|
||||
VeilidUpdateLog(this.logLevel, this.message);
|
||||
}
|
||||
|
||||
class VeilidUpdateAttachment implements VeilidUpdate {
|
||||
final AttachmentState state;
|
||||
|
||||
VeilidUpdateAttachment(this.state);
|
||||
}
|
||||
|
||||
// VeilidState
|
||||
|
||||
class VeilidState {
|
||||
final AttachmentState attachment;
|
||||
|
||||
VeilidState(this.attachment);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Veilid singleton factory
|
||||
|
||||
abstract class Veilid {
|
||||
static Veilid _instance;
|
||||
|
||||
static Veilid get instance {
|
||||
_instance ??= getVeilid();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
Stream<VeilidUpdate> startupVeilidCore(String config);
|
||||
Future<Result<VeilidState, VeilidAPIError>> getVeilidState();
|
||||
Future<Result<Unit, VeilidAPIError>> changeApiLogLevel(VeilidLogLevel logLevel);
|
||||
Future<Result<Unit, VeilidAPIError>> shutdownVeilidCore();
|
||||
String veilidVersionString();
|
||||
VeilidVersion veilidVersion();
|
||||
}
|
||||
|
Reference in New Issue
Block a user