Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core is at zero warnings! #378

Merged
merged 1 commit into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 70 additions & 12 deletions source/Meadow.Core/Configuration/ConfigurableObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,60 @@

namespace Meadow;

/// <summary>
/// Represents a configurable object.
/// </summary>
public abstract class ConfigurableObject
{
private string m_parentname;
/// <summary>
/// The default JSON file name for configuration.
/// </summary>
public const string DefaultJsonFileName = "app.config.json";

/// <summary>
/// The default YAML file name for configuration.
/// </summary>
public const string DefaultYamlFileName = "app.config.yaml";

private string m_parentname = default!;
private bool m_isArrayElement = false;

protected IConfiguration? ConfigurationRoot { get; private set; }
protected string ConfigurationRootPath { get; }
private string PathTypeName { get; }

/// <summary>
/// Gets or sets the configuration root.
/// </summary>
protected IConfiguration? ConfigurationRoot { get; private set; } = default!;

/// <summary>
/// Gets the configuration root path.
/// </summary>
protected string ConfigurationRootPath { get; } = default!;

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurableObject"/> class.
/// </summary>
protected ConfigurableObject()
{
PathTypeName = this.GetType().Name.Replace("Settings", string.Empty);
SetConfigRoot();
}

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurableObject"/> class with a parent object.
/// </summary>
/// <param name="parent">The parent object.</param>
protected ConfigurableObject(object? parent)
{
PathTypeName = this.GetType().Name.Replace("Settings", string.Empty);

if (parent != null)
{
if (parent is ConfigurableObject)
if (parent is ConfigurableObject p)
{
var p = parent as ConfigurableObject;
if (!string.IsNullOrEmpty(p.m_parentname))
if (!string.IsNullOrEmpty(p!.m_parentname))
{
m_parentname = $"{p.m_parentname}:{parent.GetType().Name}";
m_parentname = $"{p!.m_parentname}:{parent.GetType().Name}";
}
else
{
Expand All @@ -49,6 +77,11 @@ protected ConfigurableObject(object? parent)
SetConfigRoot();
}

/// <summary>
/// Initializes a new instance of the <see cref="ConfigurableObject"/> class with a parent object and a configuration root path.
/// </summary>
/// <param name="parent">The parent object.</param>
/// <param name="configRootPath">The configuration root path.</param>
protected ConfigurableObject(object? parent, string? configRootPath)
: this(parent)
{
Expand All @@ -67,9 +100,6 @@ protected ConfigurableObject(object? parent, string? configRootPath)
}
}

public const string DefaultJsonFileName = "app.config.json";
public const string DefaultYamlFileName = "app.config.yaml";

private void SetConfigRoot()
{
var b = new ConfigurationBuilder().SetBasePath(AppDomain.CurrentDomain.BaseDirectory);
Expand All @@ -94,6 +124,13 @@ private void SetConfigRoot()
}
}


/// <summary>
/// Gets the configured float value for the specified name.
/// </summary>
/// <param name="name">The name of the configuration value.</param>
/// <param name="defaultValue">The default value to return if the configuration value is not found or is invalid.</param>
/// <returns>The configured float value.</returns>
public float GetConfiguredFloat([CallerMemberName] string? name = null, float defaultValue = 0f)
{
if (string.IsNullOrWhiteSpace(name)) return defaultValue;
Expand All @@ -109,6 +146,12 @@ public float GetConfiguredFloat([CallerMemberName] string? name = null, float de
}
}

/// <summary>
/// Gets the configured boolean value for the specified name.
/// </summary>
/// <param name="name">The name of the configuration value.</param>
/// <param name="defaultValue">The default value to return if the configuration value is not found or is invalid.</param>
/// <returns>The configured boolean value.</returns>
public bool GetConfiguredBool([CallerMemberName] string? name = null, bool defaultValue = false)
{
if (string.IsNullOrWhiteSpace(name)) return defaultValue;
Expand All @@ -124,6 +167,12 @@ public bool GetConfiguredBool([CallerMemberName] string? name = null, bool defau
}
}

/// <summary>
/// Gets the configured integer value for the specified name.
/// </summary>
/// <param name="name">The name of the configuration value.</param>
/// <param name="defaultValue">The default value to return if the configuration value is not found or is invalid.</param>
/// <returns>The configured integer value.</returns>
public int GetConfiguredInt([CallerMemberName] string? name = null, int defaultValue = 0)
{
if (string.IsNullOrWhiteSpace(name)) return defaultValue;
Expand All @@ -139,6 +188,12 @@ public int GetConfiguredInt([CallerMemberName] string? name = null, int defaultV
}
}

/// <summary>
/// Gets the configured string value for the specified name.
/// </summary>
/// <param name="name">The name of the configuration value.</param>
/// <param name="defaultValue">The default value to return if the configuration value is not found or is invalid.</param>
/// <returns>The configured string value.</returns>
public string GetConfiguredString([CallerMemberName] string? name = null, string defaultValue = "")
{
if (string.IsNullOrWhiteSpace(name)) return defaultValue;
Expand All @@ -154,8 +209,11 @@ public string GetConfiguredString([CallerMemberName] string? name = null, string
}
}

private string PathTypeName { get; }

/// <summary>
/// Gets the configured value for the specified name.
/// </summary>
/// <param name="name">The name of the configuration value.</param>
/// <returns>The configured value as a string, or null if not found.</returns>
public string? GetConfiguredValue([CallerMemberName] string? name = null)
{
if (name == null) throw new ArgumentNullException(nameof(name));
Expand Down
21 changes: 15 additions & 6 deletions source/Meadow.Core/Configuration/ILifecycleSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
namespace Meadow
namespace Meadow;

/// <summary>
/// Represents the interface for lifecycle settings.
/// </summary>
public interface ILifecycleSettings
{
public interface ILifecycleSettings
{
bool RestartOnAppFailure { get; set; }
int AppFailureRestartDelaySeconds { get; set; }
}
/// <summary>
/// Gets or sets a value indicating whether to restart on application failure.
/// </summary>
bool RestartOnAppFailure { get; set; }

/// <summary>
/// Gets or sets the delay, in seconds, for restarting after application failure.
/// </summary>
int AppFailureRestartDelaySeconds { get; set; }
}
15 changes: 10 additions & 5 deletions source/Meadow.Core/Configuration/ILogLevelSettings.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
using Meadow.Logging;

namespace Meadow
namespace Meadow;

/// <summary>
/// Represents the interface for log level settings.
/// </summary>
public interface ILogLevelSettings
{
public interface ILogLevelSettings
{
LogLevel Default { get; set; }
}
/// <summary>
/// Gets or sets the default log level.
/// </summary>
LogLevel Default { get; set; }
}
21 changes: 15 additions & 6 deletions source/Meadow.Core/Configuration/ILoggingSettings.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
namespace Meadow
namespace Meadow;

/// <summary>
/// Represents the interface for logging settings.
/// </summary>
public interface ILoggingSettings
{
public interface ILoggingSettings
{
bool ShowTicks { get; set; }
ILogLevelSettings LogLevel { get; }
}
/// <summary>
/// Gets or sets a value indicating whether to show ticks in logs.
/// </summary>
bool ShowTicks { get; set; }

/// <summary>
/// Gets the log level settings.
/// </summary>
ILogLevelSettings LogLevel { get; }
}
26 changes: 18 additions & 8 deletions source/Meadow.Core/Exceptions/InterruptGroupInUseException.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,24 @@
using System;

namespace Meadow.Hardware
namespace Meadow.Hardware;

/// <summary>
/// Exception thrown when attempting to use an interrupt group that is already in use.
/// </summary>
public class InterruptGroupInUseException : Exception
{
public class InterruptGroupInUseException : Exception
{
public int Group { get; }
/// <summary>
/// Gets the interrupt group that is already in use.
/// </summary>
public int Group { get; }

public InterruptGroupInUseException(int group)
: base($"Interrupt group {group} is already in use")
{
}
/// <summary>
/// Initializes a new instance of the <see cref="InterruptGroupInUseException"/> class with the specified interrupt group.
/// </summary>
/// <param name="group">The interrupt group that is already in use.</param>
public InterruptGroupInUseException(int group)
: base($"Interrupt group {group} is already in use")
{
Group = group;
}
}
95 changes: 61 additions & 34 deletions source/Meadow.Core/Gateways/Bluetooth/AdapterCapabilities.cs
Original file line number Diff line number Diff line change
@@ -1,41 +1,68 @@
using System;
namespace Meadow.Gateways.Bluetooth;

namespace Meadow.Gateways.Bluetooth
/// <summary>
/// Describes the capabilities of the Bluetooth adapter.
/// </summary>
public class AdapterCapabilities
{
/// <summary>
/// Describes the capabilities of the Bluetooth adapter.
/// Gets a value indicating whether the adapter has support for classic Bluetooth.
/// </summary>
public class AdapterCapabilities
public bool HasClassicSupport { get; protected set; }

/// <summary>
/// Gets a value indicating whether the adapter has secure support for classic Bluetooth.
/// </summary>
public bool HasSecureClassicSupport { get; protected set; }

/// <summary>
/// Gets a value indicating whether the adapter has support for Bluetooth Low Energy (BLE).
/// </summary>
public bool HasLowEnergySupport { get; protected set; }

/// <summary>
/// Gets a value indicating whether the adapter has secure support for Bluetooth Low Energy (BLE).
/// </summary>
public bool HasLowEnergySecureSupport { get; protected set; }

/// <summary>
/// Gets a value indicating whether the adapter has support for the central role in BLE.
/// </summary>
public bool HasLowEnergyCentralRoleSupport { get; protected set; }

/// <summary>
/// Gets a value indicating whether the adapter has support for the peripheral role in BLE.
/// </summary>
public bool HasLowEnergyPeripheralRoleSupport { get; protected set; }

/// <summary>
/// Gets or sets a value indicating whether the adapter has support to offload advertising to secondary channels.
/// </summary>
public bool HasAdvertisementOffloadSupport { get; set; }

/// <summary>
/// Initializes a new instance of the <see cref="AdapterCapabilities"/> class.
/// </summary>
/// <param name="hasClassicSupport">Indicates whether the adapter has support for classic Bluetooth.</param>
/// <param name="hasSecureClassicSupport">Indicates whether the adapter has secure support for classic Bluetooth.</param>
/// <param name="hasLowEnergySupport">Indicates whether the adapter has support for Bluetooth Low Energy (BLE).</param>
/// <param name="hasLowEnergySecureSupport">Indicates whether the adapter has secure support for Bluetooth Low Energy (BLE).</param>
/// <param name="hasLowEnergyCentralRoleSupport">Indicates whether the adapter has support for the central role in BLE.</param>
/// <param name="hasLowEnergyPeripheralRoleSupport">Indicates whether the adapter has support for the peripheral role in BLE.</param>
public AdapterCapabilities(
bool hasClassicSupport,
bool hasSecureClassicSupport,
bool hasLowEnergySupport,
bool hasLowEnergySecureSupport,
bool hasLowEnergyCentralRoleSupport,
bool hasLowEnergyPeripheralRoleSupport
)
{
public bool HasClassicSupport { get; protected set; }
public bool HasSecureClassicSupport { get; protected set; }
public bool HasLowEnergySupport { get; protected set; }
public bool HasLowEnergySecureSupport { get; protected set; }
public bool HasLowEnergyCentralRoleSupport { get; protected set; }
public bool HasLowEnergyPeripheralRoleSupport { get; protected set; }

/// <summary>
/// Gets or sets a value indicating whether this <see cref="T:Meadow.Gateways.Bluetooth.AdapterCapabilities"/>
/// has support to offload advertising to secondary channels.
/// </summary>
/// <value><c>true</c> if has advertisement offload support; otherwise, <c>false</c>.</value>
public bool HasAdvertisementOffloadSupport { get; set; }

public AdapterCapabilities(
bool hasClassicSupport,
bool hasSecureClassicSupport,
bool hasLowEnergySupport,
bool hasLowEnergySecureSupport,
bool hasLowEnergyCentralRoleSupport,
bool hasLowEnergyPeripheralRoleSupport
)
{
this.HasClassicSupport = hasClassicSupport;
this.HasSecureClassicSupport = hasSecureClassicSupport;
this.HasLowEnergySupport = hasLowEnergySupport;
this.HasLowEnergySecureSupport = hasLowEnergySecureSupport;
this.HasLowEnergyCentralRoleSupport = hasLowEnergyCentralRoleSupport;
this.HasLowEnergyPeripheralRoleSupport = hasLowEnergyPeripheralRoleSupport;
}
this.HasClassicSupport = hasClassicSupport;
this.HasSecureClassicSupport = hasSecureClassicSupport;
this.HasLowEnergySupport = hasLowEnergySupport;
this.HasLowEnergySecureSupport = hasLowEnergySecureSupport;
this.HasLowEnergyCentralRoleSupport = hasLowEnergyCentralRoleSupport;
this.HasLowEnergyPeripheralRoleSupport = hasLowEnergyPeripheralRoleSupport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,14 @@ public enum CharacteristicPropertyType
ExtendedProperties = 128,

// TODO: move these to separate enum
/// <summary>
/// Characteristic notifies of required encryption
/// </summary>
NotifyEncryptionRequired = 256, //0x100

/// <summary>
/// Indicates that encryption is required
/// </summary>
IndicateEncryptionRequired = 512, //0x200
}
}
Loading
Loading