diff options
Diffstat (limited to 'redfish-core')
25 files changed, 644 insertions, 625 deletions
diff --git a/redfish-core/include/event_service_manager.hpp b/redfish-core/include/event_service_manager.hpp index 92349cca97..16af1be2a8 100644 --- a/redfish-core/include/event_service_manager.hpp +++ b/redfish-core/include/event_service_manager.hpp @@ -24,6 +24,7 @@ #include <boost/asio/io_context.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <error_messages.hpp> #include <event_service_store.hpp> #include <http_client.hpp> @@ -37,7 +38,6 @@ #include <fstream> #include <memory> #include <span> -#include <variant> namespace redfish { @@ -500,9 +500,8 @@ class Subscription : public persistent_data::UserSubscription } #endif - void filterAndSendReports( - const std::string& id, - const std::variant<telemetry::TimestampReadings>& var) + void filterAndSendReports(const std::string& id, + const dbus::utility::DbusVariantType& var) { std::string mrdUri = telemetry::metricReportDefinitionUri + ("/" + id); @@ -1315,8 +1314,7 @@ class EventServiceManager } std::string interface; - std::vector< - std::pair<std::string, std::variant<telemetry::TimestampReadings>>> + std::vector<std::pair<std::string, dbus::utility::DbusVariantType>> props; std::vector<std::string> invalidProps; msg.read(interface, props, invalidProps); @@ -1330,8 +1328,7 @@ class EventServiceManager return; } - const std::variant<telemetry::TimestampReadings>& readings = - found->second; + const dbus::utility::DbusVariantType& readings = found->second; for (const auto& it : EventServiceManager::getInstance().subscriptionsMap) { diff --git a/redfish-core/include/utils/fw_utils.hpp b/redfish-core/include/utils/fw_utils.hpp index c990023b84..658ca4d6d7 100644 --- a/redfish-core/include/utils/fw_utils.hpp +++ b/redfish-core/include/utils/fw_utils.hpp @@ -1,9 +1,9 @@ #pragma once #include <async_resp.hpp> +#include <dbus_utility.hpp> #include <algorithm> #include <string> -#include <variant> #include <vector> namespace redfish @@ -39,9 +39,9 @@ inline void { // Used later to determine running (known on Redfish as active) FW images crow::connections::systemBus->async_method_call( - [aResp, fwVersionPurpose, activeVersionPropName, populateLinkToImages]( - const boost::system::error_code ec, - const std::variant<std::vector<std::string>>& resp) { + [aResp, fwVersionPurpose, activeVersionPropName, + populateLinkToImages](const boost::system::error_code ec, + const dbus::utility::DbusVariantType& resp) { BMCWEB_LOG_DEBUG << "populateFirmwareInformation enter"; if (ec) { @@ -132,8 +132,8 @@ inline void const boost::system::error_code ec3, const boost::container::flat_map< std::string, - std::variant<bool, std::string, uint64_t, - uint32_t>>& propertiesList) { + dbus::utility::DbusVariantType>& + propertiesList) { if (ec3) { BMCWEB_LOG_ERROR << "error_code = " << ec3; @@ -150,9 +150,9 @@ inline void boost::container::flat_map< std::string, - std::variant<bool, std::string, uint64_t, - uint32_t>>::const_iterator it = - propertiesList.find("Purpose"); + dbus::utility::DbusVariantType>:: + const_iterator it = + propertiesList.find("Purpose"); if (it == propertiesList.end()) { BMCWEB_LOG_ERROR @@ -331,11 +331,10 @@ inline void getFwStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, BMCWEB_LOG_DEBUG << "getFwStatus: swId " << *swId << " svc " << dbusSvc; crow::connections::systemBus->async_method_call( - [asyncResp, - swId](const boost::system::error_code errorCode, - const boost::container::flat_map< - std::string, std::variant<bool, std::string, uint64_t, - uint32_t>>& propertiesList) { + [asyncResp, swId]( + const boost::system::error_code errorCode, + const boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>& propertiesList) { if (errorCode) { // not all fwtypes are updateable, this is ok @@ -343,9 +342,8 @@ inline void getFwStatus(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, return; } boost::container::flat_map< - std::string, std::variant<bool, std::string, uint64_t, - uint32_t>>::const_iterator it = - propertiesList.find("Activation"); + std::string, dbus::utility::DbusVariantType>::const_iterator + it = propertiesList.find("Activation"); if (it == propertiesList.end()) { BMCWEB_LOG_DEBUG << "Can't find property \"Activation\"!"; @@ -388,7 +386,7 @@ inline void { crow::connections::systemBus->async_method_call( [asyncResp, fwId](const boost::system::error_code ec, - const std::variant<std::vector<std::string>>& resp) { + dbus::utility::DbusVariantType& resp) { if (ec) { BMCWEB_LOG_DEBUG << " error_code = " << ec diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp index 865a3834f9..46f6a93b72 100644 --- a/redfish-core/lib/account_service.hpp +++ b/redfish-core/lib/account_service.hpp @@ -23,8 +23,6 @@ #include <registries/privilege_registry.hpp> #include <utils/json_utils.hpp> -#include <variant> - namespace redfish { @@ -68,10 +66,9 @@ struct LDAPConfigData std::vector<std::pair<std::string, LDAPRoleMapData>> groupRoleList; }; -using DbusVariantType = std::variant<bool, int32_t, std::string>; - using DbusInterfaceType = boost::container::flat_map< - std::string, boost::container::flat_map<std::string, DbusVariantType>>; + std::string, + boost::container::flat_map<std::string, dbus::utility::DbusVariantType>>; using ManagedObjectType = std::vector<std::pair<sdbusplus::message::object_path, DbusInterfaceType>>; @@ -295,7 +292,8 @@ inline void handleRoleMapPatch( propertyInterface, "Set", "xyz.openbmc_project.User.PrivilegeMapperEntry", "GroupName", - std::variant<std::string>(std::move(*remoteGroup))); + dbus::utility::DbusVariantType( + std::move(*remoteGroup))); } // If "LocalRole" info is provided @@ -319,7 +317,7 @@ inline void handleRoleMapPatch( propertyInterface, "Set", "xyz.openbmc_project.User.PrivilegeMapperEntry", "Privilege", - std::variant<std::string>( + dbus::utility::DbusVariantType( getPrivilegeFromRoleId(std::move(*localRole)))); } } @@ -665,7 +663,7 @@ inline void handleServiceAddressPatch( }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", ldapConfigInterface, "LDAPServerURI", - std::variant<std::string>(serviceAddressList.front())); + dbus::utility::DbusVariantType(serviceAddressList.front())); } /** * @brief updates the LDAP Bind DN and updates the @@ -696,7 +694,8 @@ inline void BMCWEB_LOG_DEBUG << "Updated the username"; }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", - ldapConfigInterface, "LDAPBindDN", std::variant<std::string>(username)); + ldapConfigInterface, "LDAPBindDN", + dbus::utility::DbusVariantType(username)); } /** @@ -728,7 +727,7 @@ inline void }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", ldapConfigInterface, "LDAPBindDNPassword", - std::variant<std::string>(password)); + dbus::utility::DbusVariantType(password)); } /** @@ -771,7 +770,7 @@ inline void }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", ldapConfigInterface, "LDAPBaseDN", - std::variant<std::string>(baseDNList.front())); + dbus::utility::DbusVariantType(baseDNList.front())); } /** * @brief updates the LDAP user name attribute and updates the @@ -807,7 +806,7 @@ inline void }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", ldapConfigInterface, "UserNameAttribute", - std::variant<std::string>(userNameAttribute)); + dbus::utility::DbusVariantType(userNameAttribute)); } /** * @brief updates the LDAP group attribute and updates the @@ -843,7 +842,7 @@ inline void handleGroupNameAttrPatch( }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", ldapConfigInterface, "GroupNameAttribute", - std::variant<std::string>(groupsAttribute)); + dbus::utility::DbusVariantType(groupsAttribute)); } /** * @brief updates the LDAP service enable and updates the @@ -874,7 +873,8 @@ inline void handleServiceEnablePatch( BMCWEB_LOG_DEBUG << "Updated Service enable = " << serviceEnabled; }, ldapDbusService, ldapConfigObject, propertyInterface, "Set", - ldapEnableInterface, "Enabled", std::variant<bool>(serviceEnabled)); + ldapEnableInterface, "Enabled", + dbus::utility::DbusVariantType(serviceEnabled)); } inline void @@ -1197,7 +1197,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", "UserEnabled", - std::variant<bool>{*enabled}); + dbus::utility::DbusVariantType{*enabled}); } if (roleId) @@ -1227,7 +1227,7 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", "UserPrivilege", - std::variant<std::string>{priv}); + dbus::utility::DbusVariantType{priv}); } if (locked) @@ -1256,7 +1256,8 @@ inline void updateUserProperties(std::shared_ptr<bmcweb::AsyncResp> asyncResp, "xyz.openbmc_project.User.Manager", dbusObjectPath.c_str(), "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.Attributes", - "UserLockedForFailedAttempt", std::variant<bool>{*locked}); + "UserLockedForFailedAttempt", + dbus::utility::DbusVariantType{*locked}); } }); } @@ -1317,8 +1318,7 @@ inline void requestAccountServiceRoutes(App& app) [asyncResp]( const boost::system::error_code ec, const std::vector< - std::pair<std::string, - std::variant<uint32_t, uint16_t, uint8_t>>>& + std::pair<std::string, dbus::utility::DbusVariantType>>& propertiesList) { if (ec) { @@ -1328,9 +1328,8 @@ inline void requestAccountServiceRoutes(App& app) BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() << "properties for AccountService"; for (const std::pair<std::string, - std::variant<uint32_t, uint16_t, - uint8_t>>& property : - propertiesList) + dbus::utility::DbusVariantType>& + property : propertiesList) { if (property.first == "MinPasswordLength") { @@ -1466,7 +1465,7 @@ inline void requestAccountServiceRoutes(App& app) "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.AccountPolicy", "AccountUnlockTimeout", - std::variant<uint32_t>(*unlockTimeout)); + dbus::utility::DbusVariantType(*unlockTimeout)); } if (lockoutThreshold) { @@ -1484,7 +1483,7 @@ inline void requestAccountServiceRoutes(App& app) "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.User.AccountPolicy", "MaxLoginAttemptBeforeLockout", - std::variant<uint16_t>(*lockoutThreshold)); + dbus::utility::DbusVariantType(*lockoutThreshold)); } }); @@ -1603,9 +1602,8 @@ inline void requestAccountServiceRoutes(App& app) // Reading AllGroups property crow::connections::systemBus->async_method_call( [asyncResp, username, password{std::move(password)}, roleId, - enabled]( - const boost::system::error_code ec, - const std::variant<std::vector<std::string>>& allGroups) { + enabled](const boost::system::error_code ec, + const dbus::utility::DbusVariantType& allGroups) { if (ec) { BMCWEB_LOG_DEBUG << "ERROR with async_method_call"; diff --git a/redfish-core/lib/certificate_service.hpp b/redfish-core/lib/certificate_service.hpp index 8a78317dad..3dca18b9d9 100644 --- a/redfish-core/lib/certificate_service.hpp +++ b/redfish-core/lib/certificate_service.hpp @@ -3,9 +3,9 @@ #include <app.hpp> #include <boost/convert.hpp> #include <boost/convert/strtol.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> -#include <variant> namespace redfish { namespace certs @@ -449,10 +449,10 @@ inline void requestRoutesCertificateActionGenerateCSR(App& app) messages::internalError(asyncResp->res); return; } - 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, + dbus::utility::DbusVariantType>>>> interfacesProperties; sdbusplus::message::object_path csrObjectPath; m.read(csrObjectPath, interfacesProperties); @@ -569,9 +569,8 @@ static void getCertificateProperties( const std::string& objectPath, const std::string& service, long certId, const std::string& certURL, const std::string& name) { - using PropertyType = - std::variant<std::string, uint64_t, std::vector<std::string>>; - using PropertiesMap = boost::container::flat_map<std::string, PropertyType>; + using PropertiesMap = + boost::container::flat_map<std::string, dbus::utility::DbusVariantType>; BMCWEB_LOG_DEBUG << "getCertificateProperties Path=" << objectPath << " certId=" << certId << " certURl=" << certURL; crow::connections::systemBus->async_method_call( diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp index 6d99313b47..df7e205686 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 @@ inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) 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 @@ inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) * 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 @@ inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, 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 @@ inline void { 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 @@ inline void getChassisUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, { 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 @@ inline void requestRoutesChassis(App& app) 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 @@ inline void requestRoutesChassis(App& app) 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 @@ inline void requestRoutesChassis(App& app) [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 @@ inline void }, processName, objectPath, "org.freedesktop.DBus.Properties", "Set", interfaceName, destProperty, - std::variant<std::string>{propertyValue}); + dbus::utility::DbusVariantType{propertyValue}); }, busName, path, interface, method, "/", 0, interfaces); } diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp index 98b556eade..79a1f501c8 100644 --- a/redfish-core/lib/ethernet.hpp +++ b/redfish-core/lib/ethernet.hpp @@ -19,13 +19,13 @@ #include <boost/container/flat_map.hpp> #include <boost/container/flat_set.hpp> #include <dbus_singleton.hpp> +#include <dbus_utility.hpp> #include <error_messages.hpp> #include <registries/privilege_registry.hpp> #include <utils/json_utils.hpp> #include <optional> #include <regex> -#include <variant> namespace redfish { @@ -34,19 +34,14 @@ namespace redfish * DBus types primitives for several generic DBus interfaces * TODO(Pawel) consider move this to separate file into boost::dbus */ -using PropertiesMapType = boost::container::flat_map< - std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, - int32_t, uint32_t, int64_t, uint64_t, double>>; +using PropertiesMapType = + boost::container::flat_map<std::string, dbus::utility::DbusVariantType>; using GetManagedObjects = std::vector<std::pair< sdbusplus::message::object_path, - std::vector<std::pair< - std::string, - boost::container::flat_map< - std::string, - std::variant<std::string, bool, uint8_t, int16_t, uint16_t, int32_t, - uint32_t, int64_t, uint64_t, double, - std::vector<std::string>>>>>>>; + std::vector<std::pair<std::string, + boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>>>>>; enum class LinkType { @@ -614,7 +609,7 @@ void changeVlanId(const std::string& ifaceId, const uint32_t& inputVlanId, std::string("/xyz/openbmc_project/network/") + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.VLAN", "Id", - std::variant<uint32_t>(inputVlanId)); + dbus::utility::DbusVariantType(inputVlanId)); } /** @@ -748,7 +743,7 @@ inline void updateIPv4DefaultGateway( "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", "DefaultGateway", - std::variant<std::string>(gateway)); + dbus::utility::DbusVariantType(gateway)); } /** * @brief Creates a static IPv4 entry @@ -1055,7 +1050,7 @@ inline void "xyz.openbmc_project.Network", "/xyz/openbmc_project/network/config", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.SystemConfiguration", "HostName", - std::variant<std::string>(hostname)); + dbus::utility::DbusVariantType(hostname)); } inline void @@ -1075,7 +1070,7 @@ inline void "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", "DomainName", - std::variant<std::vector<std::string>>(vectorDomainname)); + dbus::utility::DbusVariantType(vectorDomainname)); } inline bool isHostnameValid(const std::string& hostname) @@ -1154,7 +1149,7 @@ inline void "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.MACAddress", "MACAddress", - std::variant<std::string>(macAddress)); + dbus::utility::DbusVariantType(macAddress)); } inline void setDHCPEnabled(const std::string& ifaceId, @@ -1177,7 +1172,7 @@ inline void setDHCPEnabled(const std::string& ifaceId, "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", propertyName, - std::variant<std::string>{dhcp}); + dbus::utility::DbusVariantType{dhcp}); } inline void setEthernetInterfaceBoolProperty( @@ -1197,7 +1192,7 @@ inline void setEthernetInterfaceBoolProperty( "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", propertyName, - std::variant<bool>{value}); + dbus::utility::DbusVariantType{value}); } inline void setDHCPv4Config(const std::string& propertyName, const bool& value, @@ -1217,7 +1212,7 @@ inline void setDHCPv4Config(const std::string& propertyName, const bool& value, "/xyz/openbmc_project/network/config/dhcp", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.DHCPConfiguration", propertyName, - std::variant<bool>{value}); + dbus::utility::DbusVariantType{value}); } inline void handleDHCPPatch(const std::string& ifaceId, @@ -1550,7 +1545,7 @@ inline void handleStaticNameServersPatch( "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", "StaticNameServers", - std::variant<std::vector<std::string>>{updatedStaticNameServers}); + dbus::utility::DbusVariantType{updatedStaticNameServers}); } inline void handleIPv6StaticAddressesPatch( @@ -2172,7 +2167,7 @@ inline void requestEthernetInterfacesRoutes(App& app) "/xyz/openbmc_project/network/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.VLAN", "Id", - std::variant<uint32_t>(vlanId)); + dbus::utility::DbusVariantType(vlanId)); } else { diff --git a/redfish-core/lib/hypervisor_system.hpp b/redfish-core/lib/hypervisor_system.hpp index 01d7528332..5089206286 100644 --- a/redfish-core/lib/hypervisor_system.hpp +++ b/redfish-core/lib/hypervisor_system.hpp @@ -4,13 +4,13 @@ #include <boost/container/flat_map.hpp> #include <boost/container/flat_set.hpp> #include <dbus_singleton.hpp> +#include <dbus_utility.hpp> #include <error_messages.hpp> #include <registries/privilege_registry.hpp> #include <utils/json_utils.hpp> #include <optional> #include <utility> -#include <variant> // TODO(ed) requestRoutesHypervisorSystems seems to have copy-pasted a // lot of code, and has a number of methods that have name conflicts with the @@ -35,7 +35,7 @@ inline void getHypervisorState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) BMCWEB_LOG_DEBUG << "Get hypervisor state information."; crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& hostState) { + const dbus::utility::DbusVariantType& hostState) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -374,7 +374,7 @@ inline void "/xyz/openbmc_project/network/hypervisor/" + ethIfaceId + "/ipv4/addr0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.IP", "Address", - std::variant<std::string>(ipv4Address)); + dbus::utility::DbusVariantType(ipv4Address)); } /** @@ -406,7 +406,7 @@ inline void "/xyz/openbmc_project/network/hypervisor/" + ethIfaceId + "/ipv4/addr0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.IP", "PrefixLength", - std::variant<uint8_t>(subnet)); + dbus::utility::DbusVariantType(subnet)); } /** @@ -438,7 +438,7 @@ inline void "/xyz/openbmc_project/network/hypervisor", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.SystemConfiguration", "DefaultGateway", - std::variant<std::string>(gateway)); + dbus::utility::DbusVariantType(gateway)); } /** @@ -540,7 +540,7 @@ inline void setDHCPEnabled(const std::string& ifaceId, "/xyz/openbmc_project/network/hypervisor/" + ifaceId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.EthernetInterface", "DHCPEnabled", - std::variant<std::string>{dhcp}); + dbus::utility::DbusVariantType{dhcp}); // Set the IPv4 address origin to the DHCP / Static as per the new value // of the DHCPEnabled property @@ -570,7 +570,7 @@ inline void setDHCPEnabled(const std::string& ifaceId, "/xyz/openbmc_project/network/hypervisor/" + ifaceId + "/ipv4/addr0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.IP", "Origin", - std::variant<std::string>(origin)); + dbus::utility::DbusVariantType(origin)); } inline void handleHypervisorIPv4StaticPatch( @@ -702,7 +702,7 @@ inline void "/xyz/openbmc_project/network/hypervisor", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Network.SystemConfiguration", "HostName", - std::variant<std::string>(hostName)); + dbus::utility::DbusVariantType(hostName)); } inline void @@ -722,7 +722,7 @@ inline void "/xyz/openbmc_project/network/hypervisor/" + ifaceId + "/ipv4/addr0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Object.Enable", "Enabled", - std::variant<bool>(isActive)); + dbus::utility::DbusVariantType(isActive)); } inline void requestRoutesHypervisorSystems(App& app) @@ -738,8 +738,9 @@ inline void requestRoutesHypervisorSystems(App& app) get)([](const crow::Request&, const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec, - const std::variant<std::string>& /*hostName*/) { + [asyncResp]( + const boost::system::error_code ec, + const dbus::utility::DbusVariantType& /*hostName*/) { if (ec) { messages::resourceNotFound(asyncResp->res, "System", @@ -1098,7 +1099,7 @@ inline void requestRoutesHypervisorSystems(App& app) "/xyz/openbmc_project/state/hypervisor0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.State.Host", "RequestedHostTransition", - std::variant<std::string>{std::move(command)}); + dbus::utility::DbusVariantType{std::move(command)}); }); } } // namespace redfish::hypervisor diff --git a/redfish-core/lib/led.hpp b/redfish-core/lib/led.hpp index 1fdf5e7e13..c4a7ed8805 100644 --- a/redfish-core/lib/led.hpp +++ b/redfish-core/lib/led.hpp @@ -21,8 +21,6 @@ #include <app.hpp> -#include <variant> - namespace redfish { /** @@ -39,7 +37,7 @@ inline void BMCWEB_LOG_DEBUG << "Get led groups"; crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<bool> asserted) { + const dbus::utility::DbusVariantType asserted) { // Some systems may not have enclosure_identify_blink object so // proceed to get enclosure_identify state. if (!ec) @@ -60,7 +58,7 @@ inline void } crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec2, - const std::variant<bool> asserted2) { + const dbus::utility::DbusVariantType asserted2) { if (!ec2) { const bool* ledOn = std::get_if<bool>(&asserted2); @@ -151,13 +149,13 @@ inline void "/xyz/openbmc_project/led/groups/enclosure_identify", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Led.Group", "Asserted", - std::variant<bool>(ledOn)); + dbus::utility::DbusVariantType(ledOn)); }, "xyz.openbmc_project.LED.GroupManager", "/xyz/openbmc_project/led/groups/enclosure_identify_blink", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Led.Group", "Asserted", - std::variant<bool>(ledBlinkng)); + dbus::utility::DbusVariantType(ledBlinkng)); } /** @@ -173,7 +171,7 @@ inline void BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive"; crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<bool> asserted) { + const dbus::utility::DbusVariantType asserted) { // Some systems may not have enclosure_identify_blink object so // proceed to get enclosure_identify state. if (!ec) @@ -194,7 +192,7 @@ inline void } crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec2, - const std::variant<bool> asserted2) { + const dbus::utility::DbusVariantType asserted2) { if (!ec2) { const bool* ledOn = std::get_if<bool>(&asserted2); @@ -264,13 +262,13 @@ inline void "/xyz/openbmc_project/led/groups/enclosure_identify", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Led.Group", "Asserted", - std::variant<bool>(ledState)); + dbus::utility::DbusVariantType(ledState)); } }, "xyz.openbmc_project.LED.GroupManager", "/xyz/openbmc_project/led/groups/enclosure_identify_blink", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Led.Group", "Asserted", - std::variant<bool>(ledState)); + dbus::utility::DbusVariantType(ledState)); } } // namespace redfish diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp index 074c927d4a..d632552986 100644 --- a/redfish-core/lib/log_services.hpp +++ b/redfish-core/lib/log_services.hpp @@ -32,6 +32,7 @@ #include <boost/beast/http.hpp> #include <boost/container/flat_map.hpp> #include <boost/system/linux_error.hpp> +#include <dbus_utility.hpp> #include <error_messages.hpp> #include <registries/privilege_registry.hpp> @@ -102,9 +103,8 @@ static const Message* getMessage(const std::string_view& messageID) namespace fs = std::filesystem; -using GetManagedPropertyType = boost::container::flat_map< - std::string, std::variant<std::string, bool, uint8_t, int16_t, uint16_t, - int32_t, uint32_t, int64_t, uint64_t, double>>; +using GetManagedPropertyType = + boost::container::flat_map<std::string, dbus::utility::DbusVariantType>; using GetManagedObjectsType = boost::container::flat_map< sdbusplus::message::object_path, @@ -736,8 +736,8 @@ inline void return task::completed; } std::vector<std::pair< - std::string, - std::vector<std::pair<std::string, std::variant<std::string>>>>> + std::string, std::vector<std::pair< + std::string, dbus::utility::DbusVariantType>>>> interfacesList; sdbusplus::message::object_path objPath; @@ -900,7 +900,8 @@ inline void clearDump(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, } inline static void parseCrashdumpParameters( - const std::vector<std::pair<std::string, VariantType>>& params, + const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& + params, std::string& filename, std::string& timestamp, std::string& logfile) { for (auto property : params) @@ -1670,7 +1671,7 @@ inline void requestRoutesDBusEventLogEntry(App& app) "/xyz/openbmc_project/logging/entry/" + entryId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Logging.Entry", "Resolved", - std::variant<bool>(*resolved)); + dbus::utility::DbusVariantType(*resolved)); }); BMCWEB_ROUTE( @@ -2638,7 +2639,9 @@ static void auto getStoredLogCallback = [asyncResp, logID, &logEntryJson]( const boost::system::error_code ec, - const std::vector<std::pair<std::string, VariantType>>& params) { + const std::vector< + std::pair<std::string, dbus::utility::DbusVariantType>>& + params) { if (ec) { BMCWEB_LOG_DEBUG << "failed to get log ec: " << ec.message(); @@ -2799,7 +2802,8 @@ inline void requestRoutesCrashdumpFile(App& app) auto getStoredLogCallback = [asyncResp, logID, fileName]( const boost::system::error_code ec, - const std::vector<std::pair<std::string, VariantType>>& + const std::vector<std::pair< + std::string, dbus::utility::DbusVariantType>>& resp) { if (ec) { @@ -3318,7 +3322,7 @@ static void crow::connections::systemBus->async_method_call( [aResp, entryCount, skip, top](const boost::system::error_code ec, - const std::variant<uint16_t>& bootCount) { + const dbus::utility::DbusVariantType& bootCount) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp index ca5d8c5460..7e5b272d72 100644 --- a/redfish-core/lib/managers.hpp +++ b/redfish-core/lib/managers.hpp @@ -50,7 +50,7 @@ inline void const char* destProperty = "RequestedBMCTransition"; // Create the D-Bus variant for D-Bus call. - VariantType dbusPropertyValue(propertyValue); + dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec) { @@ -79,7 +79,7 @@ inline void const char* destProperty = "RequestedBMCTransition"; // Create the D-Bus variant for D-Bus call. - VariantType dbusPropertyValue(propertyValue); + dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec) { @@ -1178,11 +1178,11 @@ struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> const std::string& path = subtreeLocal[0].first; const std::string& owner = subtreeLocal[0].second[0].first; crow::connections::systemBus->async_method_call( - [path, owner, self]( - const boost::system::error_code ec2, - const boost::container::flat_map< - std::string, std::variant<std::vector<std::string>, - std::string>>& resp) { + [path, owner, + self](const boost::system::error_code ec2, + const boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>& + resp) { if (ec2) { BMCWEB_LOG_ERROR @@ -1396,8 +1396,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> [self, path, owner]( const boost::system::error_code ec2, const boost::container::flat_map< - std::string, std::variant<std::vector<std::string>, - std::string>>& r) { + std::string, dbus::utility::DbusVariantType>& r) { if (ec2) { BMCWEB_LOG_ERROR @@ -1487,7 +1486,7 @@ struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> }, profileConnection, profilePath, "org.freedesktop.DBus.Properties", "Set", thermalModeIface, - "Current", std::variant<std::string>(*profile)); + "Current", dbus::utility::DbusVariantType(*profile)); } for (auto& containerPair : configuration) @@ -1690,7 +1689,7 @@ inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp, crow::connections::systemBus->async_method_call( [aResp](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 " @@ -1722,7 +1721,7 @@ inline void crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - std::variant<uint64_t>& lastResetTime) { + dbus::utility::DbusVariantType& lastResetTime) { if (ec) { BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; @@ -1853,7 +1852,7 @@ inline void "/xyz/openbmc_project/software/" + firmwareId, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Software.RedundancyPriority", "Priority", - std::variant<uint8_t>(static_cast<uint8_t>(0))); + dbus::utility::DbusVariantType(static_cast<uint8_t>(0))); }, "xyz.openbmc_project.Software.BMC.Updater", "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager", @@ -1898,7 +1897,7 @@ inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp, "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Time.EpochTime", "Elapsed", - std::variant<uint64_t>(durMicroSecs)); + dbus::utility::DbusVariantType(durMicroSecs)); } else { @@ -2037,7 +2036,7 @@ inline void requestRoutesManager(App& app) { crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec, - const std::variant<double>& resp) { + const dbus::utility::DbusVariantType& resp) { if (ec) { BMCWEB_LOG_ERROR << "Error while getting progress"; @@ -2114,9 +2113,9 @@ inline void requestRoutesManager(App& app) crow::connections::systemBus->async_method_call( [asyncResp]( const boost::system::error_code ec, - const std::vector< - std::pair<std::string, - std::variant<std::string>>>& + const std::vector<std::pair< + std::string, + dbus::utility::DbusVariantType>>& propertiesList) { if (ec) { @@ -2126,7 +2125,7 @@ inline void requestRoutesManager(App& app) } for (const std::pair< std::string, - std::variant<std::string>>& + dbus::utility::DbusVariantType>& property : propertiesList) { const std::string& propertyName = diff --git a/redfish-core/lib/memory.hpp b/redfish-core/lib/memory.hpp index 90e54e82e7..49304e2150 100644 --- a/redfish-core/lib/memory.hpp +++ b/redfish-core/lib/memory.hpp @@ -19,6 +19,7 @@ #include <app.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <utils/collection.hpp> #include <utils/hex_utils.hpp> @@ -27,11 +28,8 @@ namespace redfish { -using DimmProperty = - std::variant<std::string, std::vector<uint32_t>, std::vector<uint16_t>, - uint64_t, uint32_t, uint16_t, uint8_t, bool>; - -using DimmProperties = boost::container::flat_map<std::string, DimmProperty>; +using DimmProperties = + boost::container::flat_map<std::string, dbus::utility::DbusVariantType>; inline std::string translateMemoryTypeToRedfish(const std::string& memoryType) { @@ -142,9 +140,9 @@ inline std::string translateMemoryTypeToRedfish(const std::string& memoryType) return ""; } -inline void dimmPropToHex(const std::shared_ptr<bmcweb::AsyncResp>& aResp, - const char* key, - const std::pair<std::string, DimmProperty>& property) +inline void dimmPropToHex( + const std::shared_ptr<bmcweb::AsyncResp>& aResp, const char* key, + const std::pair<std::string, dbus::utility::DbusVariantType>& property) { const uint16_t* value = std::get_if<uint16_t>(&property.second); if (value == nullptr) @@ -745,8 +743,7 @@ inline void getDimmPartitionData(std::shared_ptr<bmcweb::AsyncResp> aResp, [aResp{std::move(aResp)}]( const boost::system::error_code ec, const boost::container::flat_map< - std::string, std::variant<std::string, uint64_t, uint32_t, - bool>>& properties) { + std::string, dbus::utility::DbusVariantType>& properties) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; diff --git a/redfish-core/lib/metric_report.hpp b/redfish-core/lib/metric_report.hpp index 5ecab776b7..c36f719a56 100644 --- a/redfish-core/lib/metric_report.hpp +++ b/redfish-core/lib/metric_report.hpp @@ -4,6 +4,7 @@ #include "utils/telemetry_utils.hpp" #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> namespace redfish @@ -34,7 +35,7 @@ inline nlohmann::json toMetricValues(const Readings& readings) } inline bool fillReport(nlohmann::json& json, const std::string& id, - const std::variant<TimestampReadings>& var) + const dbus::utility::DbusVariantType& var) { json["@odata.type"] = "#MetricReport.v1_3_0.MetricReport"; json["@odata.id"] = telemetry::metricReportUri + std::string("/") + id; @@ -107,8 +108,7 @@ inline void requestRoutesMetricReport(App& app) crow::connections::systemBus->async_method_call( [asyncResp, id](const boost::system::error_code ec, - const std::variant< - telemetry::TimestampReadings>& ret) { + const dbus::utility::DbusVariantType& ret) { if (ec) { BMCWEB_LOG_ERROR diff --git a/redfish-core/lib/metric_report_definition.hpp b/redfish-core/lib/metric_report_definition.hpp index cb38633fb0..1461fd84e7 100644 --- a/redfish-core/lib/metric_report_definition.hpp +++ b/redfish-core/lib/metric_report_definition.hpp @@ -6,6 +6,7 @@ #include <app.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <tuple> @@ -23,9 +24,8 @@ using ReadingParameters = inline void fillReportDefinition( const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id, - const std::vector< - std::pair<std::string, std::variant<std::string, bool, uint64_t, - ReadingParameters>>>& ret) + const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& + ret) { asyncResp->res.jsonValue["@odata.type"] = "#MetricReportDefinition.v1_3_0.MetricReportDefinition"; @@ -421,12 +421,11 @@ inline void requestRoutesMetricReportDefinition(App& app) const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& id) { crow::connections::systemBus->async_method_call( - [asyncResp, id]( - const boost::system::error_code ec, - const std::vector<std::pair< - std::string, - std::variant<std::string, bool, uint64_t, - telemetry::ReadingParameters>>>& ret) { + [asyncResp, + id](const boost::system::error_code ec, + const std::vector<std::pair< + std::string, dbus::utility::DbusVariantType>>& + ret) { if (ec.value() == EBADR || ec == boost::system::errc::host_unreachable) { diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp index 9acf5d417a..e7411ac00b 100644 --- a/redfish-core/lib/network_protocol.hpp +++ b/redfish-core/lib/network_protocol.hpp @@ -20,6 +20,7 @@ #include "redfish_util.hpp" #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <utils/json_utils.hpp> #include <utils/stl_utils.hpp> @@ -231,7 +232,7 @@ inline void handleNTPProtocolEnabled( "xyz.openbmc_project.Settings", "/xyz/openbmc_project/time/sync_method", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Time.Synchronization", "TimeSyncMethod", - std::variant<std::string>{timeSyncMethod}); + dbus::utility::DbusVariantType{timeSyncMethod}); } inline void @@ -283,7 +284,7 @@ inline void service, objectPath, "org.freedesktop.DBus.Properties", "Set", interface, "NTPServers", - std::variant<std::vector<std::string>>{ntpServers}); + dbus::utility::DbusVariantType{ntpServers}); } } } @@ -326,7 +327,8 @@ inline void entry.second.begin()->first, entry.first, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Service.Attributes", - "Running", std::variant<bool>{protocolEnabled}); + "Running", + dbus::utility::DbusVariantType{protocolEnabled}); crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec2) { @@ -339,7 +341,8 @@ inline void entry.second.begin()->first, entry.first, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Service.Attributes", - "Enabled", std::variant<bool>{protocolEnabled}); + "Enabled", + dbus::utility::DbusVariantType{protocolEnabled}); } } }, @@ -368,7 +371,7 @@ inline void { crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code errorCode, - const std::variant<std::string>& timeSyncMethod) { + const dbus::utility::DbusVariantType& timeSyncMethod) { if (errorCode) { return; diff --git a/redfish-core/lib/pcie.hpp b/redfish-core/lib/pcie.hpp index 1872c02131..1904c26eb9 100644 --- a/redfish-core/lib/pcie.hpp +++ b/redfish-core/lib/pcie.hpp @@ -18,6 +18,7 @@ #include <app.hpp> #include <boost/system/linux_error.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> namespace redfish @@ -143,76 +144,93 @@ inline void requestRoutesSystemPCIeDevice(App& app) const std::string& device) { - auto getPCIeDeviceCallback = [asyncResp, device]( - const boost::system::error_code - ec, - boost::container::flat_map< - std::string, - std::variant<std::string>>& - pcieDevProperties) { - if (ec) - { - BMCWEB_LOG_DEBUG - << "failed to get PCIe Device properties ec: " - << ec.value() << ": " << ec.message(); - if (ec.value() == - boost::system::linux_error::bad_request_descriptor) + auto getPCIeDeviceCallback = + [asyncResp, + device](const boost::system::error_code ec, + boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>& + pcieDevProperties) { + if (ec) { - messages::resourceNotFound(asyncResp->res, - "PCIeDevice", device); + BMCWEB_LOG_DEBUG + << "failed to get PCIe Device properties ec: " + << ec.value() << ": " << ec.message(); + if (ec.value() == boost::system::linux_error:: + bad_request_descriptor) + { + messages::resourceNotFound( + asyncResp->res, "PCIeDevice", device); + } + else + { + messages::internalError(asyncResp->res); + } + return; } - else + + asyncResp->res.jsonValue = { + {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"}, + {"@odata.id", + "/redfish/v1/Systems/system/PCIeDevices/" + + device}, + {"Name", "PCIe Device"}, + {"Id", device}}; + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Manufacturer"]); + property) { - messages::internalError(asyncResp->res); + asyncResp->res.jsonValue["Manufacturer"] = + *property; } - return; - } - asyncResp->res.jsonValue = { - {"@odata.type", "#PCIeDevice.v1_4_0.PCIeDevice"}, - {"@odata.id", - "/redfish/v1/Systems/system/PCIeDevices/" + device}, - {"Name", "PCIe Device"}, - {"Id", device}}; - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Manufacturer"]); - property) - { - asyncResp->res.jsonValue["Manufacturer"] = *property; - } + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["DeviceType"]); + property) + { + asyncResp->res.jsonValue["DeviceType"] = *property; + } - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["DeviceType"]); - property) - { - asyncResp->res.jsonValue["DeviceType"] = *property; - } + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Manufacturer"]); + property) + { + asyncResp->res.jsonValue["Manufacturer"] = + *property; + } - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["GenerationInUse"]); - property) - { - std::optional<std::string> generationInUse = - redfishPcieGenerationFromDbus(*property); - if (!generationInUse) + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["DeviceType"]); + property) { - messages::internalError(asyncResp->res); - return; + asyncResp->res.jsonValue["DeviceType"] = *property; } - if (*generationInUse == "") + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["GenerationInUse"]); + property) { - // unknown, no need to handle - return; + std::optional<std::string> generationInUse = + redfishPcieGenerationFromDbus(*property); + if (!generationInUse) + { + messages::internalError(asyncResp->res); + return; + } + if (*generationInUse == "") + { + // unknown, no need to handle + return; + } + asyncResp->res + .jsonValue["PCIeInterface"]["PcieType"] = + *generationInUse; } - asyncResp->res.jsonValue["PCIeInterface"]["PcieType"] = - *generationInUse; - } - asyncResp->res.jsonValue["PCIeFunctions"] = { - {"@odata.id", - "/redfish/v1/Systems/system/PCIeDevices/" + device + - "/PCIeFunctions"}}; - }; + asyncResp->res.jsonValue["PCIeFunctions"] = { + {"@odata.id", + "/redfish/v1/Systems/system/PCIeDevices/" + + device + "/PCIeFunctions"}}; + }; std::string escapedPath = std::string(pciePath) + "/" + device; dbus::utility::escapePathForDbus(escapedPath); crow::connections::systemBus->async_method_call( @@ -250,7 +268,8 @@ inline void requestRoutesSystemPCIeFunctionCollection(App& app) ec, boost::container::flat_map< std::string, - std::variant<std::string>>& + dbus::utility:: + DbusVariantType>& pcieDevProperties) { if (ec) { @@ -317,116 +336,121 @@ inline void requestRoutesSystemPCIeFunction(App& app) bmcweb::AsyncResp>& asyncResp, const std::string& device, const std::string& function) { - auto getPCIeDeviceCallback = [asyncResp, device, function]( - const boost::system::error_code ec, - boost::container::flat_map< - std::string, - std::variant<std::string>>& - pcieDevProperties) { - if (ec) - { - BMCWEB_LOG_DEBUG - << "failed to get PCIe Device properties ec: " - << ec.value() << ": " << ec.message(); - if (ec.value() == - boost::system::linux_error::bad_request_descriptor) + auto getPCIeDeviceCallback = + [asyncResp, device, function]( + const boost::system::error_code ec, + boost::container::flat_map<std::string, + dbus::utility::DbusVariantType>& + pcieDevProperties) { + if (ec) + { + BMCWEB_LOG_DEBUG + << "failed to get PCIe Device properties ec: " + << ec.value() << ": " << ec.message(); + if (ec.value() == + boost::system::linux_error::bad_request_descriptor) + { + messages::resourceNotFound(asyncResp->res, + "PCIeDevice", device); + } + else + { + messages::internalError(asyncResp->res); + } + return; + } + + // Check if this function exists by looking for a device ID + std::string devIDProperty = + "Function" + function + "DeviceId"; + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties[devIDProperty]); + property && property->empty()) + { + messages::resourceNotFound(asyncResp->res, + "PCIeFunction", function); + return; + } + + asyncResp->res.jsonValue = { + {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"}, + {"@odata.id", + "/redfish/v1/Systems/system/PCIeDevices/" + device + + "/PCIeFunctions/" + function}, + {"Name", "PCIe Function"}, + {"Id", function}, + {"FunctionId", std::stoi(function)}, + {"Links", + {{"PCIeDevice", + {{"@odata.id", + "/redfish/v1/Systems/system/PCIeDevices/" + + device}}}}}}; + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "DeviceId"]); + property) { - messages::resourceNotFound(asyncResp->res, "PCIeDevice", - device); + asyncResp->res.jsonValue["DeviceId"] = *property; } - else + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "VendorId"]); + property) { - messages::internalError(asyncResp->res); + asyncResp->res.jsonValue["VendorId"] = *property; } - return; - } - - // Check if this function exists by looking for a device ID - std::string devIDProperty = "Function" + function + "DeviceId"; - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties[devIDProperty]); - property && property->empty()) - { - messages::resourceNotFound(asyncResp->res, "PCIeFunction", - function); - return; - } - asyncResp->res.jsonValue = { - {"@odata.type", "#PCIeFunction.v1_2_0.PCIeFunction"}, - {"@odata.id", "/redfish/v1/Systems/system/PCIeDevices/" + - device + "/PCIeFunctions/" + function}, - {"Name", "PCIe Function"}, - {"Id", function}, - {"FunctionId", std::stoi(function)}, - {"Links", - {{"PCIeDevice", - {{"@odata.id", - "/redfish/v1/Systems/system/PCIeDevices/" + - device}}}}}}; - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + "DeviceId"]); - property) - { - asyncResp->res.jsonValue["DeviceId"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + "VendorId"]); - property) - { - asyncResp->res.jsonValue["VendorId"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "FunctionType"]); - property) - { - asyncResp->res.jsonValue["FunctionType"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "DeviceClass"]); - property) - { - asyncResp->res.jsonValue["DeviceClass"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "ClassCode"]); - property) - { - asyncResp->res.jsonValue["ClassCode"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "RevisionId"]); - property) - { - asyncResp->res.jsonValue["RevisionId"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "SubsystemId"]); - property) - { - asyncResp->res.jsonValue["SubsystemId"] = *property; - } - - if (std::string* property = std::get_if<std::string>( - &pcieDevProperties["Function" + function + - "SubsystemVendorId"]); - property) - { - asyncResp->res.jsonValue["SubsystemVendorId"] = *property; - } - }; + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "FunctionType"]); + property) + { + asyncResp->res.jsonValue["FunctionType"] = *property; + } + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "DeviceClass"]); + property) + { + asyncResp->res.jsonValue["DeviceClass"] = *property; + } + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "ClassCode"]); + property) + { + asyncResp->res.jsonValue["ClassCode"] = *property; + } + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "RevisionId"]); + property) + { + asyncResp->res.jsonValue["RevisionId"] = *property; + } + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "SubsystemId"]); + property) + { + asyncResp->res.jsonValue["SubsystemId"] = *property; + } + + if (std::string* property = std::get_if<std::string>( + &pcieDevProperties["Function" + function + + "SubsystemVendorId"]); + property) + { + asyncResp->res.jsonValue["SubsystemVendorId"] = + *property; + } + }; std::string escapedPath = std::string(pciePath) + "/" + device; dbus::utility::escapePathForDbus(escapedPath); crow::connections::systemBus->async_method_call( diff --git a/redfish-core/lib/power.hpp b/redfish-core/lib/power.hpp index d7fb7dd9be..dea6be3dc1 100644 --- a/redfish-core/lib/power.hpp +++ b/redfish-core/lib/power.hpp @@ -19,6 +19,7 @@ #include "sensors.hpp" #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> namespace redfish @@ -70,7 +71,8 @@ inline void setPowerCapOverride( } auto valueHandler = [value, sensorsAsyncResp]( const boost::system::error_code ec, - const SensorVariant& powerCapEnable) { + const dbus::utility::DbusVariantType& + powerCapEnable) { if (ec) { messages::internalError(sensorsAsyncResp->asyncResp->res); @@ -112,7 +114,7 @@ inline void setPowerCapOverride( "/xyz/openbmc_project/control/host0/power_cap", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.Cap", "PowerCap", - std::variant<uint32_t>(*value)); + dbus::utility::DbusVariantType(*value)); }; crow::connections::systemBus->async_method_call( std::move(valueHandler), "xyz.openbmc_project.Settings", @@ -127,80 +129,81 @@ inline void requestRoutesPower(App& app) BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/") .privileges(redfish::privileges::getPower) - .methods(boost::beast::http::verb::get)( - [](const crow::Request&, - const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, - const std::string& chassisName) { - asyncResp->res.jsonValue["PowerControl"] = - nlohmann::json::array(); - - auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( - asyncResp, chassisName, - sensors::dbus::paths.at(sensors::node::power), - sensors::node::power); + .methods( + boost::beast::http::verb::get)([](const crow::Request&, + const std::shared_ptr< + bmcweb::AsyncResp>& asyncResp, + const std::string& chassisName) { + asyncResp->res.jsonValue["PowerControl"] = nlohmann::json::array(); + + auto sensorAsyncResp = std::make_shared<SensorsAsyncResp>( + asyncResp, chassisName, + sensors::dbus::paths.at(sensors::node::power), + sensors::node::power); + + getChassisData(sensorAsyncResp); + + // This callback verifies that the power limit is only provided + // for the chassis that implements the Chassis inventory item. + // This prevents things like power supplies providing the + // chassis power limit + auto chassisHandler = [sensorAsyncResp]( + const boost::system::error_code e, + const std::vector<std::string>& + chassisPaths) { + if (e) + { + BMCWEB_LOG_ERROR + << "Power Limit GetSubTreePaths handler Dbus error " + << e; + return; + } - getChassisData(sensorAsyncResp); - - // This callback verifies that the power limit is only provided - // for the chassis that implements the Chassis inventory item. - // This prevents things like power supplies providing the - // chassis power limit - auto chassisHandler = [sensorAsyncResp]( - const boost::system::error_code e, - const std::vector<std::string>& - chassisPaths) { - if (e) + bool found = false; + for (const std::string& chassis : chassisPaths) + { + size_t len = std::string::npos; + size_t lastPos = chassis.rfind('/'); + if (lastPos == std::string::npos) { - BMCWEB_LOG_ERROR - << "Power Limit GetSubTreePaths handler Dbus error " - << e; - return; + continue; } - bool found = false; - for (const std::string& chassis : chassisPaths) + if (lastPos == chassis.size() - 1) { - size_t len = std::string::npos; - size_t lastPos = chassis.rfind('/'); + size_t end = lastPos; + lastPos = chassis.rfind('/', lastPos - 1); if (lastPos == std::string::npos) { continue; } - if (lastPos == chassis.size() - 1) - { - size_t end = lastPos; - lastPos = chassis.rfind('/', lastPos - 1); - if (lastPos == std::string::npos) - { - continue; - } - - len = end - (lastPos + 1); - } - - std::string interfaceChassisName = - chassis.substr(lastPos + 1, len); - if (!interfaceChassisName.compare( - sensorAsyncResp->chassisId)) - { - found = true; - break; - } + len = end - (lastPos + 1); } - if (!found) + std::string interfaceChassisName = + chassis.substr(lastPos + 1, len); + if (!interfaceChassisName.compare( + sensorAsyncResp->chassisId)) { - BMCWEB_LOG_DEBUG << "Power Limit not present for " - << sensorAsyncResp->chassisId; - return; + found = true; + break; } + } - auto valueHandler = [sensorAsyncResp]( - const boost::system::error_code ec, - const std::vector<std::pair< - std::string, SensorVariant>>& - properties) { + if (!found) + { + BMCWEB_LOG_DEBUG << "Power Limit not present for " + << sensorAsyncResp->chassisId; + return; + } + + auto valueHandler = + [sensorAsyncResp]( + const boost::system::error_code ec, + const std::vector<std::pair< + std::string, dbus::utility::DbusVariantType>>& + properties) { if (ec) { messages::internalError( @@ -235,7 +238,8 @@ inline void requestRoutesPower(App& app) double powerCap = 0.0; int64_t scale = 0; - for (const std::pair<std::string, SensorVariant>& + for (const std::pair<std::string, + dbus::utility::DbusVariantType>& property : properties) { if (!property.first.compare("Scale")) @@ -298,23 +302,22 @@ inline void requestRoutesPower(App& app) } }; - crow::connections::systemBus->async_method_call( - std::move(valueHandler), "xyz.openbmc_project.Settings", - "/xyz/openbmc_project/control/host0/power_cap", - "org.freedesktop.DBus.Properties", "GetAll", - "xyz.openbmc_project.Control.Power.Cap"); - }; - crow::connections::systemBus->async_method_call( - std::move(chassisHandler), - "xyz.openbmc_project.ObjectMapper", - "/xyz/openbmc_project/object_mapper", - "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", - "/xyz/openbmc_project/inventory", 0, - std::array<const char*, 2>{ - "xyz.openbmc_project.Inventory.Item.Board", - "xyz.openbmc_project.Inventory.Item.Chassis"}); - }); + std::move(valueHandler), "xyz.openbmc_project.Settings", + "/xyz/openbmc_project/control/host0/power_cap", + "org.freedesktop.DBus.Properties", "GetAll", + "xyz.openbmc_project.Control.Power.Cap"); + }; + + crow::connections::systemBus->async_method_call( + std::move(chassisHandler), "xyz.openbmc_project.ObjectMapper", + "/xyz/openbmc_project/object_mapper", + "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", + "/xyz/openbmc_project/inventory", 0, + std::array<const char*, 2>{ + "xyz.openbmc_project.Inventory.Item.Board", + "xyz.openbmc_project.Inventory.Item.Chassis"}); + }); BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Power/") .privileges(redfish::privileges::patchPower) diff --git a/redfish-core/lib/processor.hpp b/redfish-core/lib/processor.hpp index e510768442..df0d0bb65f 100644 --- a/redfish-core/lib/processor.hpp +++ b/redfish-core/lib/processor.hpp @@ -19,6 +19,7 @@ #include <app.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <sdbusplus/message/native_types.hpp> #include <sdbusplus/utility/dedup_variant.hpp> @@ -59,9 +60,9 @@ inline void getProcessorUUID(std::shared_ptr<bmcweb::AsyncResp> aResp, { BMCWEB_LOG_DEBUG << "Get Processor UUID"; crow::connections::systemBus->async_method_call( - [objPath, - aResp{std::move(aResp)}](const boost::system::error_code ec, - const std::variant<std::string>& property) { + [objPath, aResp{std::move(aResp)}]( + const boost::system::error_code ec, + const dbus::utility::DbusVariantType& property) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; @@ -303,8 +304,7 @@ inline void getCpuAssetData(std::shared_ptr<bmcweb::AsyncResp> aResp, [objPath, aResp{std::move(aResp)}]( const boost::system::error_code ec, const boost::container::flat_map< - std::string, std::variant<std::string, uint32_t, uint16_t, - bool>>& properties) { + std::string, dbus::utility::DbusVariantType>& properties) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; @@ -395,8 +395,7 @@ inline void getCpuRevisionData(std::shared_ptr<bmcweb::AsyncResp> aResp, [objPath, aResp{std::move(aResp)}]( const boost::system::error_code ec, const boost::container::flat_map< - std::string, std::variant<std::string, uint32_t, uint16_t, - bool>>& properties) { + std::string, dbus::utility::DbusVariantType>& properties) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; @@ -432,8 +431,7 @@ inline void getAcceleratorDataByService( [acclrtrId, aResp{std::move(aResp)}]( const boost::system::error_code ec, const boost::container::flat_map< - std::string, std::variant<std::string, uint32_t, uint16_t, - bool>>& properties) { + std::string, dbus::utility::DbusVariantType>& properties) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; @@ -486,10 +484,8 @@ using BaseSpeedPrioritySettingsProperty = std::vector<std::tuple<uint32_t, std::vector<uint32_t>>>; // uint32_t and size_t may or may not be the same type, requiring a dedup'd // variant -using OperatingConfigProperties = std::vector<std::pair< - std::string, - sdbusplus::utility::dedup_variant_t<uint32_t, size_t, TurboProfileProperty, - BaseSpeedPrioritySettingsProperty>>>; +using OperatingConfigProperties = + std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>; /** * Fill out the HighSpeedCoreIDs in a Processor resource from the given @@ -551,10 +547,8 @@ inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, crow::connections::systemBus->async_method_call( [aResp, cpuId, service]( const boost::system::error_code ec, - const std::vector< - std::pair<std::string, - std::variant<sdbusplus::message::object_path, bool>>>& - properties) { + const std::vector<std::pair< + std::string, dbus::utility::DbusVariantType>>& properties) { if (ec) { BMCWEB_LOG_WARNING << "D-Bus error: " << ec << ", " @@ -604,8 +598,7 @@ inline void getCpuConfigData(const std::shared_ptr<bmcweb::AsyncResp>& aResp, crow::connections::systemBus->async_method_call( [aResp]( const boost::system::error_code ec, - const std::variant< - BaseSpeedPrioritySettingsProperty>& property) { + const dbus::utility::DbusVariantType& property) { if (ec) { BMCWEB_LOG_WARNING @@ -655,9 +648,9 @@ inline void getCpuLocationCode(std::shared_ptr<bmcweb::AsyncResp> aResp, { BMCWEB_LOG_DEBUG << "Get Cpu Location Data"; crow::connections::systemBus->async_method_call( - [objPath, - aResp{std::move(aResp)}](const boost::system::error_code ec, - const std::variant<std::string>& property) { + [objPath, aResp{std::move(aResp)}]( + const boost::system::error_code ec, + const dbus::utility::DbusVariantType& property) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error"; @@ -697,7 +690,7 @@ inline void getCpuUniqueId(const std::shared_ptr<bmcweb::AsyncResp>& aResp, BMCWEB_LOG_DEBUG << "Get CPU UniqueIdentifier"; crow::connections::systemBus->async_method_call( [aResp](boost::system::error_code ec, - const std::variant<std::string>& property) { + const dbus::utility::DbusVariantType& property) { const std::string* id = std::get_if<std::string>(&property); if (ec || id == nullptr) { @@ -1090,8 +1083,7 @@ inline void patchAppliedOperatingConfig( }, *controlService, cpuObjectPath, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Processor.CurrentOperatingConfig", - "AppliedConfig", - std::variant<sdbusplus::message::object_path>(std::move(configPath))); + "AppliedConfig", dbus::utility::DbusVariantType(std::move(configPath))); } inline void requestRoutesOperatingConfigCollection(App& app) diff --git a/redfish-core/lib/redfish_util.hpp b/redfish-core/lib/redfish_util.hpp index 7345f01a10..c0835b3563 100644 --- a/redfish-core/lib/redfish_util.hpp +++ b/redfish-core/lib/redfish_util.hpp @@ -16,6 +16,7 @@ #pragma once #ifndef BMCWEB_ENABLE_REDFISH_ONE_CHASSIS +#include <dbus_utility.hpp> namespace redfish { @@ -172,8 +173,7 @@ void getPortNumber(const std::string& socketPath, CallbackFunc&& callback) crow::connections::systemBus->async_method_call( [callback{std::move(callback)}]( const boost::system::error_code ec, - const std::variant< - std::vector<std::tuple<std::string, std::string>>>& resp) { + const dbus::utility::DbusVariantType& resp) { if (ec) { BMCWEB_LOG_ERROR << ec; diff --git a/redfish-core/lib/roles.hpp b/redfish-core/lib/roles.hpp index 8f14b2e3d5..5aa1a22bfd 100644 --- a/redfish-core/lib/roles.hpp +++ b/redfish-core/lib/roles.hpp @@ -16,6 +16,7 @@ #pragma once #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <variant> @@ -114,9 +115,8 @@ inline void requestRoutesRoleCollection(App& app) {"Description", "BMC User Roles"}}; crow::connections::systemBus->async_method_call( - [asyncResp]( - const boost::system::error_code ec, - const std::variant<std::vector<std::string>>& resp) { + [asyncResp](const boost::system::error_code ec, + const dbus::utility::DbusVariantType& resp) { if (ec) { messages::internalError(asyncResp->res); diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp index eba0652180..2f04c25058 100644 --- a/redfish-core/lib/sensors.hpp +++ b/redfish-core/lib/sensors.hpp @@ -21,6 +21,7 @@ #include <boost/container/flat_map.hpp> #include <boost/range/algorithm/replace_copy_if.hpp> #include <dbus_singleton.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <utils/json_utils.hpp> @@ -35,13 +36,11 @@ using GetSubTreeType = std::vector< std::pair<std::string, std::vector<std::pair<std::string, std::vector<std::string>>>>>; -using SensorVariant = - std::variant<int64_t, double, uint32_t, bool, std::string>; - using ManagedObjectsVectorType = std::vector<std::pair< sdbusplus::message::object_path, boost::container::flat_map< - std::string, boost::container::flat_map<std::string, SensorVariant>>>>; + std::string, boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>>>>; namespace sensors { @@ -596,8 +595,7 @@ void getChassis(const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, crow::connections::systemBus->async_method_call( [sensorsAsyncResp, callback{std::move(callback)}]( const boost::system::error_code& e, - const std::variant<std::vector<std::string>>& - variantEndpoints) { + const dbus::utility::DbusVariantType& variantEndpoints) { if (e) { if (e.value() != EBADR) @@ -742,7 +740,8 @@ inline std::string getState(const InventoryItem* inventoryItem) inline std::string getHealth( nlohmann::json& sensorJson, const boost::container::flat_map< - std::string, boost::container::flat_map<std::string, SensorVariant>>& + std::string, boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>>& interfacesDict, const InventoryItem* inventoryItem) { @@ -895,7 +894,8 @@ inline void objectInterfacesToJson( const std::string& sensorName, const std::string& sensorType, const std::shared_ptr<SensorsAsyncResp>& sensorsAsyncResp, const boost::container::flat_map< - std::string, boost::container::flat_map<std::string, SensorVariant>>& + std::string, boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>>& interfacesDict, nlohmann::json& sensorJson, InventoryItem* inventoryItem) { @@ -1101,7 +1101,8 @@ inline void objectInterfacesToJson( auto thisValueIt = interfaceProperties->second.find(std::get<1>(p)); if (thisValueIt != interfaceProperties->second.end()) { - const SensorVariant& valueVariant = thisValueIt->second; + const dbus::utility::DbusVariantType& valueVariant = + thisValueIt->second; // The property we want to set may be nested json, so use // a json_pointer for easy indexing into the json structure. @@ -1179,7 +1180,7 @@ inline void populateFanRedundancy( crow::connections::systemBus->async_method_call( [path, owner, sensorsAsyncResp](const boost::system::error_code e, - std::variant<std::vector<std::string>> + const dbus::utility::DbusVariantType& variantEndpoints) { if (e) { @@ -1215,9 +1216,7 @@ inline void populateFanRedundancy( const boost::system::error_code& err, const boost::container::flat_map< std::string, - std::variant<uint8_t, - std::vector<std::string>, - std::string>>& ret) { + dbus::utility::DbusVariantType>& ret) { if (err) { return; // don't have to have this @@ -1511,7 +1510,8 @@ inline void addInventoryItem( inline void storeInventoryItemData( InventoryItem& inventoryItem, const boost::container::flat_map< - std::string, boost::container::flat_map<std::string, SensorVariant>>& + std::string, boost::container::flat_map< + std::string, dbus::utility::DbusVariantType>>& interfacesDict) { // Get properties from Inventory.Item interface @@ -2013,61 +2013,61 @@ void getInventoryLedData( const std::string& ledPath = (*it).first; const std::string& ledConnection = (*it).second; // Response handler for Get State property - auto respHandler = - [sensorsAsyncResp, inventoryItems, ledConnections, ledPath, - callback{std::move(callback)}, - ledConnectionsIndex](const boost::system::error_code ec, - const std::variant<std::string>& ledState) { - BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter"; - if (ec) - { - BMCWEB_LOG_ERROR - << "getInventoryLedData respHandler DBus error " << ec; - messages::internalError(sensorsAsyncResp->asyncResp->res); - return; - } + auto respHandler = [sensorsAsyncResp, inventoryItems, ledConnections, + ledPath, callback{std::move(callback)}, + ledConnectionsIndex]( + const boost::system::error_code ec, + const dbus::utility::DbusVariantType& ledState) { + BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler enter"; + if (ec) + { + BMCWEB_LOG_ERROR + << "getInventoryLedData respHandler DBus error " << ec; + messages::internalError(sensorsAsyncResp->asyncResp->res); + return; + } - const std::string* state = std::get_if<std::string>(&ledState); - if (state != nullptr) + const std::string* state = std::get_if<std::string>(&ledState); + if (state != nullptr) + { + BMCWEB_LOG_DEBUG << "Led state: " << *state; + // Find inventory item with this LED object path + InventoryItem* inventoryItem = + findInventoryItemForLed(*inventoryItems, ledPath); + if (inventoryItem != nullptr) { - BMCWEB_LOG_DEBUG << "Led state: " << *state; - // Find inventory item with this LED object path - InventoryItem* inventoryItem = - findInventoryItemForLed(*inventoryItems, ledPath); - if (inventoryItem != nullptr) + // Store LED state in InventoryItem + if (boost::ends_with(*state, "On")) { - // Store LED state in InventoryItem - if (boost::ends_with(*state, "On")) - { - inventoryItem->ledState = LedState::ON; - } - else if (boost::ends_with(*state, "Blink")) - { - inventoryItem->ledState = LedState::BLINK; - } - else if (boost::ends_with(*state, "Off")) - { - inventoryItem->ledState = LedState::OFF; - } - else - { - inventoryItem->ledState = LedState::UNKNOWN; - } + inventoryItem->ledState = LedState::ON; + } + else if (boost::ends_with(*state, "Blink")) + { + inventoryItem->ledState = LedState::BLINK; + } + else if (boost::ends_with(*state, "Off")) + { + inventoryItem->ledState = LedState::OFF; + } + else + { + inventoryItem->ledState = LedState::UNKNOWN; } } - else - { - BMCWEB_LOG_DEBUG << "Failed to find State data for LED: " - << ledPath; - } + } + else + { + BMCWEB_LOG_DEBUG << "Failed to find State data for LED: " + << ledPath; + } - // Recurse to get LED data from next connection - getInventoryLedData(sensorsAsyncResp, inventoryItems, - ledConnections, std::move(callback), - ledConnectionsIndex + 1); + // Recurse to get LED data from next connection + getInventoryLedData(sensorsAsyncResp, inventoryItems, + ledConnections, std::move(callback), + ledConnectionsIndex + 1); - BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit"; - }; + BMCWEB_LOG_DEBUG << "getInventoryLedData respHandler exit"; + }; // Get the State property for the current LED crow::connections::systemBus->async_method_call( @@ -2213,7 +2213,8 @@ void getPowerSupplyAttributesData( auto respHandler = [sensorsAsyncResp, inventoryItems, callback{std::move(callback)}]( const boost::system::error_code ec, - const std::variant<uint32_t>& deratingFactor) { + const dbus::utility::DbusVariantType& + deratingFactor) { BMCWEB_LOG_DEBUG << "getPowerSupplyAttributesData respHandler enter"; if (ec) { @@ -2942,7 +2943,7 @@ inline void setSensorsOverride( }, item.second, item.first, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Sensor.Value", "Value", - std::variant<double>(iterator->second.first)); + dbus::utility::DbusVariantType(iterator->second.first)); } }; // Get object with connection for the given sensor name diff --git a/redfish-core/lib/storage.hpp b/redfish-core/lib/storage.hpp index b83e13f2d8..4ad3040bcc 100644 --- a/redfish-core/lib/storage.hpp +++ b/redfish-core/lib/storage.hpp @@ -19,6 +19,7 @@ #include "openbmc_dbus_rest.hpp" #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> namespace redfish @@ -159,9 +160,9 @@ inline void requestRoutesStorage(App& app) storageController["Status"]["State"] = "Enabled"; crow::connections::systemBus->async_method_call( - [asyncResp, - index](const boost::system::error_code ec2, - const std::variant<bool> present) { + [asyncResp, index]( + const boost::system::error_code ec2, + const dbus::utility::DbusVariantType present) { // this interface isn't necessary, only check it // if we get a good return if (ec2) @@ -192,9 +193,9 @@ inline void requestRoutesStorage(App& app) crow::connections::systemBus->async_method_call( [asyncResp, index]( const boost::system::error_code ec2, - const std::vector<std::pair< - std::string, - std::variant<bool, std::string, uint64_t>>>& + const std::vector< + std::pair<std::string, + dbus::utility::DbusVariantType>>& propertiesList) { if (ec2) { @@ -203,9 +204,8 @@ inline void requestRoutesStorage(App& app) } for (const std::pair< std::string, - std::variant<bool, std::string, - uint64_t>>& property : - propertiesList) + dbus::utility::DbusVariantType>& + property : propertiesList) { // Store DBus properties that are also // Redfish properties with same name and a @@ -268,18 +268,16 @@ inline void getDriveAsset(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const std::string& path) { crow::connections::systemBus->async_method_call( - [asyncResp]( - const boost::system::error_code ec, - const std::vector<std::pair< - std::string, std::variant<bool, std::string, uint64_t>>>& - propertiesList) { + [asyncResp](const boost::system::error_code ec, + const std::vector< + std::pair<std::string, dbus::utility::DbusVariantType>>& + propertiesList) { if (ec) { // this interface isn't necessary return; } - for (const std::pair<std::string, - std::variant<bool, std::string, uint64_t>>& + for (const std::pair<std::string, dbus::utility::DbusVariantType>& property : propertiesList) { // Store DBus properties that are also @@ -313,7 +311,7 @@ inline void getDrivePresent(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, { crow::connections::systemBus->async_method_call( [asyncResp, path](const boost::system::error_code ec, - const std::variant<bool> present) { + const dbus::utility::DbusVariantType present) { // this interface isn't necessary, only check it if // we get a good return if (ec) @@ -343,7 +341,7 @@ inline void getDriveState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, { crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec, - const std::variant<bool> rebuilding) { + const dbus::utility::DbusVariantType rebuilding) { // this interface isn't necessary, only check it // if we get a good return if (ec) diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp index 8e1a6f4079..b3094df431 100644 --- a/redfish-core/lib/systems.hpp +++ b/redfish-core/lib/systems.hpp @@ -22,6 +22,7 @@ #include <app.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <utils/fw_utils.hpp> #include <utils/json_utils.hpp> @@ -41,7 +42,7 @@ namespace redfish */ inline void updateDimmProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, - const std::variant<bool>& dimmState) + const dbus::utility::DbusVariantType& dimmState) { const bool* isDimmFunctional = std::get_if<bool>(&dimmState); if (isDimmFunctional == nullptr) @@ -74,9 +75,9 @@ inline void * * @return None. */ -inline void - modifyCpuPresenceState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, - const std::variant<bool>& cpuPresenceState) +inline void modifyCpuPresenceState( + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const dbus::utility::DbusVariantType& cpuPresenceState) { const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); @@ -110,9 +111,9 @@ inline void * * @return None. */ -inline void - modifyCpuFunctionalState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, - const std::variant<bool>& cpuFunctionalState) +inline void modifyCpuFunctionalState( + const std::shared_ptr<bmcweb::AsyncResp>& aResp, + const dbus::utility::DbusVariantType& cpuFunctionalState) { const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); @@ -142,8 +143,7 @@ inline void inline void getProcessorProperties( const std::shared_ptr<bmcweb::AsyncResp>& aResp, const std::string& service, const std::string& path, - const std::vector<std::pair< - std::string, std::variant<std::string, uint64_t, uint32_t, uint16_t>>>& + const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& properties) { @@ -151,7 +151,7 @@ inline void getProcessorProperties( auto getCpuPresenceState = [aResp](const boost::system::error_code ec3, - const std::variant<bool>& cpuPresenceCheck) { + const dbus::utility::DbusVariantType& cpuPresenceCheck) { if (ec3) { BMCWEB_LOG_ERROR << "DBUS response error " << ec3; @@ -162,7 +162,7 @@ inline void getProcessorProperties( auto getCpuFunctionalState = [aResp](const boost::system::error_code ec3, - const std::variant<bool>& cpuFunctionalCheck) { + const dbus::utility::DbusVariantType& cpuFunctionalCheck) { if (ec3) { BMCWEB_LOG_ERROR << "DBUS response error " << ec3; @@ -236,8 +236,7 @@ inline void getProcessorSummary(const std::shared_ptr<bmcweb::AsyncResp>& aResp, [aResp, service, path](const boost::system::error_code ec2, const std::vector<std::pair< - std::string, std::variant<std::string, uint64_t, uint32_t, - uint16_t>>>& properties) { + std::string, dbus::utility::DbusVariantType>>& properties) { if (ec2) { BMCWEB_LOG_ERROR << "DBUS response error " << ec2; @@ -317,8 +316,9 @@ inline void crow::connections::systemBus->async_method_call( [aResp, service{connection.first}, path](const boost::system::error_code ec2, - const std::vector< - std::pair<std::string, VariantType>>& + const std::vector<std::pair< + std::string, + dbus::utility::DbusVariantType>>& properties) { if (ec2) { @@ -333,8 +333,10 @@ inline void if (properties.size() > 0) { - for (const std::pair<std::string, - VariantType>& + for (const std::pair< + std::string, + dbus::utility:: + DbusVariantType>& property : properties) { if (property.first != @@ -379,8 +381,9 @@ inline void [aResp]( const boost::system::error_code ec3, - const std::variant<bool>& - dimmState) { + const dbus::utility:: + DbusVariantType& + dimmState) { if (ec3) { BMCWEB_LOG_ERROR @@ -423,11 +426,11 @@ inline void BMCWEB_LOG_DEBUG << "Found UUID, now get its properties."; crow::connections::systemBus->async_method_call( - [aResp]( - const boost::system::error_code ec3, - const std::vector< - std::pair<std::string, VariantType>>& - properties) { + [aResp](const boost::system::error_code ec3, + const std::vector<std::pair< + std::string, + dbus::utility::DbusVariantType>>& + properties) { if (ec3) { BMCWEB_LOG_DEBUG @@ -438,8 +441,9 @@ inline void BMCWEB_LOG_DEBUG << "Got " << properties.size() << " UUID properties."; - for (const std::pair<std::string, - VariantType>& + for (const std::pair< + std::string, + dbus::utility::DbusVariantType>& property : properties) { if (property.first == "UUID") @@ -474,11 +478,11 @@ inline void "xyz.openbmc_project.Inventory.Item.System") { crow::connections::systemBus->async_method_call( - [aResp]( - const boost::system::error_code ec2, - const std::vector< - std::pair<std::string, VariantType>>& - propertiesList) { + [aResp](const boost::system::error_code ec2, + const std::vector<std::pair< + std::string, + dbus::utility::DbusVariantType>>& + propertiesList) { if (ec2) { // doesn't have to include this @@ -488,8 +492,9 @@ inline void BMCWEB_LOG_DEBUG << "Got " << propertiesList.size() << " properties for system"; - for (const std::pair<std::string, - VariantType>& + for (const std::pair< + std::string, + dbus::utility::DbusVariantType>& property : propertiesList) { const std::string& propertyName = @@ -522,9 +527,9 @@ inline void "xyz.openbmc_project.Inventory.Decorator.Asset"); crow::connections::systemBus->async_method_call( - [aResp]( - const boost::system::error_code ec2, - const std::variant<std::string>& property) { + [aResp](const boost::system::error_code ec2, + const dbus::utility::DbusVariantType& + property) { if (ec2) { // doesn't have to include this @@ -574,7 +579,7 @@ inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) BMCWEB_LOG_DEBUG << "Get host information."; crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& hostState) { + const dbus::utility::DbusVariantType& hostState) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -781,7 +786,7 @@ inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& aResp) { crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& bootProgress) { + const dbus::utility::DbusVariantType& bootProgress) { if (ec) { // BootProgress is an optional object so just do nothing if @@ -884,7 +889,7 @@ inline void getBootOverrideType(const std::shared_ptr<bmcweb::AsyncResp>& aResp) { crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& bootType) { + const dbus::utility::DbusVariantType& bootType) { if (ec) { // not an error, don't have to have the interface @@ -934,7 +939,7 @@ inline void getBootOverrideMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) { crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& bootMode) { + const dbus::utility::DbusVariantType& bootMode) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -988,7 +993,7 @@ inline void { crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& bootSource) { + const dbus::utility::DbusVariantType& bootSource) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -1047,7 +1052,7 @@ inline void // property to set a correct value for the "BootSourceOverrideEnabled" crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<bool>& oneTime) { + const dbus::utility::DbusVariantType& oneTime) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -1095,7 +1100,7 @@ inline void { crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<bool>& bootOverrideEnable) { + const dbus::utility::DbusVariantType& bootOverrideEnable) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -1154,7 +1159,7 @@ inline void getLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - std::variant<uint64_t>& lastResetTime) { + dbus::utility::DbusVariantType& lastResetTime) { if (ec) { BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; @@ -1196,7 +1201,7 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - std::variant<bool>& autoRebootEnabled) { + dbus::utility::DbusVariantType& autoRebootEnabled) { if (ec) { BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; @@ -1221,7 +1226,8 @@ inline void getAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp) // attempts are left crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec2, - std::variant<uint32_t>& autoRebootAttemptsLeft) { + dbus::utility::DbusVariantType& + autoRebootAttemptsLeft) { if (ec2) { BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; @@ -1289,7 +1295,7 @@ inline void crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - std::variant<std::string>& policy) { + dbus::utility::DbusVariantType& policy) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -1389,7 +1395,7 @@ inline void getTrustedModuleRequiredToBoot( // Valid TPM Enable object found, now reading the current value crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - std::variant<bool>& tpmRequired) { + dbus::utility::DbusVariantType& tpmRequired) { if (ec) { BMCWEB_LOG_DEBUG @@ -1509,7 +1515,7 @@ inline void setTrustedModuleRequiredToBoot( }, serv, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", - std::variant<bool>(tpmRequired)); + dbus::utility::DbusVariantType(tpmRequired)); }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", @@ -1577,7 +1583,7 @@ inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/boot", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Boot.Type", "BootType", - std::variant<std::string>(bootTypeStr)); + dbus::utility::DbusVariantType(bootTypeStr)); } /** @@ -1641,7 +1647,7 @@ inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/boot", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Object.Enable", "Enabled", - std::variant<bool>(bootOverrideEnable)); + dbus::utility::DbusVariantType(bootOverrideEnable)); if (!bootOverrideEnable) { @@ -1667,7 +1673,7 @@ inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/boot/one_time", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Object.Enable", "Enabled", - std::variant<bool>(!bootOverridePersistent)); + dbus::utility::DbusVariantType(!bootOverridePersistent)); } /** @@ -1720,7 +1726,7 @@ inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/boot", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Boot.Source", "BootSource", - std::variant<std::string>(bootSourceStr)); + dbus::utility::DbusVariantType(bootSourceStr)); crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec) { @@ -1736,7 +1742,7 @@ inline void setBootModeOrSource(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/boot", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Boot.Mode", "BootMode", - std::variant<std::string>(bootModeStr)); + dbus::utility::DbusVariantType(bootModeStr)); } /** @@ -1829,7 +1835,7 @@ inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& aResp, }, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", - std::variant<std::string>(assetTag)); + dbus::utility::DbusVariantType(assetTag)); }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", @@ -1884,7 +1890,7 @@ inline void setAutomaticRetry(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/control/host0/auto_reboot", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", - std::variant<bool>(autoRebootEnabled)); + dbus::utility::DbusVariantType(autoRebootEnabled)); } /** @@ -1933,7 +1939,7 @@ inline void "/xyz/openbmc_project/control/host0/power_restore_policy", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", - std::variant<std::string>(powerRestorPolicy)); + dbus::utility::DbusVariantType(powerRestorPolicy)); } #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE @@ -2110,7 +2116,7 @@ inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp) // Valid Power Mode object found, now read the current value crow::connections::systemBus->async_method_call( [aResp](const boost::system::error_code ec, - const std::variant<std::string>& pmode) { + const dbus::utility::DbusVariantType& pmode) { if (ec) { BMCWEB_LOG_DEBUG @@ -2258,7 +2264,7 @@ inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& aResp, }, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.Mode", "PowerMode", - std::variant<std::string>(powerMode)); + dbus::utility::DbusVariantType(powerMode)); }, "xyz.openbmc_project.ObjectMapper", "/xyz/openbmc_project/object_mapper", @@ -2438,7 +2444,7 @@ inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/watchdog/host0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.State.Watchdog", "ExpireAction", - std::variant<std::string>(wdtTimeOutActStr)); + dbus::utility::DbusVariantType(wdtTimeOutActStr)); } if (wdtEnable) @@ -2456,7 +2462,7 @@ inline void setWDTProperties(const std::shared_ptr<bmcweb::AsyncResp>& aResp, "/xyz/openbmc_project/watchdog/host0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.State.Watchdog", "Enabled", - std::variant<bool>(*wdtEnable)); + dbus::utility::DbusVariantType(*wdtEnable)); } } @@ -2723,7 +2729,7 @@ inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, }, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "Enabled", std::variant<bool>(*ipsEnable)); + "Enabled", dbus::utility::DbusVariantType(*ipsEnable)); } if (ipsEnterUtil) { @@ -2739,7 +2745,7 @@ inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.IdlePowerSaver", "EnterUtilizationPercent", - std::variant<uint8_t>(*ipsEnterUtil)); + dbus::utility::DbusVariantType(*ipsEnterUtil)); } if (ipsEnterTime) { @@ -2756,7 +2762,8 @@ inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, }, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "EnterDwellTime", std::variant<uint64_t>(timeMilliseconds)); + "EnterDwellTime", + dbus::utility::DbusVariantType(timeMilliseconds)); } if (ipsExitUtil) { @@ -2772,7 +2779,7 @@ inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.IdlePowerSaver", "ExitUtilizationPercent", - std::variant<uint8_t>(*ipsExitUtil)); + dbus::utility::DbusVariantType(*ipsExitUtil)); } if (ipsExitTime) { @@ -2789,7 +2796,8 @@ inline void setIdlePowerSaver(const std::shared_ptr<bmcweb::AsyncResp>& aResp, }, service, path, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Control.Power.IdlePowerSaver", - "ExitDwellTime", std::variant<uint64_t>(timeMilliseconds)); + "ExitDwellTime", + dbus::utility::DbusVariantType(timeMilliseconds)); } }, "xyz.openbmc_project.ObjectMapper", @@ -2818,8 +2826,9 @@ inline void requestRoutesSystemsCollection(App& app) asyncResp->res.jsonValue["Name"] = "Computer System Collection"; crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec, - const std::variant<std::string>& /*hostName*/) { + [asyncResp]( + const boost::system::error_code ec, + const dbus::utility::DbusVariantType& /*hostName*/) { nlohmann::json& ifaceArray = asyncResp->res.jsonValue["Members"]; ifaceArray = nlohmann::json::array(); @@ -2965,7 +2974,7 @@ inline void requestRoutesSystemActionsReset(App& app) "/xyz/openbmc_project/state/host0", "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.State.Host", "RequestedHostTransition", - std::variant<std::string>{command}); + dbus::utility::DbusVariantType{command}); } else { @@ -2993,7 +3002,7 @@ inline void requestRoutesSystemActionsReset(App& app) "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", - std::variant<std::string>{command}); + dbus::utility::DbusVariantType{command}); } }); } diff --git a/redfish-core/lib/telemetry_service.hpp b/redfish-core/lib/telemetry_service.hpp index b79a5cd291..c3082d7a01 100644 --- a/redfish-core/lib/telemetry_service.hpp +++ b/redfish-core/lib/telemetry_service.hpp @@ -3,10 +3,9 @@ #include "utils/telemetry_utils.hpp" #include <app.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> -#include <variant> - namespace redfish { @@ -27,9 +26,10 @@ inline void handleTelemetryServiceGet( "/redfish/v1/TelemetryService/Triggers"; crow::connections::systemBus->async_method_call( - [asyncResp](const boost::system::error_code ec, - const std::vector<std::pair< - std::string, std::variant<uint32_t, uint64_t>>>& ret) { + [asyncResp]( + const boost::system::error_code ec, + const std::vector< + std::pair<std::string, dbus::utility::DbusVariantType>>& ret) { if (ec == boost::system::errc::host_unreachable) { asyncResp->res.jsonValue["Status"]["State"] = "Absent"; diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp index f3987d4c74..f5528e1a70 100644 --- a/redfish-core/lib/update_service.hpp +++ b/redfish-core/lib/update_service.hpp @@ -19,11 +19,10 @@ #include <app.hpp> #include <boost/container/flat_map.hpp> +#include <dbus_utility.hpp> #include <registries/privilege_registry.hpp> #include <utils/fw_utils.hpp> -#include <variant> - namespace redfish { @@ -55,7 +54,7 @@ inline static void activateImage(const std::string& objPath, }, service, objPath, "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Software.Activation", "RequestedActivation", - std::variant<std::string>( + dbus::utility::DbusVariantType( "xyz.openbmc_project.Software.Activation.RequestedActivations.Active")); } @@ -68,7 +67,7 @@ static void { std::vector<std::pair< std::string, - std::vector<std::pair<std::string, std::variant<std::string>>>>> + std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>>> interfacesProperties; sdbusplus::message::object_path objPath; @@ -135,7 +134,7 @@ static void std::string iface; boost::container::flat_map< std::string, - std::variant<std::string, uint8_t>> + dbus::utility::DbusVariantType> values; std::string index = @@ -321,7 +320,8 @@ static void monitorForSoftwareAvailable( "arg0='xyz.openbmc_project.Logging.Entry'", [asyncResp, url](sdbusplus::message::message& m) { BMCWEB_LOG_DEBUG << "Error Match fired"; - boost::container::flat_map<std::string, std::variant<std::string>> + boost::container::flat_map<std::string, + dbus::utility::DbusVariantType> values; std::string objName; m.read(objName, values); @@ -544,7 +544,7 @@ inline void requestRoutesUpdateService(App& app) // Get the current ApplyTime value crow::connections::systemBus->async_method_call( [asyncResp](const boost::system::error_code ec, - const std::variant<std::string>& applyTime) { + const dbus::utility::DbusVariantType& applyTime) { if (ec) { BMCWEB_LOG_DEBUG << "DBUS response error " << ec; @@ -654,7 +654,7 @@ inline void requestRoutesUpdateService(App& app) "org.freedesktop.DBus.Properties", "Set", "xyz.openbmc_project.Software.ApplyTime", "RequestedApplyTime", - std::variant<std::string>{applyTimeNewVal}); + dbus::utility::DbusVariantType{applyTimeNewVal}); } } } @@ -825,18 +825,22 @@ inline void requestRoutesSoftwareInventory(App& app) obj.second[0].first); crow::connections::systemBus->async_method_call( - [asyncResp, swId]( - const boost::system::error_code errorCode, - const boost::container::flat_map< - std::string, VariantType>& propertiesList) { + [asyncResp, + swId](const boost::system::error_code errorCode, + const boost::container::flat_map< + std::string, + dbus::utility::DbusVariantType>& + propertiesList) { if (errorCode) { messages::internalError(asyncResp->res); return; } boost::container::flat_map< - std::string, VariantType>::const_iterator - it = propertiesList.find("Purpose"); + std::string, + dbus::utility::DbusVariantType>:: + const_iterator it = + propertiesList.find("Purpose"); if (it == propertiesList.end()) { BMCWEB_LOG_DEBUG diff --git a/redfish-core/lib/virtual_media.hpp b/redfish-core/lib/virtual_media.hpp index 34c1c4b06d..747ca43b04 100644 --- a/redfish-core/lib/virtual_media.hpp +++ b/redfish-core/lib/virtual_media.hpp @@ -671,7 +671,7 @@ inline void doMountVmLegacy(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, constexpr const size_t secretLimit = 1024; std::shared_ptr<SecurePipe> secretPipe; - std::variant<int, SecurePipe::unix_fd> unixFd = -1; + dbus::utility::DbusVariantType unixFd = -1; if (!userName.empty() || !password.empty()) { |