sensor-cache: configure: Add option

Add --enable-sensors-cache option to enable the feature of sensor cache.
The option is disabled by default.

Signed-off-by: Lei YU <yulei.sh@bytedance.com>
Change-Id: I97bcd366c83a0bd6df42ed7024d6ef03baaf8e7e
diff --git a/configure.ac b/configure.ac
index 0fbf537..2c05fdd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -302,6 +302,24 @@
     AC_MSG_WARN([Disabling hybrid sensors feature])
 )
 
+# Sensor cache stack is disabled by default; offer a way to enable it
+AC_ARG_ENABLE([sensors-cache],
+    [ --enable-sensors-cache   Enable/disable sensors cache stack],
+    [case "${enableval}" in
+      yes) sensors_cache=true ;;
+      no) sensors_cache=false ;;
+      *) AC_MSG_ERROR([bad value ${enableval} for --enable-sensors-cache]) ;;
+      esac],[sensors_cache=false]
+      )
+AM_CONDITIONAL([FEATURE_SENSORS_CACHE], [test x$sensors_cache= xtrue])
+
+AS_IF([test x$sensors_cache = xtrue],
+    AC_MSG_NOTICE([Enabling sensors cache stack])
+    [cpp_flags="$cpp_flags -DFEATURE_SENSORS_CACHE"]
+    AC_SUBST([CPPFLAGS], [$cpp_flags]),
+    AC_MSG_WARN([Disabling sensors cache feature])
+)
+
 # Create configured output
 AC_CONFIG_FILES([
     Makefile
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index e842355..dc632d0 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -86,6 +86,7 @@
     std::unordered_map<uint8_t, get_sdr::GetSensorThresholdsResponse>;
 SensorThresholdMap sensorThresholdMap __attribute__((init_priority(101)));
 
+#ifdef FEATURE_SENSORS_CACHE
 std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match::match>>
     sensorAddedMatches __attribute__((init_priority(101)));
 std::map<uint8_t, std::unique_ptr<sdbusplus::bus::match::match>>
@@ -116,6 +117,7 @@
                 }));
     }
 }
+#endif
 
 int get_bus_for_path(const char* path, char** busname)
 {
@@ -1321,8 +1323,10 @@
 
 #ifndef FEATURE_DYNAMIC_SENSORS
 
+#ifdef FEATURE_SENSORS_CACHE
     // Initialize the sensor matches
     initSensorMatches();
+#endif
 
     // <Set Sensor Reading and Event Status>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,