getDeviceDeploymentFor method

MasterDeviceDeployment getDeviceDeploymentFor(
  1. MasterDeviceDescriptor device
)

Get the deployment configuration for the specified master device in this study deployment.

Implementation

MasterDeviceDeployment getDeviceDeploymentFor(MasterDeviceDescriptor device) {
  // Verify whether the specified device is part of the protocol of this
  // deployment and has been registrered.
  assert(_protocol.hasMasterDevice(device.roleName),
      "The specified master device with rolename '${device.roleName}' is not part of the protocol of this deployment.");
  assert(_registeredDevices.containsKey(device.roleName),
      "The specified master device with rolename '${device.roleName}' has not been registrered to this deployment.");

  // TODO - Verify whether the specified device is ready to be deployed.

  DeviceRegistration configuration = _registeredDevices[device.roleName]!;

  // mark all registrered devices as deployed
  _deployedDevices.addAll(_registeredDevices.keys);

  // determine which devices this device needs to connect to
  // TODO - only retrieve configuration for preregistered devices
  List<DeviceDescriptor> connectedDevices = _protocol.connectedDevices;

  // create a map of device registration for the connected devices
  Map<String, DeviceRegistration?> connectedDeviceConfigurations = {};
  for (var descriptor in connectedDevices) {
    connectedDeviceConfigurations[descriptor.roleName] =
        _registeredDevices[descriptor.roleName];
  }

  List<TaskDescriptor> tasks = [];
  // get all tasks which need to be executed on this master device
  tasks.addAll(protocol.getTasksForDeviceRoleName(device.roleName));

  // .. and connected devices
  // note that connected devices need NOT to be registrered to be included
  for (var descriptor in connectedDevices) {
    tasks.addAll(protocol.getTasksForDeviceRoleName(descriptor.roleName));
  }

  // Get all trigger information for this and connected devices.
  // TODO - this implementation just returns all triggers and triggered tasks.
  //      - but should check which devices are available
  Map<String, Trigger>? usedTriggers = _protocol.triggers;
  List<TriggeredTask>? triggeredTasks = _protocol.triggeredTasks;

  _status.status = StudyDeploymentStatusTypes.DeploymentReady;

  return MasterDeviceDeployment(
      deviceDescriptor: device,
      configuration: configuration,
      connectedDevices: connectedDevices,
      connectedDeviceConfigurations: connectedDeviceConfigurations,
      tasks: tasks,
      triggers: usedTriggers,
      triggeredTasks: triggeredTasks);
}