pseq: Add method to Services class to create GPIO
In the phosphor-power-sequencer application, add a method to the
Services class to create a GPIO object. This object can be used to
get/set the GPIO value.
Add the method to the entire Services class hierarchy:
- Services: Abstract base class
- BMCServices: Real implementation of Services interface
- MockServices: Mock implementation of Services interface for automated
testing
Tested:
* Ran automated test cases
Change-Id: I77120843b4124a1ad8d6617bc78cec02ce2ff557
Signed-off-by: Shawn McCarney <shawnmm@us.ibm.com>
diff --git a/phosphor-power-sequencer/src/services.hpp b/phosphor-power-sequencer/src/services.hpp
index 2f38008..25540bb 100644
--- a/phosphor-power-sequencer/src/services.hpp
+++ b/phosphor-power-sequencer/src/services.hpp
@@ -15,6 +15,7 @@
*/
#pragma once
+#include "gpio.hpp"
#include "pmbus.hpp"
#include "xyz/openbmc_project/Logging/Entry/server.hpp"
@@ -101,6 +102,16 @@
virtual bool isPresent(const std::string& inventoryPath) = 0;
/**
+ * Creates a GPIO object for getting/setting the value of a GPIO.
+ *
+ * Throws an exception if a GPIO with the specified name cannot be found.
+ *
+ * @param name GPIO name
+ * @return GPIO object
+ */
+ virtual std::unique_ptr<GPIO> createGPIO(const std::string& name) = 0;
+
+ /**
* Reads all the GPIO values on the chip with the specified label.
*
* Throws an exception if an error occurs while obtaining the values.
@@ -190,6 +201,12 @@
/** @copydoc Services::isPresent() */
virtual bool isPresent(const std::string& inventoryPath) override;
+ /** @copydoc Services::createGPIO() */
+ virtual std::unique_ptr<GPIO> createGPIO(const std::string& name) override
+ {
+ return std::make_unique<BMCGPIO>(name);
+ }
+
/** @copydoc Services::getGPIOValues() */
virtual std::vector<int> getGPIOValues(
const std::string& chipLabel) override;
diff --git a/phosphor-power-sequencer/test/mock_services.hpp b/phosphor-power-sequencer/test/mock_services.hpp
index cb1d445..8a13b6a 100644
--- a/phosphor-power-sequencer/test/mock_services.hpp
+++ b/phosphor-power-sequencer/test/mock_services.hpp
@@ -15,6 +15,7 @@
*/
#pragma once
+#include "mock_gpio.hpp"
#include "mock_pmbus.hpp"
#include "services.hpp"
@@ -50,6 +51,12 @@
(override));
MOCK_METHOD(bool, isPresent, (const std::string& inventoryPath),
(override));
+
+ virtual std::unique_ptr<GPIO> createGPIO(const std::string&) override
+ {
+ return std::make_unique<MockGPIO>();
+ }
+
MOCK_METHOD(std::vector<int>, getGPIOValues, (const std::string& chipLabel),
(override));