diff --git a/include/GpioDbusManager.hpp b/include/GpioDbusManager.hpp index 5cb85d1df8e5efda6b806757fd5b4efeb5895257..58961731914537cf882ffd4c395cd92e7b18f859 100644 --- a/include/GpioDbusManager.hpp +++ b/include/GpioDbusManager.hpp @@ -83,5 +83,6 @@ class GpioDbusManager : public Gpio * @brief Start a service. * * @param[in] target - Service name. + * @param[in] status - Current gpio status. */ -void startUnit(const std::string& target); +void startUnit(std::string target, const int status); diff --git a/src/GpioDbusManager.cpp b/src/GpioDbusManager.cpp index 365c0ff72ab866d4ee64e961995dbec5685f0b1c..89e8ddbcc24a0c8f9ecf8777a7389564f2227bb9 100644 --- a/src/GpioDbusManager.cpp +++ b/src/GpioDbusManager.cpp @@ -22,6 +22,7 @@ #include #include +#include GpioDbusManager::GpioDbusManager( const GpioInfo& gpioInfo, @@ -117,7 +118,7 @@ void GpioDbusManager::gpioEventLoop() if (target.first == BOTH || target.first == currentState) { - startUnit(target.second); + startUnit(target.second, currentState); } } } @@ -130,8 +131,20 @@ void GpioDbusManager::gpioEventLoop() }); } -void startUnit(const std::string& target) +void startUnit(std::string target, const int status) { + const std::regex regex("([a-zA-Z0-9\\-\\_\\.]+)@\\.(service)?(target)?"); + std::smatch match; + + if (std::regex_match(target, match, regex)) + { + std::string::size_type n = target.find_first_of('@'); + if (n != std::string::npos) + { + target.insert(n + 1, std::to_string(status)); + } + } + try { auto bus = sdbusplus::bus::new_default(); diff --git a/src/PowerControl.cpp b/src/PowerControl.cpp index ff030038552163228ecce33d169f728b2bd9be09..89500948762fa19937e716947c7664f38be242d8 100644 --- a/src/PowerControl.cpp +++ b/src/PowerControl.cpp @@ -81,6 +81,6 @@ PowerControl::PowerControl( /* If it is turned on by default, update the status */ if (GpioDbusManager::currentState) { - startUnit(powers.pgood.target); + startUnit(powers.pgood.target, 1); } };