Implement updating the inventory properties

Implement code needed to update the chassis AirCooled and
WaterCooled properties.

Change-Id: I9a67d1129e99f841200241e2daae08fb6119d9d3
Signed-off-by: Brandon Wyman <bjwyman@gmail.com>
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 @@
 	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 <fcntl.h>
 #include <sdbusplus/bus.hpp>
 #include <phosphor-logging/log.hpp>
+#include <utility.hpp>
 #include "cooling_type.hpp"
 
 namespace phosphor
@@ -45,11 +46,43 @@
 
 }
 
+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 @@
 
 class CoolingType
 {
+        using Property = std::string;
+        using Value = sdbusplus::message::variant<bool>;
+        // Association between property and its value
+        using PropertyMap = std::map<Property, Value>;
+        using Interface = std::string;
+        // Association between interface and the dbus property
+        using InterfaceMap = std::map<Interface, PropertyMap>;
+        using Object = sdbusplus::message::object_path;
+        // Association between object and the interface
+        using ObjectMap = std::map<Object, InterfaceMap>;
+
     public:
         CoolingType() = delete;
         ~CoolingType() = default;
@@ -26,7 +37,7 @@
          *
          * @param[in] bus - Dbus bus object
          */
-        CoolingType(sdbusplus::bus::bus& bus)
+        CoolingType(sdbusplus::bus::bus& bus) : bus(bus)
         {
         }
 
@@ -47,15 +58,27 @@
         /**
          * @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 <iostream>
-#include <memory> //make_unique
+#include <memory>
 #include <sdbusplus/bus.hpp>
 #include <phosphor-logging/log.hpp>
 #include "argument.hpp"