regs: Add manager object
Create a manager object that extends the manager interface overriding
the configure and monitor methods. This provides the framework for
receiving dbus method calls at the appropriate times during a system
poweron or poweroff.
Tested:
Used `busctl` to call the configure method
Used `busctl` to call the monitor method
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
Change-Id: I09db5a800a09205ba182824e62bacb19b10856bd
diff --git a/phosphor-regulators/src/main.cpp b/phosphor-regulators/src/main.cpp
index 5788fb4..e104ef9 100644
--- a/phosphor-regulators/src/main.cpp
+++ b/phosphor-regulators/src/main.cpp
@@ -14,13 +14,20 @@
* limitations under the License.
*/
+#include "manager.hpp"
+
#include <sdbusplus/bus.hpp>
#include <sdeventplus/event.hpp>
int main(void)
{
+ using namespace phosphor::power;
+
auto bus = sdbusplus::bus::new_default();
auto event = sdeventplus::Event::get_default();
bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+
+ regulators::Manager manager(bus);
+
return event.loop();
}
diff --git a/phosphor-regulators/src/manager.cpp b/phosphor-regulators/src/manager.cpp
new file mode 100644
index 0000000..77c715a
--- /dev/null
+++ b/phosphor-regulators/src/manager.cpp
@@ -0,0 +1,61 @@
+/**
+ * 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.hpp"
+
+#include <sdbusplus/bus.hpp>
+
+namespace phosphor
+{
+namespace power
+{
+namespace regulators
+{
+
+Manager::Manager(sdbusplus::bus::bus& bus) :
+ ManagerObject(bus, objPath, true), bus(bus)
+{
+ // TODO get property (IM keyword)
+ // call parse json function
+ // TODO subscribe to interfacesadded (IM keyword)
+ // callback would call parse json function
+
+ // Obtain dbus service name
+ bus.request_name(busName);
+}
+
+void Manager::configure()
+{
+ // TODO Configuration errors that should halt poweron,
+ // throw InternalFailure exception (or similar) to
+ // fail the call(busctl) to this method
+}
+
+void Manager::monitor(bool enable)
+{
+ if (enable)
+ {
+ // TODO Enable timer event that will do the monitoring
+ }
+ else
+ {
+ // TODO Disable/delete timer event to stop monitoring
+ }
+}
+
+} // namespace regulators
+} // namespace power
+} // namespace phosphor
diff --git a/phosphor-regulators/src/manager.hpp b/phosphor-regulators/src/manager.hpp
new file mode 100644
index 0000000..1c680ce
--- /dev/null
+++ b/phosphor-regulators/src/manager.hpp
@@ -0,0 +1,53 @@
+#pragma once
+
+#include <interfaces/manager_interface.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/server/object.hpp>
+
+namespace phosphor::power::regulators
+{
+
+constexpr auto busName = "xyz.openbmc_project.Power.Regulators";
+constexpr auto objPath = "/xyz/openbmc_project/power/regulators/manager";
+
+using ManagerObject = sdbusplus::server::object::object<
+ phosphor::power::regulators::interface::ManagerInterface>;
+
+class Manager : public ManagerObject
+{
+ public:
+ Manager() = delete;
+ Manager(const Manager&) = delete;
+ Manager(Manager&&) = delete;
+ Manager& operator=(const Manager&) = delete;
+ Manager& operator=(Manager&&) = delete;
+ ~Manager() = default;
+
+ /**
+ * Constructor
+ * Creates a manager over the regulators.
+ *
+ * @param[in] bus - the dbus bus
+ */
+ Manager(sdbusplus::bus::bus& bus);
+
+ /**
+ * @brief Overridden manager object's configure method
+ */
+ void configure() override;
+
+ /**
+ * @brief Overridden manager object's monitor method
+ *
+ * @param[in] enable - Enable or disable regulator monitoring
+ */
+ void monitor(bool enable) override;
+
+ private:
+ /**
+ * The dbus bus
+ */
+ sdbusplus::bus::bus& bus;
+};
+
+} // namespace phosphor::power::regulators
diff --git a/phosphor-regulators/src/meson.build b/phosphor-regulators/src/meson.build
index 98449fb..1bf0fb5 100644
--- a/phosphor-regulators/src/meson.build
+++ b/phosphor-regulators/src/meson.build
@@ -35,8 +35,10 @@
phosphor_regulators = executable(
'phosphor-regulators',
+ 'interfaces/manager_interface.cpp',
'journal.cpp',
'main.cpp',
+ 'manager.cpp',
dependencies: [
libi2c_dep,
phosphor_logging,