From 59ae877171ef9a7df66c465c45fa89f2d1d89d38 Mon Sep 17 00:00:00 2001 From: Brandon Wyman Date: Thu, 6 Apr 2017 15:05:18 -0500 Subject: Implement updating the inventory properties Implement code needed to update the chassis AirCooled and WaterCooled properties. Change-Id: I9a67d1129e99f841200241e2daae08fb6119d9d3 Signed-off-by: Brandon Wyman --- cooling-type/Makefile.am | 10 +++++++++- cooling-type/cooling_type.cpp | 39 ++++++++++++++++++++++++++++++++++++--- cooling-type/cooling_type.hpp | 27 +++++++++++++++++++++++++-- cooling-type/main.cpp | 2 +- 4 files changed, 71 insertions(+), 7 deletions(-) diff --git a/cooling-type/Makefile.am b/cooling-type/Makefile.am index 8be1c3e..8b41812 100644 --- a/cooling-type/Makefile.am +++ b/cooling-type/Makefile.am @@ -1,4 +1,5 @@ AM_DEFAULT_SOURCE_EXT = .cpp +AM_CPPFLAGS = -iquote ${top_srcdir} sbin_PROGRAMS = \ phosphor-cooling-type @@ -8,6 +9,13 @@ phosphor_cooling_type_SOURCES = \ argument.cpp \ cooling_type.cpp -phosphor_cooling_type_LDADD = $(SDBUSPLUS_LIBS) +phosphor_cooling_type_CXXFLAGS = \ + $(SDBUSPLUS_CFLAGS) \ + $(PHOSPHOR_LOGGING_CFLAGS) + +phosphor_cooling_type_LDADD = \ + $(top_builddir)/libfan.la \ + $(SDBUSPLUS_LIBS) \ + $(PHOSPHOR_LOGGING_LIBS) # vim: tabstop=8 noexpandtab diff --git a/cooling-type/cooling_type.cpp b/cooling-type/cooling_type.cpp index 66d9ac9..b80d72d 100644 --- a/cooling-type/cooling_type.cpp +++ b/cooling-type/cooling_type.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "cooling_type.hpp" namespace phosphor @@ -45,11 +46,43 @@ void CoolingType::setupGpio(const std::string& gpioPath) } +CoolingType::ObjectMap CoolingType::getObjectMap(const std::string& objpath) +{ + ObjectMap invObj; + InterfaceMap invIntf; + PropertyMap invProp; + + invProp.emplace("AirCooled", airCooled); + invProp.emplace("WaterCooled", waterCooled); + invIntf.emplace("xyz.openbmc_project.Inventory.Decorator.CoolingType", + std::move(invProp)); + invObj.emplace(objpath, std::move(invIntf)); + + return invObj; +} + void CoolingType::updateInventory(const std::string& objpath) { - //TODO - // setProperty(bus, ..., "AirCooled"); - // setProperty(bus, ..., "WaterCooled"); + using namespace phosphor::logging; + + ObjectMap invObj = getObjectMap(objpath); + + std::string invService; + + invService = phosphor::fan::util::getInvService(bus); + + // Update inventory + auto invMsg = bus.new_method_call(invService.c_str(), + INVENTORY_PATH, + INVENTORY_INTF, + "Notify"); + invMsg.append(std::move(invObj)); + auto invMgrResponseMsg = bus.call(invMsg); + if (invMgrResponseMsg.is_method_error()) + { + throw std::runtime_error( + "Error in inventory manager call to update inventory"); + } } } diff --git a/cooling-type/cooling_type.hpp b/cooling-type/cooling_type.hpp index e0240bd..8775a42 100644 --- a/cooling-type/cooling_type.hpp +++ b/cooling-type/cooling_type.hpp @@ -13,6 +13,17 @@ constexpr auto INVENTORY_INTF = "xyz.openbmc_project.Inventory.Manager"; class CoolingType { + using Property = std::string; + using Value = sdbusplus::message::variant; + // Association between property and its value + using PropertyMap = std::map; + using Interface = std::string; + // Association between interface and the dbus property + using InterfaceMap = std::map; + using Object = sdbusplus::message::object_path; + // Association between object and the interface + using ObjectMap = std::map; + public: CoolingType() = delete; ~CoolingType() = default; @@ -26,7 +37,7 @@ class CoolingType * * @param[in] bus - Dbus bus object */ - CoolingType(sdbusplus::bus::bus& bus) + CoolingType(sdbusplus::bus::bus& bus) : bus(bus) { } @@ -47,15 +58,27 @@ class CoolingType /** * @brief Setup the GPIO device for reading cooling type. * - * @param[in] std::string - Path to the GPIO device file to read + * @param[in] - Path to object to update */ void setupGpio(const std::string&); private: + /** @brief Connection for sdbusplus bus */ + sdbusplus::bus::bus& bus; // File descriptor for the GPIO file we are going to read. phosphor::fan::util::FileDescriptor gpioFd = -1; bool airCooled = false; bool waterCooled = false; + + /** + * @brief Construct the inventory object map for CoolingType. + * + * @param[in] - Path to object to update + * + * @return The inventory object map to update inventory + */ + ObjectMap getObjectMap(const std::string&); + }; } diff --git a/cooling-type/main.cpp b/cooling-type/main.cpp index cddbe31..91934ea 100644 --- a/cooling-type/main.cpp +++ b/cooling-type/main.cpp @@ -1,5 +1,5 @@ #include -#include //make_unique +#include #include #include #include "argument.hpp" -- cgit v1.2.1