treewide: Clean up string parameters
Change-Id: I0d3ea6a83465181d3edec1587ff824103489072e
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/config_parser.cpp b/src/config_parser.cpp
index 599908e..1e8e646 100644
--- a/src/config_parser.cpp
+++ b/src/config_parser.cpp
@@ -82,7 +82,7 @@
[](const Value& v) { return std::string(v); });
}
-void KeyCheck::operator()(const std::string& s)
+void KeyCheck::operator()(std::string_view s)
{
for (auto c : s)
{
@@ -94,7 +94,7 @@
}
}
-void SectionCheck::operator()(const std::string& s)
+void SectionCheck::operator()(std::string_view s)
{
for (auto c : s)
{
@@ -106,7 +106,7 @@
}
}
-void ValueCheck::operator()(const std::string& s)
+void ValueCheck::operator()(std::string_view s)
{
for (auto c : s)
{
diff --git a/src/config_parser.hpp b/src/config_parser.hpp
index 12ac417..461a22d 100644
--- a/src/config_parser.hpp
+++ b/src/config_parser.hpp
@@ -88,15 +88,15 @@
struct KeyCheck
{
- void operator()(const std::string& s);
+ void operator()(std::string_view s);
};
struct SectionCheck
{
- void operator()(const std::string& s);
+ void operator()(std::string_view s);
};
struct ValueCheck
{
- void operator()(const std::string& s);
+ void operator()(std::string_view s);
};
struct string_hash : public std::hash<std::string_view>
diff --git a/src/dhcp_configuration.cpp b/src/dhcp_configuration.cpp
index c14f547..5914277 100644
--- a/src/dhcp_configuration.cpp
+++ b/src/dhcp_configuration.cpp
@@ -19,8 +19,8 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-Configuration::Configuration(sdbusplus::bus_t& bus, const std::string& objPath,
- Manager& parent) :
+Configuration::Configuration(sdbusplus::bus_t& bus,
+ stdplus::const_zstring objPath, Manager& parent) :
Iface(bus, objPath.c_str(), Iface::action::defer_emit),
bus(bus), manager(parent)
{
diff --git a/src/dhcp_configuration.hpp b/src/dhcp_configuration.hpp
index 19a8888..98f8e46 100644
--- a/src/dhcp_configuration.hpp
+++ b/src/dhcp_configuration.hpp
@@ -1,7 +1,7 @@
#pragma once
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include <string>
+#include <stdplus/zstring.hpp>
#include <xyz/openbmc_project/Network/DHCPConfiguration/server.hpp>
namespace phosphor
@@ -39,7 +39,7 @@
* @param[in] objPath - Path to attach at.
* @param[in] parent - Parent object.
*/
- Configuration(sdbusplus::bus_t& bus, const std::string& objPath,
+ Configuration(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
Manager& parent);
/** @brief If true then DNS servers received from the DHCP server
diff --git a/src/ethernet_interface.cpp b/src/ethernet_interface.cpp
index 7c1f187..3f1743c 100644
--- a/src/ethernet_interface.cpp
+++ b/src/ethernet_interface.cpp
@@ -53,16 +53,16 @@
}
EthernetInterface::EthernetInterface(sdbusplus::bus_t& bus,
- const std::string& objPath,
+ stdplus::zstring_view objPath,
const config::Parser& config,
Manager& parent, bool emitSignal,
std::optional<bool> enabled) :
Ifaces(bus, objPath.c_str(),
emitSignal ? Ifaces::action::defer_emit
: Ifaces::action::emit_no_signals),
- bus(bus), manager(parent), objPath(objPath)
+ bus(bus), manager(parent), objPath(objPath.c_str())
{
- auto intfName = objPath.substr(objPath.rfind("/") + 1);
+ auto intfName = std::string(objPath.substr(objPath.rfind('/') + 1));
std::replace(intfName.begin(), intfName.end(), '_', '.');
interfaceName(intfName);
auto dhcpVal = getDHCPValue(config);
@@ -366,7 +366,7 @@
*/
std::string
- EthernetInterface::getMACAddress(const std::string& interfaceName) const
+ EthernetInterface::getMACAddress(stdplus::const_zstring interfaceName) const
{
std::string activeMACAddr = MacAddressIntf::macAddress();
@@ -386,13 +386,13 @@
stdplus::raw::refFrom<ether_addr>(ifr.ifr_hwaddr.sa_data));
}
-std::string EthernetInterface::generateId(const std::string& ipaddress,
+std::string EthernetInterface::generateId(std::string_view ipaddress,
uint8_t prefixLength,
- const std::string& gateway,
- const std::string& origin)
+ std::string_view gateway,
+ std::string_view origin)
{
std::stringstream hexId;
- std::string hashString = ipaddress;
+ std::string hashString = std::string(ipaddress);
hashString += std::to_string(prefixLength);
hashString += gateway;
hashString += origin;
@@ -402,18 +402,19 @@
return hexId.str();
}
-std::string EthernetInterface::generateNeighborId(const std::string& ipAddress,
- const std::string& macAddress)
+std::string EthernetInterface::generateNeighborId(std::string_view ipAddress,
+ std::string_view macAddress)
{
std::stringstream hexId;
- std::string hashString = ipAddress + macAddress;
+ std::string hashString = std::string(ipAddress);
+ hashString += macAddress;
// Only want 8 hex digits.
hexId << std::hex << ((std::hash<std::string>{}(hashString)) & 0xFFFFFFFF);
return hexId.str();
}
-void EthernetInterface::deleteObject(const std::string& ipaddress)
+void EthernetInterface::deleteObject(std::string_view ipaddress)
{
auto it = addrs.find(ipaddress);
if (it == addrs.end())
@@ -427,7 +428,7 @@
manager.reloadConfigs();
}
-void EthernetInterface::deleteStaticNeighborObject(const std::string& ipAddress)
+void EthernetInterface::deleteStaticNeighborObject(std::string_view ipAddress)
{
auto it = staticNeighbors.find(ipAddress);
if (it == staticNeighbors.end())
@@ -442,7 +443,7 @@
manager.reloadConfigs();
}
-void EthernetInterface::deleteVLANFromSystem(const std::string& interface)
+void EthernetInterface::deleteVLANFromSystem(stdplus::zstring_view interface)
{
const auto& confDir = manager.getConfDir();
auto networkFile = config::pathForIntfConf(confDir, interface);
@@ -466,7 +467,7 @@
}
}
-void EthernetInterface::deleteVLANObject(const std::string& interface)
+void EthernetInterface::deleteVLANObject(stdplus::zstring_view interface)
{
auto it = vlanInterfaces.find(interface);
if (it == vlanInterfaces.end())
@@ -485,9 +486,8 @@
}
std::string EthernetInterface::generateObjectPath(
- IP::Protocol addressType, const std::string& ipaddress,
- uint8_t prefixLength, const std::string& gateway,
- IP::AddressOrigin origin) const
+ IP::Protocol addressType, std::string_view ipaddress, uint8_t prefixLength,
+ std::string_view gateway, IP::AddressOrigin origin) const
{
std::string type = convertForMessage(addressType);
type = type.substr(type.rfind('.') + 1);
@@ -502,7 +502,7 @@
}
std::string EthernetInterface::generateStaticNeighborObjectPath(
- const std::string& ipAddress, const std::string& macAddress) const
+ std::string_view ipAddress, std::string_view macAddress) const
{
std::filesystem::path objectPath;
objectPath /= objPath;
@@ -657,7 +657,7 @@
// Store / Parser for the AdministrativeState return value
std::optional<bool> ret;
- auto cb = [&](const std::string& state) {
+ auto cb = [&](std::string_view state) {
if (state != "initialized")
{
ret = state != "unmanaged";
diff --git a/src/ethernet_interface.hpp b/src/ethernet_interface.hpp
index f0931d7..f726f48 100644
--- a/src/ethernet_interface.hpp
+++ b/src/ethernet_interface.hpp
@@ -7,6 +7,8 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
+#include <stdplus/zstring.hpp>
+#include <stdplus/zstring_view.hpp>
#include <string>
#include <vector>
#include <xyz/openbmc_project/Collection/DeleteAll/server.hpp>
@@ -81,7 +83,7 @@
* send.
* @param[in] enabled - Override the lookup of nicEnabled
*/
- EthernetInterface(sdbusplus::bus_t& bus, const std::string& objPath,
+ EthernetInterface(sdbusplus::bus_t& bus, stdplus::zstring_view objPath,
const config::Parser& config, Manager& parent,
bool emitSignal = true,
std::optional<bool> enabled = std::nullopt);
@@ -109,18 +111,18 @@
/* @brief delete the dbus object of the given ipAddress.
* @param[in] ipAddress - IP address.
*/
- void deleteObject(const std::string& ipAddress);
+ void deleteObject(std::string_view ipAddress);
/* @brief delete the dbus object of the given ipAddress.
* @param[in] ipAddress - IP address.
*/
- void deleteStaticNeighborObject(const std::string& ipAddress);
+ void deleteStaticNeighborObject(std::string_view ipAddress);
/* @brief delete the vlan dbus object of the given interface.
* Also deletes the device file and the network file.
* @param[in] interface - VLAN Interface.
*/
- void deleteVLANObject(const std::string& interface);
+ void deleteVLANObject(stdplus::zstring_view interface);
/* @brief creates the dbus object(IPaddres) given in the address list.
* @param[in] addrs - address list for which dbus objects needs
@@ -244,14 +246,14 @@
/* @brief delete the vlan interface from system.
* @param[in] interface - vlan Interface.
*/
- void deleteVLANFromSystem(const std::string& interface);
+ void deleteVLANFromSystem(stdplus::zstring_view interface);
/** @brief get the mac address of the interface.
* @param[in] interfaceName - Network interface name.
* @return macaddress on success
*/
- std::string getMACAddress(const std::string& interfaceName) const;
+ std::string getMACAddress(stdplus::const_zstring interfaceName) const;
/** @brief construct the ip address dbus object path.
* @param[in] addressType - Type of ip address.
@@ -264,14 +266,14 @@
*/
std::string generateObjectPath(IP::Protocol addressType,
- const std::string& ipAddress,
+ std::string_view ipAddress,
uint8_t prefixLength,
- const std::string& gateway,
+ std::string_view gateway,
IP::AddressOrigin origin) const;
std::string
- generateStaticNeighborObjectPath(const std::string& ipAddress,
- const std::string& macAddress) const;
+ generateStaticNeighborObjectPath(std::string_view ipAddress,
+ std::string_view macAddress) const;
/** @brief generates the id by doing hash of ipAddress,
* prefixlength and the gateway.
@@ -282,10 +284,10 @@
* @return hash string.
*/
- static std::string generateId(const std::string& ipAddress,
+ static std::string generateId(std::string_view ipAddress,
uint8_t prefixLength,
- const std::string& gateway,
- const std::string& origin);
+ std::string_view gateway,
+ std::string_view origin);
/** @brief generates the id by doing hash of ipAddress
* and the mac address.
@@ -293,8 +295,8 @@
* @param[in] macAddress - Gateway address.
* @return hash string.
*/
- static std::string generateNeighborId(const std::string& ipAddress,
- const std::string& macAddress);
+ static std::string generateNeighborId(std::string_view ipAddress,
+ std::string_view macAddress);
/** @brief get the NTP server list from the network conf
*
diff --git a/src/neighbor.cpp b/src/neighbor.cpp
index f68dd90..cfa8e60 100644
--- a/src/neighbor.cpp
+++ b/src/neighbor.cpp
@@ -15,6 +15,7 @@
#include <phosphor-logging/elog.hpp>
#include <stdexcept>
#include <stdplus/raw.hpp>
+#include <string>
#include <string_view>
#include <utility>
#include <vector>
@@ -86,14 +87,14 @@
return neighbors;
}
-Neighbor::Neighbor(sdbusplus::bus_t& bus, const char* objPath,
- EthernetInterface& parent, const std::string& ipAddress,
- const std::string& macAddress, State state) :
- NeighborObj(bus, objPath, NeighborObj::action::defer_emit),
+Neighbor::Neighbor(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
+ EthernetInterface& parent, std::string_view ipAddress,
+ std::string_view macAddress, State state) :
+ NeighborObj(bus, objPath.c_str(), NeighborObj::action::defer_emit),
parent(parent)
{
- NeighborObj::ipAddress(ipAddress);
- NeighborObj::macAddress(macAddress);
+ NeighborObj::ipAddress(std::string(ipAddress));
+ NeighborObj::macAddress(std::string(macAddress));
NeighborObj::state(state);
// Emit deferred signal.
diff --git a/src/neighbor.hpp b/src/neighbor.hpp
index 4672726..a29218d 100644
--- a/src/neighbor.hpp
+++ b/src/neighbor.hpp
@@ -1,5 +1,4 @@
#pragma once
-
#include "types.hpp"
#include <linux/netlink.h>
@@ -9,7 +8,7 @@
#include <optional>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include <string>
+#include <stdplus/zstring.hpp>
#include <string_view>
#include <vector>
#include <xyz/openbmc_project/Network/Neighbor/server.hpp>
@@ -80,9 +79,9 @@
* @param[in] macAddress - Low level MAC address.
* @param[in] state - The state of the neighbor entry.
*/
- Neighbor(sdbusplus::bus_t& bus, const char* objPath,
- EthernetInterface& parent, const std::string& ipAddress,
- const std::string& macAddress, State state);
+ Neighbor(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
+ EthernetInterface& parent, std::string_view ipAddress,
+ std::string_view macAddress, State state);
/** @brief Delete this d-bus object.
*/
diff --git a/src/network_manager.cpp b/src/network_manager.cpp
index eecbe68..f959a69 100644
--- a/src/network_manager.cpp
+++ b/src/network_manager.cpp
@@ -41,12 +41,11 @@
using Argument = xyz::openbmc_project::Common::InvalidArgument;
Manager::Manager(sdbusplus::bus_t& bus, const char* objPath,
- const std::string& path) :
+ const fs::path& confDir) :
details::VLANCreateIface(bus, objPath,
details::VLANCreateIface::action::defer_emit),
bus(bus), objectPath(objPath)
{
- fs::path confDir(path);
setConfDir(confDir);
}
diff --git a/src/network_manager.hpp b/src/network_manager.hpp
index edd7125..18bb7d5 100644
--- a/src/network_manager.hpp
+++ b/src/network_manager.hpp
@@ -53,9 +53,10 @@
/** @brief Constructor to put object onto bus at a dbus path.
* @param[in] bus - Bus to attach to.
* @param[in] objPath - Path to attach at.
- * @param[in] dir - Network Configuration directory path.
+ * @param[in] confDir - Network Configuration directory path.
*/
- Manager(sdbusplus::bus_t& bus, const char* objPath, const std::string& dir);
+ Manager(sdbusplus::bus_t& bus, const char* objPath,
+ const fs::path& confDir);
ObjectPath vlan(std::string interfaceName, uint32_t id) override;
diff --git a/src/system_configuration.cpp b/src/system_configuration.cpp
index a302ace..192f12d 100644
--- a/src/system_configuration.cpp
+++ b/src/system_configuration.cpp
@@ -24,7 +24,7 @@
sdbusplus::xyz::openbmc_project::Network::server::SystemConfiguration;
SystemConfiguration::SystemConfiguration(sdbusplus::bus_t& bus,
- const std::string& objPath) :
+ stdplus::const_zstring objPath) :
Iface(bus, objPath.c_str(), Iface::action::defer_emit),
bus(bus)
{
diff --git a/src/system_configuration.hpp b/src/system_configuration.hpp
index f5289ce..6bbb83f 100644
--- a/src/system_configuration.hpp
+++ b/src/system_configuration.hpp
@@ -2,6 +2,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
+#include <stdplus/zstring.hpp>
#include <string>
#include <xyz/openbmc_project/Network/SystemConfiguration/server.hpp>
@@ -37,7 +38,7 @@
* @param[in] objPath - Path to attach at.
* @param[in] parent - Parent object.
*/
- SystemConfiguration(sdbusplus::bus_t& bus, const std::string& objPath);
+ SystemConfiguration(sdbusplus::bus_t& bus, stdplus::const_zstring objPath);
/** @brief set the hostname of the system.
* @param[in] name - host name of the system.
diff --git a/src/vlan_interface.cpp b/src/vlan_interface.cpp
index 67074f0..efd1341 100644
--- a/src/vlan_interface.cpp
+++ b/src/vlan_interface.cpp
@@ -17,7 +17,8 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-VlanInterface::VlanInterface(sdbusplus::bus_t& bus, const std::string& objPath,
+VlanInterface::VlanInterface(sdbusplus::bus_t& bus,
+ stdplus::const_zstring objPath,
const config::Parser& config, bool nicEnabled,
uint32_t vlanID, EthernetInterface& intf,
Manager& parent) :
diff --git a/src/vlan_interface.hpp b/src/vlan_interface.hpp
index 09b9bb0..bc5a1c8 100644
--- a/src/vlan_interface.hpp
+++ b/src/vlan_interface.hpp
@@ -7,7 +7,7 @@
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server/object.hpp>
-#include <string>
+#include <stdplus/zstring.hpp>
#include <xyz/openbmc_project/Object/Delete/server.hpp>
namespace phosphor
@@ -47,7 +47,7 @@
*
* This constructor is called during loading the VLAN Interface
*/
- VlanInterface(sdbusplus::bus_t& bus, const std::string& objPath,
+ VlanInterface(sdbusplus::bus_t& bus, stdplus::const_zstring objPath,
const config::Parser& config, bool nicEnabled,
uint32_t vlanID, EthernetInterface& intf, Manager& parent);