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

[All] POC: ObjectFactory: Explicit components registration #4429

Merged

Conversation

fredroy
Copy link
Contributor

@fredroy fredroy commented Jan 12, 2024

⚠️ Proof-of-concept ⚠️

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:

  • add tests about plugins non-registering/registering implicitly/registering explicitly
  • add deprecations/warnings in RequiredPlugin
  • add a function registerPlugin in PluginManager. This function is simply an alias for loadPlugin() because loadPlugin() does much more than just loading a plugin by itself. In an eventual future, PluginManager should be refactored in a way that loadPlugin calls registerPlugin()

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

  • it builds with SUCCESS for all platforms on the CI.
  • it does not generate new warnings.
  • it does not generate new unit test failures.
  • it does not generate new scene test failures.
  • it does not break API compatibility.
  • it is more than 1 week old (or has fast-merge label).
@fredroy fredroy added pr: status to review To notify reviewers to review this pull-request pr: new feature Implement a new feature pr: dev meeting topic PR to be discussed in sofa-dev meeting labels Jan 12, 2024
Copy link
Contributor

@alxbilger alxbilger left a 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.


bool ObjectFactory::registerObjectsFromPlugin(const sofa::helper::system::Plugin& plugin)
{
sofa::helper::system::PluginManager& pluginManager = sofa::helper::system::PluginManager::getInstance();
Copy link
Contributor

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

@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 836ecca to cc8e302 Compare January 15, 2024 02:09
@fredroy
Copy link
Contributor Author

fredroy commented Jan 15, 2024

[ci-build][with-all-tests]

@fredroy
Copy link
Contributor Author

fredroy commented Jan 15, 2024

[ci-build][with-all-tests][force-full-build]

@fredroy fredroy force-pushed the explicit_register_objectfactory branch 2 times, most recently from a0faa0b to b27d29d Compare January 15, 2024 08:36
@fredroy
Copy link
Contributor Author

fredroy commented Jan 16, 2024

[ci-build][with-all-tests][force-full-build]

@damienmarchal
Copy link
Contributor

Maybe some ideas here: #2712

@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 91d97b6 to 9668657 Compare January 24, 2024 00:12
@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 9668657 to 058edfb Compare February 1, 2024 06:26
@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 058edfb to 77931f0 Compare February 9, 2024 02:20
@hugtalbot hugtalbot added the pr: highlighted in next release Highlight this contribution in the notes of the upcoming release label Feb 14, 2024
@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 77931f0 to 624af7c Compare February 20, 2024 04:33
@fredroy
Copy link
Contributor Author

fredroy commented Feb 20, 2024

[ci-build][with-all-tests][force-full-build]

@bakpaul bakpaul added this to the v24.06 milestone Feb 20, 2024
@fredroy
Copy link
Contributor Author

fredroy commented Feb 20, 2024

[ci-build][with-all-tests][force-full-build]

@alxbilger alxbilger force-pushed the explicit_register_objectfactory branch from f3ea4e6 to fc2f61b Compare February 21, 2024 15:13
Sofa/framework/Core/src/sofa/core/ObjectFactory.h Outdated Show resolved Hide resolved
@@ -68,6 +72,11 @@ const char* getModuleVersion()
return MODULE_VERSION;
}

void registerObjects(sofa::core::ObjectFactory* factory)
{
factory->registerObjectsFromPlugin("Sofa.Component.StateContainer");
Copy link
Contributor

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.

Copy link
Contributor

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)
Copy link
Contributor

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

Suggested change
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);
    }
Copy link
Contributor Author

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)
Copy link
Contributor

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.

@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 6eacd80 to a1914a9 Compare February 23, 2024 01:01
@hugtalbot hugtalbot added STC#17 Tasks for STC#17 coding sprint and removed pr: dev meeting topic PR to be discussed in sofa-dev meeting labels Feb 28, 2024
@fredroy fredroy added pr: status postponed To keep in mind that this PR was interesting but no one has time to make it mergeable now. and removed pr: status to review To notify reviewers to review this pull-request STC#17 Tasks for STC#17 coding sprint labels Feb 28, 2024
@hugtalbot hugtalbot removed pr: status postponed To keep in mind that this PR was interesting but no one has time to make it mergeable now. pr: highlighted in next release Highlight this contribution in the notes of the upcoming release labels Feb 28, 2024
@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 2e56888 to 001200c Compare July 3, 2024 00:56
@fredroy fredroy added pr: status wip Development in the pull-request is still in progress and removed pr: status to review To notify reviewers to review this pull-request labels Jul 3, 2024
@hugtalbot
Copy link
Contributor

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.

@hugtalbot hugtalbot added the pr: breaking Change possibly inducing a compilation error label Jul 3, 2024
@fredroy fredroy added pr: status to review To notify reviewers to review this pull-request and removed pr: status wip Development in the pull-request is still in progress labels Jul 15, 2024
@fredroy
Copy link
Contributor Author

fredroy commented Jul 15, 2024

[ci-build][with-all-tests][force-full-build]

@fredroy fredroy force-pushed the explicit_register_objectfactory branch from af1683b to 7523e5c Compare July 15, 2024 03:33
@fredroy fredroy force-pushed the explicit_register_objectfactory branch from 3acb0d5 to 9abd964 Compare July 17, 2024 01:31
@hugtalbot hugtalbot added pr: status ready Approved a pull-request, ready to be squashed and removed pr: status to review To notify reviewers to review this pull-request labels Jul 17, 2024
@hugtalbot hugtalbot merged commit eb28a2b into sofa-framework:master Jul 17, 2024
15 checks passed
@hugtalbot hugtalbot deleted the explicit_register_objectfactory branch July 17, 2024 08:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr: breaking Change possibly inducing a compilation error pr: new feature Implement a new feature pr: status ready Approved a pull-request, ready to be squashed STC#17 Tasks for STC#17 coding sprint
5 participants