control: manager: Services with no managed objs

When a D-Bus object used in events is under a service that has the
"org.freedesktop.DBus.ObjectManager", the control::json::Manager will
try to get all the managed objects under the service and add to cache.
However, in case when the results from the GetManagedObjects are empty,
it omits the attempt to directly read the object from D-Bus using the
configured information.

This patch handles this situation and allows services that have the
ObjectManager interface but empty managed objects can be read.

Example: Objects under xyz.openbmc_project.State.Host service.

root@mtmitchell-dcscm:~# busctl call xyz.openbmc_project.State.Host \
/xyz/openbmc_project/state/host0 org.freedesktop.DBus.ObjectManager \
GetManagedObjects

a{oa{sa{sv}}} 0

Signed-off-by: Chau Ly <chaul@amperecomputing.com>
Change-Id: I5eca78fdfbc8a26fb7effb861440dc3cf28959d0
diff --git a/control/json/manager.cpp b/control/json/manager.cpp
index efce6f0..0161304 100644
--- a/control/json/manager.cpp
+++ b/control/json/manager.cpp
@@ -559,9 +559,30 @@
     }
 
     auto objMgrPaths = getPaths(service, "org.freedesktop.DBus.ObjectManager");
-    if (objMgrPaths.empty())
+
+    bool useManagedObj = false;
+
+    if (!objMgrPaths.empty())
+    {
+        for (const auto& objMgrPath : objMgrPaths)
+        {
+            // Get all managed objects of service
+            auto objects =
+                util::SDBusPlus::getManagedObjects<PropertyVariantType>(
+                    _bus, service, objMgrPath);
+            if (objects.size() > 0)
+            {
+                useManagedObj = true;
+            }
+            // insert all objects that are in groups but remove any NaN values
+            insertFilteredObjects(objects);
+        }
+    }
+
+    if (!useManagedObj)
     {
         // No object manager interface provided by service?
+        // Or no object is managed?
         // Attempt to retrieve property directly
         try
         {
@@ -575,16 +596,6 @@
         {}
         return;
     }
-
-    for (const auto& objMgrPath : objMgrPaths)
-    {
-        // Get all managed objects of service
-        auto objects = util::SDBusPlus::getManagedObjects<PropertyVariantType>(
-            _bus, service, objMgrPath);
-
-        // insert all objects that are in groups but remove any NaN values
-        insertFilteredObjects(objects);
-    }
 }
 
 const std::optional<PropertyVariantType>