pseq: Begin power control implementation

Fill in the power control main method. Introduce the power control
class and header file. Introduce the power good polling loop. Update
meson file to support.

Signed-off-by: Jim Wright <jlwright@us.ibm.com>
Change-Id: I9a5f9d71a65fa4916c701e3aad334be2989b1b16
diff --git a/phosphor-power-sequencer/src/meson.build b/phosphor-power-sequencer/src/meson.build
index 5d4b953..6b42151 100644
--- a/phosphor-power-sequencer/src/meson.build
+++ b/phosphor-power-sequencer/src/meson.build
@@ -1,7 +1,19 @@
-phosphor_power_sequencer = executable(
-    'phosphor-power-control',
-    'power_control.cpp',
-    implicit_include_directories: false,
-    install: true
+phosphor_power_sequencer_include_directories = include_directories(
+    '.',
+    '../..'
 )
 
+phosphor_power_sequencer = executable(
+    'phosphor-power-control',
+    'power_control_main.cpp',
+    'power_control.cpp',
+    dependencies: [
+        phosphor_logging,
+        sdbusplus,
+        sdeventplus,
+        stdplus
+    ],
+    implicit_include_directories: false,
+    include_directories: phosphor_power_sequencer_include_directories,
+    install: true
+)
diff --git a/phosphor-power-sequencer/src/power_control.cpp b/phosphor-power-sequencer/src/power_control.cpp
index 698b0d0..d5810b1 100644
--- a/phosphor-power-sequencer/src/power_control.cpp
+++ b/phosphor-power-sequencer/src/power_control.cpp
@@ -14,7 +14,35 @@
  * limitations under the License.
  */
 
-int main()
+#include "power_control.hpp"
+
+#include "types.hpp"
+
+#include <phosphor-logging/log.hpp>
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+
+#include <chrono>
+#include <exception>
+
+using namespace phosphor::logging;
+
+namespace phosphor::power::sequencer
 {
-    return 0;
+
+PowerControl::PowerControl(sdbusplus::bus::bus& bus,
+                           const sdeventplus::Event& event) :
+    bus{bus},
+    eventLoop{event}, timer{event, std::bind(&PowerControl::pollPgood, this),
+                            std::chrono::milliseconds(pollInterval)}
+{
+    // Obtain dbus service name
+    bus.request_name(POWER_IFACE);
 }
+
+void PowerControl::pollPgood()
+{
+}
+
+} // namespace phosphor::power::sequencer
diff --git a/phosphor-power-sequencer/src/power_control.hpp b/phosphor-power-sequencer/src/power_control.hpp
new file mode 100644
index 0000000..c7c7951
--- /dev/null
+++ b/phosphor-power-sequencer/src/power_control.hpp
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <sdbusplus/bus.hpp>
+#include <sdbusplus/message.hpp>
+#include <sdbusplus/server/object.hpp>
+#include <sdeventplus/event.hpp>
+#include <sdeventplus/utility/timer.hpp>
+
+#include <chrono>
+
+namespace phosphor::power::sequencer
+{
+
+/**
+ * @class PowerControl
+ * This class implements GPIO control of power on / off, and monitoring of the
+ * chassis power good.
+ */
+class PowerControl
+{
+  public:
+    PowerControl() = delete;
+    PowerControl(const PowerControl&) = delete;
+    PowerControl& operator=(const PowerControl&) = delete;
+    PowerControl(PowerControl&&) = delete;
+    PowerControl& operator=(PowerControl&&) = delete;
+    ~PowerControl() = default;
+
+    /**
+     * Creates a controller object for power on and off.
+     * @param[in] bus D-Bus bus object
+     * @param[in] event event object
+     */
+    PowerControl(sdbusplus::bus::bus& bus, const sdeventplus::Event& event);
+
+  private:
+    /**
+     * The D-Bus bus object
+     */
+    sdbusplus::bus::bus& bus;
+
+    /**
+     * Event to loop on
+     */
+    sdeventplus::Event eventLoop;
+
+    /**
+     * Timer to poll the pgood
+     */
+    sdeventplus::utility::Timer<sdeventplus::ClockId::Monotonic> timer;
+
+    /**
+     * Poll interval constant
+     */
+    static constexpr int pollInterval{3000}; // Milliseconds
+
+    /**
+     * Polling method for monitoring the system power good
+     */
+    void pollPgood();
+};
+
+} // namespace phosphor::power::sequencer
diff --git a/phosphor-power-sequencer/src/power_control_main.cpp b/phosphor-power-sequencer/src/power_control_main.cpp
new file mode 100644
index 0000000..7433caf
--- /dev/null
+++ b/phosphor-power-sequencer/src/power_control_main.cpp
@@ -0,0 +1,30 @@
+/**
+ * Copyright © 2021 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 "power_control.hpp"
+
+#include <sdbusplus/bus.hpp>
+#include <sdeventplus/event.hpp>
+
+int main()
+{
+    auto bus = sdbusplus::bus::new_default();
+    auto event = sdeventplus::Event::get_default();
+    bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
+
+    phosphor::power::sequencer::PowerControl control{bus, event};
+    return event.loop();
+}