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

adding disposable, shared controller interface and gpiocontroller interface #1167

Closed
wants to merge 2 commits into from

Conversation

colombod
Copy link
Member

With this PR I am trying to propose a discussion around some interfaces used during the development of the piTop bindings

  • introduction of a IGpioController interface to make it possible to have mocks and implement shared proxy
  • share controller class to create a view over a controller so that devices and other part of applications can manage pins and callbacks with the ability to clean up just the portion of state interested
  • disposable factory to create disposable object to simplify the closing of pins and the unregistration of callbacks

@pgrawehr
Copy link
Contributor

Unfortunatelly, there's a big issue: System.Device.Gpio interfaces must be kept backwards compatible. Breaking changes must have very good reasoning. Note also that some interface concept discussions have been open for a long time already (but where postponed due to other tasks and long absences of the responsible maintainers). See #1128 and #878.

@colombod
Copy link
Member Author

Unfortunatelly, there's a big issue: System.Device.Gpio interfaces must be kept backwards compatible. Breaking changes must have very good reasoning. Note also that some interface concept discussions have been open for a long time already (but where postponed due to other tasks and long absences of the responsible maintainers). See #1128 and #878.

Makes sense, the contract change on the OpenPin and RegisterCallBack is something that could be left out, would it still make the case of having IGpioController interface a big issue with the api backward compatibility?

@colombod
Copy link
Member Author

Unfortunatelly, there's a big issue: System.Device.Gpio interfaces must be kept backwards compatible. Breaking changes must have very good reasoning. Note also that some interface concept discussions have been open for a long time already (but where postponed due to other tasks and long absences of the responsible maintainers). See #1128 and #878.

Thank you for you feedback, I realized I really just need the IGpioController interface so I can build proxy and adaptors, the other api changes can be done as extension methods so not to make the type too big or break existing contract. Thank you

@colombod colombod marked this pull request as draft August 26, 2020 16:56
@pgrawehr
Copy link
Contributor

Makes sense, the contract change on the OpenPin and RegisterCallBack is something that could be left out, would it still make the case of having IGpioController interface a big issue with the api backward compatibility?

I guess so. Interfaces don't scale well (because every change to an interface, including adding methods, is a breaking change). What we're probably going to do (is under discussion now), is to unseal the GpioController class and change its methods to virtual. This (besides other reasons) also allow the mocking support you want.

@colombod
Copy link
Member Author

@pgrawehr the unselaed class would be fine. Any time frame idea for such a change? That would actually enable all api addition I am doing to be an external package that user can adopt if they are interested in some additional pattern and utilities.

@pgrawehr
Copy link
Contributor

@colombod : Vote for/have a look at #1128. That contains quite a few concept updates, and it would be great to have a broad discussion on them.

@colombod
Copy link
Member Author

@colombod : Vote for/have a look at #1128. That contains quite a few concept updates, and it would be great to have a broad discussion on them.

that PR is what I call Christmas present. It is absolutely brilliant with the controller and spi management and all the rest.

@Ellerbach Ellerbach added the area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins label Oct 14, 2020
@krwq
Copy link
Member

krwq commented Nov 3, 2020

This seem to overlap with some of the other conversations we have in other issues:
#383
#80
#1182
#637
#878

I'm hoping we will figure out the abstraction subject as we're having request from different directions about it

/// <param name="controller">The GPioController.</param>
/// <param name="pinNumber">The pin number in the controller's numbering scheme.</param>
/// <returns>A disposable that will close the pin if disposed.</returns>
public static IDisposable OpenPinAsDisposable(this IGpioController controller, int pinNumber)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're actually thinking of having GpioPin class instead, see #215

/// <param name="eventTypes">The event types to wait for.</param>
/// <param name="callback">The callback method that will be invoked.</param>
/// <returns>A disposable object that will remove the added callback </returns>
public static IDisposable RegisterCallbackForPinValueChangedEventAsDisposable(this IGpioController controller, int pinNumber,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather have us introduce the real abstraction for this (i.e. CallbackForPinValueChanged) implementing IDisposable

@krwq
Copy link
Member

krwq commented Nov 3, 2020

I do like confirmation from here that adding GpioPin is the right direction and also looking at this PR seems like another person trying to bypass GpioDriver abstraction which makes me thinking to perhaps just deprecate it and make everything implement GpioController directly (so unseal and virtualize it as proposed by @pgrawehr as well and just not have GpioDriver - and of course leave compat GpioController to make old code still work)

@pgrawehr
Copy link
Contributor

pgrawehr commented Nov 3, 2020

...and just not have GpioDriver - and of course leave compat GpioController to make old code still work)

I think that extra driver class is fine to keep, even if the Controller is unsealed - it separates responsibilities. The Controller handles pin management, while the driver handles the low-level operations on individual pins.

@Ellerbach
Copy link
Member

I do like confirmation from here that adding GpioPin is the right direction

Yes, this really help to clearly see the need of abstraction, separating drivers from the controller itself and having GpioPin as well.

The Controller handles pin management, while the driver handles the low-level operations on individual pins.

I agree, this would perfectly work.

This seem to overlap with some of the other conversations we have in other issues:
#383
#80
#1182
#637
#878

And the good news is that with all this, I feel we're all ready to move forward. Once the new model will be present, the trendy topic shouldn't be GpioController anymore on the various issues :-)

@joperezr
Copy link
Member

[Triage] Hey @colombod we have been making good progress on this PR: #1254 which might help you out with your needs and might be related to this one. Can you check that one to see if that would solve your needs?

@colombod
Copy link
Member Author

[Triage] Hey @colombod we have been making good progress on this PR: #1254 which might help you out with your needs and might be related to this one. Can you check that one to see if that would solve your needs?

This pr looks good and enables quite few things for me

@joperezr
Copy link
Member

joperezr commented Dec 3, 2020

[Triage] @colombod do you think there is still value on keeping this PR open or would #1254 cover your needs? If the latter then we can go ahead and close this PR.

@colombod
Copy link
Member Author

colombod commented Dec 3, 2020

Will close this or as I have different things based on your nee library

@colombod colombod closed this Dec 23, 2020
@colombod colombod deleted the feature/interface_extensions branch December 23, 2020 12:36
@github-actions github-actions bot locked and limited conversation to collaborators Dec 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Device.Gpio Contains types for using general-purpose I/O (GPIO) pins
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants