Skip to content

Commit

Permalink
add - Added full nullability support
Browse files Browse the repository at this point in the history
---

You can now use BassBoom in null-aware applications and libraries.

---

Type: add
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 4, 2024
1 parent 864a20a commit 84f6c69
Show file tree
Hide file tree
Showing 27 changed files with 287 additions and 214 deletions.
13 changes: 7 additions & 6 deletions BassBoom.Basolia/Devices/DeviceTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ namespace BassBoom.Basolia.Devices
/// </summary>
public static class DeviceTools
{
internal static string activeDriver;
internal static string activeDevice;
internal static string? activeDriver;
internal static string? activeDevice;

/// <summary>
/// Gets a read only dictionary that lists all the drivers
Expand All @@ -55,7 +55,7 @@ public static ReadOnlyDictionary<string, string> GetDrivers()
{
// Query the drivers
var handle = MpgNative._out123Handle;
var @delegate = MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_drivers>(nameof(NativeOutputLib.out123_drivers));
var @delegate = MpgNative.GetDelegate<NativeOutputLib.out123_drivers>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_drivers));
int driversStatus = @delegate.Invoke(handle, ref names, ref descr);
if (driversStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't query the drivers", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -96,7 +96,7 @@ public static ReadOnlyDictionary<string, string> GetDevices(string driver, ref s
{
// Query the devices
var handle = MpgNative._out123Handle;
var @delegate = MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_devices>(nameof(NativeOutputLib.out123_devices));
var @delegate = MpgNative.GetDelegate<NativeOutputLib.out123_devices>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_devices));
int devicesStatus = @delegate.Invoke(handle, driver, out names, out descr, ref active);
if (devicesStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't query the devices", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -132,7 +132,7 @@ public static (string driver, string device) GetCurrent()
var handle = MpgNative._out123Handle;
IntPtr driverPtr = IntPtr.Zero;
IntPtr devicePtr = IntPtr.Zero;
var @delegate = MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_driver_info>(nameof(NativeOutputLib.out123_driver_info));
var @delegate = MpgNative.GetDelegate<NativeOutputLib.out123_driver_info>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_driver_info));
int devicesStatus = @delegate.Invoke(handle, ref driverPtr, ref devicePtr);
if (devicesStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't query the devices", mpg123_errors.MPG123_ERR);
Expand All @@ -147,7 +147,7 @@ public static (string driver, string device) GetCurrent()
/// </summary>
/// <returns>Current cached device and driver</returns>
/// <exception cref="BasoliaException"></exception>
public static (string driver, string device) GetCurrentCached()
public static (string? driver, string? device) GetCurrentCached()
{
InitBasolia.CheckInited();
return (activeDriver, activeDevice);
Expand All @@ -174,6 +174,7 @@ public static void SetActiveDriver(string driver)
/// <exception cref="BasoliaException"></exception>
public static void SetActiveDevice(string driver, string device)
{
activeDevice = "";
var deviceList = GetDevices(driver, ref activeDevice);
if (string.IsNullOrEmpty(device))
return;
Expand Down
6 changes: 3 additions & 3 deletions BassBoom.Basolia/Exceptions/BasoliaException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BasoliaException : Exception
/// <param name="error">An MPG123 error value to use.</param>
internal BasoliaException(mpg123_errors error) :
base($"General Basolia error\n" +
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeError.mpg123_plain_strerror>(nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]")
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeError.mpg123_plain_strerror>(MpgNative.libManagerMpg, nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]")
{ }

/// <summary>
Expand All @@ -45,7 +45,7 @@ internal BasoliaException(mpg123_errors error) :
/// <param name="error">An MPG123 error value to use.</param>
internal BasoliaException(string message, mpg123_errors error) :
base($"{message}\n" +
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeError.mpg123_plain_strerror>(nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]")
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeError.mpg123_plain_strerror>(MpgNative.libManagerMpg, nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]")
{ }

/// <summary>
Expand All @@ -56,7 +56,7 @@ internal BasoliaException(string message, mpg123_errors error) :
/// <param name="error">An MPG123 error value to use.</param>
internal BasoliaException(string message, Exception innerException, mpg123_errors error) :
base($"{message}\n" +
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeError.mpg123_plain_strerror>(nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]", innerException)
$"MPG123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeError.mpg123_plain_strerror>(MpgNative.libManagerMpg, nameof(NativeError.mpg123_plain_strerror)).Invoke((int)error))}]", innerException)
{ }
}
}
6 changes: 3 additions & 3 deletions BassBoom.Basolia/Exceptions/BasoliaOutException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class BasoliaOutException : Exception
/// <param name="error">An OUT123 error value to use.</param>
internal BasoliaOutException(out123_error error) :
base($"General Basolia output system error\n" +
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_plain_strerror>(nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]")
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeOutputLib.out123_plain_strerror>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]")
{ }

/// <summary>
Expand All @@ -45,7 +45,7 @@ internal BasoliaOutException(out123_error error) :
/// <param name="error">An OUT123 error value to use.</param>
internal BasoliaOutException(string message, out123_error error) :
base($"{message}\n" +
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_plain_strerror>(nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]")
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeOutputLib.out123_plain_strerror>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]")
{ }

/// <summary>
Expand All @@ -56,7 +56,7 @@ internal BasoliaOutException(string message, out123_error error) :
/// <param name="error">An OUT123 error value to use.</param>
internal BasoliaOutException(string message, Exception innerException, out123_error error) :
base($"{message}\n" +
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.libManagerOut.GetNativeMethodDelegate<NativeOutputLib.out123_plain_strerror>(nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]", innerException)
$"OUT123 returned the following error: [{error} - {Marshal.PtrToStringAnsi(MpgNative.GetDelegate<NativeOutputLib.out123_plain_strerror>(MpgNative.libManagerOut, nameof(NativeOutputLib.out123_plain_strerror)).Invoke((int)error))}]", innerException)
{ }
}
}
10 changes: 5 additions & 5 deletions BassBoom.Basolia/File/FileTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class FileTools
{
private static bool isOpened = false;
private static bool isRadioStation = false;
private static FileType currentFile;
private static FileType? currentFile;
private static readonly string[] supportedExts =
[
".mp3",
Expand Down Expand Up @@ -68,7 +68,7 @@ public static class FileTools
/// <summary>
/// Current file
/// </summary>
public static FileType CurrentFile =>
public static FileType? CurrentFile =>
currentFile;

/// <summary>
Expand All @@ -95,7 +95,7 @@ public static void OpenFile(string path)
{
// Open the file
var handle = MpgNative._mpg123Handle;
var @delegate = MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeInput.mpg123_open>(nameof(NativeInput.mpg123_open));
var @delegate = MpgNative.GetDelegate<NativeInput.mpg123_open>(MpgNative.libManagerMpg, nameof(NativeInput.mpg123_open));
int openStatus = @delegate.Invoke(handle, path);
if (openStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't open file", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -146,7 +146,7 @@ public static async Task OpenUrlAsync(string path)
{
// Open the radio station
var handle = MpgNative._mpg123Handle;
var @delegate = MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeInput.mpg123_open_feed>(nameof(NativeInput.mpg123_open_feed));
var @delegate = MpgNative.GetDelegate<NativeInput.mpg123_open_feed>(MpgNative.libManagerMpg, nameof(NativeInput.mpg123_open_feed));
int openStatus = @delegate.Invoke(handle);
if (openStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't open radio station", mpg123_errors.MPG123_ERR);
Expand Down Expand Up @@ -179,7 +179,7 @@ public static void CloseFile()
{
// Close the file
var handle = MpgNative._mpg123Handle;
var @delegate = MpgNative.libManagerMpg.GetNativeMethodDelegate<NativeInput.mpg123_close>(nameof(NativeInput.mpg123_close));
var @delegate = MpgNative.GetDelegate<NativeInput.mpg123_close>(MpgNative.libManagerMpg, nameof(NativeInput.mpg123_close));
int closeStatus = @delegate.Invoke(handle);
if (closeStatus == (int)mpg123_errors.MPG123_ERR)
throw new BasoliaException("Can't close file", mpg123_errors.MPG123_ERR);
Expand Down
10 changes: 5 additions & 5 deletions BassBoom.Basolia/File/FileType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public class FileType
{
private bool isLink;
private string path;
private Stream stream;
private HttpResponseHeaders headers;
private Stream? stream;
private HttpResponseHeaders? headers;
private string stationName;

/// <summary>
Expand All @@ -49,13 +49,13 @@ public class FileType
/// <summary>
/// Radio station stream
/// </summary>
public Stream Stream =>
public Stream? Stream =>
stream;

/// <summary>
/// Radio station ICY headers
/// </summary>
public HttpResponseHeaders Headers =>
public HttpResponseHeaders? Headers =>
headers;

/// <summary>
Expand All @@ -64,7 +64,7 @@ public class FileType
public string StationName =>
stationName;

internal FileType(bool isLink, string path, Stream stream, HttpResponseHeaders headers, string stationName)
internal FileType(bool isLink, string path, Stream? stream, HttpResponseHeaders? headers, string stationName)
{
this.isLink = isLink;
this.path = path ?? throw new ArgumentNullException(nameof(path));
Expand Down
Loading

0 comments on commit 84f6c69

Please sign in to comment.