addTaskControl method
bool
addTaskControl(
- TriggerConfiguration trigger,
- TaskConfiguration task,
- DeviceConfiguration<
DeviceRegistration> destinationDevice, [ - Control control = Control.Start,
inherited
Add a task to be started or stopped (determined by control) on a
destinationDevice once a trigger within this protocol is initiated.
In case the trigger or task are not yet included in this study protocol,
it will be added.
The destinationDevice needs to be added prior to this call since it needs
to be set up as either a primary device or connected device.
Throws an error if the destinationDevice is not included in this
study protocol.
Returns true if the task control has been added; false if the same control
is already present.
Implementation
bool addTaskControl(
TriggerConfiguration trigger,
TaskConfiguration task,
DeviceConfiguration destinationDevice, [
Control control = Control.Start,
]) {
assert(
primaryDevices.contains(destinationDevice) ||
connectedDevices!.contains(destinationDevice),
'The passed device to which the task needs to be sent is not included in this study protocol.');
// Add trigger and task to ensure they are included in the protocol.
// Set the trigger's destination device if not specified.
trigger.sourceDeviceRoleName ??= destinationDevice.roleName;
addTrigger(trigger);
addTask(task);
// create and add a task control
int triggerId = indexOfTrigger(trigger);
if (triggerId >= 0) {
taskControls.add(TaskControl(
triggerId: triggerId,
task: task,
targetDevice: destinationDevice,
control: control,
));
return true;
}
return false;
}