Add/Remove event timers by event name

Using the event name as the key, each timer an event adds to the list of
timers are associated to that event. This allows quick removal of those
timers when the event is removed and more efficient searching for a
timer within the smaller list of timers per event name.

Change-Id: I4624918d3a3bbe2a5224cde4bc3fc529e5b40df3
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/zone.cpp b/control/zone.cpp
index 3077f08..32a297b 100644
--- a/control/zone.cpp
+++ b/control/zone.cpp
@@ -347,23 +347,24 @@
         _signalEvents.erase(sigIter);
     }
 
-    // Remove timers of the event
-    auto it = findTimer(std::get<groupPos>(event),
-                        std::get<actionsPos>(event));
-    if (it != std::end(getTimerEvents()))
+    // Remove event timers
+    auto timIter = _timerEvents.find(std::get<sseNamePos>(event));
+    if (timIter != _timerEvents.end())
     {
-        removeTimer(it);
+        _timerEvents.erase(timIter);
     }
 }
 
 std::vector<TimerEvent>::iterator Zone::findTimer(
         const Group& eventGroup,
-        const std::vector<Action>& eventActions)
+        const std::vector<Action>& eventActions,
+        std::vector<TimerEvent>& eventTimers)
 {
-    for (auto it = _timerEvents.begin(); it != _timerEvents.end(); ++it)
+    for (auto it = eventTimers.begin(); it != eventTimers.end(); ++it)
     {
         const auto& teEventData = *std::get<timerEventDataPos>(*it);
-        if (std::get<eventActionsPos>(teEventData).size() ==
+        if (std::get<eventGroupPos>(teEventData) == eventGroup &&
+            std::get<eventActionsPos>(teEventData).size() ==
             eventActions.size())
         {
             // TODO openbmc/openbmc#2328 - Use the action function target
@@ -374,8 +375,7 @@
                         return a1.target_type().name() ==
                                a2.target_type().name();
                     };
-            if (std::get<eventGroupPos>(teEventData) == eventGroup &&
-                std::equal(eventActions.begin(),
+            if (std::equal(eventActions.begin(),
                            eventActions.end(),
                            std::get<eventActionsPos>(teEventData).begin(),
                            actsEqual))
@@ -385,10 +385,11 @@
         }
     }
 
-    return _timerEvents.end();
+    return eventTimers.end();
 }
 
-void Zone::addTimer(const Group& group,
+void Zone::addTimer(const std::string& name,
+                    const Group& group,
                     const std::vector<Action>& actions,
                     const TimerConf& tConf)
 {
@@ -416,7 +417,7 @@
     {
         throw std::invalid_argument("Invalid Timer Type");
     }
-    _timerEvents.emplace_back(std::move(eventData), std::move(timer));
+    _timerEvents[name].emplace_back(std::move(eventData), std::move(timer));
 }
 
 void Zone::timerExpired(const Group& eventGroup,