Condense std::variants

Where possible, reduce to a single std::variant type to reduce binary
size.

Change-Id: I73b59765109ce1ccd7339f0e214d1ec3929e1ffc
Signed-off-by: Jason M. Bills <jason.m.bills@intel.com>
diff --git a/include/biosxml.hpp b/include/biosxml.hpp
index 6b170bd..ad092df 100644
--- a/include/biosxml.hpp
+++ b/include/biosxml.hpp
@@ -4,6 +4,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
+#include <types.hpp>
 
 #include <map>
 #include <sstream>
@@ -18,7 +19,7 @@
  * For example
  *  <option text="TIS" value="0x0"/>
  */
-using OptionType = std::tuple<std::string, std::variant<int64_t, std::string>>;
+using OptionType = std::tuple<std::string, ipmi::DbusVariant>;
 
 /* Can hold one 'options'
  * For example
@@ -45,8 +46,7 @@
  */
 using BiosBaseTableTypeEntry =
     std::tuple<std::string, bool, std::string, std::string, std::string,
-               std::variant<int64_t, std::string>,
-               std::variant<int64_t, std::string>, OptionTypeVector>;
+               ipmi::DbusVariant, ipmi::DbusVariant, OptionTypeVector>;
 
 /* Can hold one 'biosknobs'
  * biosknobs has array of 'knob' */
diff --git a/include/manufacturingcommands.hpp b/include/manufacturingcommands.hpp
index 82039f5..e0ff303 100644
--- a/include/manufacturingcommands.hpp
+++ b/include/manufacturingcommands.hpp
@@ -22,7 +22,6 @@
 #include <sdbusplus/bus.hpp>
 #include <sdbusplus/message.hpp>
 #include <sdbusplus/timer.hpp>
-#include <variantvisitors.hpp>
 
 #include <vector>
 
diff --git a/include/smbiosmdrv2handler.hpp b/include/smbiosmdrv2handler.hpp
index b83e2d4..9bfb54f 100644
--- a/include/smbiosmdrv2handler.hpp
+++ b/include/smbiosmdrv2handler.hpp
@@ -20,6 +20,7 @@
 
 #include <oemcommands.hpp>
 #include <sdbusplus/timer.hpp>
+#include <types.hpp>
 
 static constexpr const char* mdrType2File = "/var/lib/smbios/smbios2";
 static constexpr const char* smbiosPath = "/var/lib/smbios";
@@ -273,7 +274,7 @@
     bool smbiosTryLock(uint8_t flag, uint8_t index, uint16_t* session,
                        uint16_t timeout);
     int sdplusMdrv2GetProperty(const std::string& name,
-                               std::variant<uint8_t>& value,
+                               ipmi::DbusVariant& value,
                                const std::string& service);
 
     Mdr2DirStruct smbiosDir{smbiosAgentVersion,
diff --git a/include/types.hpp b/include/types.hpp
index 373835c..fc68b5e 100644
--- a/include/types.hpp
+++ b/include/types.hpp
@@ -30,7 +30,9 @@
 
 using DbusVariant =
     std::variant<std::string, bool, uint8_t, uint16_t, int16_t, uint32_t,
-                 int32_t, uint64_t, int64_t, double, std::vector<Association>>;
+                 int32_t, uint64_t, int64_t, double, std::vector<Association>,
+                 std::vector<std::string>, std::vector<uint8_t>,
+                 std::vector<uint64_t>>;
 
 using GetSubTreeType = std::vector<
     std::pair<std::string,
diff --git a/include/variantvisitors.hpp b/include/variantvisitors.hpp
deleted file mode 100644
index b24481c..0000000
--- a/include/variantvisitors.hpp
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
-// Copyright (c) 2017 Intel Corporation
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//      http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-*/
-
-#pragma once
-#include <sdbusplus/bus.hpp>
-
-#include <cstdint>
-#include <limits>
-namespace ipmi
-{
-
-using DbusVariant = std::variant<std::string, bool, uint8_t, uint16_t, int16_t,
-                                 uint32_t, int32_t, uint64_t, int64_t, double>;
-} // namespace ipmi
diff --git a/src/appcommands.cpp b/src/appcommands.cpp
index 1d61889..722c471 100644
--- a/src/appcommands.cpp
+++ b/src/appcommands.cpp
@@ -20,6 +20,7 @@
 #include <ipmid/utils.hpp>
 #include <nlohmann/json.hpp>
 #include <phosphor-logging/log.hpp>
+#include <types.hpp>
 
 #include <fstream>
 #include <regex>
@@ -83,7 +84,7 @@
         sdbusplus::bus::match::rules::propertiesChanged(objInfo.first,
                                                         bmcStateIntf),
         [](sdbusplus::message_t& msg) {
-            std::map<std::string, std::variant<std::string>> props;
+            std::map<std::string, ipmi::DbusVariant> props;
             std::vector<std::string> inVal;
             std::string iface;
             try
diff --git a/src/biosconfigcommands.cpp b/src/biosconfigcommands.cpp
index 83b8959..c444112 100644
--- a/src/biosconfigcommands.cpp
+++ b/src/biosconfigcommands.cpp
@@ -121,8 +121,7 @@
 };
 
 using PendingAttributesType =
-    std::map<std::string,
-             std::tuple<std::string, std::variant<int64_t, std::string>>>;
+    std::map<std::string, std::tuple<std::string, ipmi::DbusVariant>>;
 
 AttributesType getAttrType(const std::string_view typeDbus)
 {
@@ -146,7 +145,7 @@
 }
 
 bool fillPayloadData(std::string& payloadData,
-                     const std::variant<int64_t, std::string>& attributes,
+                     const ipmi::DbusVariant& attributes,
                      const std::string_view key, AttributesType& attrType)
 {
     payloadData += key;
diff --git a/src/bmccontrolservices.cpp b/src/bmccontrolservices.cpp
index e30c4a9..484c426 100644
--- a/src/bmccontrolservices.cpp
+++ b/src/bmccontrolservices.cpp
@@ -20,6 +20,7 @@
 #include <ipmid/api.hpp>
 #include <ipmid/utils.hpp>
 #include <phosphor-logging/log.hpp>
+#include <types.hpp>
 
 #include <variant>
 
@@ -148,7 +149,7 @@
                             yield, ec, getServiceConfigMgrName().c_str(),
                             obj.first.str, dBusPropIntf, "Set",
                             serviceConfigAttrIntf, propMasked,
-                            std::variant<bool>(!state));
+                            ipmi::DbusVariant(!state));
                         checkAndThrowError(ec, "Set Masked property failed");
                         // Multiple instances may be present, so continue
                     }
