Skip to content

Commit

Permalink
Rearchitect library
Browse files Browse the repository at this point in the history
  • Loading branch information
Craftplacer committed Nov 7, 2024
1 parent 1f569f3 commit 558a0d7
Show file tree
Hide file tree
Showing 21 changed files with 589 additions and 487 deletions.
2 changes: 1 addition & 1 deletion packages/sane/example/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void main(List<String> args) async {
print('${record.level.name}: ${record.time}: ${record.message}');
});

final sane = SaneNative(sane: SaneDev());
final sane = NativeSane(sane: SaneDev());

Check failure on line 15 in packages/sane/example/main.dart

View workflow job for this annotation

GitHub Actions / analyze

The named parameter 'sane' isn't defined.

Try correcting the name to an existing named parameter's name, or defining a named parameter with the name 'sane'. See https://dart.dev/diagnostics/undefined_named_parameter to learn more about this problem.
await sane.spawn();

Check failure on line 16 in packages/sane/example/main.dart

View workflow job for this annotation

GitHub Actions / analyze

The method 'spawn' isn't defined for the type 'NativeSane'.

Try correcting the name to the name of an existing method, or defining a method named 'spawn'. See https://dart.dev/diagnostics/undefined_method to learn more about this problem.

await sane.init();
Expand Down
11 changes: 11 additions & 0 deletions packages/sane/lib/src/bindings.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,17 @@ class LibSane {
'sane_strstatus');
late final _sane_strstatus =
_sane_strstatusPtr.asFunction<SANE_String_Const Function(int)>();

late final addresses = _SymbolAddresses(this);
}

class _SymbolAddresses {
final LibSane _library;

_SymbolAddresses(this._library);

ffi.Pointer<ffi.NativeFunction<ffi.Void Function(SANE_Handle)>>
get sane_close => _library._sane_closePtr;
}

enum SANE_Status {
Expand Down
91 changes: 35 additions & 56 deletions packages/sane/lib/src/impl/sane_dev.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import 'dart:async';
import 'dart:typed_data';

import 'package:logging/logging.dart';
import 'package:sane/sane.dart';
import 'package:sane/src/sane.dart';

final _logger = Logger('sane.dev');

class SaneDev implements Sane {
@override
Future<void> cancel(SaneHandle handle) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_cancel()');
});
}

@override
Future<void> close(SaneHandle handle) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_close()');
});
}

@override
Future<SaneOptionResult<bool>> controlBoolOption({

Check warning on line 12 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
required SaneHandle handle,
required int handle,
required int index,
required SaneAction action,
bool? value,
Expand All @@ -35,7 +23,7 @@ class SaneDev implements Sane {

@override
Future<SaneOptionResult<Null>> controlButtonOption({

Check warning on line 25 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
required SaneHandle handle,
required int handle,
required int index,
}) {
return Future.delayed(const Duration(seconds: 1), () {
Expand All @@ -46,7 +34,7 @@ class SaneDev implements Sane {

@override
Future<SaneOptionResult<double>> controlFixedOption({

Check warning on line 36 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
required SaneHandle handle,
required int handle,
required int index,
required SaneAction action,
double? value,
Expand All @@ -59,7 +47,7 @@ class SaneDev implements Sane {

@override
Future<SaneOptionResult<int>> controlIntOption({

Check warning on line 49 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
required SaneHandle handle,
required int handle,
required int index,
required SaneAction action,
int? value,
Expand All @@ -72,7 +60,7 @@ class SaneDev implements Sane {

@override
Future<SaneOptionResult<String>> controlStringOption({

Check warning on line 62 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
required SaneHandle handle,
required int handle,
required int index,
required SaneAction action,
String? value,
Expand All @@ -84,15 +72,14 @@ class SaneDev implements Sane {
}

@override
Future<void> exit() {
Future<void> dispose() {
return Future(() {
_logger.finest('sane_exit()');
});
}

@override
Future<List<SaneOptionDescriptor>> getAllOptionDescriptors(
SaneHandle handle,
Future<List<SaneOptionDescriptor>> getAllOptionDescriptors(int handle,

Check warning on line 82 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_getAllOptionDescriptors()');
Expand All @@ -113,26 +100,19 @@ class SaneDev implements Sane {
}

@override
Future<List<SaneDevice>> getDevices({
Future<List<SaneDevDevice>> getDevices({
required bool localOnly,
}) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_getDevices()');
return [
for (var i = 0; i < 3; i++)
SaneDevice(
name: 'name $i',
vendor: 'Vendor$i',
model: 'Model$i',
type: 'Type$i',
),
for (var i = 0; i < 3; i++) SaneDevDevice(i),
];
});
}

@override
Future<SaneOptionDescriptor> getOptionDescriptor(
SaneHandle handle,
Future<SaneOptionDescriptor> getOptionDescriptor(int handle,

Check warning on line 115 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
int index,
) {
return Future.delayed(const Duration(seconds: 1), () {
Expand All @@ -152,7 +132,7 @@ class SaneDev implements Sane {
}

@override
Future<SaneParameters> getParameters(SaneHandle handle) {
Future<SaneParameters> getParameters(int handle) {

Check warning on line 135 in packages/sane/lib/src/impl/sane_dev.dart

View workflow job for this annotation

GitHub Actions / analyze

The method doesn't override an inherited method.

Try updating this class to match the superclass, or removing the override annotation. See https://dart.dev/diagnostics/override_on_non_overriding_member to learn more about this problem.
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_getParameters()');
return SaneParameters(
Expand All @@ -165,52 +145,51 @@ class SaneDev implements Sane {
);
});
}
}

@override
Future<int> init({
AuthCallback? authCallback,
}) {
return Future(() {
_logger.finest('sane_init()');
return 1;
});
}
class SaneDevDevice implements SaneDevice {
const SaneDevDevice(this.index);

final int index;

@override
Future<SaneHandle> open(String deviceName) {
Future<void> cancel() {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_open()');
return SaneHandle(deviceName: deviceName);
_logger.finest('sane_cancel()');
});
}

@override
Future<SaneHandle> openDevice(SaneDevice device) {
Future<void> close() {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_openDevice()');
return SaneHandle(deviceName: device.name);
_logger.finest('sane_close()');
});
}

@override
Future<Uint8List> read(SaneHandle handle, int bufferSize) {
String get model => 'Model $index';

@override
String get name => 'Name $index';

@override
Future<Uint8List> read({required int bufferSize}) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_read()');
return Uint8List.fromList([]);
});
}

@override
Future<void> setIOMode(SaneHandle handle, SaneIOMode mode) {
Future<void> start() {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_setIOMode()');
_logger.finest('sane_start()');
});
}

@override
Future<void> start(SaneHandle handle) {
return Future.delayed(const Duration(seconds: 1), () {
_logger.finest('sane_start()');
});
}
String get type => 'Type $index';

@override
String? get vendor => 'Vendor $index';
}
Loading

0 comments on commit 558a0d7

Please sign in to comment.