inventory: implement deserialization

Use Cereal to deserialize inventory information persisted in the
filesystem and restore that to create inventory d-bus objects. Perform
the restore when the app starts.

Change-Id: I0f36a9cbdde223e4bfd9e178e33f5677217ba881
Signed-off-by: Deepak Kodihalli <dkodihal@in.ibm.com>
diff --git a/serialize.hpp b/serialize.hpp
index 281f61c..7c30b9c 100644
--- a/serialize.hpp
+++ b/serialize.hpp
@@ -31,4 +31,25 @@
     oarchive(object);
 }
 
+/** @brief Deserialize inventory item
+ *
+ *  @param[in] path - DBus object path
+ *  @param[in] iface - Inventory interface name
+ *  @param[in] object - Object to be serialized
+ */
+template <typename T>
+inline void deserialize(
+    const Path& path, const Interface& iface, T& object)
+{
+    fs::path p(PIM_PERSIST_PATH);
+    p /= path;
+    p /= iface;
+    if (fs::exists(p))
+    {
+        std::ifstream is(p, std::ios::in | std::ios::binary);
+        cereal::JSONInputArchive iarchive(is);
+        iarchive(object);
+    }
+}
+
 } // namespace cereal