diff --git a/src/firmware-update.cpp b/src/firmware-update.cpp
index b622d31..05b6576 100644
--- a/src/firmware-update.cpp
+++ b/src/firmware-update.cpp
@@ -476,8 +476,8 @@
             "xyz.openbmc_project.Software.BMC.Updater", objPath,
             "org.freedesktop.DBus.Properties", "Set",
             "xyz.openbmc_project.Software.Activation", "RequestedActivation",
-            std::variant<std::string>("xyz.openbmc_project.Software.Activation."
-                                      "RequestedActivations.Active"));
+            ipmi::DbusVariant("xyz.openbmc_project.Software.Activation."
+                              "RequestedActivations.Active"));
     }
     else
     {
@@ -582,9 +582,9 @@
     auto callback = [&](sdbusplus::message_t& m) {
         bool flag = false;
 
-        std::vector<std::pair<
-            std::string,
-            std::vector<std::pair<std::string, std::variant<std::string>>>>>
+        std::vector<
+            std::pair<std::string,
+                      std::vector<std::pair<std::string, ipmi::DbusVariant>>>>
             intfPropsPair;
         sdbusplus::message::object_path objPath;
 
diff --git a/src/manufacturingcommands.cpp b/src/manufacturingcommands.cpp
index 42185a7..df47887 100644
--- a/src/manufacturingcommands.cpp
+++ b/src/manufacturingcommands.cpp
@@ -21,6 +21,7 @@
 #include <ipmid/api.hpp>
 #include <manufacturingcommands.hpp>
 #include <oemcommands.hpp>
+#include <types.hpp>
 
 #include <filesystem>
 #include <fstream>
diff --git a/src/oemcommands.cpp b/src/oemcommands.cpp
index 910330d..1f8b99b 100644
--- a/src/oemcommands.cpp
+++ b/src/oemcommands.cpp
@@ -1658,8 +1658,7 @@
 
 bool getFanProfileInterface(
     sdbusplus::bus_t& bus,
-    boost::container::flat_map<
-        std::string, std::variant<std::vector<std::string>, std::string>>& resp)
+    boost::container::flat_map<std::string, ipmi::DbusVariant>& resp)
 {
     auto call = bus.new_method_call(settingsBusName, thermalModePath, PROP_INTF,
                                     "GetAll");
@@ -1715,9 +1714,7 @@
     }
 
     // todo: tell bios to only send first 2 bytes
-    boost::container::flat_map<
-        std::string, std::variant<std::vector<std::string>, std::string>>
-        profileData;
+    boost::container::flat_map<std::string, ipmi::DbusVariant> profileData;
     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
     if (!getFanProfileInterface(*dbus, profileData))
     {
@@ -1791,9 +1788,7 @@
         return ipmi::responseInvalidFieldRequest();
     }
 
-    boost::container::flat_map<
-        std::string, std::variant<std::vector<std::string>, std::string>>
-        profileData;
+    boost::container::flat_map<std::string, ipmi::DbusVariant> profileData;
 
     std::shared_ptr<sdbusplus::asio::connection> dbus = getSdBus();
     if (!getFanProfileInterface(*dbus, profileData))
@@ -2277,8 +2272,7 @@
     }
 }
 
