Repository navigation
feat(resources): add dynamically loaded resource plugins #905
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #ifndef PHLEX_RESOURCE_HPP | ||
| #define PHLEX_RESOURCE_HPP | ||
|
|
||
| #include "phlex/core/graph_proxy.hpp" | ||
| #include "phlex/detail/plugin_macros.hpp" | ||
|
|
||
| #include <utility> | ||
|
|
||
| namespace phlex::detail { | ||
|
|
||
| /// @brief Proxy for registering resources. | ||
| /// | ||
| /// Passed to @c PHLEX_REGISTER_RESOURCES plugin entry points. Only resource | ||
| /// registration is accessible. Users never construct this type directly. | ||
| class resources_graph_proxy { | ||
| public: | ||
| explicit resources_graph_proxy(graph_registration_bundle bundle) : resources_{bundle.resources} | ||
| { | ||
| } | ||
|
|
||
| template <typename Resource, typename... Args> | ||
| requires unlimited_resource_registration<Resource, Args...> | ||
| void add_unlimited_resource(Args&&... args) const | ||
| { | ||
| resources_.template add_unlimited<Resource>(std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| template <typename Resource, typename... Args> | ||
| requires serialized_resource_registration<Resource, Args...> | ||
| void add_serialized_resource(Args&&... args) const | ||
| { | ||
| resources_.template add_serialized<Resource>(std::forward<Args>(args)...); | ||
| } | ||
|
|
||
| private: | ||
| resource_catalog& resources_; // NOLINT(cppcoreguidelines-avoid-const-or-ref-data-members) | ||
| }; | ||
|
|
||
| namespace internal { | ||
| using resource_creator_t = void(resources_graph_proxy const&, configuration const&); | ||
|
|
||
| // The plugin mechanism requires a template, but resources_graph_proxy doesn't need to be one. | ||
| // The following template alias is the workaround. | ||
| template <std::same_as<void_tag> T> | ||
| using resources_graph_proxy_shim = resources_graph_proxy; | ||
| } | ||
| } | ||
|
|
||
| #define PHLEX_REGISTER_RESOURCES(...) \ | ||
| PHLEX_DETAIL_REGISTER_PLUGIN( \ | ||
| phlex::detail::internal::resources_graph_proxy_shim, create, create_resources, __VA_ARGS__) | ||
|
|
||
| #endif // PHLEX_RESOURCE_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
knoepfel marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "phlex/configuration.hpp" | ||
| #include "phlex/resource.hpp" | ||
| #include "test/plugins/resources_for_testing.hpp" | ||
|
|
||
| using namespace phlex; | ||
| using namespace test::plugins; | ||
|
|
||
| namespace { | ||
| using proxy = detail::resources_graph_proxy; | ||
|
|
||
| template <typename T> | ||
| concept exposes_observe = | ||
| requires(T const& resource_proxy) { resource_proxy.observe("invalid", [](int) {}); }; | ||
|
|
||
| static_assert(requires(proxy const& r) { | ||
| r.template add_unlimited_resource<configured_resource>(1); | ||
| r.template add_serialized_resource<serialized_resource>(); | ||
| }); | ||
| static_assert(not exposes_observe<proxy>); | ||
| } | ||
|
|
||
| PHLEX_REGISTER_RESOURCES(r, config) | ||
| { | ||
| r.add_unlimited_resource<configured_resource>(config.get<int>("value")); | ||
| r.add_serialized_resource<serialized_resource>(); | ||
| } |
|
knoepfel marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| #ifndef TEST_PLUGINS_RESOURCES_FOR_TESTING_HPP | ||
| #define TEST_PLUGINS_RESOURCES_FOR_TESTING_HPP | ||
|
|
||
| namespace test::plugins { | ||
| struct configured_resource { | ||
| explicit configured_resource(int value) : value{value} {} | ||
|
|
||
| int value; | ||
| }; | ||
|
|
||
| struct serialized_resource { | ||
| using token_type = serialized_resource const*; | ||
| }; | ||
| } | ||
|
|
||
| #endif // TEST_PLUGINS_RESOURCES_FOR_TESTING_HPP |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| resources: { | ||
| resources_for_testing: { | ||
| cpp: 'register_resources_for_testing', | ||
| value: 42, | ||
| }, | ||
| }, | ||
| driver: { | ||
| cpp: 'generate_layers', | ||
| layers: { | ||
| event: { parent: 'job', total: 10, starting_number: 1 }, | ||
| }, | ||
| }, | ||
| sources: { | ||
| provider: { | ||
| cpp: 'ij_source', | ||
| }, | ||
| }, | ||
| modules: { | ||
| verify_resources: { | ||
| cpp: 'verify_resources', | ||
| }, | ||
| }, | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.