This commit is contained in:
John Smith
2022-02-06 21:18:42 -05:00
parent d660d86884
commit 70960fa592
53 changed files with 2062 additions and 2316 deletions

View File

@@ -1,367 +0,0 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target
part of 'bridge_generated.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more informations: https://github.com/rrousselGit/freezed#custom-getters-and-methods');
/// @nodoc
class _$VeilidUpdateTearOff {
const _$VeilidUpdateTearOff();
Log log({required VeilidLogLevel logLevel, required String message}) {
return Log(
logLevel: logLevel,
message: message,
);
}
Attachment attachment(AttachmentState field0) {
return Attachment(
field0,
);
}
}
/// @nodoc
const $VeilidUpdate = _$VeilidUpdateTearOff();
/// @nodoc
mixin _$VeilidUpdate {
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(VeilidLogLevel logLevel, String message) log,
required TResult Function(AttachmentState field0) attachment,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(Log value) log,
required TResult Function(Attachment value) attachment,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
}) =>
throw _privateConstructorUsedError;
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
required TResult orElse(),
}) =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $VeilidUpdateCopyWith<$Res> {
factory $VeilidUpdateCopyWith(
VeilidUpdate value, $Res Function(VeilidUpdate) then) =
_$VeilidUpdateCopyWithImpl<$Res>;
}
/// @nodoc
class _$VeilidUpdateCopyWithImpl<$Res> implements $VeilidUpdateCopyWith<$Res> {
_$VeilidUpdateCopyWithImpl(this._value, this._then);
final VeilidUpdate _value;
// ignore: unused_field
final $Res Function(VeilidUpdate) _then;
}
/// @nodoc
abstract class $LogCopyWith<$Res> {
factory $LogCopyWith(Log value, $Res Function(Log) then) =
_$LogCopyWithImpl<$Res>;
$Res call({VeilidLogLevel logLevel, String message});
}
/// @nodoc
class _$LogCopyWithImpl<$Res> extends _$VeilidUpdateCopyWithImpl<$Res>
implements $LogCopyWith<$Res> {
_$LogCopyWithImpl(Log _value, $Res Function(Log) _then)
: super(_value, (v) => _then(v as Log));
@override
Log get _value => super._value as Log;
@override
$Res call({
Object? logLevel = freezed,
Object? message = freezed,
}) {
return _then(Log(
logLevel: logLevel == freezed
? _value.logLevel
: logLevel // ignore: cast_nullable_to_non_nullable
as VeilidLogLevel,
message: message == freezed
? _value.message
: message // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// @nodoc
class _$Log implements Log {
const _$Log({required this.logLevel, required this.message});
@override
final VeilidLogLevel logLevel;
@override
final String message;
@override
String toString() {
return 'VeilidUpdate.log(logLevel: $logLevel, message: $message)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is Log &&
const DeepCollectionEquality().equals(other.logLevel, logLevel) &&
const DeepCollectionEquality().equals(other.message, message));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(logLevel),
const DeepCollectionEquality().hash(message));
@JsonKey(ignore: true)
@override
$LogCopyWith<Log> get copyWith => _$LogCopyWithImpl<Log>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(VeilidLogLevel logLevel, String message) log,
required TResult Function(AttachmentState field0) attachment,
}) {
return log(logLevel, message);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
}) {
return log?.call(logLevel, message);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
required TResult orElse(),
}) {
if (log != null) {
return log(logLevel, message);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(Log value) log,
required TResult Function(Attachment value) attachment,
}) {
return log(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
}) {
return log?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
required TResult orElse(),
}) {
if (log != null) {
return log(this);
}
return orElse();
}
}
abstract class Log implements VeilidUpdate {
const factory Log(
{required VeilidLogLevel logLevel, required String message}) = _$Log;
VeilidLogLevel get logLevel;
String get message;
@JsonKey(ignore: true)
$LogCopyWith<Log> get copyWith => throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $AttachmentCopyWith<$Res> {
factory $AttachmentCopyWith(
Attachment value, $Res Function(Attachment) then) =
_$AttachmentCopyWithImpl<$Res>;
$Res call({AttachmentState field0});
}
/// @nodoc
class _$AttachmentCopyWithImpl<$Res> extends _$VeilidUpdateCopyWithImpl<$Res>
implements $AttachmentCopyWith<$Res> {
_$AttachmentCopyWithImpl(Attachment _value, $Res Function(Attachment) _then)
: super(_value, (v) => _then(v as Attachment));
@override
Attachment get _value => super._value as Attachment;
@override
$Res call({
Object? field0 = freezed,
}) {
return _then(Attachment(
field0 == freezed
? _value.field0
: field0 // ignore: cast_nullable_to_non_nullable
as AttachmentState,
));
}
}
/// @nodoc
class _$Attachment implements Attachment {
const _$Attachment(this.field0);
@override
final AttachmentState field0;
@override
String toString() {
return 'VeilidUpdate.attachment(field0: $field0)';
}
@override
bool operator ==(dynamic other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is Attachment &&
const DeepCollectionEquality().equals(other.field0, field0));
}
@override
int get hashCode =>
Object.hash(runtimeType, const DeepCollectionEquality().hash(field0));
@JsonKey(ignore: true)
@override
$AttachmentCopyWith<Attachment> get copyWith =>
_$AttachmentCopyWithImpl<Attachment>(this, _$identity);
@override
@optionalTypeArgs
TResult when<TResult extends Object?>({
required TResult Function(VeilidLogLevel logLevel, String message) log,
required TResult Function(AttachmentState field0) attachment,
}) {
return attachment(field0);
}
@override
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
}) {
return attachment?.call(field0);
}
@override
@optionalTypeArgs
TResult maybeWhen<TResult extends Object?>({
TResult Function(VeilidLogLevel logLevel, String message)? log,
TResult Function(AttachmentState field0)? attachment,
required TResult orElse(),
}) {
if (attachment != null) {
return attachment(field0);
}
return orElse();
}
@override
@optionalTypeArgs
TResult map<TResult extends Object?>({
required TResult Function(Log value) log,
required TResult Function(Attachment value) attachment,
}) {
return attachment(this);
}
@override
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
}) {
return attachment?.call(this);
}
@override
@optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
TResult Function(Log value)? log,
TResult Function(Attachment value)? attachment,
required TResult orElse(),
}) {
if (attachment != null) {
return attachment(this);
}
return orElse();
}
}
abstract class Attachment implements VeilidUpdate {
const factory Attachment(AttachmentState field0) = _$Attachment;
AttachmentState get field0;
@JsonKey(ignore: true)
$AttachmentCopyWith<Attachment> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -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();
}

