-
Notifications
You must be signed in to change notification settings - Fork 585
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
First draft for new ComponentInformation support #1965
Conversation
With reagards to the output, it would be certainly useful to have both the tree (as an object graph), but also a string to uniquely identify the 'Component'. Finally I would split the driver and the board information in two different levels of the tree, so that comparing the information would be easier. |
@raffaeler Looks like we have a similar understanding. Look at the code, I think it exactly has what you're asking for. Each component is currently identified by it's type name. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for not reading the code before, but I didn't have time.
Love the general structure. I added a couple of comments even if it is still very early for a deep review.
I am thinking whether or not it could be possible to go in much detail about the "capabilities" so that it is easier to take decisions based on that instead of a raw string with the board model.
private readonly List<ComponentInformation> _subComponents; | ||
|
||
public ComponentInformation(object instance, string name) | ||
: this(instance, name, string.Empty) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a record, why not using the primary ctor and optional parameters with a default value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer explicit overloads, but that's just syntax and can be adjustedat the end.
src/System.Device.Gpio/System/Device/IQueryComponentInformation.cs
Outdated
Show resolved
Hide resolved
535755c
to
5a6e024
Compare
Make interface IQueryComponentInformation internal for now (since not used for calling), make ComponentInformation read-only, remove argument from QueryComponentInformation.
5a6e024
to
bbef47b
Compare
I like the idea. Now, in terms of implementation, that will require to add the IQueryComponentInformation and the implementation in all Boards and associated drivers, correct? |
Given that the abstract driver class implements the interface, the answer is yes. |
I'm actually not sure yet we really need the interface itself (just yet). We will have the method in several abstract base classes, but since we don't need something like a "list of all objects which can be queried" the interface itself is probably not needed. But this won't change the overall concept. |
@pgrawehr Not sure to understand what exactly is your current design. |
I'm trying out some refactoring, to be able to check the design for the next stage. This will be separated from this PR. |
10f6c8a
to
bbef47b
Compare
So, I think the concept should hold now. This is now waiting for PR #2019 to avoid conflicts. |
} | ||
|
||
return ci; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly
string ToString() { return $"{{ {string.Join(Subcomponents.Select(...))} }}"; }
string ToString() { return $"{{ {_interruptDriver}, ... }}"; }
In case there's a loop in it
And keep separate list in ManagedGpioController, so we don't need to expose the list.
/// This event is raised when <see cref="QueryComponentInformation"/> of the base class is called. This is can be used for bindings | ||
/// to intercept that call on their own I2C device, so they can add additional information | ||
/// </summary> | ||
public event Action<ComponentInformation>? OnQueryComponentInformation; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be just callback rather than event especially given 1:1 relationship with device. Why not Func<ComponentInformation>
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok my question in the end got answered by the code below. First sentence is still valid though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
btw I like this approach much more than inheritance initially proposed but I'll suggest to do only printing in the initial PR and in the following one we can focus on the approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you mean to remove this for now?
/// <inheritdoc /> | ||
public override ComponentInformation QueryComponentInformation() | ||
{ | ||
return new ComponentInformation(this, "Pca9685 PWM Channel"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll suggest to move this to base class and just use type name given spaces do not add virtually any new information
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, however this merely serves as a place holder and, once the design is finalized, all the components should be reviewed and additional information added, if useful.
I had a look at
|
This means just .NET Framework and Mono. I won't be too worried for those.
That's by design, if we want to get rid of a type.
You are right, but this can be resolved with some extension methods.
Let's discuss this. I understand @krwq being worried to introduce a new type which is basically everywhere. |
BTW, even if I prefer the extension methods approach, this code using Expand includes the support to methods:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, if you can add the rest of the DeviceInformation property on the FT devices, it would be perfect!
{ | ||
var self = new ComponentInformation(this, "Ftx232HI2c I2C Bus driver"); | ||
self.Properties["BusNo"] = "0"; | ||
foreach (var device in _usedAddresses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add all the properties of the DeviceInformation
?
/// <inheritdoc /> | ||
public override ComponentInformation QueryComponentInformation() | ||
{ | ||
return base.QueryComponentInformation() with { Description = "Ftx232 Device" }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add all the properties of the DeviceInformation
?
self.Properties["BusNo"] = "0"; | ||
self.Properties["Description"] = DeviceInformation.Description; | ||
self.Properties["SerialNumber"] = DeviceInformation.SerialNumber; | ||
foreach (var device in _usedAddresses) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add all the properties of the DeviceInformation
?
…rmation # Conflicts: # src/devices/Board/RaspberryPiBoard.cs # src/devices/Board/samples/Program.cs
Concept for first part of #1962
All important classes (
GpioDriver
,GpiController
,I2cDriver
,SpiDriver
etc.) now contain a methodQueryComponentInformation
that return an instance ofComponentInformation
. This class represents a tree of the active drivers and/or bindings. Further extension will allow to provide possible drivers as well.[Further extension: It is intended that later
ComponentInformation
can be provided to a factory that constructs a device instance from such an information tree. One problem there is however, how one would know what is available. Providing a class that knows all possible drivers is quite ugly, and even instantiating a driver without initializing it (e.g. just to find out it's capabilities or whether it would work) is currently not possible without relying on exceptions. Separating the constructor from the initialization could improve this. ]Example
This code:
Generates this output on a Raspberry Pi 4:
Microsoft Reviewers: Open in CodeFlow