diff --git a/src/System.Device.Gpio/System.Device.Gpio.csproj b/src/System.Device.Gpio/System.Device.Gpio.csproj
index 3415d2b218..8cfbcd95b7 100644
--- a/src/System.Device.Gpio/System.Device.Gpio.csproj
+++ b/src/System.Device.Gpio/System.Device.Gpio.csproj
@@ -66,5 +66,9 @@
+
+
+
+
diff --git a/src/System.Device.Gpio/System/Device/ComponentInformation.cs b/src/System.Device.Gpio/System/Device/ComponentInformation.cs
index ee1f770839..1c35495fb0 100644
--- a/src/System.Device.Gpio/System/Device/ComponentInformation.cs
+++ b/src/System.Device.Gpio/System/Device/ComponentInformation.cs
@@ -3,6 +3,9 @@
using System;
using System.Collections.Generic;
+using System.ComponentModel;
+using System.Linq;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
@@ -23,6 +26,11 @@ public ComponentInformation(object instance, string name, string version)
{
}
+ public ComponentInformation(object instance, string name, ComponentState state)
+ : this(instance, name, string.Empty, state)
+ {
+ }
+
public ComponentInformation(object instance, string name, string version, ComponentState componentState)
{
if (instance == null)
@@ -35,6 +43,18 @@ public ComponentInformation(object instance, string name, string version, Compon
Version = version;
State = componentState;
+
+ if (string.IsNullOrWhiteSpace(Version))
+ {
+ var assembly = instance.GetType().Assembly;
+ var v = (AssemblyInformationalVersionAttribute?)assembly.GetCustomAttributes().FirstOrDefault(x => x is AssemblyInformationalVersionAttribute);
+
+ if (v != null)
+ {
+ Version = v.InformationalVersion;
+ }
+ }
+
_subComponents = new List();
}
@@ -45,20 +65,17 @@ public string Type
public string Name
{
- get;
- set;
+ get; init;
}
public string Version
{
- get;
- set;
+ get; init;
}
public ComponentState State
{
- get;
- set;
+ get; init;
}
public IReadOnlyList SubComponents => _subComponents.AsReadOnly();
@@ -73,23 +90,34 @@ public void AddSubComponent(ComponentInformation subComponent)
_subComponents.Add(subComponent);
}
+ private static string PrintComponentDescription(ComponentInformation component)
+ {
+ string v = string.Empty;
+ if (!string.IsNullOrWhiteSpace(component.Version))
+ {
+ v = $" Version {component.Version}";
+ }
+
+ return $"{{{component.Type}}} {component.Name}{v}{Environment.NewLine}";
+ }
+
protected virtual void SubComponentToString(StringBuilder output, int ident)
{
foreach (var component in _subComponents)
{
output.Append(new string(' ', ident));
output.Append('\u2514'); // border element
- output.Append($"{{{component.Type}}} {component.Name}{Environment.NewLine}");
+ output.Append(PrintComponentDescription(component));
component.SubComponentToString(output, ident + 1);
}
}
public override string ToString()
{
- StringBuilder b = new StringBuilder($"{{{Type}}} {Name}{Environment.NewLine}");
+ StringBuilder b = new StringBuilder(PrintComponentDescription(this));
SubComponentToString(b, 1);
- return b.ToString();
+ return b.ToString().TrimEnd();
}
}
}
diff --git a/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3Driver.cs b/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3Driver.cs
index ea374029d3..d5999d366a 100644
--- a/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3Driver.cs
+++ b/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3Driver.cs
@@ -281,8 +281,8 @@ protected override void Dispose(bool disposing)
}
///
- public override ComponentInformation QueryComponentInformation(bool onlyActive)
+ public override ComponentInformation QueryComponentInformation()
{
- return _internalDriver.QueryComponentInformation(onlyActive);
+ return _internalDriver.QueryComponentInformation();
}
}
diff --git a/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3LinuxDriver.cs b/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3LinuxDriver.cs
index 757d825445..999b46fdac 100644
--- a/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3LinuxDriver.cs
+++ b/src/System.Device.Gpio/System/Device/Gpio/Drivers/RaspberryPi3LinuxDriver.cs
@@ -766,7 +766,7 @@ protected override void Dispose(bool disposing)
}
///
- public override ComponentInformation QueryComponentInformation(bool onlyActive)
+ public override ComponentInformation QueryComponentInformation()
{
StringBuilder sb = new StringBuilder();
Initialize();
@@ -789,7 +789,7 @@ public override ComponentInformation QueryComponentInformation(bool onlyActive)
if (_interruptDriver != null)
{
- ci.AddSubComponent(_interruptDriver.QueryComponentInformation(onlyActive));
+ ci.AddSubComponent(_interruptDriver.QueryComponentInformation());
}
return ci;
diff --git a/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs b/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
index 2a91db7ddc..1289a79e2f 100644
--- a/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
+++ b/src/System.Device.Gpio/System/Device/Gpio/GpioController.cs
@@ -480,21 +480,16 @@ private static GpioDriver GetBestDriverForBoardOnWindows()
}
///
- public virtual ComponentInformation QueryComponentInformation(bool onlyActive)
+ public virtual ComponentInformation QueryComponentInformation()
{
ComponentInformation self = new ComponentInformation(this, "Generic GPIO Controller", string.Empty, ComponentState.Active);
if (_driver != null)
{
- ComponentInformation driverInfo = _driver.QueryComponentInformation(onlyActive);
+ ComponentInformation driverInfo = _driver.QueryComponentInformation();
self.AddSubComponent(driverInfo);
}
- if (!onlyActive)
- {
- // ...
- }
-
return self;
}
}
diff --git a/src/System.Device.Gpio/System/Device/Gpio/GpioDriver.cs b/src/System.Device.Gpio/System/Device/Gpio/GpioDriver.cs
index 31f11058bd..f4f978a340 100644
--- a/src/System.Device.Gpio/System/Device/Gpio/GpioDriver.cs
+++ b/src/System.Device.Gpio/System/Device/Gpio/GpioDriver.cs
@@ -144,7 +144,7 @@ protected virtual void Dispose(bool disposing)
}
///
- public virtual ComponentInformation QueryComponentInformation(bool onlyActive)
+ public virtual ComponentInformation QueryComponentInformation()
{
return new ComponentInformation(this, "Gpio Driver", string.Empty, ComponentState.Active);
}
diff --git a/src/System.Device.Gpio/System/Device/IQueryComponentInformation.cs b/src/System.Device.Gpio/System/Device/IQueryComponentInformation.cs
index 90371ddbe6..316947943e 100644
--- a/src/System.Device.Gpio/System/Device/IQueryComponentInformation.cs
+++ b/src/System.Device.Gpio/System/Device/IQueryComponentInformation.cs
@@ -9,14 +9,14 @@ namespace System.Device
{
///
/// Interface to support querying component information from a class
+ /// (declared internal for now, since it doesn't need exposing as long as the callers operate on the actual type of the components)
///
- public interface IQueryComponentInformation
+ internal interface IQueryComponentInformation
{
///
/// Query information about a component and it's children.
///
- /// True to return only active components, false to also list possible alternatives or inactive drivers
/// A tree of instances.
- public ComponentInformation QueryComponentInformation(bool onlyActive);
+ public ComponentInformation QueryComponentInformation();
}
}
diff --git a/src/System.Device.Gpio/System/Device/IsExternalInit.cs b/src/System.Device.Gpio/System/Device/IsExternalInit.cs
new file mode 100644
index 0000000000..6d3fc4246a
--- /dev/null
+++ b/src/System.Device.Gpio/System/Device/IsExternalInit.cs
@@ -0,0 +1,22 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System.ComponentModel;
+
+namespace System.Runtime.CompilerServices
+{
+ ///
+ /// Reserved to be used by the compiler for tracking metadata.
+ /// This class should not be used by developers in source code.
+ /// This dummy class is required to compile records when targeting .NET Standard
+ ///
+ [EditorBrowsable(EditorBrowsableState.Never)]
+#if BUILDING_IOT_DEVICE_BINDINGS
+ internal
+#else
+ public
+#endif
+ static class IsExternalInit
+ {
+ }
+}
diff --git a/src/devices/Board/Board.cs b/src/devices/Board/Board.cs
index c552a3094b..7451125d45 100644
--- a/src/devices/Board/Board.cs
+++ b/src/devices/Board/Board.cs
@@ -22,7 +22,7 @@ namespace Iot.Device.Board
/// There should be exactly one instance of a board class per hardware component in an application, but it is possible to work with multiple boards
/// at once (i.e. when having a GPIO expander connected to the Raspberry Pi)
///
- public abstract class Board : MarshalByRefObject, IDisposable, IQueryComponentInformation
+ public abstract class Board : MarshalByRefObject, IDisposable
{
// See comment at GetBestDriverForBoardOnWindows. This should get some specific factory pattern
private const string BaseBoardProductRegistryValue = @"SYSTEM\HardwareConfig\Current\BaseBoardProduct";
@@ -642,19 +642,19 @@ public static Board Create()
return board;
}
- ///
- public virtual ComponentInformation QueryComponentInformation(bool onlyActive)
+ ///
+ public virtual ComponentInformation QueryComponentInformation()
{
- ComponentInformation self = new ComponentInformation(this, "Generic Board", string.Empty, ComponentState.Active);
+ ComponentInformation self = new ComponentInformation(this, "Generic Board", ComponentState.Active);
var controller = CreateGpioController();
- var controllerInfo = controller.QueryComponentInformation(onlyActive);
+ var controllerInfo = controller.QueryComponentInformation();
self.AddSubComponent(controllerInfo);
foreach (var e in _i2cBuses)
{
- self.AddSubComponent(e.Value.QueryComponentInformation(onlyActive));
+ self.AddSubComponent(e.Value.QueryComponentInformation());
}
return self;
diff --git a/src/devices/Board/CustomBoard.cs b/src/devices/Board/CustomBoard.cs
index 95ce5e68d0..a124300e0f 100644
--- a/src/devices/Board/CustomBoard.cs
+++ b/src/devices/Board/CustomBoard.cs
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Device;
using System.Device.Gpio;
using System.Device.I2c;
using System.Device.Pwm;
@@ -70,5 +71,15 @@ protected override PwmChannel CreateSimplePwmChannel(int chip, int channel, int
{
return _pwmChannelCreator(channel);
}
+
+ ///
+ public override ComponentInformation QueryComponentInformation()
+ {
+ var ret = base.QueryComponentInformation();
+ return ret with
+ {
+ Name = "Custom Board"
+ };
+ }
}
}
diff --git a/src/devices/Board/I2cBusManager.cs b/src/devices/Board/I2cBusManager.cs
index 6521ee2482..6d6a56c7a1 100644
--- a/src/devices/Board/I2cBusManager.cs
+++ b/src/devices/Board/I2cBusManager.cs
@@ -13,7 +13,7 @@ namespace Iot.Device.Board
///
/// Manages an I2C bus instance
///
- public class I2cBusManager : I2cBus, IDisposable, IQueryComponentInformation
+ public class I2cBusManager : I2cBus, IDisposable
{
private readonly int _sdaPin;
private readonly int _sclPin;
@@ -123,10 +123,13 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
- ///
- public ComponentInformation QueryComponentInformation(bool onlyActive)
+ ///
+ /// Query the component information (the tree of active drivers) for diagnostic purposes.
+ ///
+ /// A instance
+ public ComponentInformation QueryComponentInformation()
{
- return new ComponentInformation(this, $"I2C Bus Manager, Bus number {_bus}", string.Empty, ComponentState.Active);
+ return new ComponentInformation(this, $"I2C Bus Manager, Bus number {_bus}", ComponentState.Active);
}
}
}
diff --git a/src/devices/Board/RaspberryPiBoard.cs b/src/devices/Board/RaspberryPiBoard.cs
index 7e569233a0..fc801568ee 100644
--- a/src/devices/Board/RaspberryPiBoard.cs
+++ b/src/devices/Board/RaspberryPiBoard.cs
@@ -9,6 +9,7 @@
using System.Device.I2c;
using System.Device.Pwm;
using System.Device.Spi;
+using System.IO;
using System.Text;
namespace Iot.Device.Board
@@ -534,12 +535,13 @@ protected override void Dispose(bool disposing)
}
///
- public override ComponentInformation QueryComponentInformation(bool onlyActive)
+ public override ComponentInformation QueryComponentInformation()
{
- ComponentInformation self = base.QueryComponentInformation(onlyActive);
- self.Name = "Raspberry Pi Board";
-
- return self;
+ ComponentInformation self = base.QueryComponentInformation();
+ return self with
+ {
+ Name = "Raspberry Pi"
+ };
}
}
}
diff --git a/src/devices/Board/samples/Program.cs b/src/devices/Board/samples/Program.cs
index 61bd1c96a1..11f85696b1 100644
--- a/src/devices/Board/samples/Program.cs
+++ b/src/devices/Board/samples/Program.cs
@@ -43,7 +43,7 @@ private static void WindowsDesktop()
const int led2 = 2;
using Board b = Board.Create();
Console.WriteLine("Hardware detected: ");
- Console.WriteLine(b.QueryComponentInformation(true));
+ Console.WriteLine(b.QueryComponentInformation());
using GpioController controller = b.CreateGpioController();
if (controller.PinCount > 0)
@@ -133,7 +133,7 @@ private static void RaspberryPiTest()
{
using var raspi = Board.Create();
Console.WriteLine("Hardware detected: ");
- Console.WriteLine(raspi.QueryComponentInformation(true));
+ Console.WriteLine(raspi.QueryComponentInformation());
PwmRaspiTest(raspi);
SpiRaspiTestWithSoftwareCs(raspi);
SpiRaspiTestWithHardwareCs(raspi);