Skip to content

Commit

Permalink
Merge pull request #116
Browse files Browse the repository at this point in the history
develop
  • Loading branch information
ksidirop-laerdal authored May 2, 2024
2 parents a9ba8ac + 0670432 commit f9e7aea
Show file tree
Hide file tree
Showing 24 changed files with 411 additions and 40 deletions.
2 changes: 1 addition & 1 deletion Laerdal.McuMgr.Bindings.Android.Native/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ dependencyResolutionManagement {
mavenCentral()
}
}
rootProject.name = "LaerdalMcuMgrWrapperAndSampleApp"
rootProject.name = "LaerdalMcuMgrWrapper"
include ':app'
include ':mcumgr-laerdal-wrapper'
4 changes: 4 additions & 0 deletions Laerdal.McuMgr.Tests/FileDownloader/FileDownloaderTestbed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@ public void FatalErrorOccurredAdvertisement(string resource, string errorMessage

public void FileDownloadProgressPercentageAndDataThroughputChangedAdvertisement(int progressPercentage, float averageThroughput)
=> _downloaderCallbacksProxy.FileDownloadProgressPercentageAndDataThroughputChangedAdvertisement(progressPercentage, averageThroughput); //raises the actual event

public void Dispose()
{
}
}
}
}
8 changes: 8 additions & 0 deletions Laerdal.McuMgr.Tests/FileUploader/FileUploaderTestbed.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public void FileUploadProgressPercentageAndDataThroughputChangedAdvertisement(in
public bool TrySetContext(object context) => throw new NotImplementedException();
public bool TrySetBluetoothDevice(object bluetoothDevice) => throw new NotImplementedException();
public bool TryInvalidateCachedTransport() => throw new NotImplementedException();

public void Dispose()
{
}

public void CleanupResourcesOfLastUpload()
{
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ public void FatalErrorOccurredAdvertisement(EFirmwareInstallationState state, EF

public void FirmwareUploadProgressPercentageAndDataThroughputChangedAdvertisement(int progressPercentage, float averageThroughput)
=> _firmwareInstallerCallbacksProxy.FirmwareUploadProgressPercentageAndDataThroughputChangedAdvertisement(progressPercentage, averageThroughput); //raises the actual event

public void CleanupResourcesOfLastInstallation()
{
}

public void Dispose()
{
}
}
}
}
33 changes: 32 additions & 1 deletion Laerdal.McuMgr/Droid/FileDownloader/FileDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,39 @@ internal AndroidFileDownloaderProxy(INativeFileDownloaderCallbacksProxy fileDown
_fileDownloaderCallbacksProxy = fileDownloaderCallbacksProxy ?? throw new ArgumentNullException(nameof(fileDownloaderCallbacksProxy));
}

// public new void Dispose() { ... } dont there is no need to override the base implementation

private bool _alreadyDisposed;
protected override void Dispose(bool disposing)
{
if (_alreadyDisposed)
{
base.Dispose(disposing); //vital
return;
}

if (disposing)
{
CleanupInfrastructure();
}

_alreadyDisposed = true;

base.Dispose(disposing);
}

private void CleanupInfrastructure()
{
try
{
Disconnect();
}
catch
{
// ignored
}
}

#region commands

public new EFileDownloaderVerdict BeginDownload(string remoteFilePath)
Expand All @@ -66,7 +98,6 @@ internal AndroidFileDownloaderProxy(INativeFileDownloaderCallbacksProxy fileDown
}

#endregion commands