View File

@@ -0,0 +1,106 @@
import 'dart:async';
import 'dart:ffi' as ffi;
import 'dart:io';
import 'dart:typed_data';
import 'package:ffi/ffi.dart';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:oxidized/oxidized.dart';
//////////////////////////////////////////////////////////
// Load the veilid_flutter library once
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);
// Linkage for initialization
typedef _dart_postCObject = NativeFunction<Int8 Function(Int64, Pointer<Dart_CObject>)>;
// fn free_string(s: *mut std::os::raw::c_char)
typedef _free_string_C = Void Function(Pointer<Utf8>);
typedef _free_string_Dart = void Function(Pointer<Utf8>);
// fn initialize_veilid_flutter(dart_post_c_object_ptr: ffi::DartPostCObjectFnType)
typedef _initializeVeilidFlutter_C = Void Function(Pointer<_dart_postCObject>);
typedef _initializeVeilidFlutter_Dart = void Function(Pointer<_dart_postCObject>);
// fn startup_veilid_core(port: i64, config: FfiStr)
typedef _startup_veilid_core_C = Void Function(Int64, Pointer<Utf8>);
typedef _startup_veilid_core_Dart = void Function(int, Pointer<Utf8>);
// fn get_veilid_state(port: i64)
typedef _get_veilid_state_C = Void Function(Int64);
typedef _get_veilid_state_Dart = void Function(int);
// fn change_api_log_level(port: i64, log_level: FfiStr)
typedef _change_api_log_level_C = Void Function(Int64, Pointer<Utf8>);
typedef _change_api_log_level_Dart = void Function(int, Pointer<Utf8>);
// fn shutdown_veilid_core(port: i64)
typedef _shutdown_veilid_core_C = Void Function(Int64);
typedef _shutdown_veilid_core_Dart = void Function(int);
// fn veilid_version_string() -> *mut c_char
typedef _veilid_version_string_C = Pointer<Utf8> Function();
typedef _veilid_version_string_Dart = Pointer<Utf8> Function();
// fn veilid_version() -> VeilidVersion
class VeilidVersion extends Struct {
@Uint32()
external int major;
@Uint32()
external int minor;
@Uint32()
external int patch;
}
typedef _veilid_version_C = VeilidVersion Function();
typedef _veilid_version_Dart = VeilidVersion Function();
// Interface factory for high level Veilid API
Veilid getVeilid() => VeilidFFI(_dylib);
// FFI implementation of high level Veilid API
class VeilidFFI {
// veilid_core shared library
final DynamicLibrary _dylib;
// Shared library functions
final _free_string_Dart _freeString;
final _startup_veilid_core_Dart _startupVeilidCore;
final _get_veilid_state_Dart _getVeilidState;
final _change_api_log_level_Dart _changeApiLogLevel;
final _shutdown_veilid_core_Dart _shutdownVeilidCore;
final _veilid_version_string_Dart _veilidVersionString;
final _veilid_version_Dat _veilidVersion;
VeilidFFI(DynamicLibrary dylib): _dylib = dylib {
var initializeVeilidFlutter = _dylib.lookupFunction<_initializeVeilidFlutter_C, _initializeVeilidFlutter_Dart>('initialize_veilid_flutter');
initializeVeilidFlutter(NativeApi.postCObject);
// Look up shared library functions
_freeString = dylib.lookupFunction<_free_string_C, _free_string_Dart>('free_string');
_startupVeilidCore = dylib.lookupFunction<_startup_veilid_core_C, _startup_veilid_core_Dart>('startup_veilid_core');
_getveilidState = dylib.lookupFunction<_get_veilid_state_C, _get_veilid_state_Dart>('get_veilid_state');
_changeApiLogLevel = dylib.lookupFunction<_change_api_log_level_C, _change_api_log_level_Dart>('change_api_log_level');
_shutdownVeilidCore = dylib.lookupFunction<_shutdown_veilid_core_C, _shutdown_veilid_core_Dart>('shutdown_veilid_core');
_veilidVersionString = dylib.lookupFunction<_veilid_version_string_C, _veilid_version_string_Dart>('veilid_version_string');
_veilidVersion = dylib.lookupFunction<_veilid_version_C, _veilid_version_Dart>('veilid_version');
}
Stream<VeilidUpdate> startupVeilidCore(String config);
Future<Result<VeilidState, VeilidAPIError>> getVeilidState();
Future<Result<Unit, VeilidAPIError>> changeApiLogLevel(VeilidLogLevel logLevel);
Future<Result<Unit, VeilidAPIError>> shutdownVeilidCore() async {
// xxx continue here
}
String veilidVersionString() {
final version_string = _veilidVersionString();
String ret = version_string.toDartString();
_freeString(version_string);
return version_string;
}
VeilidVersion veilidVersion() {
return _veilidVersion();
}
}

