summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--monitor/fan.cpp47
-rw-r--r--monitor/fan.hpp8
-rw-r--r--utility.cpp9
-rw-r--r--utility.hpp48
4 files changed, 60 insertions, 52 deletions
diff --git a/monitor/fan.cpp b/monitor/fan.cpp
index ba0744a..a6af74a 100644
--- a/monitor/fan.cpp
+++ b/monitor/fan.cpp
@@ -18,6 +18,7 @@
#include "fan.hpp"
#include "types.hpp"
#include "utility.hpp"
+#include "sdbusplus.hpp"
namespace phosphor
{
@@ -28,14 +29,6 @@ namespace monitor
using namespace phosphor::logging;
-constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
-constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
-
-constexpr auto FUNCTIONAL_PROPERTY = "Functional";
-constexpr auto OPERATIONAL_STATUS_INTF =
- "xyz.openbmc_project.State.Decorator.OperationalStatus";
-
-
Fan::Fan(Mode mode,
sdbusplus::bus::bus& bus,
phosphor::fan::event::EventPtr& events,
@@ -221,18 +214,17 @@ void Fan::timerExpired(TachSensor& sensor)
void Fan::updateInventory(bool functional)
{
- ObjectMap objectMap = getObjectMap(functional);
- std::string service;
-
- service = phosphor::fan::util::getInvService(_bus);
-
- auto msg = _bus.new_method_call(service.c_str(),
- INVENTORY_PATH,
- INVENTORY_INTF,
- "Notify");
-
- msg.append(std::move(objectMap));
- auto response = _bus.call(msg);
+ auto objectMap = util::getObjMap<bool>(
+ _name,
+ util::OPERATIONAL_STATUS_INTF,
+ util::FUNCTIONAL_PROPERTY,
+ functional);
+ auto response = util::SDBusPlus::lookupAndCallMethod(
+ _bus,
+ util::INVENTORY_PATH,
+ util::INVENTORY_INTF,
+ "Notify",
+ objectMap);
if (response.is_method_error())
{
log<level::ERR>("Error in Notify call to update inventory");
@@ -243,21 +235,6 @@ void Fan::updateInventory(bool functional)
_functional = functional;
}
-
-Fan::ObjectMap Fan::getObjectMap(bool functional)
-{
- ObjectMap objectMap;
- InterfaceMap interfaceMap;
- PropertyMap propertyMap;
-
- propertyMap.emplace(FUNCTIONAL_PROPERTY, functional);
- interfaceMap.emplace(OPERATIONAL_STATUS_INTF, std::move(propertyMap));
- objectMap.emplace(_name, std::move(interfaceMap));
-
- return objectMap;
-}
-
-
}
}
}
diff --git a/monitor/fan.hpp b/monitor/fan.hpp
index b366c44..5a21e31 100644
--- a/monitor/fan.hpp
+++ b/monitor/fan.hpp
@@ -160,14 +160,6 @@ class Fan
void updateInventory(bool functional);
/**
- * @brief Returns the object map to use when updating the inventory
- *
- * @param[in] functional - If the Functional property should
- * be set to true or false.
- */
- ObjectMap getObjectMap(bool functional);
-
- /**
* @brief the dbus object
*/
sdbusplus::bus::bus& _bus;
diff --git a/utility.cpp b/utility.cpp
index 7da1557..249fe2f 100644
--- a/utility.cpp
+++ b/utility.cpp
@@ -29,15 +29,6 @@ using namespace phosphor::logging;
using InternalFailure = sdbusplus::xyz::openbmc_project::Common::
Error::InternalFailure;
-//TODO Should get these from phosphor-objmgr config.h
-constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
-constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
-constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
-
-//TODO Should get these from phosphor-inventory-manager config.h
-const auto INVENTORY_PATH = "/xyz/openbmc_project/inventory"s;
-const auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"s;
-
std::string getInvService(sdbusplus::bus::bus& bus)
{
return getService(INVENTORY_PATH, INVENTORY_INTF, bus);
diff --git a/utility.hpp b/utility.hpp
index 32d055e..bb23dea 100644
--- a/utility.hpp
+++ b/utility.hpp
@@ -20,6 +20,17 @@ namespace fan
namespace util
{
+constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
+constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
+constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
+
+constexpr auto INVENTORY_PATH = "/xyz/openbmc_project/inventory";
+constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager";
+
+constexpr auto OPERATIONAL_STATUS_INTF =
+ "xyz.openbmc_project.State.Decorator.OperationalStatus";
+constexpr auto FUNCTIONAL_PROPERTY = "Functional";
+
class FileDescriptor
{
public:
@@ -90,6 +101,43 @@ std::string getService(const std::string& path,
const std::string& interface,
sdbusplus::bus::bus& bus);
+/**
+ * @brief Get the object map for creating or updating an object property
+ *
+ * @param[in] path - The dbus object path name
+ * @param[in] intf - The dbus interface
+ * @param[in] prop - The dbus property
+ * @param[in] value - The property value
+ *
+ * @return - The full object path containing the property value
+ */
+template <typename T>
+auto getObjMap(const std::string& path,
+ const std::string& intf,
+ const std::string& prop,
+ const T& value)
+{
+ using Property = std::string;
+ using Value = sdbusplus::message::variant<T>;
+ using PropertyMap = std::map<Property, Value>;
+
+ using Interface = std::string;
+ using InterfaceMap = std::map<Interface, PropertyMap>;
+
+ using Object = sdbusplus::message::object_path;
+ using ObjectMap = std::map<Object, InterfaceMap>;
+
+ ObjectMap objectMap;
+ InterfaceMap interfaceMap;
+ PropertyMap propertyMap;
+
+ propertyMap.emplace(prop, value);
+ interfaceMap.emplace(intf, std::move(propertyMap));
+ objectMap.emplace(path, std::move(interfaceMap));
+
+ return objectMap;
+}
+
}
}
}
OpenPOWER on IntegriCloud