|
1 | 1 | import 'package:sane/src/isolate_messages/interface.dart'; |
| 2 | +import 'package:sane/src/sane.dart'; |
2 | 3 | import 'package:sane/src/structures.dart'; |
3 | 4 |
|
4 | | -class ControlOptionMessage<T> implements IsolateMessage { |
5 | | - ControlOptionMessage({ |
6 | | - required this.handle, |
| 5 | +class ControlValueOptionMessage<T> implements IsolateMessage { |
| 6 | + ControlValueOptionMessage({ |
| 7 | + required this.saneHandle, |
7 | 8 | required this.index, |
8 | 9 | required this.action, |
9 | 10 | this.value, |
10 | 11 | }); |
11 | 12 |
|
12 | | - final SaneHandle handle; |
| 13 | + final SaneHandle saneHandle; |
13 | 14 | final int index; |
14 | 15 | final SaneAction action; |
15 | 16 | final T? value; |
| 17 | + |
| 18 | + @override |
| 19 | + Future<ControlValueOptionResponse> handle(Sane sane) async { |
| 20 | + switch (value) { |
| 21 | + case final bool value: |
| 22 | + return ControlValueOptionResponse<bool>( |
| 23 | + result: await sane.controlBoolOption( |
| 24 | + handle: saneHandle, |
| 25 | + index: index, |
| 26 | + action: action, |
| 27 | + value: value, |
| 28 | + ), |
| 29 | + ); |
| 30 | + case final int value: |
| 31 | + return ControlValueOptionResponse<int>( |
| 32 | + result: await sane.controlIntOption( |
| 33 | + handle: saneHandle, |
| 34 | + index: index, |
| 35 | + action: action, |
| 36 | + value: value, |
| 37 | + ), |
| 38 | + ); |
| 39 | + case final double value: |
| 40 | + return ControlValueOptionResponse<double>( |
| 41 | + result: await sane.controlFixedOption( |
| 42 | + handle: saneHandle, |
| 43 | + index: index, |
| 44 | + action: action, |
| 45 | + value: value, |
| 46 | + ), |
| 47 | + ); |
| 48 | + case final String value: |
| 49 | + return ControlValueOptionResponse<String>( |
| 50 | + result: await sane.controlStringOption( |
| 51 | + handle: saneHandle, |
| 52 | + index: index, |
| 53 | + action: action, |
| 54 | + value: value, |
| 55 | + ), |
| 56 | + ); |
| 57 | + default: |
| 58 | + throw Exception('Invalid value type.'); |
| 59 | + } |
| 60 | + } |
16 | 61 | } |
17 | 62 |
|
18 | | -class ControlOptionResponse<T> implements IsolateResponse { |
19 | | - ControlOptionResponse({required this.result}); |
| 63 | +class ControlValueOptionResponse<T> implements IsolateResponse { |
| 64 | + ControlValueOptionResponse({required this.result}); |
20 | 65 |
|
21 | 66 | final SaneOptionResult<T> result; |
22 | 67 | } |
0 commit comments