Generate parameterUpdated calls in parametersLoaded - #1097
Conversation
The generated parametersLoaded base implementation was empty, so a component that centralizes update handling in parameterUpdated did not get called for each parameter at load time and had to iterate manually. It now calls parameterUpdated once per parameter, giving full coverage on load with no manual iteration. This is a behavior change: parameterUpdated now fires for every parameter when parameters are loaded. Because parametersLoaded stays a virtual hook, a component can override it to restore the previous no-op behavior, for example to avoid double-handling when updates are managed elsewhere. Updated the affected component and tester base reference outputs. Signed-off-by: Seçkin Sefa Durası <i@seckin.ws>
Wrap each generated parameterUpdated call in a VALID check so notification only fires for successfully loaded parameters, per review. Also drop the dead emptyparams branch, since the hook is only generated when the component has parameters. Regenerated component reference outputs.
|
I pushed in 1802ae8. Each parameterUpdated call is now wrapped in a VALID check, reusing the existing checkValidityFlag helper, so notification only fires for parameters that loaded successfully: if (this->m_param_ParamU32_valid == Fw::ParamValid::VALID) { I also removed the dead emptyparams branch you flagged, since the hook is only generated when the component has parameters. Reference outputs regenerated; component tests pass. On the parameterLoaded hook idea: I think that's a good addition separating "loaded" from "updated" avoids the information loss you mentioned. I'd suggest keeping this PR to the validity guarded behavior and opening a separate issue for the new hook, so this one stays focused. Happy to take that on as a followup if you agree. |
|
Thanks!
I discussed this with @LeStarch. We would like to add the |
|
Also, let's call the |
Add a parameterLoaded(id, valid) hook that by default calls parameterUpdated when FW_PARAM_OK holds (valid or default). Call it from the load path as each parameter is loaded, and keep parametersLoaded as a do-nothing notifier by default. Include Fw/Prm/ParamValid.hpp for FW_PARAM_OK. Regenerated reference outputs.
|
I pushed in ed7513c Replaced the manual VALID check with FW_PARAM_OK(valid), so both VALID and DEFAULT are accepted. Added the Fw/Prm/ParamValid.hpp include to the generated .cpp so the macro is defined. Reference outputs regenerated; fpp-to-cpp tests and unit tests pass. |
| val prmValidHeader = if hasParameters then List("Fw/Prm/ParamValid.hpp") else Nil | ||
| val userHeaders = (List( | ||
| "Fw/Types/Assert.hpp", | ||
| "Fw/Types/ExternalString.hpp", | ||
| "Fw/Types/String.hpp", | ||
| s.getIncludePath(componentSymbol, fileName) | ||
| ).sorted.map(CppWriter.headerString).flatMap({ | ||
| ) ++ prmValidHeader).sorted.map(CppWriter.headerString).flatMap({ |
There was a problem hiding this comment.
| val prmValidHeader = if hasParameters then List("Fw/Prm/ParamValid.hpp") else Nil | |
| val userHeaders = (List( | |
| "Fw/Types/Assert.hpp", | |
| "Fw/Types/ExternalString.hpp", | |
| "Fw/Types/String.hpp", | |
| s.getIncludePath(componentSymbol, fileName) | |
| ).sorted.map(CppWriter.headerString).flatMap({ | |
| ) ++ prmValidHeader).sorted.map(CppWriter.headerString).flatMap({ | |
| val userHeaders = List.concat( | |
| guardedList (hasParameters) (List("Fw/Prm/ParamValid.hpp")), | |
| List( | |
| "Fw/Types/Assert.hpp", | |
| "Fw/Types/ExternalString.hpp", | |
| "Fw/Types/String.hpp", | |
| s.getIncludePath(componentSymbol, fileName) | |
| ) | |
| ).sorted.map(CppWriter.headerString).flatMap({ |
| getParamUpdateHookFunction, | ||
| getParamLoadHookFunction | ||
| getParamLoadHookFunction, | ||
| getParamLoadedHookFunction |
There was a problem hiding this comment.
For consistency, let's rename getParamLoadedHookFunction to getParamsLoadHookFunction.
|
@durasi This is looking good. I made a couple more coding suggestions. Can you confirm that the unit tests pass in F Prime when you use this build of FPP? You can use the procedure here: https://github.com/nasa/fpp/wiki/Adding-New-Features-to-FPP#integration-with-f-prime. If this change causes anything to break in F Prime, then we will need to make a tandem PR to F Prime. |
Implements #1098.
Per @Willmac16's guidance on the issue, the calls go in the parametersLoaded hook rather than the loadParameters body.
The generated parametersLoaded base implementation was empty, so a component that centralizes update handling in parameterUpdated did not get called for each parameter at load time and had to iterate manually. It now calls parameterUpdated once per parameter, giving full coverage on load with no manual iteration.
This is a behavior change: parameterUpdated now fires for every parameter when parameters are loaded. Because parametersLoaded stays a virtual hook, a component can override it to restore the previous no-op behavior, for example to avoid double-handling when updates are managed elsewhere.
Updated the affected component and tester base reference outputs.
Testing: Scala unit tests pass (633). Component command-line tests pass, reference outputs regenerated.