PEL: Use the real system names property

There is now a 'Names' property on the new
xyz.openbmc_project.Configuration.IBMCompatibleSystem interface that the
DataInterface::getSystemNames function will read.  The existing code was
mostly a placeholder until the actual interface showed up on D-Bus.

Since the path that holds the interface is system specific, and the PEL
code should only rarely need this, the code was changed to read it on
demand instead of at caching it startup.

Since getSystemNames() no longer returns a cached value, the signature
was changed slightly to remove the reference from the returned
std::vector<std::string> value.

The UserHeader constructor used to make a call to getSystemNames every
time, and that was changed to only call it when actually necessary,
which is when there is a severity value defined in the message registry
that depends on the system name.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I1d4f307ef38287b631f94dae2b8929307d129029
diff --git a/extensions/openpower-pels/data_interface.cpp b/extensions/openpower-pels/data_interface.cpp
index 4cad337..de6591a 100644
--- a/extensions/openpower-pels/data_interface.cpp
+++ b/extensions/openpower-pels/data_interface.cpp
@@ -64,8 +64,8 @@
     "xyz.openbmc_project.Inventory.Item.Board.Motherboard";
 constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI";
 constexpr auto locCode = "com.ibm.ipzvpd.Location";
-constexpr auto invCompatible =
-    "xyz.openbmc_project.Inventory.Decorator.Compatible";
+constexpr auto compatible =
+    "xyz.openbmc_project.Configuration.IBMCompatibleSystem";
 constexpr auto vpdManager = "com.ibm.VPD.Manager";
 constexpr auto association = "xyz.openbmc_project.Association";
 constexpr auto ledGroup = "xyz.openbmc_project.Led.Group";
@@ -153,13 +153,6 @@
         *this, [this](const auto& value) {
             this->_hostState = std::get<std::string>(value);
         }));
-
-    // Watch the compatible system names property
-    _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>(
-        bus, object_path::chassisInv, interface::invCompatible, "Names", *this,
-        [this](const auto& value) {
-            this->_systemNames = std::get<std::vector<std::string>>(value);
-        }));
 }
 
 DBusPropertyMap
@@ -444,5 +437,32 @@
     _bus.call(method);
 }
 
+std::vector<std::string> DataInterface::getSystemNames() const
+{
+    DBusSubTree subtree;
+    DBusValue names;
+
+    auto method = _bus.new_method_call(service_name::objectMapper,
+                                       object_path::objectMapper,
+                                       interface::objectMapper, "GetSubTree");
+    method.append(std::string{"/"}, 0,
+                  std::vector<std::string>{interface::compatible});
+    auto reply = _bus.call(method);
+
+    reply.read(subtree);
+    if (subtree.empty())
+    {
+        throw std::runtime_error("Compatible interface not on D-Bus");
+    }
+
+    const auto& object = *(subtree.begin());
+    const auto& path = object.first;
+    const auto& service = object.second.begin()->first;
+
+    getProperty(service, path, interface::compatible, "Names", names);
+
+    return std::get<std::vector<std::string>>(names);
+}
+
 } // namespace pels
 } // namespace openpower