Renamed event for clarity, inlined public methods only used in event, anyway.

This commit is contained in:
Florian Nücke
2022-02-13 16:09:47 +01:00
parent 927f7f425a
commit d84a674cb4
2 changed files with 14 additions and 23 deletions

View File

@@ -34,7 +34,7 @@ public class CommonDeviceBusController implements DeviceBusController {
///////////////////////////////////////////////////////////////////
public final Event onAfterBusScan = new Event();
public final Event onBeforeScan = new Event();
public final Event onBeforeDeviceScan = new Event();
public final ParameterizedEvent<AfterDeviceScanEvent> onAfterDeviceScan = new ParameterizedEvent<>();
public final ParameterizedEvent<DevicesChangedEvent> onDevicesAdded = new ParameterizedEvent<>();
public final ParameterizedEvent<DevicesChangedEvent> onDevicesRemoved = new ParameterizedEvent<>();
@@ -90,7 +90,7 @@ public class CommonDeviceBusController implements DeviceBusController {
@Override
public void scanDevices() {
onBeforeScan();
onBeforeDeviceScan();
final HashSet<Device> newDevices = new HashSet<>();
final HashMap<Device, Set<UUID>> newDeviceIds = new HashMap<>();
@@ -238,8 +238,8 @@ public class CommonDeviceBusController implements DeviceBusController {
onAfterBusScan.run();
}
protected void onBeforeScan() {
onBeforeScan.run();
protected void onBeforeDeviceScan() {
onBeforeDeviceScan.run();
}
protected void onAfterDeviceScan(final boolean didDevicesChange) {

View File

@@ -65,7 +65,7 @@ public abstract class AbstractVirtualMachine implements VirtualMachine {
public AbstractVirtualMachine(final CommonDeviceBusController busController) {
this.busController = busController;
busController.onBeforeScan.add(this::handleBeforeScan);
busController.onBeforeDeviceScan.add(this::handleBeforeDeviceScan);
busController.onAfterDeviceScan.add(this::handleAfterDeviceScan);
busController.onDevicesAdded.add(this::handleDevicesAdded);
busController.onDevicesRemoved.add(this::handleDevicesRemoved);
@@ -167,21 +167,6 @@ public abstract class AbstractVirtualMachine implements VirtualMachine {
stopRunnerAndReset();
}
public void pauseAndReload() {
state.rpcAdapter.pause();
// This is typically called when a device bus starts a scan. Since scans
// can be delayed we must adjust our run state accordingly, to avoid
// running before the scan finishes.
if (runState == VMRunState.RUNNING) {
runState = VMRunState.LOADING_DEVICES;
}
}
public void resume(final boolean didDevicesChange) {
state.rpcAdapter.resume(busController, didDevicesChange);
}
public void tick() {
busController.scan();
setBusState(busController.getState());
@@ -390,12 +375,18 @@ public abstract class AbstractVirtualMachine implements VirtualMachine {
handleBootErrorChanged(value);
}
private void handleBeforeScan() {
pauseAndReload();
private void handleBeforeDeviceScan() {
state.rpcAdapter.pause();
// Since scans can be delayed we must adjust our run state accordingly, to avoid
// running before the scan finishes.
if (runState == VMRunState.RUNNING) {
runState = VMRunState.LOADING_DEVICES;
}
}
private void handleAfterDeviceScan(final CommonDeviceBusController.AfterDeviceScanEvent event) {
resume(event.didDevicesChange());
state.rpcAdapter.resume(busController, event.didDevicesChange());
}
private void handleDevicesAdded(final CommonDeviceBusController.DevicesChangedEvent event) {