-
Couldn't load subscription status.
- Fork 44
Participant parameters #165
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
Draft
KonradBreitsprecherBkd
wants to merge
2
commits into
main
Choose a base branch
from
dev_participant_parameters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // SPDX-FileCopyrightText: 2023 Vector Informatik GmbH | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #include <memory> | ||
| #include <string> | ||
|
|
||
| #include "gtest/gtest.h" | ||
| #include "silkit/vendor/CreateSilKitRegistry.hpp" | ||
| #include "silkit/SilKit.hpp" | ||
|
|
||
| namespace { | ||
|
|
||
| struct ITest_GetParameter : public testing::Test | ||
| { | ||
|
|
||
| void checkGetParameterValues(SilKit::IParticipant* participant, std::unordered_map<SilKit::Parameter, std::string> expectedParameters) | ||
| { | ||
| for (auto it : expectedParameters) | ||
| { | ||
| std::string parameterValue = participant->GetParameter(it.first); | ||
| std::string expectedValue = it.second; | ||
| EXPECT_EQ(expectedValue, parameterValue); | ||
| } | ||
| } | ||
|
|
||
| const std::string _registryUriAnyPort = "silkit://127.0.0.1:0"; | ||
| }; | ||
|
|
||
| // Check that GetParameter return the values set via api | ||
| TEST_F(ITest_GetParameter, get_parameter_set_by_api) | ||
| { | ||
| const std::string participantNameByApi = "P1"; | ||
|
|
||
| auto emptyParticipantConfig = SilKit::Config::ParticipantConfigurationFromString(""); | ||
|
|
||
| auto registry = SilKit::Vendor::Vector::CreateSilKitRegistry(emptyParticipantConfig); | ||
| auto registryUriByApi = registry->StartListening(_registryUriAnyPort); | ||
|
|
||
| auto participant = SilKit::CreateParticipant(emptyParticipantConfig, participantNameByApi, registryUriByApi); | ||
|
|
||
| checkGetParameterValues(participant.get(), {{SilKit::Parameter::ParticipantName, participantNameByApi}, | ||
| {SilKit::Parameter::RegistryUri, registryUriByApi}}); | ||
| } | ||
|
|
||
| // Config values take precedence over api values | ||
| // Check that GetParameter actually return the config values if both are set | ||
| TEST_F(ITest_GetParameter, get_parameter_set_by_config) | ||
| { | ||
| const std::string participantNameByApi = "P2"; | ||
| const std::string registryUriByApi = "silkit://127.0.0.42:0"; | ||
|
|
||
| const std::string participantNameByConfig = "P1"; | ||
|
|
||
| auto emptyParticipantConfig = SilKit::Config::ParticipantConfigurationFromString(""); | ||
|
|
||
| auto registry = SilKit::Vendor::Vector::CreateSilKitRegistry(emptyParticipantConfig); | ||
| auto registryUriByConfig = registry->StartListening(_registryUriAnyPort); | ||
|
|
||
| std::ostringstream ss; | ||
| ss << R"({ "ParticipantName": ")" << participantNameByConfig << R"(", "Middleware": { "RegistryUri": ")" | ||
| << registryUriByConfig << R"(" }})"; | ||
| auto participantConfig = SilKit::Config::ParticipantConfigurationFromString(ss.str()); | ||
|
|
||
| auto participant = SilKit::CreateParticipant(participantConfig, participantNameByApi, registryUriByApi); | ||
|
|
||
| checkGetParameterValues(participant.get(), {{SilKit::Parameter::ParticipantName, participantNameByConfig}, | ||
| {SilKit::Parameter::RegistryUri, registryUriByConfig}}); | ||
|
|
||
| } | ||
|
|
||
| } //end namespace |
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,29 @@ | ||
| // SPDX-FileCopyrightText: 2024 Vector Informatik GmbH | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
| #include <stdint.h> | ||
| #include "SilKitMacros.h" | ||
|
|
||
| #pragma pack(push) | ||
| #pragma pack(8) | ||
|
|
||
| SILKIT_BEGIN_DECLS | ||
|
|
||
| /*! Internal parameter provider. */ | ||
| typedef struct SilKit_ParamterProvider SilKit_ParamterProvider; | ||
|
|
||
| /*! A parameter set by an API call and/or the participant configuration. */ | ||
| typedef int16_t SilKit_Parameter; | ||
|
|
||
| /*! An undefined parameter */ | ||
| #define SilKit_Parameter_Undefined ((SilKit_Parameter)0) | ||
| /*! The name of the participant */ | ||
| #define SilKit_Parameter_ParticipantName ((SilKit_Parameter)1) | ||
| /*! The registry URI */ | ||
| #define SilKit_Parameter_ReistryUri ((SilKit_Parameter)2) | ||
|
|
||
| SILKIT_END_DECLS | ||
|
|
||
| #pragma pack(pop) |
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
72 changes: 72 additions & 0 deletions
72
SilKit/include/silkit/detail/impl/participant/ParameterProvider.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,72 @@ | ||
| // SPDX-FileCopyrightText: 2024 Vector Informatik GmbH | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
| #include "silkit/capi/Parameters.h" | ||
|
|
||
| namespace SilKit { | ||
| DETAIL_SILKIT_DETAIL_VN_NAMESPACE_BEGIN | ||
| namespace Impl { | ||
|
|
||
| class ParameterProvider | ||
| { | ||
| public: | ||
| inline ParameterProvider(); | ||
|
|
||
| inline ~ParameterProvider() = default; | ||
|
|
||
| inline auto GetParameter(SilKit_Participant* participant, Parameter parameter) -> std::string; | ||
|
|
||
| }; | ||
|
|
||
| } // namespace Impl | ||
| DETAIL_SILKIT_DETAIL_VN_NAMESPACE_CLOSE | ||
| } // namespace SilKit | ||
|
|
||
|
|
||
| // ================================================================================ | ||
| // Inline Implementations | ||
| // ================================================================================ | ||
|
|
||
| #include "silkit/detail/impl/ThrowOnError.hpp" | ||
|
|
||
| namespace SilKit { | ||
| DETAIL_SILKIT_DETAIL_VN_NAMESPACE_BEGIN | ||
| namespace Impl { | ||
|
|
||
| ParameterProvider::ParameterProvider() | ||
| { | ||
| } | ||
|
|
||
| auto ParameterProvider::GetParameter(SilKit_Participant* participant, Parameter parameter) -> std::string | ||
| { | ||
| std::vector<char> buffer; | ||
| size_t size = 0; | ||
| SilKit_Parameter cParameter = static_cast<SilKit_Parameter>(parameter); | ||
|
|
||
| // Query the size by passing nullptr for the outParameterValue | ||
| { | ||
| const auto returnCode = SilKit_Participant_GetParameter(nullptr, &size, cParameter, participant); | ||
| ThrowOnError(returnCode); | ||
| } | ||
|
|
||
| // Loop as the size might changed intermediately | ||
| while (size > buffer.size()) | ||
| { | ||
| buffer.resize(size); | ||
| const auto returnCode = SilKit_Participant_GetParameter(buffer.data(), &size, cParameter, participant); | ||
| ThrowOnError(returnCode); | ||
| } | ||
|
|
||
| // Value-initialized to nul | ||
| buffer.resize(size + 1); | ||
|
|
||
| return std::string{buffer.data()}; | ||
| } | ||
|
|
||
| } // namespace Impl | ||
| DETAIL_SILKIT_DETAIL_VN_NAMESPACE_CLOSE | ||
| } // namespace SilKit |
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,23 @@ | ||
| // SPDX-FileCopyrightText: 2024 Vector Informatik GmbH | ||
| // | ||
| // SPDX-License-Identifier: MIT | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "silkit/capi/Parameters.h" | ||
|
|
||
| namespace SilKit { | ||
|
|
||
| // note: never reuse old numbers! | ||
| //! \brief Available parameters to query | ||
| enum class Parameter : SilKit_Parameter | ||
| { | ||
| //! An undefined parameter | ||
| Undefined = SilKit_Parameter_Undefined, | ||
| //! The name of the participant | ||
| ParticipantName = SilKit_Parameter_ParticipantName, | ||
| //! The registry URI | ||
| RegistryUri = SilKit_Parameter_ReistryUri, | ||
| }; | ||
|
|
||
| } // namespace SilKit | ||
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
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.
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.
Typo