Suya add get and set and notification support to the fields in the configuration#313
Conversation
- Introduce dedicated LolaFieldInstanceDeployment class replacing the former LolaEventInstanceDeployment type alias, adding field-specific members use_get_if_available_ and use_set_if_available_. - Fix mw_com_config_schema.json: move useGetIfAvailable and useSetIfAvailable into the field "properties" object so they are correctly validated when additionalProperties is false. Issue: SWP-250429
- Update config_parser.cpp to read optional field values useGetIfAvailable/useSetIfAvailable - Fix existing unit test of loloa field instance deployment. Issue: SWP-250429
Update existing tests which refer LolaFieldInstanceDeployment to support additional optional useGetIfAvailable and useSetIfAvailable Issue: SWP-250429
- Add tests to verfiy behaviour of option field values useGetIfAvailable/useSetIfAvailable Issue: SWP-250429
- Update ReadMe and UML diagram to refelct updated changes optional field values useGetIfAvailable/useSetIfAvailable Issue: SWP-250429
1090c8b to
fc98eba
Compare
| { | ||
|
|
||
| using LolaFieldInstanceDeployment = LolaEventInstanceDeployment; | ||
| class LolaFieldInstanceDeployment |
There was a problem hiding this comment.
A field is a composition of an event and 0 to 2 methods. I would reflect this in the config object. i.e instead of dupcliating LolaEventInstanceDeployment here and adding field specific stuff, why not simply store a LolaEventInstanceDeployment as a member here. e.g.
LolaEventInstanceDeployment lola_event_instance_deployment_{};
bool use_get_if_available_{false};
// coverity[autosar_cpp14_m11_0_1_violation]
bool use_set_if_available_{false};
There was a problem hiding this comment.
I'd thought over this point and IMHO using composition approach will make coupling tight and LolaFieldInstanceDeployment will do more than 1 task (SRP breaks). Any changes in LolaEventInstanceDeployment e.g. member addition etc will appear in LolaFieldInstanceDeployment as well. Also Serialization part cant be shared cleanly due to use of different JSON key (eventName vs fieldName), plus acess pattern will not be clean e.g. field.max_subscribers_ ---> field.event_.max_subscribers_ .
There was a problem hiding this comment.
These classes are tightly coupled either way. The question is just whether we duplicate all the code in LolaEventInstanceDeployment in LolaFieldInstanceDeployment. If we extend LolaEventInstanceDeployment then we want it to be also extended in LolaFieldInstanceDeployment because a field composes an event, and so this should be reflected in the configuration object IMO.
LolaFieldInstanceDeployment will do more than 1 task (SRP breaks)
What additional task is it doing when composing a LolaEventInstanceDeployment vs duplicating all the code within LolaFieldInstanceDeployment?
Also Serialization part cant be shared cleanly due to use of different JSON key
IMO, this should not be the deciding factor about how we structure this code. Once we make a decision about the above point, we can discuss how the serialization code might look.
plus acess pattern will not be clean e.g. field.max_subscribers_ ---> field.event_.max_subscribers_ .
IMO, that actually makes sense. I think it's exactly what we want to have something like:
field.event.max_subscribers_;
field.method.queue_size_;
...
@crimson11 what do you think about this?
There was a problem hiding this comment.
I'm also all in for "aggregation" ;)
Why: Because a field in mw::com IS already/explicitly an aggregate of a event plus optional methods. So why should this be "different" only on config level. ... and as you implied: It is the rule, that if we extend the event-config, we also need to extend the field-event config. I.e. updating the event-config and NOT updating the event-config part of a field would be an absolute exception to the rule.
As a side-note ... with the property naming eventName, fieldName, methodName ... we messed up imho :p - if it would be simpy name everywhere ... the serialization code would be generic ... but I guess it is too late already to change because our config structure is a "public interface", which is hard to change.
| "useGetIfAvailable": { | ||
| "type": "boolean", | ||
| "title": "Use Field Getter If Available", | ||
| "description": "When true, the getter for this field will be used if the service type declares one.", |
There was a problem hiding this comment.
"...if the service type declares one in the C++ service interface"
There was a problem hiding this comment.
Corrected the description
| "useSetIfAvailable": { | ||
| "type": "boolean", | ||
| "title": "Use Field Setter If Available", | ||
| "description": "When true, the setter for this field will be used if the service type declares one.", |
There was a problem hiding this comment.
"...if the service type declares one in the C++ service interface"
There was a problem hiding this comment.
Corrected the description
| // coverity[autosar_cpp14_m11_0_1_violation] | ||
| bool enforce_max_samples_; | ||
| // coverity[autosar_cpp14_m11_0_1_violation] | ||
| bool use_get_if_available_{false}; |
There was a problem hiding this comment.
No need for this here. the value is initialized in the constructor.
| // coverity[autosar_cpp14_m11_0_1_violation] | ||
| bool use_get_if_available_{false}; | ||
| // coverity[autosar_cpp14_m11_0_1_violation] | ||
| bool use_set_if_available_{false}; |
There was a problem hiding this comment.
No need for this here. the value is initialized in the constructor.
| @@ -2103,6 +2103,262 @@ TEST(ConfigParser, LolaFieldOptionalEnforceMaxSamples) | |||
| EXPECT_EQ(deploymentInfo.fields_.at("CurrentTemperatureFrontLeft").enforce_max_samples_, false); | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
Please also modify ParseExampleJson test
There was a problem hiding this comment.
I've added assertions to ParseExampleJson for the defaults as example json omits the flags. Note: dedicated tests for those flags (LolaFieldUseGetIfAvailableSetToTrue, LolaFieldUseSetIfAvailableSetToTrue, LolaFieldOmittingBothFlagsDefaultsBothToFalse) and hence only assertion test in ParseExampleJson with existing json file.
There was a problem hiding this comment.
See my other comment ... I feel, that updating/extending the example/mw_com_config.json with some of the new properties makes sense. Why - because many people (including me) are sometimes too lazy to look up properties in the schema and check the example/mw_com_config.json instead ... it is more human-readable ;)
| ] | ||
| } | ||
| )"_json; | ||
| const auto config = score::mw::com::impl::configuration::Parse(std::move(j2)); |
There was a problem hiding this comment.
PLease also add when, then sections https://cc-github.bmwgroup.net/swh/safe-posix-platform/blob/master/platform/aas/mw/com/test/testing_guidelines.md#given-when-expecting--then
There was a problem hiding this comment.
Done. Added appropriate comments
| const LolaFieldInstanceDeployment reconstructed_unit{serialized_unit}; | ||
|
|
||
| // Then use_get_if_available is preserved and use_set_if_available is unaffected | ||
| EXPECT_TRUE(reconstructed_unit.use_get_if_available_); |
There was a problem hiding this comment.
Better to extract values passed into unit constructor into variables and check the reconstructed value is the same. e.g. EXPECT_EQ(reconstructed_unit.use_get_if_available_, is_get_enabled)
There was a problem hiding this comment.
Updated the tests with use of local vars to validate against serialized <-> de-serialized values.
|
|
||
| TEST_F(LolaFieldInstanceDeploymentFixture, UseGetAndUseSetFlagsAreIndependentOfEachOther) | ||
| { | ||
| // Given four deployments covering all flag combinations |
There was a problem hiding this comment.
this duplicates tests above? IMO, we just need these tests:
- UseGetIfAvailableIsTrueAfterRoundTripSerialisation
- UseSetIfAvailableIsTrueAfterRoundTripSerialisation
BothFlagsDefaultToFalseAfterRoundTripSerialisation is checked in CanCreateFromSerializedObjectWithoutOptionals
| + enforce_max_samples_ : score::cpp::optional<bool> | ||
| + is_set_configured: bool | ||
| + is_get_configured: bool | ||
| {static} + constexpr serializationVersion : std::uint32_t |
There was a problem hiding this comment.
The class diagrams are not meant to reflect the c++ code exactly. We only add as much detyail as is helpful. You can leave it as it was before IMO
There was a problem hiding this comment.
Yes LolaFieldInstanceDeployment appears to be too verbose. I've reduced boiler plate info and make it aligned to LolamethodInstanceDeployment.
Fix review comments and remove redundant testcases Issue: SWP-250429
| "useGetIfAvailable": { | ||
| "type": "boolean", | ||
| "title": "Use Field Getter If Available", | ||
| "description": "When true, the getter for this field will be used if the service type declares one in the C++ service interface.", |
There was a problem hiding this comment.
please annotate, that this property is only "relevant" for the proxy side/consumer side.
And should we re-think whether default is "false"? Maybe default should be "true" and you should explicitly disable the use?
And please also extend the example/mw_com_confg.json with the new properties.
| "description": "When true, the getter for this field will be used if the service type declares one in the C++ service interface.", | ||
| "default": false | ||
| }, | ||
| "useSetIfAvailable": { |
| { | ||
|
|
||
| using LolaFieldInstanceDeployment = LolaEventInstanceDeployment; | ||
| class LolaFieldInstanceDeployment |
There was a problem hiding this comment.
I'm also all in for "aggregation" ;)
Why: Because a field in mw::com IS already/explicitly an aggregate of a event plus optional methods. So why should this be "different" only on config level. ... and as you implied: It is the rule, that if we extend the event-config, we also need to extend the field-event config. I.e. updating the event-config and NOT updating the event-config part of a field would be an absolute exception to the rule.
As a side-note ... with the property naming eventName, fieldName, methodName ... we messed up imho :p - if it would be simpy name everywhere ... the serialization code would be generic ... but I guess it is too late already to change because our config structure is a "public interface", which is hard to change.
| @@ -2103,6 +2103,262 @@ TEST(ConfigParser, LolaFieldOptionalEnforceMaxSamples) | |||
| EXPECT_EQ(deploymentInfo.fields_.at("CurrentTemperatureFrontLeft").enforce_max_samples_, false); | |||
| } | |||
|
|
|||
There was a problem hiding this comment.
See my other comment ... I feel, that updating/extending the example/mw_com_config.json with some of the new properties makes sense. Why - because many people (including me) are sometimes too lazy to look up properties in the schema and check the example/mw_com_config.json instead ... it is more human-readable ;)
Add useGetIfAvailable/useSetIfAvailable to LoLa field deployment
former LolaEventInstanceDeployment type alias, adding field-specific
members use_get_if_available_ and use_set_if_available_.
useSetIfAvailable into the field "properties" object so they are
correctly validated when additionalProperties is false.
Issue: SWP-250429