Support event multi targets
Description:
- Support event multi targets.
Design:
- The origin multi-gpio-monitor doesn't detect the comming events are
rising or falling and it can only start one service after events
triggered.
- We need to do corresponding actions when gpio pin rising or falling.
So we modify multi-gpio-monitor config json and read the rising
actions and falling actions in it.
- When service monitored one gpio status is changed,
service will detect that it is a rising or falling event and then
call systemd startUnit to start services that set in config json.
- For example with config json below:
When PowerGood is falling, "PowerGoodFalling.service"
and "PowerOff.service" will start.
[
{
"Name": "PowerGood",
"ChipId": "0",
"GpioNum": 14,
"EventMon": "BOTH",
"Targets": {
"FALLING": ["PowerGoodFalling.service", "PowerOff.service"],
"RISING": ["PowerGoodRising.service", "PowerOn.service"]
},
"Continue": true
}
]
Test Case:
Check that corresponding targets start or not - pass
Signed-off-by: Delphine CC Chiu <Delphine_CC_Chiu@wiwynn.com>
Change-Id: I043d4385b91a04d360a4d50048320db15e63ac74
diff --git a/gpioMonMain.cpp b/gpioMonMain.cpp
index bb30a8e..8530ffc 100644
--- a/gpioMonMain.cpp
+++ b/gpioMonMain.cpp
@@ -103,6 +103,9 @@
/* target to start */
std::string target;
+ /* multi targets to start */
+ std::map<std::string, std::vector<std::string>> targets;
+
if (obj.find("LineName") == obj.end())
{
/* If there is no line Name defined then gpio num nd chip
@@ -173,9 +176,15 @@
target = obj["Target"];
}
+ /* Parse out the targets argument if multi-targets are needed.*/
+ if (obj.find("Targets") != obj.end())
+ {
+ obj.at("Targets").get_to(targets);
+ }
+
/* Create a monitor object and let it do all the rest */
gpios.push_back(std::make_unique<phosphor::gpio::GpioMonitor>(
- line, config, io, target, lineMsg, flag));
+ line, config, io, target, targets, lineMsg, flag));
}
io.run();