-
Notifications
You must be signed in to change notification settings - Fork 305
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
[All] POC: ObjectFactory: Explicit components registration #4429
[All] POC: ObjectFactory: Explicit components registration #4429
Conversation
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.
Very interesting PR. I have some suggestions to make the code clearer and more expressive.
Sofa/Component/StateContainer/src/sofa/component/statecontainer/init.cpp
Outdated
Show resolved
Hide resolved
|
||
bool ObjectFactory::registerObjectsFromPlugin(const sofa::helper::system::Plugin& plugin) | ||
{ | ||
sofa::helper::system::PluginManager& pluginManager = sofa::helper::system::PluginManager::getInstance(); |
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.
In the quest of removing the singletons, you could pass the pluginManager instance as a parameter
836ecca
to
cc8e302
Compare
[ci-build][with-all-tests] |
[ci-build][with-all-tests][force-full-build] |
a0faa0b
to
b27d29d
Compare
[ci-build][with-all-tests][force-full-build] |
Maybe some ideas here: #2712 |
Sofa/Component/StateContainer/src/sofa/component/statecontainer/init.cpp
Outdated
Show resolved
Hide resolved
91d97b6
to
9668657
Compare
9668657
to
058edfb
Compare
058edfb
to
77931f0
Compare
77931f0
to
624af7c
Compare
[ci-build][with-all-tests][force-full-build] |
[ci-build][with-all-tests][force-full-build] |
f3ea4e6
to
fc2f61b
Compare
@@ -68,6 +72,11 @@ const char* getModuleVersion() | |||
return MODULE_VERSION; | |||
} | |||
|
|||
void registerObjects(sofa::core::ObjectFactory* factory) | |||
{ | |||
factory->registerObjectsFromPlugin("Sofa.Component.StateContainer"); |
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 am annoyed that a meta-module must call the "dynamic" functions (using strings) as if it does not have access to it statically.
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.
sofa::component::statecontainer::target = "Sofa.Component.StateContainer"
ObjectRegistrationEntry() :func(nullptr) {} | ||
} ObjectRegistrationEntry; | ||
|
||
bool ObjectFactory::registerObjectsFromPlugin(const std::string& pluginName) |
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.
Instead, I suggest the following
bool ObjectFactory::registerObjectsFromPlugin(const std::string& pluginName) | |
bool ObjectFactory::registerObjectsFromPlugin(const helper::system::Plugin& plugin) |
In Main.cpp
, you would need to do:
for (const auto& [_, plugin] : pluginManager.getPluginMap())
{
objectFactory->registerObjectsFromPlugin(plugin);
}
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.
Actually it was what it was done at the beginning
bool registerObjectsFromPlugin(const sofa::helper::system::Plugin& plugin); |
But how do use it in Sofa/Component/src/sofa/component/init.cpp ? You would still need to:
- get the pluginmanager (of course)
- find the plugin in the pluginMap (with its string ID)
- then calling registerObjectsFromPlugin on the retrieved pointer (after a nullptr check)
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 understand. But this is what bothers me. I don't like that a meta-module needs the PluginManager
(and even a Plugin
object) to be able to interact with its own dependencies. If we use the PluginManager
in Sofa.Component
to load all the sub-modules, it's not even necessary to have them as a dependency of the module.
6eacd80
to
a1914a9
Compare
2e56888
to
001200c
Compare
For @sofa-framework/reviewers : this PR is now ready but it will have a massive impact on all the code base. Any feedback is more than welcome. A compatibility layer is obviously implemented We suggest to merge this PR but temporarily de-activating all the warnings (compilation-time and runtime). Another PR will start the cleaning within SOFA and its official plugins. When the main part will be done, warnings will be re-activated so that plugin authors can be informed. |
[ci-build][with-all-tests][force-full-build] |
af1683b
to
7523e5c
Compare
3acb0d5
to
9abd964
Compare
Main goal is to remove the ObjectFactory singleton (later) and the implicit registration of objects while loading dynamic libraries (plugins)
In this PR, the explicit registration is applied on components of
Sofa.Component.StateContainer
The legacy RegisterObject mechanism is preserved and will warn the user at the compilation and at run-time.
EDIT:
By submitting this pull request, I acknowledge that
I have read, understand, and agree SOFA Developer Certificate of Origin (DCO).
Reviewers will merge this pull-request only if