treewide: Codify memory pinning

This enforces movability constraints.

Change-Id: I49dbd43a791c1d70eb7e97f30708231c053901d9
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/system_configuration.cpp b/src/system_configuration.cpp
index bccdb02..58b6dfc 100644
--- a/src/system_configuration.cpp
+++ b/src/system_configuration.cpp
@@ -2,6 +2,7 @@
 
 #include <phosphor-logging/elog-errors.hpp>
 #include <phosphor-logging/log.hpp>
+#include <stdplus/pinned.hpp>
 #include <xyz/openbmc_project/Common/error.hpp>
 
 namespace phosphor
@@ -22,40 +23,43 @@
     "interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',"
     "arg0='org.freedesktop.hostname1'";
 
-SystemConfiguration::SystemConfiguration(sdbusplus::bus_t& bus,
-                                         stdplus::const_zstring objPath) :
+SystemConfiguration::SystemConfiguration(
+    stdplus::PinnedRef<sdbusplus::bus_t> bus, stdplus::const_zstring objPath) :
     Iface(bus, objPath.c_str(), Iface::action::defer_emit),
-    bus(bus), hostnamePropMatch(bus, propMatch, [&](sdbusplus::message_t& m) {
-        std::string intf;
-        std::unordered_map<std::string, std::variant<std::string>> values;
-        try
-        {
-            m.read(intf, values);
-            auto it = values.find("Hostname");
-            if (it == values.end())
+    bus(bus),
+    hostnamePropMatch(
+        bus, propMatch,
+        [sc = stdplus::PinnedRef(*this)](sdbusplus::message_t& m) {
+            std::string intf;
+            std::unordered_map<std::string, std::variant<std::string>> values;
+            try
             {
-                return;
+                m.read(intf, values);
+                auto it = values.find("Hostname");
+                if (it == values.end())
+                {
+                    return;
+                }
+                sc.get().Iface::hostName(std::get<std::string>(it->second));
             }
-            Iface::hostName(std::get<std::string>(it->second));
-        }
-        catch (const std::exception& e)
-        {
-            log<level::ERR>(
-                fmt::format("Hostname match parsing failed: {}", e.what())
-                    .c_str(),
-                entry("ERROR=%s", e.what()));
-        }
-    })
+            catch (const std::exception& e)
+            {
+                log<level::ERR>(
+                    fmt::format("Hostname match parsing failed: {}", e.what())
+                        .c_str(),
+                    entry("ERROR=%s", e.what()));
+            }
+        })
 {
     try
     {
         std::variant<std::string> name;
         auto req =
-            bus.new_method_call(HOSTNAMED_SVC, HOSTNAMED_OBJ,
-                                "org.freedesktop.DBus.Properties", "Get");
+            bus.get().new_method_call(HOSTNAMED_SVC, HOSTNAMED_OBJ,
+                                      "org.freedesktop.DBus.Properties", "Get");
 
         req.append(HOSTNAMED_INTF, "Hostname");
-        auto reply = bus.call(req);
+        auto reply = req.call();
         reply.read(name);
         SystemConfigIntf::hostName(std::get<std::string>(name), true);
     }
@@ -76,10 +80,10 @@
     }
     try
     {
-        auto method = bus.new_method_call(HOSTNAMED_SVC, HOSTNAMED_OBJ,
-                                          HOSTNAMED_INTF, "SetStaticHostname");
+        auto method = bus.get().new_method_call(
+            HOSTNAMED_SVC, HOSTNAMED_OBJ, HOSTNAMED_INTF, "SetStaticHostname");
         method.append(name, /*interactive=*/false);
-        bus.call_noreply(method);
+        bus.get().call_noreply(method);
         return SystemConfigIntf::hostName(std::move(name));
     }
     catch (const std::exception& e)