summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Tanous <ed.tanous@intel.com>2018-11-30 22:35:41 +0300
committerEd Tanous <ed.tanous@intel.com>2018-12-10 23:54:40 +0300
commit1b6b96c570fdf7ca5c643f3d0776581656e78070 (patch)
treed96338cf9f95ea763e4fb6570d83e4d1808d3f41
parent789a6a317b51abba38cf064dd5ee2abd051d02bf (diff)
downloadbmcweb-1b6b96c570fdf7ca5c643f3d0776581656e78070.tar.xz
Remove custom version of getPtr
Now that sdbusplus variant supports std::get_if, we can remove our custom, mapbox namespaced implementation that does the same thing. Change-Id: I854c473003e28e41dd45dba08ca683433f1c1774 Signed-off-by: Ed Tanous <ed.tanous@intel.com>
-rw-r--r--include/dbus_singleton.hpp13
-rw-r--r--redfish-core/lib/account_service.hpp8
-rw-r--r--redfish-core/lib/chassis.hpp4
-rw-r--r--redfish-core/lib/cpudimm.hpp12
-rw-r--r--redfish-core/lib/ethernet.hpp41
-rw-r--r--redfish-core/lib/log_services.hpp7
-rw-r--r--redfish-core/lib/managers.hpp33
-rw-r--r--redfish-core/lib/network_protocol.hpp7
-rw-r--r--redfish-core/lib/sensors.hpp8
-rw-r--r--redfish-core/lib/systems.hpp42
-rw-r--r--redfish-core/lib/update_service.hpp10
11 files changed, 97 insertions, 88 deletions
diff --git a/include/dbus_singleton.hpp b/include/dbus_singleton.hpp
index 9fe966f565..63c88b7544 100644
--- a/include/dbus_singleton.hpp
+++ b/include/dbus_singleton.hpp
@@ -1,18 +1,5 @@
#pragma once
-#include <iostream>
#include <sdbusplus/asio/connection.hpp>
-#include <sdbusplus/message/types.hpp>
-#include <type_traits>
-
-namespace mapbox
-{
-template <typename T, typename... Types>
-const T* getPtr(const sdbusplus::message::variant<Types...>& v)
-{
- namespace variant_ns = sdbusplus::message::variant_ns;
- return variant_ns::get_if<std::remove_const_t<T>, Types...>(&v);
-}
-} // namespace mapbox
namespace crow
{
diff --git a/redfish-core/lib/account_service.hpp b/redfish-core/lib/account_service.hpp
index aba69c186a..a93407aa74 100644
--- a/redfish-core/lib/account_service.hpp
+++ b/redfish-core/lib/account_service.hpp
@@ -317,8 +317,8 @@ class ManagerAccount : public Node
if (property.first == "UserEnabled")
{
const bool* userEnabled =
- mapbox::getPtr<const bool>(
- property.second);
+ sdbusplus::message::variant_ns::
+ get_if<bool>(&property.second);
if (userEnabled == nullptr)
{
BMCWEB_LOG_ERROR
@@ -332,8 +332,8 @@ class ManagerAccount : public Node
"UserLockedForFailedAttempt")
{
const bool* userLocked =
- mapbox::getPtr<const bool>(
- property.second);
+ sdbusplus::message::variant_ns::
+ get_if<bool>(&property.second);
if (userLocked == nullptr)
{
BMCWEB_LOG_ERROR
diff --git a/redfish-core/lib/chassis.hpp b/redfish-core/lib/chassis.hpp
index 0f2b92b055..0e1cf1b330 100644
--- a/redfish-core/lib/chassis.hpp
+++ b/redfish-core/lib/chassis.hpp
@@ -198,8 +198,8 @@ class Chassis : public Node
&property : propertiesList)
{
const std::string *value =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (value != nullptr)
{
asyncResp->res.jsonValue[property.first] =
diff --git a/redfish-core/lib/cpudimm.hpp b/redfish-core/lib/cpudimm.hpp
index 6001d63615..ef73150496 100644
--- a/redfish-core/lib/cpudimm.hpp
+++ b/redfish-core/lib/cpudimm.hpp
@@ -93,7 +93,8 @@ void getCpuDataByService(std::shared_ptr<AsyncResp> aResp,
return;
}
const uint16_t *coresCount =
- mapbox::getPtr<const uint16_t>(coresCountProperty->second);
+ sdbusplus::message::variant_ns::get_if<uint16_t>(
+ &coresCountProperty->second);
if (coresCount == nullptr)
{
// Important property not in desired type
@@ -123,7 +124,8 @@ void getCpuDataByService(std::shared_ptr<AsyncResp> aResp,
{
aResp->res.jsonValue["Manufacturer"] = property.second;
const std::string *value =
- mapbox::getPtr<const std::string>(property.second);
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &property.second);
if (value != nullptr)
{
// Otherwise would be unexpected.
@@ -224,7 +226,8 @@ void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
return;
}
const uint32_t *memorySize =
- mapbox::getPtr<const uint32_t>(memorySizeProperty->second);
+ sdbusplus::message::variant_ns::get_if<uint32_t>(
+ &memorySizeProperty->second);
if (memorySize == nullptr)
{
// Important property not in desired type
@@ -253,7 +256,8 @@ void getDimmDataByService(std::shared_ptr<AsyncResp> aResp,
else if (property.first == "MemoryType")
{
const auto *value =
- mapbox::getPtr<const std::string>(property.second);
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &property.second);
if (value != nullptr)
{
aResp->res.jsonValue["MemoryDeviceType"] = *value;
diff --git a/redfish-core/lib/ethernet.hpp b/redfish-core/lib/ethernet.hpp
index 8712710624..58896d84aa 100644
--- a/redfish-core/lib/ethernet.hpp
+++ b/redfish-core/lib/ethernet.hpp
@@ -171,8 +171,8 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
if (propertyPair.first == "MACAddress")
{
const std::string *mac =
- mapbox::getPtr<const std::string>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&propertyPair.second);
if (mac != nullptr)
{
ethData.mac_address = *mac;
@@ -186,8 +186,9 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
{
if (propertyPair.first == "Id")
{
- const uint32_t *id = mapbox::getPtr<const uint32_t>(
- propertyPair.second);
+ const uint32_t *id =
+ sdbusplus::message::variant_ns::get_if<
+ uint32_t>(&propertyPair.second);
if (id != nullptr)
{
ethData.vlan_id = *id;
@@ -203,7 +204,8 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
if (propertyPair.first == "AutoNeg")
{
const bool *auto_neg =
- mapbox::getPtr<const bool>(propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<bool>(
+ &propertyPair.second);
if (auto_neg != nullptr)
{
ethData.auto_neg = *auto_neg;
@@ -212,8 +214,8 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
else if (propertyPair.first == "Speed")
{
const uint32_t *speed =
- mapbox::getPtr<const uint32_t>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ uint32_t>(&propertyPair.second);
if (speed != nullptr)
{
ethData.speed = *speed;
@@ -229,8 +231,8 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
if (propertyPair.first == "HostName")
{
const std::string *hostname =
- mapbox::getPtr<const std::string>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&propertyPair.second);
if (hostname != nullptr)
{
ethData.hostname = *hostname;
@@ -239,8 +241,8 @@ inline void extractEthernetInterfaceData(const std::string &ethiface_id,
else if (propertyPair.first == "DefaultGateway")
{
const std::string *defaultGateway =
- mapbox::getPtr<const std::string>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&propertyPair.second);
if (defaultGateway != nullptr)
{
ethData.default_gateway = *defaultGateway;
@@ -286,8 +288,8 @@ inline void
if (property.first == "Address")
{
const std::string *address =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (address != nullptr)
{
ipv4_address.address = *address;
@@ -296,8 +298,8 @@ inline void
else if (property.first == "Gateway")
{
const std::string *gateway =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (gateway != nullptr)
{
ipv4_address.gateway = *gateway;
@@ -306,8 +308,8 @@ inline void
else if (property.first == "Origin")
{
const std::string *origin =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (origin != nullptr)
{
ipv4_address.origin =
@@ -318,7 +320,8 @@ inline void
else if (property.first == "PrefixLength")
{
const uint8_t *mask =
- mapbox::getPtr<uint8_t>(property.second);
+ sdbusplus::message::variant_ns::get_if<uint8_t>(
+ &property.second);
if (mask != nullptr)
{
// convert it to the string
@@ -1739,7 +1742,6 @@ class VlanNetworkInterfaceCollection : public Node
messages::internalError(asyncResp->res);
return;
}
-
nlohmann::json postReq;
if (!json_util::processJsonFromRequest(res, req, postReq))
{
@@ -1747,6 +1749,7 @@ class VlanNetworkInterfaceCollection : public Node
}
auto vlanIdJson = postReq.find("VLANId");
+
if (vlanIdJson == postReq.end())
{
messages::propertyMissing(asyncResp->res, "VLANId");
diff --git a/redfish-core/lib/log_services.hpp b/redfish-core/lib/log_services.hpp
index cf4af02231..6f87307c20 100644
--- a/redfish-core/lib/log_services.hpp
+++ b/redfish-core/lib/log_services.hpp
@@ -1102,7 +1102,7 @@ class CPULogEntry : public Node
return;
}
const std::string *log =
- mapbox::getPtr<const std::string>(resp);
+ sdbusplus::message::variant_ns::get_if<std::string>(&resp);
if (log == nullptr)
{
messages::internalError(asyncResp->res);
@@ -1204,8 +1204,9 @@ class ImmediateCPULog : public Node
std::string, sdbusplus::message::variant<std::string>>>
interfacesAdded;
m.read(objPath, interfacesAdded);
- const std::string *log = mapbox::getPtr<const std::string>(
- interfacesAdded[cpuLogInterface]["Log"]);
+ const std::string *log =
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &interfacesAdded[cpuLogInterface]["Log"]);
if (log == nullptr)
{
messages::internalError(asyncResp->res);
diff --git a/redfish-core/lib/managers.hpp b/redfish-core/lib/managers.hpp
index 44725b1f8f..f3c3ec32c7 100644
--- a/redfish-core/lib/managers.hpp
+++ b/redfish-core/lib/managers.hpp
@@ -174,7 +174,8 @@ static void asyncPopulatePid(const std::string& connection,
return;
}
const std::string* namePtr =
- mapbox::getPtr<const std::string>(findName->second);
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &findName->second);
if (namePtr == nullptr)
{
BMCWEB_LOG_ERROR << "Pid Name Field illegal";
@@ -214,8 +215,9 @@ static void asyncPopulatePid(const std::string& connection,
// zones
if (intfPair.first == pidZoneConfigurationIface)
{
- const double* ptr = mapbox::getPtr<const double>(
- propertyPair.second);
+ const double* ptr =
+ sdbusplus::message::variant_ns::get_if<double>(
+ &propertyPair.second);
if (ptr == nullptr)
{
BMCWEB_LOG_ERROR << "Field Illegal "
@@ -233,8 +235,9 @@ static void asyncPopulatePid(const std::string& connection,
auto findClass = intfPair.second.find("Class");
if (findClass != intfPair.second.end())
{
- classPtr = mapbox::getPtr<const std::string>(
- findClass->second);
+ classPtr =
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&findClass->second);
}
if (classPtr == nullptr)
{
@@ -274,9 +277,9 @@ static void asyncPopulatePid(const std::string& connection,
if (propertyPair.first == "Zones")
{
const std::vector<std::string>* inputs =
- mapbox::getPtr<
- const std::vector<std::string>>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::vector<std::string>>(
+ &propertyPair.second);
if (inputs == nullptr)
{
@@ -309,9 +312,9 @@ static void asyncPopulatePid(const std::string& connection,
{
auto& data = element[propertyPair.first];
const std::vector<std::string>* inputs =
- mapbox::getPtr<
- const std::vector<std::string>>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::vector<std::string>>(
+ &propertyPair.second);
if (inputs == nullptr)
{
@@ -335,8 +338,8 @@ static void asyncPopulatePid(const std::string& connection,
propertyPair.first == "SlewPos")
{
const double* ptr =
- mapbox::getPtr<const double>(
- propertyPair.second);
+ sdbusplus::message::variant_ns::get_if<
+ double>(&propertyPair.second);
if (ptr == nullptr)
{
BMCWEB_LOG_ERROR << "Field Illegal "
@@ -752,8 +755,8 @@ class Manager : public Node
if (property.first == "Version")
{
const std::string* value =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (value == nullptr)
{
continue;
diff --git a/redfish-core/lib/network_protocol.hpp b/redfish-core/lib/network_protocol.hpp
index 47244e02d0..90f12dd629 100644
--- a/redfish-core/lib/network_protocol.hpp
+++ b/redfish-core/lib/network_protocol.hpp
@@ -166,9 +166,10 @@ class NetworkProtocol : public Node
}
const std::vector<std::tuple<
std::string, std::string>>* responsePtr =
- mapbox::getPtr<const std::vector<
- std::tuple<std::string, std::string>>>(
- resp);
+ sdbusplus::message::variant_ns::get_if<
+ std::vector<std::tuple<std::string,
+ std::string>>>(
+ &resp);
if (responsePtr == nullptr ||
responsePtr->size() < 1)
{
diff --git a/redfish-core/lib/sensors.hpp b/redfish-core/lib/sensors.hpp
index b689f09664..f866e5d778 100644
--- a/redfish-core/lib/sensors.hpp
+++ b/redfish-core/lib/sensors.hpp
@@ -273,7 +273,7 @@ void objectInterfacesToJson(
if (scaleIt != valueIt->second.end())
{
const int64_t* int64Value =
- mapbox::getPtr<const int64_t>(scaleIt->second);
+ sdbusplus::message::variant_ns::get_if<int64_t>(&scaleIt->second);
if (int64Value != nullptr)
{
scaleMultiplier = *int64Value;
@@ -370,10 +370,12 @@ void objectInterfacesToJson(
nlohmann::json& valueIt = sensor_json[std::get<2>(p)];
// Attempt to pull the int64 directly
const int64_t* int64Value =
- mapbox::getPtr<const int64_t>(valueVariant);
+ sdbusplus::message::variant_ns::get_if<int64_t>(
+ &valueVariant);
const double* doubleValue =
- mapbox::getPtr<const double>(valueVariant);
+ sdbusplus::message::variant_ns::get_if<double>(
+ &valueVariant);
double temp = 0.0;
if (int64Value != nullptr)
{
diff --git a/redfish-core/lib/systems.hpp b/redfish-core/lib/systems.hpp
index 7d0cc0236e..12f15d1d1b 100644
--- a/redfish-core/lib/systems.hpp
+++ b/redfish-core/lib/systems.hpp
@@ -87,8 +87,8 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
&property : propertiesList)
{
const std::string *value =
- mapbox::getPtr<const std::string>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&property.second);
if (value != nullptr)
{
aResp->res.jsonValue[property.first] =
@@ -140,9 +140,10 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
"MemorySizeInKb")
{
const uint64_t *value =
- mapbox::getPtr<
- const uint64_t>(
- property.second);
+ sdbusplus::message::
+ variant_ns::get_if<
+ uint64_t>(
+ &property.second);
if (value != nullptr)
{
aResp->res.jsonValue
@@ -188,9 +189,10 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
"ProcessorFamily")
{
const std::string *value =
- mapbox::getPtr<
- const std::string>(
- property.second);
+ sdbusplus::message::
+ variant_ns::get_if<
+ std::string>(
+ &property.second);
if (value != nullptr)
{
nlohmann::json
@@ -245,9 +247,10 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
if (property.first == "BIOSVer")
{
const std::string *value =
- mapbox::getPtr<
- const std::string>(
- property.second);
+ sdbusplus::message::
+ variant_ns::get_if<
+ std::string>(
+ &property.second);
if (value != nullptr)
{
aResp->res.jsonValue
@@ -258,9 +261,10 @@ void getComputerSystem(std::shared_ptr<AsyncResp> aResp,
if (property.first == "UUID")
{
const std::string *value =
- mapbox::getPtr<
- const std::string>(
- property.second);
+ sdbusplus::message::
+ variant_ns::get_if<
+ std::string>(
+ &property.second);
if (value != nullptr)
{
@@ -351,8 +355,8 @@ void getLedGroupIdentify(std::shared_ptr<AsyncResp> aResp,
if (property.first == "Asserted")
{
const bool *asserted =
- mapbox::getPtr<const bool>(
- property.second);
+ sdbusplus::message::variant_ns::get_if<
+ bool>(&property.second);
if (nullptr != asserted)
{
callback(*asserted, aResp);
@@ -395,7 +399,8 @@ void getLedIdentify(std::shared_ptr<AsyncResp> aResp, CallbackFunc &&callback)
if (property.first == "State")
{
const std::string *s =
- mapbox::getPtr<std::string>(property.second);
+ sdbusplus::message::variant_ns::get_if<std::string>(
+ &property.second);
if (nullptr != s)
{
BMCWEB_LOG_DEBUG << "Identify Led State: " << *s;
@@ -449,7 +454,8 @@ void getHostState(std::shared_ptr<AsyncResp> aResp)
return;
}
- const std::string *s = mapbox::getPtr<const std::string>(hostState);
+ const std::string *s =
+ sdbusplus::message::variant_ns::get_if<std::string>(&hostState);
BMCWEB_LOG_DEBUG << "Host state: " << *s;
if (s != nullptr)
{
diff --git a/redfish-core/lib/update_service.hpp b/redfish-core/lib/update_service.hpp
index f600c14e2f..d5ecf24765 100644
--- a/redfish-core/lib/update_service.hpp
+++ b/redfish-core/lib/update_service.hpp
@@ -260,8 +260,8 @@ class SoftwareInventoryCollection : public Node
}
const std::string *swActivationStatus =
- mapbox::getPtr<const std::string>(
- activation);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&activation);
if (swActivationStatus == nullptr)
{
messages::internalError(asyncResp->res);
@@ -401,7 +401,8 @@ class SoftwareInventory : public Node
return;
}
const std::string *swInvPurpose =
- mapbox::getPtr<const std::string>(it->second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&it->second);
if (swInvPurpose == nullptr)
{
BMCWEB_LOG_DEBUG
@@ -426,7 +427,8 @@ class SoftwareInventory : public Node
BMCWEB_LOG_DEBUG << "Version found!";
const std::string *version =
- mapbox::getPtr<const std::string>(it->second);
+ sdbusplus::message::variant_ns::get_if<
+ std::string>(&it->second);
if (version == nullptr)
{