Manager: Auto-generate the code

Auto-generate the Manager code during build time
using the sdbus++ tool.

Closes: openbmc/phosphor-logging#1

Change-Id: Idb66725dc2b3a919981dc1a0acfebfde16c4420f
Signed-off-by: Adriana Kobylak <anoo@linux.vnet.ibm.com>
diff --git a/.gitignore b/.gitignore
index e15877d..122f6eb 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,4 @@
 configure
 stamp-h1
 phosphor-logging-*.*
+xyz/openbmc_project/Logging/Internal/Manager/
diff --git a/Makefile.am b/Makefile.am
index d0b1de0..f56fc37 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,7 +5,9 @@
 	phosphor-logging/elog-errors-HostEvent.hpp
 
 # Generate this header, don't export in a distro
-nodist_include_HEADERS = elog-gen.hpp
+nodist_include_HEADERS = \
+	elog-gen.hpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.hpp
 
 libphosphor_logging_FILES = \
 	elog.cpp
@@ -26,17 +28,23 @@
 sbin_PROGRAMS = phosphor-log-manager
 
 phosphor_log_manager_SOURCES = \
-	xyz.openbmc_project.Logging.Internal.Manager.cpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.cpp \
 	log_manager.cpp \
 	log_manager_main.cpp \
 	elog_entry.cpp
 
 # Be sure to build needed files before compiling
-BUILT_SOURCES = elog-gen.hpp elog-lookup.cpp
+BUILT_SOURCES = \
+	elog-gen.hpp \
+	elog-lookup.cpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.cpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.hpp
 
 CLEANFILES = \
 	elog-gen.hpp \
-	elog-lookup.cpp
+	elog-lookup.cpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.cpp \
+	xyz/openbmc_project/Logging/Internal/Manager/server.hpp
 
 # systemd required for journal interfaces
 logging_test_LDFLAGS = $(SYSTEMD_LIBS) $(SDBUSPLUS_LIBS)
@@ -50,6 +58,14 @@
 		$(SDBUSPLUS_CFLAGS) \
 		$(PHOSPHOR_DBUS_INTERFACES_CFLAGS)
 
+xyz/openbmc_project/Logging/Internal/Manager/server.cpp: xyz/openbmc_project/Logging/Internal/Manager.interface.yaml xyz/openbmc_project/Logging/Internal/Manager/server.hpp
+	@mkdir -p `dirname $@`
+	$(SDBUSPLUSPLUS) -r $(srcdir) interface server-cpp xyz.openbmc_project.Logging.Internal.Manager > $@
+
+xyz/openbmc_project/Logging/Internal/Manager/server.hpp: xyz/openbmc_project/Logging/Internal/Manager.interface.yaml
+	@mkdir -p `dirname $@`
+	$(SDBUSPLUSPLUS) -r $(srcdir) interface server-header xyz.openbmc_project.Logging.Internal.Manager > $@
+
 ELOG_MAKO ?= elog-gen-template.mako.hpp
 LOOKUP_MAKO ?= elog-lookup-template.mako.cpp
 ELOG_YAML_DIR ?= tools/example/xyz/openbmc_project/Example/
diff --git a/configure.ac b/configure.ac
index 3c6caca..c99fc1f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -14,6 +14,8 @@
 AM_PROG_AR
 AC_PROG_INSTALL #Checks/sets the install variable to be used
 AC_PROG_MAKE_SET
+AC_PROG_MKDIR_P
+AC_CHECK_PROG([DIRNAME], dirname, dirname)
 # Python
 AM_PATH_PYTHON([2.7], [AC_SUBST([PYTHON], [echo "$PYTHON"])], [AC_MSG_ERROR(
     [Could not find python-2.7 installed...python-2.7 is required])])
@@ -29,12 +31,10 @@
 AX_PKG_CHECK_MODULES([SDBUSPLUS], [sdbusplus], [], [], [AC_MSG_ERROR(["sdbusplus required and not found."])])
 AX_PKG_CHECK_MODULES([PHOSPHOR_DBUS_INTERFACES], [], [phosphor-dbus-interfaces], [], [AC_MSG_ERROR(["phosphor-dbus-interfaces required and not found."])])
 
