libpldmresponder: Create default D-Bus object when generate PDR

In order to make each sensor correspond to its D-Bus object, on a system
where the D-Bus object path does not exist, when the D-Bus object
specified here can not be found, a default D-Bus object should be
created.

Tested:
Before: When the number of composite sensors is inconsistent with the
number of D-Bus objects, the wrong D-Bus object will be obtained through
the SensorID.
After: The number of composite sensors is the same as the number of D-Bus
objects, and the correct D-Bus object can be obtained through the
GetStateSensorReadings command.

Signed-off-by: George Liu <liuxiwei@inspur.com>
Change-Id: Ib35fc97471a427e50406c57fed2bd66b51330b79
diff --git a/libpldmresponder/pdr_numeric_effecter.hpp b/libpldmresponder/pdr_numeric_effecter.hpp
index 0258ab2..9152320 100644
--- a/libpldmresponder/pdr_numeric_effecter.hpp
+++ b/libpldmresponder/pdr_numeric_effecter.hpp
@@ -192,21 +192,24 @@
         auto propertyName = dbusEntry.value("property_name", "");
         auto propertyType = dbusEntry.value("property_type", "");
 
+        DbusMappings dbusMappings{};
+        DbusValMaps dbusValMaps{};
+        pldm::utils::DBusMapping dbusMapping{};
         try
         {
             auto service =
                 dBusIntf.getService(objectPath.c_str(), interface.c_str());
+
+            dbusMapping = pldm::utils::DBusMapping{objectPath, interface,
+                                                   propertyName, propertyType};
         }
         catch (const std::exception& e)
         {
-            continue;
+            std::cerr << "D-Bus object path does not exist, effecter ID: "
+                      << pdr->effecter_id << "\n";
         }
-
-        pldm::utils::DBusMapping dbusMapping{objectPath, interface,
-                                             propertyName, propertyType};
-        DbusMappings dbusMappings{};
-        DbusValMaps dbusValMaps{};
         dbusMappings.emplace_back(std::move(dbusMapping));
+
         handler.addDbusObjMaps(
             pdr->effecter_id,
             std::make_tuple(std::move(dbusMappings), std::move(dbusValMaps)));
diff --git a/libpldmresponder/pdr_state_effecter.hpp b/libpldmresponder/pdr_state_effecter.hpp
index b47686b..aa0e912 100644
--- a/libpldmresponder/pdr_state_effecter.hpp
+++ b/libpldmresponder/pdr_state_effecter.hpp
@@ -132,27 +132,26 @@
             auto propertyName = dbusEntry.value("property_name", "");
             auto propertyType = dbusEntry.value("property_type", "");
 
+            StatestoDbusVal dbusIdToValMap{};
+            pldm::utils::DBusMapping dbusMapping{};
             try
             {
                 auto service =
                     dBusIntf.getService(objectPath.c_str(), interface.c_str());
+
+                dbusMapping = pldm::utils::DBusMapping{
+                    objectPath, interface, propertyName, propertyType};
+                dbusIdToValMap = populateMapping(
+                    propertyType, dbusEntry["property_values"], stateValues);
             }
             catch (const std::exception& e)
             {
-                continue;
+                std::cerr << "D-Bus object path does not exist, effecter ID: "
+                          << pdr->effecter_id << "\n";
             }
 
-            pldm::utils::DBusMapping dbusMapping{objectPath, interface,
-                                                 propertyName, propertyType};
             dbusMappings.emplace_back(std::move(dbusMapping));
-
-            Json propValues = dbusEntry["property_values"];
-            StatestoDbusVal dbusIdToValMap =
-                populateMapping(propertyType, propValues, stateValues);
-            if (!dbusIdToValMap.empty())
-            {
-                dbusValMaps.emplace_back(std::move(dbusIdToValMap));
-            }
+            dbusValMaps.emplace_back(std::move(dbusIdToValMap));
         }
         handler.addDbusObjMaps(
             pdr->effecter_id,
diff --git a/libpldmresponder/pdr_state_sensor.hpp b/libpldmresponder/pdr_state_sensor.hpp
index 04b6965..b94b297 100644
--- a/libpldmresponder/pdr_state_sensor.hpp
+++ b/libpldmresponder/pdr_state_sensor.hpp
@@ -144,27 +144,26 @@
             auto propertyName = dbusEntry.value("property_name", "");
             auto propertyType = dbusEntry.value("property_type", "");
 
+            StatestoDbusVal dbusIdToValMap{};
+            pldm::utils::DBusMapping dbusMapping{};
             try
             {
                 auto service =
                     dBusIntf.getService(objectPath.c_str(), interface.c_str());
+
+                dbusMapping = pldm::utils::DBusMapping{
+                    objectPath, interface, propertyName, propertyType};
+                dbusIdToValMap = populateMapping(
+                    propertyType, dbusEntry["property_values"], stateValues);
             }
             catch (const std::exception& e)
             {
-                continue;
+                std::cerr << "D-Bus object path does not exist, sensor ID: "
+                          << pdr->sensor_id << "\n";
             }
 
-            pldm::utils::DBusMapping dbusMapping{objectPath, interface,
-                                                 propertyName, propertyType};
             dbusMappings.emplace_back(std::move(dbusMapping));
-
-            Json propValues = dbusEntry["property_values"];
-            StatestoDbusVal dbusIdToValMap =
-                populateMapping(propertyType, propValues, stateValues);
-            if (!dbusIdToValMap.empty())
-            {
-                dbusValMaps.emplace_back(std::move(dbusIdToValMap));
-            }
+            dbusValMaps.emplace_back(std::move(dbusIdToValMap));
         }
 
         handler.addDbusObjMaps(