addTrigger method

void addTrigger(
  1. TriggerConfiguration trigger
)

Add the trigger to this protocol, if not already added.

Its id is the number of triggers before it ('0', '1', ...). If the trigger has no source device, primaryDevice is used.

Implementation

void addTrigger(TriggerConfiguration trigger) {
  // early out if already added
  if (triggers.values.contains(trigger)) return;

  // if source is not defined, use the primary device role name
  trigger.sourceDeviceRoleName ??= primaryDevice.roleName;

  // so much for null-safety "#%"&?
  if (trigger.requiresPrimaryDevice != null && trigger.requiresPrimaryDevice!) {
    assert(
      hasPrimaryDevice(trigger.sourceDeviceRoleName!),
      'The passed trigger cannot be initiated by its specified source device '
      'since it is not a primary device which is part of this protocol.',
    );
  }

  triggers['${triggers.length}'] = trigger;
}