Blame SOURCES/0002-backend-switch-to-using-generated-logind-proxy.patch

657d8e
From 063db6c9a7504a4d7baae28f7899bd661c459c41 Mon Sep 17 00:00:00 2001
657d8e
From: Ray Strode <rstrode@redhat.com>
657d8e
Date: Mon, 14 Jan 2019 11:11:01 -0500
657d8e
Subject: [PATCH 2/9] backend: switch to using generated logind proxy
657d8e
657d8e
Right now we listen to prepare-for-sleep using
657d8e
raw gdbus calls.
657d8e
657d8e
This commit switches it over to use a generated
657d8e
proxy, which will become useful in a future commit,
657d8e
for adding suspending inhibitors.
657d8e
---
657d8e
 src/backends/meta-backend.c    | 60 ++++++++++++++++++++++------------
657d8e
 src/org.freedesktop.login1.xml | 13 ++++++++
657d8e
 2 files changed, 52 insertions(+), 21 deletions(-)
657d8e
657d8e
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
657d8e
index 23ab2faec..5d71977c6 100644
657d8e
--- a/src/backends/meta-backend.c
657d8e
+++ b/src/backends/meta-backend.c
657d8e
@@ -65,6 +65,7 @@
657d8e
 #include "meta/main.h"
657d8e
 #include "meta/meta-backend.h"
657d8e
 #include "meta/util.h"
657d8e
+#include "meta-dbus-login1.h"
657d8e
 
657d8e
 #ifdef HAVE_REMOTE_DESKTOP
657d8e
 #include "backends/meta-dbus-session-watcher.h"
657d8e
@@ -145,10 +146,12 @@ struct _MetaBackendPrivate
657d8e
   GDBusProxy *upower_proxy;
657d8e
   gboolean lid_is_closed;
657d8e
 
657d8e
-  guint sleep_signal_id;
657d8e
   GCancellable *cancellable;
657d8e
   GDBusConnection *system_bus;
657d8e
 
657d8e
+  Login1Manager *logind_proxy;
657d8e
+  int            inhibit_sleep_fd;
657d8e
+
657d8e
   gboolean was_headless;
657d8e
 };
657d8e
 typedef struct _MetaBackendPrivate MetaBackendPrivate;
657d8e
@@ -156,6 +159,10 @@ typedef struct _MetaBackendPrivate MetaBackendPrivate;
657d8e
 static void
657d8e
 initable_iface_init (GInitableIface *initable_iface);
657d8e
 
