Add Callout class

This class will be used to put a hardware callout object
on D-Bus that shows the serial number and part number information
for what is being called out in an error log.

It will remain even after that part is replaced with a new part with
a new SN, so the data needs to be persisted as opposed to being
looked up in the inventory on startup.  The persisting will be
done in a future commit.  Note it will also survive an error log
being resolved, which would delete the inventory assocation interface
on the error log.

The object path of the callout objects will look something like
/xyz/openbmc_project/logging/entry/5/callouts/0, where this would be
the first callout on error log 5.

Tested: N/A - not used yet

Change-Id: I7e2f0c61705880ad70d5f6a49209f73a499785b9
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/Makefile.am b/Makefile.am
index 5cc1a1f..1b2bbcd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3,6 +3,7 @@
 sbin_PROGRAMS = ibm-log-manager
 
 ibm_log_manager_SOURCES = \
+	callout.cpp \
 	dbus.cpp \
 	main.cpp \
 	manager.cpp \
diff --git a/callout.cpp b/callout.cpp
new file mode 100644
index 0000000..ef72414
--- /dev/null
+++ b/callout.cpp
@@ -0,0 +1,70 @@
+/** Copyright © 2018 IBM Corporation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include "callout.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+
+Callout::Callout(sdbusplus::bus::bus& bus, const std::string& objectPath,
+                 size_t id, uint64_t timestamp) :
+    CalloutObject(bus, objectPath.c_str(), true),
+    entryID(id), timestamp(timestamp)
+{
+}
+
+Callout::Callout(sdbusplus::bus::bus& bus, const std::string& objectPath,
+                 const std::string& inventoryPath, size_t id,
+                 uint64_t timestamp, const DbusPropertyMap& properties) :
+    CalloutObject(bus, objectPath.c_str(), true),
+    entryID(id), timestamp(timestamp)
+{
+    path(inventoryPath);
+
+    auto it = properties.find("BuildDate");
+    if (it != properties.end())
+    {
+        buildDate(it->second.get<std::string>());
+    }
+
+    it = properties.find("Manufacturer");
+    if (it != properties.end())
+    {
+        manufacturer(it->second.get<std::string>());
+    }
+
+    it = properties.find("Model");
+    if (it != properties.end())
+    {
+        model(it->second.get<std::string>());
+    }
+
+    it = properties.find("PartNumber");
+    if (it != properties.end())
+    {
+        partNumber(it->second.get<std::string>());
+    }
+
+    it = properties.find("SerialNumber");
+    if (it != properties.end())
+    {
+        serialNumber(it->second.get<std::string>());
+    }
+
+    emit_object_added();
+}
+}
+}
diff --git a/callout.hpp b/callout.hpp
new file mode 100644
index 0000000..7eec934
--- /dev/null
+++ b/callout.hpp
@@ -0,0 +1,118 @@
+#pragma once
+
+#include <experimental/filesystem>
+#include "dbus.hpp"
+#include "interfaces.hpp"
+
+namespace ibm
+{
+namespace logging
+{
+
+namespace fs = std::experimental::filesystem;
+
+/**
+ *  @class Callout
+ *
+ *  This class provides information about a callout by utilizing the
+ *  xyz.openbmc_project.Inventory.Decorator.Asset and
+ *  xyz.openbmc_project.Common.ObjectPath interfaces.
+ *
+ *  It also has the ability to persist and restore its data.
+ */
+class Callout : public CalloutObject
+{
+  public:
+    Callout() = delete;
+    Callout(const Callout&) = delete;
+    Callout& operator=(const Callout&) = delete;
+    Callout(Callout&&) = default;
+    Callout& operator=(Callout&&) = default;
+    ~Callout() = default;
+
+    /**
+     * Constructor
+     *
+     * Populates the Asset D-Bus properties with data from the property map.
+     *
+     * @param[in] bus - D-Bus object
+     * @param[in] objectPath - object path
+     * @param[in] inventoryPath - inventory path of the callout
+     * @param[in] id - which callout this is
+     * @param[in] timestamp - timestamp when the log was created
+     * @param[in] properties - the properties for the Asset interface.
+     */
+    Callout(sdbusplus::bus::bus& bus, const std::string& objectPath,
+            const std::string& inventoryPath, size_t id, uint64_t timestamp,
+            const DbusPropertyMap& properties);
+    /**
+     * Constructor
+     *
+     * This version is for when the object is being restored and does
+     * not take the properties map.
+     *
+     * @param[in] bus - D-Bus object
+     * @param[in] objectPath - object path
+     * @param[in] id - which callout this is
+     * @param[in] timestamp - timestamp when the log was created
+     * @param[in] properties - the properties for the Asset interface.
+     */
+    Callout(sdbusplus::bus::bus& bus, const std::string& objectPath, size_t id,
+            uint64_t timestamp);
+
+    /**
+     * Returns the callout ID
+     *
+     * @return id - the ID
+     */
+    inline auto id() const
+    {
+        return entryID;
+    }
+
+    /**
+     * Sets the callout ID
+     *
+     * @param[in] id - the ID
+     */
+    inline void id(uint32_t id)
+    {
+        entryID = id;
+    }
+
+    /**
+     * Returns the timestamp
+     *
+     * @return timestamp
+     */
+    inline auto ts() const
+    {
+        return timestamp;
+    }
+
+    /**
+     * Sets the timestamp
+     *
+     * @param[in] ts - the timestamp
+     */
+    inline void ts(uint64_t ts)
+    {
+        timestamp = ts;
+    }
+
+  private:
+    /**
+     * The unique identifier for the callout, as error logs can have
+     * multiple callouts.  They start at 0.
+     */
+    size_t entryID;
+
+    /**
+     * The timestamp of when the error log was created.
+     * Used for ensuring the callout data is being restored for
+     * the correct error log.
+     */
+    uint64_t timestamp;
+};
+}
+}
diff --git a/interfaces.hpp b/interfaces.hpp
index 0dfa668..6c7651f 100644
--- a/interfaces.hpp
+++ b/interfaces.hpp
@@ -1,6 +1,8 @@
 #pragma once
 
 #include <com/ibm/Logging/Policy/server.hpp>
+#include <xyz/openbmc_project/Common/ObjectPath/server.hpp>
+#include <xyz/openbmc_project/Inventory/Decorator/Asset/server.hpp>
 
 namespace ibm
 {
@@ -10,11 +12,19 @@
 template <typename... T>
 using ServerObject = typename sdbusplus::server::object::object<T...>;
 
+using ObjectPathInterface =
+    sdbusplus::xyz::openbmc_project::Common::server::ObjectPath;
+
+using CalloutInterface =
+    sdbusplus::xyz::openbmc_project::Inventory::Decorator::server::Asset;
+using CalloutObject = ServerObject<CalloutInterface, ObjectPathInterface>;
+
 using PolicyInterface = sdbusplus::com::ibm::Logging::server::Policy;
 using PolicyObject = ServerObject<PolicyInterface>;
 
 enum class InterfaceType
 {
+    CALLOUT,
     POLICY
 };
 }