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

Callback-based system. #27

Open
DarkMatterCore opened this issue Jan 15, 2023 · 5 comments
Open

Callback-based system. #27

DarkMatterCore opened this issue Jan 15, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@DarkMatterCore
Copy link
Owner

DarkMatterCore commented Jan 15, 2023

Is your feature request related to a problem? Please describe.
Back when I designed the interface for this library in 2020, it seemed like a no-brainer to use an event-based system based on the ABI used by multiple Switch background services, which in turn makes it possible for the application using the library to span a single additional background thread that uses waitMulti() to handle multiple events and call it a day.

However, this very same reasoning falls short if the application using the library doesn't use events at all, which is something I never stopped to consider. This forces the developer to span an additional background thread to exclusively handle changes from the library, which is a bit overkill.

Please consider this library was specifically designed with nxdumptool in mind before it became a much broader project, and that application relies heavily on background services that do use this kind of ABI.

Describe the solution you'd like
A callback-based system that uses a function pointer provided by the user to handle UMS status changes under the library's very own background thread.

This new system should be able to co-exist with the current event-based system, because both designs have their own particular use cases.

Additional context
Initially proposed by averne and discussed in #26.

@DarkMatterCore DarkMatterCore added the enhancement New feature or request label Jan 15, 2023
@averne
Copy link
Contributor

averne commented Jan 15, 2023

Additionally this could be used to enable advanced communication with the user.
For instance, there could be a callback used prior to creating the fs context and mounting to devoptab, where the user could decide on a different mountpoint, if he wants to mount as read-only, maybe even have advanced settings based on the filesystem, ...

@DarkMatterCore
Copy link
Owner Author

Sure thing. This will be an ongoing WIP I intend to further explore over the course of the next week.

Changes will surely be pushed to dev, so feel free to take a peek at that branch and/or let me know if you want write access.

@DarkMatterCore
Copy link
Owner Author

Just pushed the first changes related to this issue to dev, check 0299eae. A single callback is used at this moment, others may follow down the road.

I tested it a bit with all my flash drives and it seems to work fine.

@averne
Copy link
Contributor

averne commented Jan 19, 2023

Thanks for the quick patch, I'll try to move my app to this system soon and give you feedback.
At a glance, I think the UsbHsFsPopulateCb could take an additional void* parameter, passed by the user in usbHsFsSetPopulateCallback. This way the user can conveniently access any kind of structure (eg. a drive manager object) from the callback.

@DarkMatterCore
Copy link
Owner Author

@averne Had some time to spare, so I went ahead and implemented support for a user data pointer in 2c401e8. I'll be waiting for your feedback, there's some other stuff I want to tackle in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants