diff --git a/models/vehicle_management/events_manager/include/watch_values_base.hh b/models/vehicle_management/events_manager/include/watch_values_base.hh index 7df24027..5f12c7f1 100644 --- a/models/vehicle_management/events_manager/include/watch_values_base.hh +++ b/models/vehicle_management/events_manager/include/watch_values_base.hh @@ -57,10 +57,29 @@ class WatchValuesBase : public WatchValuesBaseCore { /***************************************************************************** set_watch Purpose:(Sets the variable and the reference against which it will be compared) +Notes: +- If the variable passed in is not of type watchType, the compiler would + implicitly cast that variable to a temporary storage space of the expected + type, and the watch value would monitor that temporary storage space, not + the intended variable, for changes. This is a big problem if a user gets the + type wrong in setting up their WatchValue, or setse it up correctly and the + variable type later changes. +- To rule that out and explicitly require a type match, we delete set_watch + for all types of "var", then implement only the one in which "var" is of + type "watchType". Now if the types do not match, the project will not build. +- When setting the reference by pointer: set_watch( T1&, T2*) + T2 must be of type watchType already; everything else is blocked. + So we only need to check on the type of var. *****************************************************************************/ + template + void set_watch (const T& var, watchType ref) = delete; + template + void set_watch (const T1& var, const watchType * ref) = delete; + + // ************************************************************************ // ** reference is fixed-value ** // ************************************************************************ - void set_watch( const watchType & var, watchType ref) { + void set_watch( const watchType & var, watchType ref) { variable = &var; reference = ref; reference_is_variable = false; @@ -391,4 +410,12 @@ Purpose:(Generates the new reference value.) reference += variable_at_activation; } }; + +template <> inline void WatchValuesBase::set_dbl_reference(double ref) +{ + // Semantically equivalent to static_cast(ref) (i.e., ref != 0.0), + // but avoids '=='/'!=' comparisons that trigger -Wfloat-equal. + reference = (ref > 0.0) || (ref < 0.0) || std::isnan(ref); +} + #endif \ No newline at end of file diff --git a/models/vehicle_management/events_manager/include/watch_values_base_core.hh b/models/vehicle_management/events_manager/include/watch_values_base_core.hh index d8885b8b..430f4614 100644 --- a/models/vehicle_management/events_manager/include/watch_values_base_core.hh +++ b/models/vehicle_management/events_manager/include/watch_values_base_core.hh @@ -64,14 +64,18 @@ class WatchValuesBaseCore : public SubscriptionBase { std::string name; /* (--) Name, primarily for debugging purposes. May be left blank.*/ bool locked{false}; /* (--) - Boolean used to lock at each cycle, so each WatchValuesBase cannot be - tested more than once per cycle, leading to unintended behavior.*/ + Boolean used to lock at each cycle, so each WatchValuesBase cannot be + tested more than once per cycle. Elaborate extension of WatchValuesBaseCore + -- such as EventTrigger -- caan create false negatives if evaluated + multiple times with the same value of the watch-variable. */ bool externally_managed{false}; /* (--) Boolean setting that bool "locked" is set to once trigger is evaluated true: lock after evaluation - (commonly set in CompoundEventsManager::create_trigger()) + (commonly set when an WatchValue is added to the CompoundEventsManager's + managed_triggers listi, such as when using create)trigger(...)) false: do not lock after evaluation, can be evaluated multiple times per - logging cycle (default, but overriden by create_trigger()) */ + logging cycle (default, but overriden by + CompoundEventssManager::add_trigger(...)) */ protected: diff --git a/models/vehicle_management/events_manager/src/watch_values_set.cc b/models/vehicle_management/events_manager/src/watch_values_set.cc index 24f1818b..c35c3716 100644 --- a/models/vehicle_management/events_manager/src/watch_values_set.cc +++ b/models/vehicle_management/events_manager/src/watch_values_set.cc @@ -47,6 +47,13 @@ WatchValuesSet::initialize( std::list * active_watch_in) return; } for (WatchValuesBaseCore * trigger : triggers) { + // if (require_all) { + // // force multi_shot for all triggers when the set requires all triggers + // // to be fulfilled for the set to be fulfilled. This fixes a discrepancy + // // with DataCollect's behavior without requiring the logging user to be + // // careful with the multi_shot optimization. + // trigger->multi_shot = true; + // } trigger->add_self_to_manager_active_list = false; trigger->SubscriptionBase::initialize(); }