control: Rework/optimize preloading timer groups

Employ the use of the service name defined on the group instead of
retrieving the service for each group member if its given in the group's
configuration. In addition, switch to getting the service, when not
configured on the group, from the service tree cache.

Change-Id: Ice7b19c90c8fc03cb7201ebdb884c23366c1f23e
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index ae007ad..afeff2f 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -623,15 +623,18 @@
 
 void Manager::addGroup(const Group& group)
 {
-    std::set<std::string> services;
+    std::string service = "";
+    std::set<std::string> grpServices;
     for (const auto& member : group.getMembers())
     {
         try
         {
-            const auto& service =
-                util::SDBusPlus::getService(member, group.getInterface());
+            service = group.getService();
+            if (service.empty())
+            {
+                service = getService(member, group.getInterface());
+            }
 
-            // TODO - Optimize to only retrieve the paths on this service
             auto objMgrPaths =
                 getPaths(service, "org.freedesktop.DBus.ObjectManager");
 
@@ -656,9 +659,9 @@
                 continue;
             }
 
-            if (services.find(service) == services.end())
+            if (grpServices.find(service) == grpServices.end())
             {
-                services.insert(service);
+                grpServices.insert(service);
                 for (const auto& objMgrPath : objMgrPaths)
                 {
                     // Get all managed objects from the service
@@ -671,10 +674,10 @@
                 }
             }
         }
-        catch (const util::DBusServiceError&)
+        catch (const util::DBusError&)
         {
-            // No service found for group member containing the group's
-            // configured interface
+            // No service or property found for group member with the
+            // group's configured interface
             continue;
         }
     }