main
 1import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_backend.dart';
 2import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_discovery.dart';
 3import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_low_energy/ble_manager.dart';
 4import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_service.dart';
 5import 'package:blood_pressure_app/features/bluetooth/backend/bluetooth_state.dart';
 6import 'package:blood_pressure_app/features/bluetooth/backend/flutter_blue_plus/fbp_manager.dart';
 7import 'package:blood_pressure_app/features/bluetooth/backend/mock/mock_manager.dart';
 8import 'package:blood_pressure_app/logging.dart';
 9
10/// Base class for a bluetooth manager
11abstract class BluetoothManager<BackendDevice, BackendUuid, BackendService, BackendCharacteristic> with TypeLogger {
12  /// Instantiate the correct [BluetoothManager] implementation.
13  static BluetoothManager create([BluetoothBackend? backend]) {
14    switch (backend) {
15      case BluetoothBackend.mock:
16        return MockBluetoothManager();
17      case BluetoothBackend.flutterBluePlus:
18        return FlutterBluePlusManager();
19      case BluetoothBackend.bluetoothLowEnergy:
20      default:
21        return BluetoothLowEnergyManager();
22    }
23  }
24
25  /// Trigger the device to request the user for bluetooth ermissions
26  ///
27  /// Returns null if no permissions were requested (ie because its not needed on a platform)
28  /// or true/false to indicate whether requesting permissions succeeded (not if it was granted)
29  Future<bool?> enable(); // TODO: use task specific plugin/native code
30
31  /// Last known adapter state
32  ///
33  /// For convenience [BluetoothAdapterStateParser] instances already track the last known state,
34  /// so that state only needs to be returned in a backend's manager implementation
35  BluetoothAdapterState get lastKnownAdapterState;
36
37  /// Getter for the state stream
38  Stream<BluetoothAdapterState> get stateStream;
39
40  /// Device discovery implementation
41  BluetoothDeviceDiscovery get discovery;
42
43  /// Convert a BackendDevice into a BluetoothDevice
44  BluetoothDevice createDevice(BackendDevice device);
45
46  /// Convert a BackendUuid into a BluetoothUuid
47  BluetoothUuid createUuid(BackendUuid uuid);
48
49  /// Create a BluetoothUuid from a String
50  BluetoothUuid createUuidFromString(String uuid);
51
52  /// Convert a BackendService into a BluetoothService
53  BluetoothService createService(BackendService service);
54
55  /// Convert a BackendCharacteristic into a BluetoothCharacteristic
56  BluetoothCharacteristic createCharacteristic(BackendCharacteristic characteristic);
57}