From 7385df624ead75e83b40c25390fc900f9d29b241 Mon Sep 17 00:00:00 2001 From: Tian Jingzai Date: Thu, 20 Jun 2024 16:47:32 +0800 Subject: [PATCH] GpioDbusManager: Support for adding gpio parameters to the service When using the service template, the GPIO value will be passed as a parameter. Signed-off-by: Tian Jingzai Change-Id: I0589f4a214cf15b6e150d3e9f154ab3498293423 --- include/GpioDbusManager.hpp | 3 ++- src/GpioDbusManager.cpp | 17 +++++++++++++++-- src/PowerControl.cpp | 2 +- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/GpioDbusManager.hpp b/include/GpioDbusManager.hpp index 5cb85d1..5896173 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 365c0ff..89e8ddb 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 ff03003..8950094 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); } }; -- Gitee