View File

@@ -0,0 +1,41 @@
import 'veilid.dart';
import 'dart:js';
import 'dart:async';
import 'dart:typed_data';
import 'package:flutter/services.dart';
import 'package:flutter/material.dart';
import 'package:oxidized/oxidized.dart';
//////////////////////////////////////////////////////////
Veilid getVeilid() => VeilidJS();
class VeilidJS {
Stream<VeilidUpdate> startupVeilidCore(Object? configCallback(String key)) {
throw UnimplementedError();
}
Future<VeilidState> getVeilidState() {
throw UnimplementedError();
}
Future<void> changeApiLogLevel(VeilidLogLevel logLevel) {
throw UnimplementedError();
}
Future<void> shutdownVeilidCore() {
throw UnimplementedError();
}
Future<String> veilidVersionString() {
throw UnimplementedError();
}
Future<VeilidVersion> veilidVersion() {
throw UnimplementedError();
}
}

View File

@@ -11,7 +11,7 @@ import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// xxx link in WASM version of veilid-flutter
/// A web implementation of the Veilid plugin.
class VeilidWeb {
class VeilidPluginStubWeb {
static void registerWith(Registrar registrar) {
// final MethodChannel channel = MethodChannel(
// 'veilid',

View File

@@ -0,0 +1,3 @@
import 'veilid.dart'
Veilid getVeilid() => throw UnsupportedError('Cannot create Veilid object');