dbus-sdr: prevent handler registration if dbus-sdr is enabled

Compile out the handler registration if it is using dynamic stack.
Reorder the handlers to have common handlers between the two
implementations alway registered.

Managing the handlers like this all code to be compiled during CI while
providing some control over the handlers used.

Change-Id: I6e9cffacfac4127d2307e8c5e548c84323742c94
Signed-off-by: Willy Tu <wltu@google.com>
diff --git a/configure.ac b/configure.ac
index 8ec8c40..0fbf537 100644
--- a/configure.ac
+++ b/configure.ac
@@ -277,6 +277,13 @@
       )
 AM_CONDITIONAL([FEATURE_DYNAMIC_SENSORS], [test x$dynamic_sensors = xtrue])
 
+AS_IF([test x$dynamic_sensors = xtrue],
+    AC_MSG_NOTICE([Enabling dynamic sensors feature])
+    [cpp_flags="$cpp_flags -DFEATURE_DYNAMIC_SENSORS"]
+    AC_SUBST([CPPFLAGS], [$cpp_flags]),
+    AC_MSG_WARN([Disabling dynamic sensors feature])
+)
+
 # hybrid sensors stack is disabled by default; offer a way to enable it
 AC_ARG_ENABLE([hybrid-sensors],
     [ --enable-hybrid-sensors   Enable/disable Hybrid Sensors stack],
diff --git a/dbus-sdr/storagecommands.cpp b/dbus-sdr/storagecommands.cpp
index cd7825f..da60042 100644
--- a/dbus-sdr/storagecommands.cpp
+++ b/dbus-sdr/storagecommands.cpp
@@ -1239,7 +1239,7 @@
     startMatch();
 
     // <Get FRU Inventory Area Info>
-    ipmi::registerHandler(ipmi::prioOemBase, ipmi::netFnStorage,
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
                           ipmi::storage::cmdGetFruInventoryAreaInfo,
                           ipmi::Privilege::User, ipmiStorageGetFruInvAreaInfo);
     // <READ FRU Data>
diff --git a/sensorhandler.cpp b/sensorhandler.cpp
index 7c5aa06..e2b2874 100644
--- a/sensorhandler.cpp
+++ b/sensorhandler.cpp
@@ -1104,15 +1104,10 @@
 
 void register_netfn_sen_functions()
 {
-    // <Platform Event Message>
-    ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_PLATFORM_EVENT, nullptr,
-                           ipmicmdPlatformEvent, PRIVILEGE_OPERATOR);
+    // Handlers with dbus-sdr handler implementation.
+    // Do not register the hander if it dynamic sensors stack is used.
 
-    // <Get Sensor Type>
-    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
-                          ipmi::sensor_event::cmdGetSensorType,
-                          ipmi::Privilege::User, ipmiGetSensorType);
-
+#ifndef FEATURE_DYNAMIC_SENSORS
     // <Set Sensor Reading and Event Status>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
                           ipmi::sensor_event::cmdSetSensorReadingAndEvtSts,
@@ -1132,14 +1127,26 @@
                           ipmi::sensor_event::cmdGetDeviceSdrInfo,
                           ipmi::Privilege::User, ipmiSensorGetDeviceSdrInfo);
 
-    // <Get Device SDR>
-    ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, nullptr,
-                           ipmi_sen_get_sdr, PRIVILEGE_USER);
-
     // <Get Sensor Thresholds>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
                           ipmi::sensor_event::cmdGetSensorThreshold,
                           ipmi::Privilege::User, ipmiSensorGetSensorThresholds);
 
+#endif
+
+    // Common Handers used by both implementation.
+
+    // <Platform Event Message>
+    ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_PLATFORM_EVENT, nullptr,
+                           ipmicmdPlatformEvent, PRIVILEGE_OPERATOR);
+
+    // <Get Sensor Type>
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnSensor,
+                          ipmi::sensor_event::cmdGetSensorType,
+                          ipmi::Privilege::User, ipmiGetSensorType);
+
+    // <Get Device SDR>
+    ipmi_register_callback(NETFUN_SENSOR, IPMI_CMD_GET_DEVICE_SDR, nullptr,
+                           ipmi_sen_get_sdr, PRIVILEGE_USER);
     return;
 }
diff --git a/storagehandler.cpp b/storagehandler.cpp
index 9608dcc..0bc842c 100644
--- a/storagehandler.cpp
+++ b/storagehandler.cpp
@@ -849,6 +849,10 @@
 {
     selCacheMapInitialized = false;
     initSELCache();
+    // Handlers with dbus-sdr handler implementation.
+    // Do not register the hander if it dynamic sensors stack is used.
+
+#ifndef FEATURE_DYNAMIC_SENSORS
     // <Get SEL Info>
     ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
                           ipmi::storage::cmdGetSelInfo, ipmi::Privilege::User,
@@ -864,10 +868,6 @@
                           ipmi::storage::cmdSetSelTime,
                           ipmi::Privilege::Operator, ipmiStorageSetSelTime);
 
-    // <Reserve SEL>
-    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
-                          ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
-                          ipmiStorageReserveSel);
     // <Get SEL Entry>
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SEL_ENTRY, NULL,
                            getSELEntry, PRIVILEGE_USER);
@@ -911,6 +911,15 @@
     ipmi_register_callback(NETFUN_STORAGE, IPMI_CMD_GET_SDR, nullptr,
                            ipmi_sen_get_sdr, PRIVILEGE_USER);
 
+#endif
+
+    // Common Handers used by both implementation.
+
+    // <Reserve SEL>
+    ipmi::registerHandler(ipmi::prioOpenBmcBase, ipmi::netFnStorage,
+                          ipmi::storage::cmdReserveSel, ipmi::Privilege::User,
+                          ipmiStorageReserveSel);
+
     ipmi::fru::registerCallbackHandler();
     return;
 }