-using crConfigVariant =
-    std::variant<bool, uint8_t, uint32_t, std::vector<uint8_t>, std::string>;
+using crConfigVariant = ipmi::DbusVariant;
 
 int setCRConfig(ipmi::Context::ptr ctx, const std::string& property,
                 const crConfigVariant& value,
@@ -2941,7 +2935,7 @@
     uint8_t specialModeValue = 0;
 
     boost::system::error_code ec;
-    auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
+    auto varRestrMode = ctx->bus->yield_method_call<ipmi::DbusVariant>(
         ctx->yield, ec, restricionModeService, restricionModeBasePath,
         dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
         restricionModeProperty);
@@ -2955,11 +2949,10 @@
     restrictionModeValue = static_cast<uint8_t>(
         securityNameSpace::RestrictionMode::convertModesFromString(
             std::get<std::string>(varRestrMode)));
-    auto varSpecialMode =
-        ctx->bus->yield_method_call<std::variant<std::string>>(
-            ctx->yield, ec, specialModeService, specialModeBasePath,
-            dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf,
-            specialModeProperty);
+    auto varSpecialMode = ctx->bus->yield_method_call<ipmi::DbusVariant>(
+        ctx->yield, ec, specialModeService, specialModeBasePath,
+        dBusPropertyIntf, dBusPropertyGetMethod, specialModeIntf,
+        specialModeProperty);
     if (ec)
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(
@@ -3017,7 +3010,7 @@
     }
 
     boost::system::error_code ec;
-    auto varRestrMode = ctx->bus->yield_method_call<std::variant<std::string>>(
+    auto varRestrMode = ctx->bus->yield_method_call<ipmi::DbusVariant>(
         ctx->yield, ec, restricionModeService, restricionModeBasePath,
         dBusPropertyIntf, dBusPropertyGetMethod, restricionModeIntf,
         restricionModeProperty);
@@ -3050,7 +3043,7 @@
         ctx->yield, ec, restricionModeService, restricionModeBasePath,
         dBusPropertyIntf, dBusPropertySetMethod, restricionModeIntf,
         restricionModeProperty,
-        static_cast<std::variant<std::string>>(
+        static_cast<ipmi::DbusVariant>(
             securityNameSpace::convertForMessage(reqMode)));
 
     if (ec)
@@ -3078,10 +3071,9 @@
             ctx->yield, ec, specialModeService, specialModeBasePath,
             dBusPropertyIntf, dBusPropertySetMethod, specialModeIntf,
             specialModeProperty,
-            static_cast<std::variant<std::string>>(
-                securityNameSpace::convertForMessage(
-                    static_cast<securityNameSpace::SpecialMode::Modes>(
-                        specialMode.value()))));
+            static_cast<ipmi::DbusVariant>(securityNameSpace::convertForMessage(
+                static_cast<securityNameSpace::SpecialMode::Modes>(
+                    specialMode.value()))));
 
         if (ec)
         {
@@ -3349,8 +3341,7 @@
     {
         std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
 
-        std::variant<std::vector<uint8_t>> offsets =
-            field.get<std::vector<uint8_t>>();
+        ipmi::DbusVariant offsets = field.get<std::vector<uint8_t>>();
         auto call = bus->new_method_call(
             settingsBusName, dimmOffset::offsetPath, PROP_INTF, "Set");
         call.append(dimmOffset::offsetInterface, dimmOffset::property, offsets);
@@ -3656,10 +3647,7 @@
     return ipmi::responseSuccess();
 }
 
-using BasicVariantType =
-    std::variant<std::vector<std::string>, std::vector<uint64_t>, std::string,
-                 int64_t, uint64_t, double, int32_t, uint32_t, int16_t,
-                 uint16_t, uint8_t, bool>;
+using BasicVariantType = ipmi::DbusVariant;
 using PropertyMapType =
     boost::container::flat_map<std::string, BasicVariantType>;
 static constexpr const std::array<const char*, 1> psuPresenceTypes = {
diff --git a/src/sensorcommands.cpp b/src/sensorcommands.cpp
index b8b40e0..0fb04f7 100644
--- a/src/sensorcommands.cpp
+++ b/src/sensorcommands.cpp
@@ -128,8 +128,7 @@
     "type='signal',member='PropertiesChanged',interface='org.freedesktop.DBus."
     "Properties',arg0namespace='xyz.openbmc_project.Sensor.Threshold'",
     [](sdbusplus::message_t& m) {
-        boost::container::flat_map<std::string, std::variant<bool, double>>
-            values;
+        boost::container::flat_map<std::string, ipmi::DbusVariant> values;
         m.read(std::string(), values);
 
         auto findAssert =
diff --git a/src/smbioshandler.cpp b/src/smbioshandler.cpp
index e330e5a..cc882be 100644
--- a/src/smbioshandler.cpp
+++ b/src/smbioshandler.cpp
@@ -20,6 +20,7 @@
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
 #include <smbioshandler.hpp>
+#include <types.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 #include <cstdint>
@@ -90,8 +91,7 @@
     return IPMI_CC_OK;
 }
 
-int sdplus_mdrv1_get_property(const std::string& name,
-                              std::variant<uint8_t, uint16_t>& value,
+int sdplus_mdrv1_get_property(const std::string& name, ipmi::DbusVariant& value,
                               std::string& service)
 {
     std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
@@ -115,7 +115,7 @@
     std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
     auto method = bus->new_method_call(service.c_str(), MDRV1_PATH,
                                        DBUS_PROPERTIES, "Set");
-    std::variant<uint8_t> value{regionId};
+    ipmi::DbusVariant value{regionId};
     method.append(MDRV1_INTERFACE, "RegionId", value);
     auto region = bus->call(method);
     if (region.is_method_error())
@@ -134,7 +134,7 @@
     auto requestData = reinterpret_cast<const RegionCompleteRequest*>(request);
     uint8_t status;
 
-    std::variant<uint8_t, uint16_t> value;
+    ipmi::DbusVariant value;
 
     if (*data_len != sizeof(RegionCompleteRequest))
     {
@@ -210,8 +210,8 @@
 {
     auto requestData = reinterpret_cast<const RegionReadRequest*>(request);
     auto responseData = reinterpret_cast<RegionReadResponse*>(response);
-    std::variant<uint8_t, uint16_t> regUsedVal;
-    std::variant<uint8_t, uint16_t> lockPolicyVal;
+    ipmi::DbusVariant regUsedVal;
+    ipmi::DbusVariant lockPolicyVal;
     std::vector<uint8_t> res;
 
     if (*data_len < sizeof(RegionReadRequest))
@@ -317,7 +317,7 @@
         return IPMI_CC_REQ_DATA_LEN_INVALID;
     }
 
-    std::variant<uint8_t, uint16_t> value;
+    ipmi::DbusVariant value;
 
     *data_len = 0;
 
@@ -400,7 +400,7 @@
 {
     auto requestData = reinterpret_cast<const RegionLockRequest*>(request);
     uint8_t regionId = requestData->regionId - 1;
-    std::variant<uint8_t, uint16_t> value;
+    ipmi::DbusVariant value;
     auto res = reinterpret_cast<uint8_t*>(response);
     uint8_t lockResponse;
 
diff --git a/src/smbiosmdrv2handler.cpp b/src/smbiosmdrv2handler.cpp
index 59f38fa..c5d00a1 100644
--- a/src/smbiosmdrv2handler.cpp
+++ b/src/smbiosmdrv2handler.cpp
@@ -60,7 +60,7 @@
 }
 
 int MDRV2::sdplusMdrv2GetProperty(const std::string& name,
-                                  std::variant<uint8_t>& value,
+                                  ipmi::DbusVariant& value,
                                   const std::string& service)
 {
     std::shared_ptr<sdbusplus::asio::connection> bus = getSdBus();
@@ -297,7 +297,7 @@
         return ipmi::responseParmOutOfRange();
     }
 
-    std::variant<uint8_t> value = static_cast<uint8_t>(0);
+    ipmi::DbusVariant value = static_cast<uint8_t>(0);
     if (0 != mdrv2->sdplusMdrv2GetProperty("DirectoryEntries", value, service))
     {
         phosphor::logging::log<phosphor::logging::level::ERR>(