Take bus as input parameter in util function
Change-Id: I2de92a1d82939a539e19aca69561ad58a171a5d0
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
diff --git a/chassishandler.cpp b/chassishandler.cpp
index c047108..947c96c 100644
--- a/chassishandler.cpp
+++ b/chassishandler.cpp
@@ -292,18 +292,22 @@
// as SETTINGS_MATCH.
// Later SETTINGS_MATCH will be replaced with busname.
- auto ipObjectInfo = ipmi::getDbusObject(IP_INTERFACE, SETTINGS_ROOT,
- SETTINGS_MATCH);
- auto macObjectInfo = ipmi::getDbusObject(MAC_INTERFACE, SETTINGS_ROOT,
- SETTINGS_MATCH);
+ sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
- properties = ipmi::getAllDbusProperties(ipObjectInfo.second,
- ipObjectInfo.first, IP_INTERFACE);
+ auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
+ SETTINGS_ROOT, SETTINGS_MATCH);
+
+ auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
+ SETTINGS_ROOT, SETTINGS_MATCH);
+
+ properties = ipmi::getAllDbusProperties(bus, ipObjectInfo.second,
+ ipObjectInfo.first, IP_INTERFACE);
auto variant =
- ipmi::getDbusProperty(macObjectInfo.second, macObjectInfo.first,
+ ipmi::getDbusProperty(bus, macObjectInfo.second,
+ macObjectInfo.first,
MAC_INTERFACE, "MACAddress");
- auto ipAddress = properties["Address"].get<std::string>();
+ auto ipAddress = properties["Address"].get<std::string>();
auto gateway = properties["Gateway"].get<std::string>();
@@ -542,23 +546,25 @@
",mac="s + mac + ",addressOrigin="s + addressOrigin;
- auto ipObjectInfo = ipmi::getDbusObject(IP_INTERFACE, SETTINGS_ROOT,
- SETTINGS_MATCH);
- auto macObjectInfo = ipmi::getDbusObject(MAC_INTERFACE, SETTINGS_ROOT,
- SETTINGS_MATCH);
+ sdbusplus::bus::bus bus(ipmid_get_sd_bus_connection());
+
+ auto ipObjectInfo = ipmi::getDbusObject(bus, IP_INTERFACE,
+ SETTINGS_ROOT, SETTINGS_MATCH);
+ auto macObjectInfo = ipmi::getDbusObject(bus, MAC_INTERFACE,
+ SETTINGS_ROOT, SETTINGS_MATCH);
// set the dbus property
- ipmi::setDbusProperty(ipObjectInfo.second, ipObjectInfo.first,
+ ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
IP_INTERFACE, "Address", std::string(ipAddress));
- ipmi::setDbusProperty(ipObjectInfo.second, ipObjectInfo.first,
+ ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
IP_INTERFACE, "PrefixLength", prefix);
- ipmi::setDbusProperty(ipObjectInfo.second, ipObjectInfo.first,
+ ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
IP_INTERFACE, "Origin", addressOrigin);
- ipmi::setDbusProperty(ipObjectInfo.second, ipObjectInfo.first,
+ ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
IP_INTERFACE, "Gateway", std::string(gateway));
- ipmi::setDbusProperty(ipObjectInfo.second, ipObjectInfo.first,
+ ipmi::setDbusProperty(bus, ipObjectInfo.second, ipObjectInfo.first,
IP_INTERFACE, "Type",
std::string("xyz.openbmc_project.Network.IP.Protocol.IPv4"));
- ipmi::setDbusProperty(macObjectInfo.second, macObjectInfo.first,
+ ipmi::setDbusProperty(bus, macObjectInfo.second, macObjectInfo.first,
MAC_INTERFACE,"MACAddress", std::string(mac));
log<level::DEBUG>("Network configuration changed",
diff --git a/utils.cpp b/utils.cpp
index ad5f997..fa92e48 100644
--- a/utils.cpp
+++ b/utils.cpp
@@ -10,13 +10,6 @@
using namespace phosphor::logging;
using namespace sdbusplus::xyz::openbmc_project::Common::Error;
-/** @brief Gets the dbus object info implementing the given interface
- * from the given subtree.
- * @param[in] interface - Dbus interface.
- * @param[in] serviceRoot - subtree from where the search should start.
- * @param[in] match - identifier for object.
- * @return On success returns the object having objectpath and servicename.
- */
//TODO There may be cases where an interface is implemented by multiple
// objects,to handle such cases we are interested on that object
@@ -24,14 +17,14 @@
// Currently mapper doesn't give the readable busname(gives busid) so we can't
// use busname to find the object,will do later once the support is there.
-DbusObjectInfo getDbusObject(const std::string& interface,
+DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus,
+ const std::string& interface,
const std::string& serviceRoot,
const std::string& match)
{
std::vector<DbusInterface> interfaces;
interfaces.emplace_back(interface);
- auto bus = sdbusplus::bus::new_default();
auto depth = 0;
auto mapperCall = bus.new_method_call(MAPPER_BUS_NAME,
@@ -91,15 +84,8 @@
}
-/** @brief Gets the value associated with the given object
- * and the interface.
- * @param[in] service - Dbus service name.
- * @param[in] objPath - Dbus object path.
- * @param[in] interface - Dbus interface.
- * @param[in] property - name of the property.
- * @return On success returns the value of the property.
- */
-Value getDbusProperty(const std::string& service,
+Value getDbusProperty(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface,
const std::string& property)
@@ -107,8 +93,6 @@
Value value;
- auto bus = sdbusplus::bus::new_default();
-
auto method = bus.new_method_call(
service.c_str(),
objPath.c_str(),
@@ -133,19 +117,12 @@
return value;
}
-/** @brief Gets all the properties associated with the given object
- * and the interface.
- * @param[in] service - Dbus service name.
- * @param[in] objPath - Dbus object path.
- * @param[in] interface - Dbus interface.
- * @return On success returns the map of name value pair.
- */
-PropertyMap getAllDbusProperties(const std::string& service,
+PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface)
{
PropertyMap properties;
- auto bus = sdbusplus::bus::new_default();
auto method = bus.new_method_call(
service.c_str(),
@@ -169,21 +146,13 @@
return properties;
}
-/** @brief Sets the property value of the given object.
- * @param[in] service - Dbus service name.
- * @param[in] objPath - Dbus object path.
- * @param[in] interface - Dbus interface.
- * @param[in] property - name of the property.
- * @param[in] value - value which needs to be set.
- */
-void setDbusProperty(const std::string& service,
+void setDbusProperty(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface,
const std::string& property,
const Value& value)
{
- auto bus = sdbusplus::bus::new_default();
-
auto method = bus.new_method_call(
service.c_str(),
objPath.c_str(),
diff --git a/utils.hpp b/utils.hpp
index 628b241..0c7ae76 100644
--- a/utils.hpp
+++ b/utils.hpp
@@ -36,47 +36,55 @@
/** @brief Gets the dbus object info implementing the given interface
* from the given subtree.
+ * @param[in] bus - DBUS Bus Object.
* @param[in] interface - Dbus interface.
* @param[in] subtreePath - subtree from where the search should start.
* @param[in] match - identifier for object.
* @return On success returns the object having objectpath and servicename.
*/
-DbusObjectInfo getDbusObject(const std::string& interface,
+DbusObjectInfo getDbusObject(sdbusplus::bus::bus& bus,
+ const std::string& interface,
const std::string& subtreePath = ROOT,
const std::string& match = {});
/** @brief Gets the value associated with the given object
* and the interface.
+ * @param[in] bus - DBUS Bus Object.
* @param[in] service - Dbus service name.
* @param[in] objPath - Dbus object path.
* @param[in] interface - Dbus interface.
* @param[in] property - name of the property.
* @return On success returns the value of the property.
*/
-Value getDbusProperty(const std::string& service,
+Value getDbusProperty(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface,
const std::string& property);
/** @brief Gets all the properties associated with the given object
* and the interface.
+ * @param[in] bus - DBUS Bus Object.
* @param[in] service - Dbus service name.
* @param[in] objPath - Dbus object path.
* @param[in] interface - Dbus interface.
* @return On success returns the map of name value pair.
*/
-PropertyMap getAllDbusProperties(const std::string& service,
+PropertyMap getAllDbusProperties(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface);
/** @brief Sets the property value of the given object.
+ * @param[in] bus - DBUS Bus Object.
* @param[in] service - Dbus service name.
* @param[in] objPath - Dbus object path.
* @param[in] interface - Dbus interface.
* @param[in] property - name of the property.
* @param[in] value - value which needs to be set.
*/
-void setDbusProperty(const std::string& service,
+void setDbusProperty(sdbusplus::bus::bus& bus,
+ const std::string& service,
const std::string& objPath,
const std::string& interface,
const std::string& property,