657d8e
+
657d8e
+static void prepare_for_sleep_cb (MetaBackend *backend,
657d8e
+                                  gboolean     suspending);
657d8e
+
657d8e
 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (MetaBackend, meta_backend, G_TYPE_OBJECT,
657d8e
                                   G_ADD_PRIVATE (MetaBackend)
657d8e
                                   G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
657d8e
@@ -177,8 +184,6 @@ meta_backend_finalize (GObject *object)
657d8e
   g_clear_object (&priv->remote_access_controller);
657d8e
 #endif
657d8e
 
657d8e
-  if (priv->sleep_signal_id)
657d8e
-    g_dbus_connection_signal_unsubscribe (priv->system_bus, priv->sleep_signal_id);
657d8e
   if (priv->upower_watch_id)
657d8e
     g_bus_unwatch_name (priv->upower_watch_id);
657d8e
   g_cancellable_cancel (priv->cancellable);
657d8e
@@ -764,13 +769,8 @@ meta_backend_create_renderer (MetaBackend *backend,
657d8e
 }
657d8e
 
657d8e
 static void
657d8e
-prepare_for_sleep_cb (GDBusConnection *connection,
657d8e
-                      const gchar     *sender_name,
657d8e
-                      const gchar     *object_path,
657d8e
-                      const gchar     *interface_name,
657d8e
-                      const gchar     *signal_name,
657d8e
-                      GVariant        *parameters,
657d8e
-                      gpointer         user_data)
657d8e
+prepare_for_sleep_cb (MetaBackend *backend,
657d8e
+                      gboolean     suspending)
657d8e
 {
657d8e
   gboolean suspending;
657d8e
 
657d8e
@@ -780,12 +780,31 @@ prepare_for_sleep_cb (GDBusConnection *connection,
657d8e
   meta_idle_monitor_reset_idletime (meta_idle_monitor_get_core ());
657d8e
 }
657d8e
 
657d8e
+static Login1Manager *
657d8e
+get_logind_proxy (GCancellable *cancellable,
657d8e
+                  GError      **error)
657d8e
+{
657d8e
+  Login1Manager *proxy;
657d8e
+
657d8e
+  proxy =
657d8e
+    login1_manager_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
657d8e
+                                           G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
657d8e
+                                           "org.freedesktop.login1",
657d8e
+                                           "/org/freedesktop/login1",
657d8e
+                                           cancellable, error);
657d8e
+  if (!proxy)
657d8e
+    g_prefix_error (error, "Could not get logind proxy: ");
657d8e
+
657d8e
+  return proxy;
657d8e
+}
657d8e
+
657d8e
 static void
657d8e
 system_bus_gotten_cb (GObject      *object,
657d8e
                       GAsyncResult *res,
657d8e
                       gpointer      user_data)
657d8e
 {
657d8e
   MetaBackendPrivate *priv;
657d8e
+  g_autoptr (GError) error = NULL;
657d8e
   GDBusConnection *bus;
657d8e
 
657d8e
   bus = g_bus_get_finish (res, NULL);
657d8e
@@ -794,17 +813,16 @@ system_bus_gotten_cb (GObject      *object,
657d8e
 
657d8e
   priv = meta_backend_get_instance_private (user_data);
657d8e
   priv->system_bus = bus;
657d8e
-  priv->sleep_signal_id =
657d8e
-    g_dbus_connection_signal_subscribe (priv->system_bus,
657d8e
-                                        "org.freedesktop.login1",
657d8e
-                                        "org.freedesktop.login1.Manager",
657d8e
-                                        "PrepareForSleep",
657d8e
-                                        "/org/freedesktop/login1",
657d8e
-                                        NULL,
657d8e
-                                        G_DBUS_SIGNAL_FLAGS_NONE,
657d8e
-                                        prepare_for_sleep_cb,
657d8e
-                                        NULL,
657d8e
-                                        NULL);
657d8e
+  priv->logind_proxy = get_logind_proxy (priv->cancellable, &error);
657d8e
+
657d8e
+  if (!priv->logind_proxy)
657d8e
+    g_warning ("Failed to get logind proxy: %s", error->message);
657d8e
+
657d8e
+  g_signal_connect_object (priv->logind_proxy,
657d8e
+                           "prepare-for-sleep",
657d8e
+                           G_CALLBACK (prepare_for_sleep_cb),
657d8e
+                           user_data,
657d8e
+                           G_CONNECT_SWAPPED);
657d8e
 }
657d8e
 
657d8e
 static gboolean
657d8e
diff --git a/src/org.freedesktop.login1.xml b/src/org.freedesktop.login1.xml
657d8e
index 765475132..1ecfd976f 100644
657d8e
--- a/src/org.freedesktop.login1.xml
657d8e
+++ b/src/org.freedesktop.login1.xml
657d8e
@@ -43,4 +43,17 @@
657d8e
       <arg name="vt" type="u"/>
657d8e
     </method>
657d8e
   </interface>
657d8e
+
657d8e
+  <interface name="org.freedesktop.login1.Manager">
657d8e
+    <method name="Inhibit">
657d8e
+      <arg name="what" type="s" direction="in"/>
657d8e
+      <arg name="who" type="s" direction="in"/>
657d8e
+      <arg name="why" type="s" direction="in"/>
657d8e
+      <arg name="mode" type="s" direction="in"/>
657d8e
+      <arg name="fd" type="h" direction="out"/>
657d8e
+    </method>
657d8e
+    <signal name="PrepareForSleep">
657d8e
+      <arg name="active" type="b"/>
657d8e
+    </signal>
657d8e
+  </interface>
657d8e
 </node>
657d8e
-- 
657d8e
2.21.0
657d8e