Support multi power buttons with multi behaviors
For supporting more-than-one power buttons behaviors,
add new matches and instances by following json config.
This change is for multiple slots integrated on one chassis,
and each slot has button to control power status.
For example:
/xyz/openbmc_project/Chassis/Buttons/Power01 for button on slot1
/xyz/openbmc_project/Chassis/Buttons/Power02 for button on slot2
Moreover, support multi-level power control by json config,
chassis now can do action by corresponding pressing duration.
Tested:
Press buttons and check corresponding behaviors.
Change-Id: I7789f0367d5e846dd9e68f966ba0755fc916217a
Signed-off-by: Rush Chen <rush.chen.wiwynn@gmail.com>
diff --git a/inc/button_factory.hpp b/inc/button_factory.hpp
index 83cf530..2b7c9b9 100644
--- a/inc/button_factory.hpp
+++ b/inc/button_factory.hpp
@@ -35,13 +35,27 @@
template <typename T>
void addToRegistry()
{
- buttonIfaceRegistry[std::string(T::getFormFactorName())] =
+ buttonIfaceRegistry[T::getFormFactorName()] =
[](sdbusplus::bus_t& bus, EventPtr& event,
ButtonConfig& buttonCfg) {
- return std::make_unique<T>(bus, T::getDbusObjectPath(), event,
- buttonCfg);
+ return std::make_unique<T>(bus, T::getDbusObjectPath().c_str(),
+ event, buttonCfg);
};
}
+
+ template <typename T>
+ void addToRegistry(size_t index)
+ {
+ auto indexStr = std::to_string(index);
+ buttonIfaceRegistry[T::getFormFactorName() + indexStr] =
+ [=](sdbusplus::bus_t& bus, EventPtr& event,
+ ButtonConfig& buttonCfg) {
+ return std::make_unique<T>(
+ bus, (T::getDbusObjectPath() + indexStr).c_str(), event,
+ buttonCfg);
+ };
+ }
+
/**
* @brief this method returns the button interface object
* corresponding to the button formfactor name provided
@@ -76,4 +90,15 @@
// register the class factory function
ButtonFactory::instance().addToRegistry<T>();
}
+
+ explicit ButtonIFRegister(size_t count)
+ {
+ // register the class factory function
+ // The index, 'countIter', starts at 1 and increments,
+ // representing slot_1 through slot_N.
+ for (size_t countIter = 1; countIter <= count; countIter++)
+ {
+ ButtonFactory::instance().addToRegistry<T>(countIter);
+ }
+ }
};
diff --git a/inc/button_handler.hpp b/inc/button_handler.hpp
index 1332a0f..ff8850b 100644
--- a/inc/button_handler.hpp
+++ b/inc/button_handler.hpp
@@ -1,10 +1,16 @@
#pragma once
+#include "config.hpp"
#include "power_button_profile.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
+#include <algorithm>
+#include <numeric>
+#include <sstream>
+#include <string>
+
namespace phosphor
{
namespace button
@@ -16,6 +22,19 @@
powerReleased,
resetReleased
};
+
+enum class PwrCtl
+{
+ chassisOn,
+ chassisOff,
+ chassisCycle,
+};
+
+inline static size_t numberOfChassis()
+{
+ return instances.size();
+}
+
/**
* @class Handler
*
@@ -129,6 +148,7 @@
* @return void
*/
void handlePowerEvent(PowerEvent powerEventType,
+ const std::string& objectPath,
std::chrono::microseconds duration);
/**
@@ -147,6 +167,12 @@
std::unique_ptr<sdbusplus::bus::match_t> powerButtonLongPressed;
/**
+ * @brief Matches on the multi power button released signal
+ */
+ std::vector<std::unique_ptr<sdbusplus::bus::match_t>>
+ multiPowerButtonReleased;
+
+ /**
* @brief Matches on the ID button released signal
*/
std::unique_ptr<sdbusplus::bus::match_t> idButtonReleased;
@@ -165,6 +191,17 @@
* @brief The custom power handler profile object.
*/
std::unique_ptr<PowerButtonProfile> powerButtonProfile;
+
+ /**
+ * @brief Flag to indicate multi power button mode(false) or host select
+ * button mode(true)
+ */
+ bool hostSelectButtonMode = false;
+
+ /**
+ * @brief Flag to indicate if the button supports multi action
+ */
+ bool isButtonMultiActionSupport = true;
};
} // namespace button
diff --git a/inc/debugHostSelector_button.hpp b/inc/debugHostSelector_button.hpp
index bbae539..17431d4 100644
--- a/inc/debugHostSelector_button.hpp
+++ b/inc/debugHostSelector_button.hpp
@@ -13,8 +13,7 @@
#include <phosphor-logging/elog-errors.hpp>
#include <phosphor-logging/lg2.hpp>
-static constexpr std::string_view DEBUG_SELECTOR_BUTTON =
- "DEBUG_SELECTOR_BUTTON";
+static constexpr auto DEBUG_SELECTOR_BUTTON = "DEBUG_SELECTOR_BUTTON";
class DebugHostSelector final :
public sdbusplus::server::object_t<
@@ -44,12 +43,12 @@
void simLongPress() override;
void handleEvent(sd_event_source* es, int fd, uint32_t revents) override;
- static constexpr std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return DEBUG_SELECTOR_BUTTON;
}
- static const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return DBG_HS_DBUS_OBJECT_NAME;
}
diff --git a/inc/hostSelector_switch.hpp b/inc/hostSelector_switch.hpp
index 70e31e0..04f80bb 100644
--- a/inc/hostSelector_switch.hpp
+++ b/inc/hostSelector_switch.hpp
@@ -15,7 +15,7 @@
#include <fstream>
#include <iostream>
-static constexpr std::string_view HOST_SELECTOR = "HOST_SELECTOR";
+static constexpr auto HOST_SELECTOR = "HOST_SELECTOR";
static constexpr auto INVALID_INDEX = std::numeric_limits<size_t>::max();
@@ -51,12 +51,12 @@
deInit();
}
- static constexpr std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return HOST_SELECTOR;
}
- static const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return HS_DBUS_OBJECT_NAME;
}
diff --git a/inc/host_then_chassis_poweroff.hpp b/inc/host_then_chassis_poweroff.hpp
index 96d7aee..cf29a4a 100644
--- a/inc/host_then_chassis_poweroff.hpp
+++ b/inc/host_then_chassis_poweroff.hpp
@@ -61,7 +61,7 @@
* @brief Returns the name that matches the value in
* meson_options.txt.
*/
- static constexpr std::string_view getName()
+ static constexpr std::string getName()
{
return "host_then_chassis_poweroff";
}
diff --git a/inc/id_button.hpp b/inc/id_button.hpp
index 5239d77..7329bae 100644
--- a/inc/id_button.hpp
+++ b/inc/id_button.hpp
@@ -27,7 +27,7 @@
#include <phosphor-logging/elog-errors.hpp>
-static constexpr std::string_view ID_BUTTON = "ID_BTN";
+static constexpr auto ID_BUTTON = "ID_BTN";
class IDButton :
public sdbusplus::server::object_t<
@@ -52,11 +52,11 @@
void simPress() override;
- static constexpr std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return ID_BUTTON;
}
- static constexpr const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return ID_DBUS_OBJECT_NAME;
}
diff --git a/inc/power_button.hpp b/inc/power_button.hpp
index 2cf28e4..f1e8ca2 100644
--- a/inc/power_button.hpp
+++ b/inc/power_button.hpp
@@ -29,7 +29,7 @@
#include <chrono>
-static constexpr std::string_view POWER_BUTTON = "POWER_BUTTON";
+static constexpr auto POWER_BUTTON = "POWER_BUTTON";
class PowerButton :
public sdbusplus::server::object_t<
@@ -55,11 +55,11 @@
void simPress() override;
void simLongPress() override;
- static constexpr std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return POWER_BUTTON;
}
- static constexpr const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return POWER_DBUS_OBJECT_NAME;
}
diff --git a/inc/power_button_profile_factory.hpp b/inc/power_button_profile_factory.hpp
index 3f05c77..ea8ca2e 100644
--- a/inc/power_button_profile_factory.hpp
+++ b/inc/power_button_profile_factory.hpp
@@ -33,7 +33,7 @@
template <typename T>
void addToRegistry()
{
- profileRegistry[std::string(T::getName())] = [](sdbusplus::bus_t& bus) {
+ profileRegistry[T::getName()] = [](sdbusplus::bus_t& bus) {
return std::make_unique<T>(bus);
};
}
diff --git a/inc/reset_button.hpp b/inc/reset_button.hpp
index 79a6096..f370ed4 100644
--- a/inc/reset_button.hpp
+++ b/inc/reset_button.hpp
@@ -27,7 +27,7 @@
#include <phosphor-logging/elog-errors.hpp>
-static constexpr std::string_view RESET_BUTTON = "RESET_BUTTON";
+static constexpr auto RESET_BUTTON = "RESET_BUTTON";
class ResetButton :
public sdbusplus::server::object_t<
@@ -52,12 +52,12 @@
void simPress() override;
- static constexpr std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return RESET_BUTTON;
}
- static constexpr const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return RESET_DBUS_OBJECT_NAME;
}
diff --git a/inc/serial_uart_mux.hpp b/inc/serial_uart_mux.hpp
index a280cb4..1e954da 100644
--- a/inc/serial_uart_mux.hpp
+++ b/inc/serial_uart_mux.hpp
@@ -14,9 +14,8 @@
#include <phosphor-logging/elog-errors.hpp>
#include <sdbusplus/bus.hpp>
#include <sdbusplus/bus/match.hpp>
-static constexpr std::string_view DEBUG_CARD_PRESENT_GPIO =
- "debug_card_present";
-static constexpr std::string_view SERIAL_CONSOLE_SWITCH = "SERIAL_UART_MUX";
+static constexpr auto DEBUG_CARD_PRESENT_GPIO = "debug_card_present";
+static constexpr auto SERIAL_CONSOLE_SWITCH = "SERIAL_UART_MUX";
class SerialUartMux final : public ButtonIface
{
@@ -58,11 +57,11 @@
deInit();
}
void init() override;
- static const std::string_view getFormFactorName()
+ static constexpr std::string getFormFactorName()
{
return SERIAL_CONSOLE_SWITCH;
}
- static const char* getDbusObjectPath()
+ static constexpr std::string getDbusObjectPath()
{
return "NO_DBUS_OBJECT";
}