Skip to content

Commit

Permalink
fix (FirmwareInstaller::OnStateChanged()): fix event-firing order
Browse files Browse the repository at this point in the history
   fix a bug which was causing the state-changed event to be raised before the 'OnIdenticalFirmwareCachedOnTargetDeviceDetected()'
   was invoked causing the later event to not be received by the calling environment because
  • Loading branch information
ksidirop-laerdal committed May 2, 2024
1 parent 2336a21 commit 0670432
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions Laerdal.McuMgr/Shared/FirmwareInstaller/FirmwareInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,30 @@ void FirmwareInstallationAsyncOnFatalErrorOccurred(object sender, FatalErrorOccu

private void OnStateChanged(StateChangedEventArgs ea)
{
_stateChanged?.Invoke(this, ea);

switch (ea)
try
{
case { NewState: EFirmwareInstallationState.Idle }:
_fileUploadProgressEventsCount = 0; //its vital to reset the counter here to account for retries
break;
switch (ea)
{
case { NewState: EFirmwareInstallationState.Idle }:
_fileUploadProgressEventsCount = 0; //its vital to reset the counter here to account for retries
break;

case { NewState: EFirmwareInstallationState.Testing } when _fileUploadProgressEventsCount <= 1: //works both on ios and android
OnIdenticalFirmwareCachedOnTargetDeviceDetected(new(ECachedFirmwareType.CachedButInactive));
break;
case { NewState: EFirmwareInstallationState.Testing } when _fileUploadProgressEventsCount <= 1: //works both on ios and android
OnIdenticalFirmwareCachedOnTargetDeviceDetected(new(ECachedFirmwareType.CachedButInactive));
break;

case { NewState: EFirmwareInstallationState.Complete } when _fileUploadProgressEventsCount <= 1: //works both on ios and android
OnIdenticalFirmwareCachedOnTargetDeviceDetected(new(ECachedFirmwareType.CachedAndActive));
break;
case { NewState: EFirmwareInstallationState.Complete } when _fileUploadProgressEventsCount <= 1: //works both on ios and android
OnIdenticalFirmwareCachedOnTargetDeviceDetected(new(ECachedFirmwareType.CachedAndActive));
break;
}
}
finally
{
_stateChanged?.Invoke(this, ea); //00 must be dead last
}

//00 if we raise the state-changed event before the switch statement then the calling environment will unwire the event handlers of
// the identical-firmware-cached-on-target-device-detected event before it gets fired and the event will be ignored altogether
}

private int _fileUploadProgressEventsCount;
Expand Down

0 comments on commit 0670432

Please sign in to comment.