// Copyright (C) 2025, uvok cheetah
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
import 'dart:async';
import 'package:uvok_epaper_badge/control/scanner_controller.dart';
import 'package:meta/meta.dart';
import 'package:uvok_epaper_badge/model/device/device.dart';
import 'package:rxdart/rxdart.dart';
/// Helper class which provides the setStatus method.
abstract class ScannerControllerImpl implements ScannerController {
final BehaviorSubject _scanStatusController =
BehaviorSubject();
final BehaviorSubject> _deviceContoller =
BehaviorSubject>();
final BehaviorSubject _availabilityController =
BehaviorSubject();
@override
Stream get statusStream => _scanStatusController.stream;
@override
Stream> get scanResultsStream => _deviceContoller.stream;
@override
Stream get availabilityStream =>
_availabilityController.stream;
@protected
void setStatus(ScanStatus newStatus) {
if (_scanStatusController.isClosed) return;
_scanStatusController.add(newStatus);
}
@protected
void setDevices(List devices) {
if (_deviceContoller.isClosed) return;
_deviceContoller.add(devices);
}
@protected
void setAvailability(ScanAvailability available) {
_availabilityController.add(available);
}
@override
void dispose() {
_scanStatusController.close().ignore();
_deviceContoller.close().ignore();
_availabilityController.close().ignore();
}
}