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);
+ }
+ }
};