-
Notifications
You must be signed in to change notification settings - Fork 88
feat(mw::com): Implement Field Notifier support for Generic Skeleton #455
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
Open
ShoroukRamzy
wants to merge
14
commits into
eclipse-score:main
Choose a base branch
from
Valeo-S-CORE-Organization:generic_skeleton_field_notifier
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.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9ae1989
feat: implement generic skeleton field with notifier support
ShoroukRamzy 22e64ed
fix compilation issue
ShoroukRamzy 66a76a8
add comments and fix IsSetHandlerRegistered check
ShoroukRamzy 4aa9fc4
fix field double registeration issue and add unit test
ShoroukRamzy 0d4f2a5
Adapt the code to use the new ReferenceToMovable class
ShoroukRamzy 10fe011
remove RegisterGetHandler and update the update function logic
ShoroukRamzy 8a14b70
update RegisterSetHandler API signature
ShoroukRamzy cd7a56c
update generic_skeleton design doc
ShoroukRamzy b5bda9a
fix unit test in generic_skeleton_field
ShoroukRamzy 2ec16dd
suppress unused private field warnings in GenericSkeletonField
ShoroukRamzy b632800
trigger ci
ShoroukRamzy 827a979
simplify genericSkeleton creation API
ShoroukRamzy a78115c
add RegisterGetHandler API
ShoroukRamzy a65337c
testing: extend generic skeleton with field unit tests
ShoroukRamzy 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,27 @@ std::string_view GetEventName(const InstanceIdentifier& identifier, std::string_ | |
|
|
||
| return std::visit(visitor, service_type_deployment.binding_info_); | ||
| } | ||
|
|
||
| // Helper to fetch the stable field name from the Configuration | ||
| std::string_view GetFieldName(const InstanceIdentifier& identifier, std::string_view search_name) | ||
| { | ||
| const auto& service_type_deployment = InstanceIdentifierView{identifier}.GetServiceTypeDeployment(); | ||
|
|
||
| auto visitor = score::cpp::overload( | ||
| [&](const LolaServiceTypeDeployment& deployment) -> std::string_view { | ||
| const auto it = deployment.fields_.find(std::string{search_name}); | ||
| if (it != deployment.fields_.end()) | ||
| { | ||
| return it->first; // Return the stable address of the Key from the Config Map | ||
| } | ||
| return {}; | ||
| }, | ||
| [](const score::cpp::blank&) noexcept -> std::string_view { | ||
| return {}; | ||
| }); | ||
|
|
||
| return std::visit(visitor, service_type_deployment.binding_info_); | ||
| } | ||
| } // namespace | ||
|
|
||
| Result<GenericSkeleton> GenericSkeleton::Create(const InstanceSpecifier& specifier, | ||
|
|
@@ -134,6 +155,61 @@ Result<GenericSkeleton> GenericSkeleton::Create(const InstanceIdentifier& identi | |
| } | ||
| } | ||
|
|
||
| // 3. Create fields directly in the map | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess you need to extend |
||
| for (const auto& info : in.fields) | ||
| { | ||
| // Check for duplicates | ||
| if (skeleton.fields_->find(info.name) != skeleton.fields_->cend()) | ||
| { | ||
| score::mw::log::LogError("GenericSkeleton") << "Duplicate field name provided: " << info.name; | ||
| return MakeUnexpected(ComErrc::kServiceElementAlreadyExists); | ||
| } | ||
|
|
||
| std::string_view stable_name = GetFieldName(identifier, info.name); | ||
|
|
||
| if (stable_name.empty()) | ||
| { | ||
| score::mw::log::LogError("GenericSkeleton") << "Field name not found in configuration: " << info.name; | ||
| return MakeUnexpected(ComErrc::kBindingFailure); | ||
| } | ||
|
|
||
| // Validate & convert the public DataTypeMetaInfo into the internal DataTypeSizeInfo. | ||
| auto data_type_size_info_result = MakeDataTypeSizeInfo(info.data_type_meta_info); | ||
| if (!data_type_size_info_result.has_value()) | ||
| { | ||
| score::mw::log::LogError("GenericSkeleton") | ||
| << "Invalid data type meta-info provided for field: " << info.name; | ||
| return MakeUnexpected(ComErrc::kInvalidConfiguration); | ||
| } | ||
|
|
||
| auto event_binding_result = | ||
| GenericSkeletonEventBindingFactory::Create(skeleton, info.name, data_type_size_info_result.value()); | ||
|
|
||
| if (!event_binding_result.has_value()) | ||
| { | ||
| return MakeUnexpected(ComErrc::kBindingFailure); | ||
| } | ||
|
|
||
| // Use the hidden constructor tag so the event doesn't register itself in the events_ map | ||
| auto generic_event = | ||
| std::make_unique<GenericSkeletonEvent>(skeleton, | ||
| stable_name, | ||
| std::move(event_binding_result).value(), | ||
| GenericSkeletonEvent::FieldOnlyConstructorEnabler{}); | ||
|
|
||
| const auto emplace_result = skeleton.fields_->emplace( | ||
| std::piecewise_construct, | ||
| std::forward_as_tuple(stable_name), | ||
| std::forward_as_tuple( | ||
| skeleton, stable_name, std::move(generic_event), info.has_getter, info.has_setter, info.has_notifier)); | ||
|
|
||
| if (!emplace_result.second) | ||
| { | ||
| score::mw::log::LogError("GenericSkeleton") << "Failed to emplace field in map: " << info.name; | ||
| return MakeUnexpected(ComErrc::kBindingFailure); | ||
| } | ||
| } | ||
|
|
||
| return skeleton; | ||
| } | ||
|
|
||
|
|
@@ -142,6 +218,11 @@ ServiceElementMapView<GenericSkeletonEvent> GenericSkeleton::GetEvents() const n | |
| return ServiceElementMapViewFactory<GenericSkeletonEvent>::Create(*events_); | ||
| } | ||
|
|
||
| GenericSkeleton::FieldMapView GenericSkeleton::GetFields() const noexcept | ||
| { | ||
| return ServiceElementMapViewFactory<GenericSkeletonField>::Create(*fields_); | ||
| } | ||
|
|
||
| Result<void> GenericSkeleton::OfferService() noexcept | ||
| { | ||
| return SkeletonBase::OfferService(); | ||
|
|
@@ -154,7 +235,8 @@ void GenericSkeleton::StopOfferService() noexcept | |
|
|
||
| GenericSkeleton::GenericSkeleton(const InstanceIdentifier& identifier, std::unique_ptr<SkeletonBinding> binding) | ||
| : SkeletonBase(std::move(binding), identifier), | ||
| events_(std::make_unique<std::map<std::string_view, GenericSkeletonEvent>>()) | ||
| events_(std::make_unique<std::map<std::string_view, GenericSkeletonEvent>>()), | ||
| fields_(std::make_unique<std::map<std::string_view, GenericSkeletonField>>()) | ||
| { | ||
| } | ||
|
|
||
|
|
||
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
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.
I guess you need to extend
generic_skeleton_test.cppfor testing this?