regs: Add private manager dbus interface

Create a manager interface that is private to the regulators application
which can be extended to provide a dbus inteface containing methods to
configure and monitor regulators. Since this interface is private to the
regulators application, it will only be accessed thru a standalone
application, TBD, which will be maintained within the
phosphor-regulators repository.

Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I615e2a0f711baa8a8e70d443f6256dc175b4abca
diff --git a/phosphor-regulators/src/interfaces/manager_interface.cpp b/phosphor-regulators/src/interfaces/manager_interface.cpp
new file mode 100644
index 0000000..f4df124
--- /dev/null
+++ b/phosphor-regulators/src/interfaces/manager_interface.cpp
@@ -0,0 +1,119 @@
+/**
+ * Copyright © 2020 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 "manager_interface.hpp"
+
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/exception.hpp>
+#include <sdbusplus/sdbus.hpp>
+#include <sdbusplus/server.hpp>
+
+#include <string>
+#include <tuple>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+namespace interface
+{
+
+ManagerInterface::ManagerInterface(sdbusplus::bus::bus& bus, const char* path) :
+    _serverInterface(bus, path, interface, _vtable, this)
+{
+}
+
+int ManagerInterface::callbackConfigure(sd_bus_message* msg, void* context,
+                                        sd_bus_error* error)
+{
+    if (msg != nullptr && context != nullptr)
+    {
+        try
+        {
+            auto m = sdbusplus::message::message(msg);
+
+            auto mgrObj = static_cast<ManagerInterface*>(context);
+            mgrObj->configure();
+
+            auto reply = m.new_method_return();
+
+            reply.method_return();
+        }
+        catch (sdbusplus::internal_exception_t& e)
+        {
+            return sd_bus_error_set(error, e.name(), e.description());
+        }
+    }
+    else
+    {
+        // The message or context were null
+        using namespace phosphor::logging;
+        log<level::ERR>("Unable to service Configure method callback");
+        return -1;
+    }
+
+    return 1;
+}
+
+int ManagerInterface::callbackMonitor(sd_bus_message* msg, void* context,
+                                      sd_bus_error* error)
+{
+    if (msg != nullptr && context != nullptr)
+    {
+        try
+        {
+            bool enable{};
+            auto m = sdbusplus::message::message(msg);
+
+            m.read(enable);
+
+            auto mgrObj = static_cast<ManagerInterface*>(context);
+            mgrObj->monitor(enable);
+
+            auto reply = m.new_method_return();
+
+            reply.method_return();
+        }
+        catch (sdbusplus::internal_exception_t& e)
+        {
+            return sd_bus_error_set(error, e.name(), e.description());
+        }
+    }
+    else
+    {
+        // The message or context were null
+        using namespace phosphor::logging;
+        log<level::ERR>("Unable to service Monitor method callback");
+        return -1;
+    }
+
+    return 1;
+}
+
+const sdbusplus::vtable::vtable_t ManagerInterface::_vtable[] = {
+    sdbusplus::vtable::start(),
+    // No configure method parameters and returns void
+    sdbusplus::vtable::method("Configure", "", "", callbackConfigure),
+    // Monitor method takes a boolean parameter and returns void
+    sdbusplus::vtable::method("Monitor", "b", "", callbackMonitor),
+    sdbusplus::vtable::end()};
+
+} // namespace interface
+} // namespace regulators
+} // namespace power
+} // namespace phosphor
diff --git a/phosphor-regulators/src/interfaces/manager_interface.hpp b/phosphor-regulators/src/interfaces/manager_interface.hpp
new file mode 100644
index 0000000..3f262d3
--- /dev/null
+++ b/phosphor-regulators/src/interfaces/manager_interface.hpp
@@ -0,0 +1,98 @@
+#pragma once
+
+#include <systemd/sd-bus.h>
+
+#include <sdbusplus/sdbus.hpp>
+#include <sdbusplus/server/interface.hpp>
+#include <sdbusplus/vtable.hpp>
+
+#include <string>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+namespace interface
+{
+
+class ManagerInterface
+{
+  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.
+     */
+    ManagerInterface() = delete;
+    ManagerInterface(const ManagerInterface&) = delete;
+    ManagerInterface& operator=(const ManagerInterface&) = delete;
+    ManagerInterface(ManagerInterface&&) = delete;
+    ManagerInterface& operator=(ManagerInterface&&) = delete;
+    virtual ~ManagerInterface() = 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.
+     */
+    ManagerInterface(sdbusplus::bus::bus& bus, const char* path);
+
+    /**
+     * @brief Implementation for the configure method
+     * Request to configure the regulators according to the
+     * machine's regulators configuration file.
+     */
+    virtual void configure() = 0;
+
+    /**
+     * @brief Implementation for the monitor method
+     * Begin to monitor the regulators according to the
+     * machine's regulators configuration file.
+     *
+     * @param[in] enable - Enable or disable monitoring of the regulators.
+     */
+    virtual void monitor(bool enable) = 0;
+
+    /**
+     * @brief This dbus interface's name
+     */
+    static constexpr auto interface =
+        "xyz.openbmc_project.Power.Regulators.Manager";
+
+  private:
+    /**
+     * @brief Systemd bus callback for the configure method
+     */
+    static int callbackConfigure(sd_bus_message* msg, void* context,
+                                 sd_bus_error* error);
+
+    /**
+     * @brief Systemd bus callback for the monitor method
+     */
+    static int callbackMonitor(sd_bus_message* msg, void* context,
+                               sd_bus_error* error);
+
+    /**
+     * @brief Systemd vtable structure that contains all the
+     * methods, signals, and properties of this interface with their
+     * respective systemd attributes
+     */
+    static const sdbusplus::vtable::vtable_t _vtable[];
+
+    /**
+     * @brief Holder for the instance of this interface to be
+     * on dbus
+     */
+    sdbusplus::server::interface::interface _serverInterface;
+};
+
+} // namespace interface
+} // namespace regulators
+} // namespace power
+} // namespace phosphor