Merge "Make entity manager produce values for device names"
diff --git a/overlay_templates/SkylakeCPU.template b/overlay_templates/SkylakeCPU.template
index c614916..9f886b4 100644
--- a/overlay_templates/SkylakeCPU.template
+++ b/overlay_templates/SkylakeCPU.template
@@ -10,56 +10,9 @@
 
             peci-hwmon@Skylake_CPU_$cpu_id {
                 compatible = "intel,peci-hwmon";
+                oemname1 = "$name";
                 reg = <$address>;
                 status = "okay";
-
-                oemname1 = "Die_Temp_CPU$cpu_id";
-                oemname2 = "DTS_Thermal_Margin_CPU$cpu_id";
-                oemname3 = "TControl_CPU$cpu_id";
-                oemname4 = "TThrottle_CPU$cpu_id";
-                oemname5 = "Tjmax_CPU$cpu_id";
-
-                oemname100 = "Core0_Temp_CPU$cpu_id";
-                oemname101 = "Core1_Temp_CPU$cpu_id";
-                oemname102 = "Core2_Temp_CPU$cpu_id";
-                oemname103 = "Core3_Temp_CPU$cpu_id";
-                oemname104 = "Core4_Temp_CPU$cpu_id";
-                oemname105 = "Core5_Temp_CPU$cpu_id";
-                oemname106 = "Core6_Temp_CPU$cpu_id";
-                oemname107 = "Core7_Temp_CPU$cpu_id";
-                oemname108 = "Core8_Temp_CPU$cpu_id";
-                oemname109 = "Core9_Temp_CPU$cpu_id";
-                oemname110 = "Core10_Temp_CPU$cpu_id";
-                oemname111 = "Core11_Temp_CPU$cpu_id";
-                oemname112 = "Core12_Temp_CPU$cpu_id";
-                oemname113 = "Core13_Temp_CPU$cpu_id";
-                oemname114 = "Core14_Temp_CPU$cpu_id";
-                oemname115 = "Core15_Temp_CPU$cpu_id";
-                oemname116 = "Core16_Temp_CPU$cpu_id";
-                oemname117 = "Core17_Temp_CPU$cpu_id";
-                oemname118 = "Core18_Temp_CPU$cpu_id";
-                oemname119 = "Core19_Temp_CPU$cpu_id";
-                oemname120 = "Core20_Temp_CPU$cpu_id";
-                oemname121 = "Core21_Temp_CPU$cpu_id";
-                oemname122 = "Core22_Temp_CPU$cpu_id";
-                oemname123 = "Core23_Temp_CPU$cpu_id";
-                oemname124 = "Core24_Temp_CPU$cpu_id";
-                oemname125 = "Core25_Temp_CPU$cpu_id";
-                oemname126 = "Core26_Temp_CPU$cpu_id";
-                oemname127 = "Core27_Temp_CPU$cpu_id";
-
-                oemname200 = "DIMM0_Temp_CPU$cpu_id";
-                oemname201 = "DIMM1_Temp_CPU$cpu_id";
-                oemname202 = "DIMM2_Temp_CPU$cpu_id";
-                oemname203 = "DIMM3_Temp_CPU$cpu_id";
-                oemname204 = "DIMM4_Temp_CPU$cpu_id";
-                oemname205 = "DIMM5_Temp_CPU$cpu_id";
-                oemname206 = "DIMM6_Temp_CPU$cpu_id";
-                oemname207 = "DIMM7_Temp_CPU$cpu_id";
-                oemname208 = "DIMM8_Temp_CPU$cpu_id";
-                oemname209 = "DIMM9_Temp_CPU$cpu_id";
-                oemname210 = "DIMM10_Temp_CPU$cpu_id";
-                oemname211 = "DIMM11_Temp_CPU$cpu_id";
             };
         };
     };
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index 7b91159..c9d0c15 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -100,6 +100,10 @@
         &interfaceDevices,
     std::string interface)
 {
+    // todo: this is only static because the mapper is unreliable as of today
+    static boost::container::flat_map<std::string,
+                                      boost::container::flat_set<std::string>>
+        connections;
     // find all connections in the mapper that expose a specific type
     static const dbus::endpoint mapper("xyz.openbmc_project.ObjectMapper",
                                        "/xyz/openbmc_project/object_mapper",
@@ -112,32 +116,60 @@
         std::cerr << "Pack Failed GetSensorSubtree\n";
         return false;
     }
-    dbus::message getMapResp = connection->send(getMap);
+
     GetSubTreeType interfaceSubtree;
-    if (!getMapResp.unpack(interfaceSubtree))
+    size_t retries = 1;
+    bool unpackStatus = false;
+    // the mapper seems to hang occasionally, not responding, so we give it a
+    // timeout and retries
+    do
     {
-        std::cerr << "Error communicating to mapper\n";
-        return false;
-    }
-    boost::container::flat_set<std::string> connections;
-    for (auto &object : interfaceSubtree)
+        dbus::message getMapResp =
+            connection->send(getMap, std::chrono::seconds(2));
+        unpackStatus = getMapResp.unpack(interfaceSubtree);
+
+    } while (retries-- && !unpackStatus);
+
+    auto &interfaceConnections = connections[interface];
+    if (!unpackStatus)
     {
-        for (auto &connPair : object.second)
+        std::cerr << "Error communicating to mapper, using cached data if "
+                     "available\n";
+        if (interfaceConnections.empty())
         {
-            connections.insert(connPair.first);
+            return false;
+        }
+    }
+
+    if (unpackStatus)
+    {
+        interfaceConnections.clear();
+        for (auto &object : interfaceSubtree)
+        {
+            for (auto &connPair : object.second)
+            {
+                interfaceConnections.insert(connPair.first);
+            }
         }
     }
     // iterate through the connections, adding creating individual device
     // dictionaries
-    for (auto &conn : connections)
+    for (auto &conn : interfaceConnections)
     {
         auto managedObj =
             dbus::endpoint(conn, "/", "org.freedesktop.DBus.ObjectManager",
                            "GetManagedObjects");
         dbus::message getManagedObj = dbus::message::new_call(managedObj);
-        dbus::message getManagedObjResp = connection->send(getManagedObj);
         ManagedObjectType managedInterface;
-        if (!getManagedObjResp.unpack(managedInterface))
+        retries = 1;
+        unpackStatus = false;
+        do
+        {
+            dbus::message getManagedObjResp = connection->send(getManagedObj);
+            unpackStatus = getManagedObjResp.unpack(managedInterface);
+        } while (retries-- && !unpackStatus);
+
+        if (!unpackStatus)
         {
             std::cerr << "error getting managed object for device " << conn
                       << "\n";