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

Add ability to get list of registered subsystem #6475

Open
fovea1959 opened this issue Mar 27, 2024 · 5 comments · May be fixed by #6526
Open

Add ability to get list of registered subsystem #6475

fovea1959 opened this issue Mar 27, 2024 · 5 comments · May be fixed by #6526
Labels
component: command-based WPILib Command Based Library good first issue Good for newcomers. type: feature Brand new functionality, features, pages, workflows, endpoints, etc.

Comments

@fovea1959
Copy link
Contributor

Is your feature request related to a problem? Please describe.
We would like the ability to run over the list of registered subsystems to check for annotations and any implementations.

Describe the solution you'd like
Add a CommandScheduler.getAllSubsystems() method.

Describe alternatives you've considered
Hacking in with reflection.

Additional context
I'm willing to take this one on after CMP.

@Starlight220
Copy link
Member

Sounds good.
One point for question: should the returned collection be read-only, a capture, or fully backed and writeable?

@Starlight220 Starlight220 added type: feature Brand new functionality, features, pages, workflows, endpoints, etc. good first issue Good for newcomers. component: command-based WPILib Command Based Library labels Mar 27, 2024
@fovea1959
Copy link
Contributor Author

Sounds good.
One point for question: should the returned collection be read-only, a capture, or fully backed and writeable?

Good question, I would have just put a getter for the existing collection in there, which would have made for some interesting bugs when teams started tweaking the returned collection.

For the purposes I envision, a read-only would be great. A writable capture would be confusing, and fully backed would be problematic (how to detect and properly respond to changes to the collection?)

For performance reasons, I wonder if a read-only copy should be kept and maintained by the scheduler as subsystems are added. I would worry about someone putting a for (var subsystem : CommandScheduler.getAllSubsystems()) in a periodic. Is that a legit concern?

@Starlight220
Copy link
Member

Starlight220 commented Mar 27, 2024

If ImmutableSet(m_subsystems.keySet()) still reads from the backing set (rather than a one-time copy), that can be a simple solution.
EDIT: Collections.unmodifiableSet looks like exactly what we need.

C++ would also be interesting, I'm not versed enough with C++ STL/LLVM collections to know how this can be done properly.
EDIT: C++20 has https://en.cppreference.com/w/cpp/ranges/keys_view, that might do what we need if it's compatible with llvm::DenseMap

@spacey-sooty
Copy link
Contributor

C++ would also be interesting, I'm not versed enough with C++ STL/LLVM collections to know how this can be done properly. EDIT: C++20 has https://en.cppreference.com/w/cpp/ranges/keys_view, that might do what we need if it's compatible with llvm::DenseMap

Is WPILib using C++ 20 yet? If not would we want to upgrade?

spacey-sooty added a commit to spacey-sooty/allwpilib that referenced this issue Apr 20, 2024
Still needs C++, most likely to be done with
https://en.cppreference.com/w/cpp/ranges/keys_view depending on
compatibility with `llvm::DenseMap` and C++ 20 support.

Resolves wpilibsuite#6475
@calcmogul
Copy link
Member

WPILib enables C++20, but ranges support isn't complete on all compilers. You can use whatever passes CI.

spacey-sooty added a commit to spacey-sooty/allwpilib that referenced this issue Apr 21, 2024
Still needs C++, most likely to be done with
https://en.cppreference.com/w/cpp/ranges/keys_view depending on
compatibility with `llvm::DenseMap` and C++ 20 support.

Resolves wpilibsuite#6475
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: command-based WPILib Command Based Library good first issue Good for newcomers. type: feature Brand new functionality, features, pages, workflows, endpoints, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants