mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-13 07:56:17 +01:00
gio: Do not block when low-memory-monitor daemon appears
This commit is contained in:
parent
a7000cd989
commit
92399e7114
@ -25,6 +25,7 @@
|
|||||||
#include "giomodule-priv.h"
|
#include "giomodule-priv.h"
|
||||||
#include "glibintl.h"
|
#include "glibintl.h"
|
||||||
#include "glib/gstdio.h"
|
#include "glib/gstdio.h"
|
||||||
|
#include "gcancellable.h"
|
||||||
#include "gdbusproxy.h"
|
#include "gdbusproxy.h"
|
||||||
#include "gdbusnamewatching.h"
|
#include "gdbusnamewatching.h"
|
||||||
|
|
||||||
@ -38,6 +39,7 @@ struct _GMemoryMonitorDBus
|
|||||||
GObject parent_instance;
|
GObject parent_instance;
|
||||||
|
|
||||||
guint watch_id;
|
guint watch_id;
|
||||||
|
GCancellable *cancellable;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
gulong signal_id;
|
gulong signal_id;
|
||||||
};
|
};
|
||||||
@ -77,24 +79,15 @@ proxy_signal_cb (GDBusProxy *proxy,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lmm_appeared_cb (GDBusConnection *connection,
|
lmm_proxy_cb (GObject *source_object,
|
||||||
const gchar *name,
|
GAsyncResult *res,
|
||||||
const gchar *name_owner,
|
gpointer user_data)
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
GMemoryMonitorDBus *dbus = user_data;
|
GMemoryMonitorDBus *dbus = user_data;
|
||||||
GDBusProxy *proxy;
|
GDBusProxy *proxy;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
proxy = g_dbus_proxy_new_finish (res, &error);
|
||||||
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
|
||||||
NULL,
|
|
||||||
"org.freedesktop.LowMemoryMonitor",
|
|
||||||
"/org/freedesktop/LowMemoryMonitor",
|
|
||||||
"org.freedesktop.LowMemoryMonitor",
|
|
||||||
NULL,
|
|
||||||
&error);
|
|
||||||
|
|
||||||
if (!proxy)
|
if (!proxy)
|
||||||
{
|
{
|
||||||
g_debug ("Failed to create LowMemoryMonitor D-Bus proxy: %s",
|
g_debug ("Failed to create LowMemoryMonitor D-Bus proxy: %s",
|
||||||
@ -106,6 +99,26 @@ lmm_appeared_cb (GDBusConnection *connection,
|
|||||||
dbus->signal_id = g_signal_connect (G_OBJECT (proxy), "g-signal",
|
dbus->signal_id = g_signal_connect (G_OBJECT (proxy), "g-signal",
|
||||||
G_CALLBACK (proxy_signal_cb), dbus);
|
G_CALLBACK (proxy_signal_cb), dbus);
|
||||||
dbus->proxy = proxy;
|
dbus->proxy = proxy;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
lmm_appeared_cb (GDBusConnection *connection,
|
||||||
|
const gchar *name,
|
||||||
|
const gchar *name_owner,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
GMemoryMonitorDBus *dbus = user_data;
|
||||||
|
|
||||||
|
g_dbus_proxy_new (connection,
|
||||||
|
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
|
||||||
|
NULL,
|
||||||
|
"org.freedesktop.LowMemoryMonitor",
|
||||||
|
"/org/freedesktop/LowMemoryMonitor",
|
||||||
|
"org.freedesktop.LowMemoryMonitor",
|
||||||
|
dbus->cancellable,
|
||||||
|
lmm_proxy_cb,
|
||||||
|
dbus);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -126,6 +139,7 @@ g_memory_monitor_dbus_initable_init (GInitable *initable,
|
|||||||
{
|
{
|
||||||
GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (initable);
|
GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (initable);
|
||||||
|
|
||||||
|
dbus->cancellable = g_cancellable_new ();
|
||||||
dbus->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
|
dbus->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
|
||||||
"org.freedesktop.LowMemoryMonitor",
|
"org.freedesktop.LowMemoryMonitor",
|
||||||
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
G_BUS_NAME_WATCHER_FLAGS_AUTO_START,
|
||||||
@ -142,6 +156,8 @@ g_memory_monitor_dbus_finalize (GObject *object)
|
|||||||
{
|
{
|
||||||
GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (object);
|
GMemoryMonitorDBus *dbus = G_MEMORY_MONITOR_DBUS (object);
|
||||||
|
|
||||||
|
g_cancellable_cancel (dbus->cancellable);
|
||||||
|
g_clear_object (&dbus->cancellable);
|
||||||
g_clear_signal_handler (&dbus->signal_id, dbus->proxy);
|
g_clear_signal_handler (&dbus->signal_id, dbus->proxy);
|
||||||
g_clear_object (&dbus->proxy);
|
g_clear_object (&dbus->proxy);
|
||||||
g_clear_handle_id (&dbus->watch_id, g_bus_unwatch_name);
|
g_clear_handle_id (&dbus->watch_id, g_bus_unwatch_name);
|
||||||
|
Loading…
Reference in New Issue
Block a user