#region android callbacks -> csharp event emitters
Expand Down
38 changes: 38 additions & 0 deletions Laerdal.McuMgr/Droid/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,45 @@ internal AndroidFileUploaderProxy(INativeFileUploaderCallbacksProxy fileUploader
{
_fileUploaderCallbacksProxy = fileUploaderCallbacksProxy ?? throw new ArgumentNullException(nameof(fileUploaderCallbacksProxy));
}

// public new void Dispose() { ... } dont there is no need to override the base implementation

private bool _alreadyDisposed;
protected override void Dispose(bool disposing)
{
if (_alreadyDisposed)
{
base.Dispose(disposing); //vital
return;
}

if (disposing)
{
CleanupInfrastructure();
}

_alreadyDisposed = true;

base.Dispose(disposing);
}

private void CleanupInfrastructure()
{
try
{
Disconnect();
}
catch
{
// ignored
}
}

public void CleanupResourcesOfLastUpload()
{
//nothing to do in android
}

#region commands

public new EFileUploaderVerdict BeginUpload(string remoteFilePath, byte[] data)
Expand Down
46 changes: 46 additions & 0 deletions Laerdal.McuMgr/Droid/FirmwareInstaller/FirmwareInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,46 @@ internal AndroidFirmwareInstallerProxy(INativeFirmwareInstallerCallbacksProxy fi
{
_firmwareInstallerCallbacksProxy = firmwareInstallerCallbacksProxy ?? throw new ArgumentNullException(nameof(firmwareInstallerCallbacksProxy));
}

// public new void Dispose() { ... } dont there is no need to override the base implementation

private bool _alreadyDisposed;
protected override void Dispose(bool disposing)
{
if (_alreadyDisposed)
{
base.Dispose(disposing); //vital
return;
}

if (disposing)
{
CleanupInfrastructure();
}

_alreadyDisposed = true;

base.Dispose(disposing);
}

private void CleanupInfrastructure()
{
try
{
Disconnect();
}
catch
{
// ignored
}
}

public void CleanupResourcesOfLastInstallation()
{
//nothing to do here for android only ios needs this
}

#region commands

public EFirmwareInstallationVerdict BeginInstallation(
byte[] data,
Expand All @@ -83,6 +123,10 @@ public EFirmwareInstallationVerdict BeginInstallation(

return TranslateFirmwareInstallationVerdict(nativeVerdict);
}

#endregion

#region callbacks -> events

public override void FatalErrorOccurredAdvertisement(EAndroidFirmwareInstallationState state, EAndroidFirmwareInstallerFatalErrorType fatalErrorType, string errorMessage)
{
Expand Down Expand Up @@ -164,6 +208,8 @@ public override void FirmwareUploadProgressPercentageAndDataThroughputChangedAdv
progressPercentage: progressPercentage
);
}

#endregion

static private EAndroidFirmwareInstallationMode TranslateFirmwareInstallationMode(EFirmwareInstallationMode mode) => mode switch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable EventNeverSubscribedTo.Global

using System;

namespace Laerdal.McuMgr.FileDownloader.Contracts
{
/// <summary>Downloads a file on a specific Nordic-chip-based BLE device</summary>
/// <remarks>For the file-downloading process to even commence you need to be authenticated with the AED device that's being targeted.</remarks>
public interface IFileDownloader : IFileDownloaderCommandable, IFileDownloaderQueryable, IFileDownloaderEventSubscribable
public interface IFileDownloader :
IFileDownloaderCommandable,
IFileDownloaderQueryable,
IFileDownloaderEventSubscribable,
IDisposable
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
namespace Laerdal.McuMgr.FileDownloader.Contracts.Native
using System;

namespace Laerdal.McuMgr.FileDownloader.Contracts.Native
{
internal interface INativeFileDownloaderProxy : INativeFileDownloaderQueryableProxy, INativeFileDownloaderCommandableProxy, INativeFileDownloaderCallbacksProxy
internal interface INativeFileDownloaderProxy :
INativeFileDownloaderQueryableProxy,
INativeFileDownloaderCommandableProxy,
INativeFileDownloaderCallbacksProxy,
IDisposable
{
}
}
7 changes: 7 additions & 0 deletions Laerdal.McuMgr/Shared/FileDownloader/FileDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ internal FileDownloader(INativeFileDownloaderProxy nativeFileDownloaderProxy)
_nativeFileDownloaderProxy = nativeFileDownloaderProxy ?? throw new ArgumentNullException(nameof(nativeFileDownloaderProxy));
_nativeFileDownloaderProxy.FileDownloader = this; //vital
}

public void Dispose()
{
_nativeFileDownloaderProxy?.Dispose();

GC.SuppressFinalize(this);
}

public string LastFatalErrorMessage => _nativeFileDownloaderProxy?.LastFatalErrorMessage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable EventNeverSubscribedTo.Global

using System;

namespace Laerdal.McuMgr.FileUploader.Contracts
{
/// <summary>Uploads a file on a specific Nordic-chip-based BLE device</summary>
/// <remarks>For the file-uploading process to even commence you need to be authenticated with the AED device that's being targeted.</remarks>
public interface IFileUploader : IFileUploaderCommandable, IFileUploaderQueryable, IFileUploaderEventSubscribable
public interface IFileUploader :
IFileUploaderCommandable,
IFileUploaderQueryable,
IFileUploaderEventSubscribable,
IFileUploaderCleanupable,
IDisposable
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Laerdal.McuMgr.FileUploader.Contracts
{
public interface IFileUploaderCleanupable
{
void CleanupResourcesOfLastUpload();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Laerdal.McuMgr.FileUploader.Contracts.Native
{
internal interface INativeFileUploaderCleanupProxy
{
void CleanupResourcesOfLastUpload();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
namespace Laerdal.McuMgr.FileUploader.Contracts.Native
using System;

namespace Laerdal.McuMgr.FileUploader.Contracts.Native
{
internal interface INativeFileUploaderProxy : INativeFileUploaderQueryableProxy, INativeFileUploaderCommandableProxy, INativeFileUploaderCallbacksProxy
internal interface INativeFileUploaderProxy :
INativeFileUploaderQueryableProxy,
INativeFileUploaderCommandableProxy,
INativeFileUploaderCallbacksProxy,
INativeFileUploaderCleanupProxy,
IDisposable
{
}
}
10 changes: 10 additions & 0 deletions Laerdal.McuMgr/Shared/FileUploader/FileUploader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ internal FileUploader(INativeFileUploaderProxy nativeFileUploaderProxy)
_nativeFileUploaderProxy.FileUploader = this; //vital
}

public void Dispose()
{
_nativeFileUploaderProxy?.Dispose();

GC.SuppressFinalize(this);
}

public bool TrySetContext(object context) => _nativeFileUploaderProxy?.TrySetContext(context) ?? false;
public bool TrySetBluetoothDevice(object bluetoothDevice) => _nativeFileUploaderProxy?.TrySetContext(bluetoothDevice) ?? false;
public bool TryInvalidateCachedTransport() => _nativeFileUploaderProxy?.TryInvalidateCachedTransport() ?? false;
Expand All @@ -49,6 +56,7 @@ public EFileUploaderVerdict BeginUpload(string remoteFilePath, byte[] data)

public void Cancel() => _nativeFileUploaderProxy?.Cancel();
public void Disconnect() => _nativeFileUploaderProxy?.Disconnect();
public void CleanupResourcesOfLastUpload() => _nativeFileUploaderProxy?.CleanupResourcesOfLastUpload();

private event EventHandler<CancelledEventArgs> _cancelled;
private event EventHandler<LogEmittedEventArgs> _logEmitted;
Expand Down Expand Up @@ -265,6 +273,8 @@ ex is not ArgumentException //10 wops probably missing native lib symbols!
Cancelled -= UploadAsyncOnCancelled;
StateChanged -= UploadAsyncOnStateChanged;
FatalErrorOccurred -= UploadAsyncOnFatalErrorOccurred;

CleanupResourcesOfLastUpload(); //vital
}

void UploadAsyncOnCancelled(object sender, CancelledEventArgs ea)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// ReSharper disable UnusedMember.Global
// ReSharper disable EventNeverSubscribedTo.Global

using System;

namespace Laerdal.McuMgr.FirmwareInstaller.Contracts
{
/// <summary>Upgrades the firmware on a specific Nordic-chip-based BLE device</summary>
public interface IFirmwareInstaller : IFirmwareInstallerQueryable, IFirmwareInstallerEventSubscribable, IFirmwareInstallerCommandable
public interface IFirmwareInstaller :
IFirmwareInstallerQueryable,
IFirmwareInstallerEventSubscribable,
IFirmwareInstallerCommandable,
IDisposable
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Laerdal.McuMgr.FirmwareInstaller.Contracts.Native
{
internal interface INativeFirmwareInstallerCleanupableProxy
{
void CleanupResourcesOfLastInstallation();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
using System;

namespace Laerdal.McuMgr.FirmwareInstaller.Contracts.Native
{
internal interface INativeFirmwareInstallerProxy : INativeFirmwareInstallerCommandableProxy, INativeFirmwareInstallerQueryableProxy, INativeFirmwareInstallerCallbacksProxy
internal interface INativeFirmwareInstallerProxy :
INativeFirmwareInstallerCommandableProxy,
INativeFirmwareInstallerQueryableProxy,
INativeFirmwareInstallerCleanupableProxy,
INativeFirmwareInstallerCallbacksProxy,
IDisposable
{
string Nickname { get; set; }
}
Expand Down
Loading

0 comments on commit f9e7aea

Please sign in to comment.