Move to common variant

This saves approximately 34kB in the compressed binary size of bmcweb
due to reduced template instantiations.  This amounts to a 2.5%
reduction in the overall size.

Note, there were a few places where we broke const-correctness in the
form of pulling a non-const reference out of a const variant.  This
new variant now requires const correctness, so some consts are
added where required.

Tested: Code compiles.

Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I6a60c8881c1268627eedb4ffddf16689dc5f6ed2
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 6d99313..df7e205 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -20,11 +20,10 @@
 
 #include <app.hpp>
 #include <boost/container/flat_map.hpp>
+#include <dbus_utility.hpp>
 #include <registries/privilege_registry.hpp>
 #include <utils/collection.hpp>
 
-#include <variant>
-
 namespace redfish
 {
 
@@ -40,7 +39,7 @@
     crow::connections::systemBus->async_method_call(
         [aResp{std::move(aResp)}](
             const boost::system::error_code ec,
-            const std::variant<std::string>& chassisState) {
+            const dbus::utility::DbusVariantType& chassisState) {
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error " << ec;
@@ -76,16 +75,14 @@
  * DBus types primitives for several generic DBus interfaces
  * TODO(Pawel) consider move this to separate file into boost::dbus
  */
-// Note, this is not a very useful Variant, but because it isn't used to get
-// values, it should be as simple as possible
-// TODO(ed) invent a nullvariant type
-using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>;
 using ManagedObjectsType = std::vector<std::pair<
     sdbusplus::message::object_path,
-    std::vector<std::pair<std::string,
-                          std::vector<std::pair<std::string, VariantType>>>>>>;
+    std::vector<std::pair<
+        std::string,
+        std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>>>>>;
 
-using PropertiesType = boost::container::flat_map<std::string, VariantType>;
+using PropertiesType =
+    boost::container::flat_map<std::string, dbus::utility::DbusVariantType>;
 
 inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp,
                                   const std::string& service,
@@ -95,7 +92,7 @@
 
     crow::connections::systemBus->async_method_call(
         [aResp{std::move(aResp)}](const boost::system::error_code ec,
-                                  const std::variant<std::string>& value) {
+                                  const dbus::utility::DbusVariantType& value) {
             if (ec)
             {
                 // do not add err msg in redfish response, because this is not
@@ -186,7 +183,7 @@
 {
     crow::connections::systemBus->async_method_call(
         [asyncResp](const boost::system::error_code ec,
-                    const std::variant<std::string>& property) {
+                    const dbus::utility::DbusVariantType& property) {
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error for Location";
@@ -214,7 +211,7 @@
 {
     crow::connections::systemBus->async_method_call(
         [asyncResp](const boost::system::error_code ec,
-                    const std::variant<std::string>& chassisUUID) {
+                    const dbus::utility::DbusVariantType& chassisUUID) {
             if (ec)
             {
                 BMCWEB_LOG_DEBUG << "DBUS response error for UUID";
@@ -282,9 +279,8 @@
                             std::make_shared<HealthPopulate>(asyncResp);
 
                         crow::connections::systemBus->async_method_call(
-                            [health](
-                                const boost::system::error_code ec2,
-                                std::variant<std::vector<std::string>>& resp) {
+                            [health](const boost::system::error_code ec2,
+                                     dbus::utility::DbusVariantType& resp) {
                                 if (ec2)
                                 {
                                     return; // no sensors = no failures
@@ -344,7 +340,8 @@
                             crow::connections::systemBus->async_method_call(
                                 [asyncResp, chassisId(std::string(chassisId))](
                                     const boost::system::error_code ec,
-                                    const std::variant<std::string>& property) {
+                                    const dbus::utility::DbusVariantType&
+                                        property) {
                                     if (ec)
                                     {
                                         BMCWEB_LOG_DEBUG
@@ -386,9 +383,12 @@
                             [asyncResp, chassisId(std::string(chassisId))](
                                 const boost::system::error_code /*ec2*/,
                                 const std::vector<
-                                    std::pair<std::string, VariantType>>&
+                                    std::pair<std::string,
+                                              dbus::utility::DbusVariantType>>&
                                     propertiesList) {
-                                for (const std::pair<std::string, VariantType>&
+                                for (const std::pair<
+                                         std::string,
+                                         dbus::utility::DbusVariantType>&
                                          property : propertiesList)
                                 {
                                     // Store DBus properties that are also
@@ -673,7 +673,7 @@
                 },
                 processName, objectPath, "org.freedesktop.DBus.Properties",
                 "Set", interfaceName, destProperty,
-                std::variant<std::string>{propertyValue});
+                dbus::utility::DbusVariantType{propertyValue});
         },
         busName, path, interface, method, "/", 0, interfaces);
 }