-AC_CHECK_HEADER(systemd/sd-journal.h, ,[AC_MSG_ERROR([Could not find \
-systemd/sd-journal.h...systemd developement package required])])
-AC_CHECK_HEADER(systemd/sd-bus.h, ,[AC_MSG_ERROR([Could not find \
-systemd/sd-bus.h...systemd developement package required])])
-AC_CHECK_HEADER(sdbusplus/server.hpp, ,[AC_MSG_ERROR([Could not find \
-sdbusplus/server.hpp...openbmc/sdbusplus package required])])
+# Check for sdbus++
+AC_PATH_PROG([SDBUSPLUSPLUS], [sdbus++])
+AS_IF([test "x$SDBUSPLUSPLUS" == "x"],
+    AC_MSG_ERROR(["Requires sdbus++"]))
 
 # Check/set gtest specific functions.
 AX_PTHREAD([GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=1"],[GTEST_CPPFLAGS="-DGTEST_HAS_PTHREAD=0"])
diff --git a/xyz.openbmc_project.Logging.Internal.Manager.cpp b/xyz.openbmc_project.Logging.Internal.Manager.cpp
deleted file mode 100644
index 2afdb6d..0000000
--- a/xyz.openbmc_project.Logging.Internal.Manager.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-#include <algorithm>
-#include <sdbusplus/server.hpp>
-#include <sdbusplus/exception.hpp>
-#include <xyz/openbmc_project/Logging/Internal/Manager/server.hpp>
-
-
-namespace sdbusplus
-{
-namespace xyz
-{
-namespace openbmc_project
-{
-namespace Logging
-{
-namespace Internal
-{
-namespace server
-{
-
-Manager::Manager(bus::bus& bus, const char* path)
-        : _xyz_openbmc_project_Logging_Internal_Manager_interface(
-                bus, path, _interface, _vtable, this)
-{
-}
-
-
-int Manager::_callback_Commit(
-        sd_bus_message* msg, void* context, sd_bus_error* error)
-{
-    using sdbusplus::server::binding::details::convertForMessage;
-
-    try
-    {
-        auto m = message::message(sd_bus_message_ref(msg));
-
-        uint64_t transactionId{};
-    std::string errMsg{};
-
-        m.read(transactionId, errMsg);
-
-        auto o = static_cast<Manager*>(context);
-        o->commit(transactionId, errMsg);
-
-        auto reply = m.new_method_return();
-        // No data to append on reply.
-
-        reply.method_return();
-    }
-    catch(sdbusplus::internal_exception_t& e)
-    {
-        sd_bus_error_set_const(error, e.name(), e.description());
-        return -EINVAL;
-    }
-
-    return true;
-}
-
-namespace details
-{
-namespace Manager
-{
-static const auto _param_Commit =
-        utility::tuple_to_array(message::types::type_id<
-                uint64_t, std::string>());
-static const auto _return_Commit =
-        utility::tuple_to_array(std::make_tuple('\0'));
-}
-}
-
-
-
-
-const vtable::vtable_t Manager::_vtable[] = {
-    vtable::start(),
-
-    vtable::method("Commit",
-                   details::Manager::_param_Commit
-                        .data(),
-                   details::Manager::_return_Commit
-                        .data(),
-                   _callback_Commit),
-    vtable::end()
-};
-
-} // namespace server
-} // namespace Internal
-} // namespace Logging
-} // namespace openbmc_project
-} // namespace xyz
-} // namespace sdbusplus
-
diff --git a/xyz/openbmc_project/Logging/Internal/Manager/server.hpp b/xyz/openbmc_project/Logging/Internal/Manager/server.hpp
deleted file mode 100644
index bbbdef8..0000000
--- a/xyz/openbmc_project/Logging/Internal/Manager/server.hpp
+++ /dev/null
@@ -1,82 +0,0 @@
-#pragma once
-#include <tuple>
-#include <systemd/sd-bus.h>
-#include <sdbusplus/server.hpp>
-
-namespace sdbusplus
-{
-namespace xyz
-{
-namespace openbmc_project
-{
-namespace Logging
-{
-namespace Internal
-{
-namespace server
-{
-
-class Manager
-{
-    public:
-        /* Define all of the basic class operations:
-         *     Not allowed:
-         *         - Default constructor to avoid nullptrs.
-         *         - Copy operations due to internal unique_ptr.
-         *         - Move operations due to 'this' being registered as the
-         *           'context' with sdbus.
-         *     Allowed:
-         *         - Destructor.
-         */
-        Manager() = delete;
-        Manager(const Manager&) = delete;
-        Manager& operator=(const Manager&) = delete;
-        Manager(Manager&&) = delete;
-        Manager& operator=(Manager&&) = delete;
-        virtual ~Manager() = default;
-
-        /** @brief Constructor to put object onto bus at a dbus path.
-         *  @param[in] bus - Bus to attach to.
-         *  @param[in] path - Path to attach at.
-         */
-        Manager(bus::bus& bus, const char* path);
-
-
-
-        /** @brief Implementation for Commit
-         *  Write the requested error/event entry with its associated metadata fields to flash.
-         *
-         *  @param[in] transactionId - The unique identifier of the journal entry(ies) to be committed.
-         *  @param[in] errMsg - The error exception message associated with the error event log to be committed.
-         */
-        virtual void commit(
-            uint64_t transactionId,
-            std::string errMsg) = 0;
-
-
-
-
-    private:
-
-        /** @brief sd-bus callback for Commit
-         */
-        static int _callback_Commit(
-            sd_bus_message*, void*, sd_bus_error*);
-
-
-        static constexpr auto _interface = "xyz.openbmc_project.Logging.Internal.Manager";
-        static const vtable::vtable_t _vtable[];
-        sdbusplus::server::interface::interface
-                _xyz_openbmc_project_Logging_Internal_Manager_interface;
-
-
-};
-
-
-} // namespace server
-} // namespace Internal
-} // namespace Logging
-} // namespace openbmc_project
-} // namespace xyz
-} // namespace sdbusplus
-