deviceDeploymentReceived method

void deviceDeploymentReceived([
  1. TDeviceDeployment? deployment
])

A new primary device deployment determining what data to collect for this study has been received.

If deployment is not specified, the previously received deployment is marked as updated. An already held deployment is not replaced. Reports a deployment error instead if no deploymentStatus has been received yet, or if the deployment is for another device role name. Otherwise emits StudyStatusEventTypes.DeviceDeploymentReceived and listens to updates of the deployment.

Implementation

void deviceDeploymentReceived([TDeviceDeployment? deployment]) {
  if (deploymentStatus == null) {
    deploymentError(
      "$runtimeType - Deployment status is null. "
      "Can't receive device deployment before having received deployment status.",
    );
    return;
  }

  _deployment ??= deployment;

  // if this is a new deployment, check that the role name matches
  if (deployment != null) {
    if (this.deployment?.deviceConfiguration.roleName != deviceRoleName) {
      deploymentError(
        "$runtimeType - The deployment is intended for a device with a different role name."
        "Was expecting '$deviceRoleName' but got '${this.deployment?.deviceConfiguration.roleName}'.",
      );
      return;
    }
  }

  // Listen to updates to the deployment - which is also the restored one when
  // called without a deployment.
  this.deployment?.onUpdated = deploymentUpdated;

  createEvent(StudyStatusEvent(this, StudyStatusEventTypes.DeviceDeploymentReceived));
}