mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-29 10:20:11 +01:00
sleep-monitor: merge branch 'th/sleep-monitor-merge-bgo765682'
https://bugzilla.gnome.org/show_bug.cgi?id=765682
(cherry picked from commit e0cf9319b7)
This commit is contained in:
commit
f5e0eae6af
6 changed files with 119 additions and 242 deletions
|
|
@ -170,6 +170,5 @@ src/nm-config.c
|
|||
src/nm-iface-helper.c
|
||||
src/nm-logging.c
|
||||
src/nm-manager.c
|
||||
src/nm-sleep-monitor-systemd.c
|
||||
src/settings/plugins/ibft/plugin.c
|
||||
src/settings/plugins/ifcfg-rh/reader.c
|
||||
|
|
|
|||
|
|
@ -438,6 +438,7 @@ libNetworkManager_la_SOURCES = \
|
|||
nm-rfkill-manager.h \
|
||||
nm-session-monitor.h \
|
||||
nm-session-monitor.c \
|
||||
nm-sleep-monitor.c \
|
||||
nm-sleep-monitor.h \
|
||||
nm-types.h \
|
||||
nm-core-utils.c \
|
||||
|
|
@ -446,13 +447,6 @@ libNetworkManager_la_SOURCES = \
|
|||
NetworkManagerUtils.h
|
||||
|
||||
|
||||
if SUSPEND_RESUME_UPOWER
|
||||
libNetworkManager_la_SOURCES += nm-sleep-monitor-upower.c
|
||||
else
|
||||
# systemd/consolekit suspend/resume used whenever upower is not enabled
|
||||
libNetworkManager_la_SOURCES += nm-sleep-monitor-systemd.c
|
||||
endif
|
||||
|
||||
if WITH_WEXT
|
||||
libNetworkManager_la_SOURCES += \
|
||||
platform/wifi/wifi-utils-wext.c \
|
||||
|
|
|
|||
|
|
@ -4071,21 +4071,12 @@ impl_manager_sleep (NMManager *self,
|
|||
}
|
||||
|
||||
static void
|
||||
sleeping_cb (NMSleepMonitor *monitor, gpointer user_data)
|
||||
sleeping_cb (NMSleepMonitor *monitor, gboolean is_about_to_suspend, gpointer user_data)
|
||||
{
|
||||
NMManager *self = user_data;
|
||||
|
||||
_LOGD (LOGD_SUSPEND, "Received sleeping signal");
|
||||
_internal_sleep (self, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
resuming_cb (NMSleepMonitor *monitor, gpointer user_data)
|
||||
{
|
||||
NMManager *self = user_data;
|
||||
|
||||
_LOGD (LOGD_SUSPEND, "Received resuming signal");
|
||||
_internal_sleep (self, FALSE);
|
||||
_LOGD (LOGD_SUSPEND, "Received %s signal", is_about_to_suspend ? "sleeping" : "resuming");
|
||||
_internal_sleep (self, is_about_to_suspend);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -5273,11 +5264,9 @@ nm_manager_init (NMManager *self)
|
|||
self);
|
||||
|
||||
/* sleep/wake handling */
|
||||
priv->sleep_monitor = g_object_ref (nm_sleep_monitor_get ());
|
||||
priv->sleep_monitor = nm_sleep_monitor_new ();
|
||||
g_signal_connect (priv->sleep_monitor, NM_SLEEP_MONITOR_SLEEPING,
|
||||
G_CALLBACK (sleeping_cb), self);
|
||||
g_signal_connect (priv->sleep_monitor, NM_SLEEP_MONITOR_RESUMING,
|
||||
G_CALLBACK (resuming_cb), self);
|
||||
|
||||
/* Listen for authorization changes */
|
||||
g_signal_connect (nm_auth_manager_get (),
|
||||
|
|
@ -5533,7 +5522,6 @@ dispose (GObject *object)
|
|||
|
||||
if (priv->sleep_monitor) {
|
||||
g_signal_handlers_disconnect_by_func (priv->sleep_monitor, sleeping_cb, manager);
|
||||
g_signal_handlers_disconnect_by_func (priv->sleep_monitor, resuming_cb, manager);
|
||||
g_clear_object (&priv->sleep_monitor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,135 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2012 Red Hat, Inc.
|
||||
* Author: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include "nm-core-internal.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
#include "nm-sleep-monitor.h"
|
||||
|
||||
#define UPOWER_DBUS_SERVICE "org.freedesktop.UPower"
|
||||
|
||||
struct _NMSleepMonitor {
|
||||
GObject parent_instance;
|
||||
|
||||
GDBusProxy *upower_proxy;
|
||||
};
|
||||
|
||||
struct _NMSleepMonitorClass {
|
||||
GObjectClass parent_class;
|
||||
|
||||
void (*sleeping) (NMSleepMonitor *monitor);
|
||||
void (*resuming) (NMSleepMonitor *monitor);
|
||||
};
|
||||
|
||||
|
||||
enum {
|
||||
SLEEPING,
|
||||
RESUMING,
|
||||
LAST_SIGNAL,
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
G_DEFINE_TYPE (NMSleepMonitor, nm_sleep_monitor, G_TYPE_OBJECT);
|
||||
|
||||
/********************************************************************/
|
||||
|
||||
static void
|
||||
upower_sleeping_cb (GDBusProxy *proxy, gpointer user_data)
|
||||
{
|
||||
nm_log_dbg (LOGD_SUSPEND, "Received UPower sleeping signal");
|
||||
g_signal_emit (user_data, signals[SLEEPING], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
upower_resuming_cb (GDBusProxy *proxy, gpointer user_data)
|
||||
{
|
||||
nm_log_dbg (LOGD_SUSPEND, "Received UPower resuming signal");
|
||||
g_signal_emit (user_data, signals[RESUMING], 0);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_sleep_monitor_init (NMSleepMonitor *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
self->upower_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START |
|
||||
G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
|
||||
NULL,
|
||||
UPOWER_DBUS_SERVICE,
|
||||
"/org/freedesktop/UPower",
|
||||
"org.freedesktop.UPower",
|
||||
NULL, &error);
|
||||
if (self->upower_proxy) {
|
||||
_nm_dbus_signal_connect (self->upower_proxy, "Sleeping", NULL,
|
||||
G_CALLBACK (upower_sleeping_cb), self);
|
||||
_nm_dbus_signal_connect (self->upower_proxy, "Resuming", NULL,
|
||||
G_CALLBACK (upower_resuming_cb), self);
|
||||
} else {
|
||||
nm_log_warn (LOGD_SUSPEND, "could not initialize UPower D-Bus proxy: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
finalize (GObject *object)
|
||||
{
|
||||
NMSleepMonitor *self = NM_SLEEP_MONITOR (object);
|
||||
|
||||
g_clear_object (&self->upower_proxy);
|
||||
|
||||
G_OBJECT_CLASS (nm_sleep_monitor_parent_class)->finalize (object);
|
||||
}
|
||||
|
||||
static void
|
||||
nm_sleep_monitor_class_init (NMSleepMonitorClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class;
|
||||
|
||||
gobject_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
gobject_class->finalize = finalize;
|
||||
|
||||
signals[SLEEPING] = g_signal_new (NM_SLEEP_MONITOR_SLEEPING,
|
||||
NM_TYPE_SLEEP_MONITOR,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (NMSleepMonitorClass, sleeping),
|
||||
NULL, /* accumulator */
|
||||
NULL, /* accumulator data */
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[RESUMING] = g_signal_new (NM_SLEEP_MONITOR_RESUMING,
|
||||
NM_TYPE_SLEEP_MONITOR,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (NMSleepMonitorClass, resuming),
|
||||
NULL, /* accumulator */
|
||||
NULL, /* accumulator data */
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
}
|
||||
|
||||
NM_DEFINE_SINGLETON_GETTER (NMSleepMonitor, nm_sleep_monitor_get, NM_TYPE_SLEEP_MONITOR);
|
||||
|
||||
/* ---------------------------------------------------------------------------------------------------- */
|
||||
|
|
@ -13,12 +13,14 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2012 Red Hat, Inc.
|
||||
* (C) Copyright 2012-2016 Red Hat, Inc.
|
||||
* Author: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
#include "nm-sleep-monitor.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
|
@ -27,19 +29,24 @@
|
|||
#include "nm-core-internal.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
|
||||
#include "nm-sleep-monitor.h"
|
||||
|
||||
#if defined (SUSPEND_RESUME_SYSTEMD) == defined (SUSPEND_RESUME_CONSOLEKIT)
|
||||
#error either define SUSPEND_RESUME_SYSTEMD or SUSPEND_RESUME_CONSOLEKIT
|
||||
#endif
|
||||
#if defined (SUSPEND_RESUME_UPOWER)
|
||||
|
||||
#ifdef SUSPEND_RESUME_SYSTEMD
|
||||
#define SUSPEND_DBUS_NAME "org.freedesktop.UPower"
|
||||
#define SUSPEND_DBUS_PATH "/org/freedesktop/UPower"
|
||||
#define SUSPEND_DBUS_INTERFACE "org.freedesktop.UPower"
|
||||
#define USE_UPOWER 1
|
||||
#define _NMLOG_PREFIX_NAME "sleep-monitor-up"
|
||||
|
||||
#elif defined (SUSPEND_RESUME_SYSTEMD)
|
||||
|
||||
#define SUSPEND_DBUS_NAME "org.freedesktop.login1"
|
||||
#define SUSPEND_DBUS_PATH "/org/freedesktop/login1"
|
||||
#define SUSPEND_DBUS_INTERFACE "org.freedesktop.login1.Manager"
|
||||
#define USE_UPOWER 0
|
||||
#define _NMLOG_PREFIX_NAME "sleep-monitor-sd"
|
||||
|
||||
#else
|
||||
#elif defined(SUSPEND_RESUME_CONSOLEKIT)
|
||||
|
||||
/* ConsoleKit2 has added the same suspend/resume DBUS API that Systemd
|
||||
* uses. http://consolekit2.github.io/ConsoleKit2/#Manager.Inhibit
|
||||
|
|
@ -48,15 +55,21 @@
|
|||
#define SUSPEND_DBUS_NAME "org.freedesktop.ConsoleKit"
|
||||
#define SUSPEND_DBUS_PATH "/org/freedesktop/ConsoleKit/Manager"
|
||||
#define SUSPEND_DBUS_INTERFACE "org.freedesktop.ConsoleKit.Manager"
|
||||
#define USE_UPOWER 0
|
||||
#define _NMLOG_PREFIX_NAME "sleep-monitor-ck"
|
||||
|
||||
#else
|
||||
|
||||
#error define one of SUSPEND_RESUME_SYSTEMD, SUSPEND_RESUME_CONSOLEKIT, or SUSPEND_RESUME_UPOWER
|
||||
|
||||
#endif
|
||||
|
||||
struct _NMSleepMonitor {
|
||||
GObject parent_instance;
|
||||
|
||||
GDBusProxy *sd_proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
/* used both during construction of sd_proxy and during Inhibit call. */
|
||||
/* used both during construction of proxy and during Inhibit call. */
|
||||
GCancellable *cancellable;
|
||||
|
||||
gint inhibit_fd;
|
||||
|
|
@ -71,49 +84,48 @@ struct _NMSleepMonitorClass {
|
|||
|
||||
enum {
|
||||
SLEEPING,
|
||||
RESUMING,
|
||||
LAST_SIGNAL,
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = {0};
|
||||
|
||||
G_DEFINE_TYPE (NMSleepMonitor, nm_sleep_monitor, G_TYPE_OBJECT);
|
||||
|
||||
NM_DEFINE_SINGLETON_GETTER (NMSleepMonitor, nm_sleep_monitor_get, NM_TYPE_SLEEP_MONITOR);
|
||||
static void sleep_signal (NMSleepMonitor *self, gboolean is_about_to_suspend);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#ifdef SUSPEND_RESUME_SYSTEMD
|
||||
#define _NMLOG_PREFIX_NAME "sleep-monitor-sd"
|
||||
#else
|
||||
#define _NMLOG_PREFIX_NAME "sleep-monitor-ck"
|
||||
#endif
|
||||
|
||||
#define _NMLOG_DOMAIN LOGD_SUSPEND
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START { \
|
||||
const NMLogLevel __level = (level); \
|
||||
\
|
||||
if (nm_logging_enabled (__level, _NMLOG_DOMAIN)) { \
|
||||
char __prefix[20]; \
|
||||
const NMSleepMonitor *const __self = (self); \
|
||||
\
|
||||
_nm_log (__level, _NMLOG_DOMAIN, 0, \
|
||||
"%s%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
|
||||
_NMLOG_PREFIX_NAME, \
|
||||
(!__self || __self == singleton_instance \
|
||||
? "" \
|
||||
: nm_sprintf_buf (__prefix, "[%p]", __self)) \
|
||||
_NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
||||
} \
|
||||
nm_log ((level), _NMLOG_DOMAIN, \
|
||||
"%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
|
||||
_NMLOG_PREFIX_NAME \
|
||||
_NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
||||
} G_STMT_END
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if USE_UPOWER
|
||||
|
||||
static void
|
||||
upower_sleeping_cb (GDBusProxy *proxy, gpointer user_data)
|
||||
{
|
||||
sleep_signal (user_data, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
upower_resuming_cb (GDBusProxy *proxy, gpointer user_data)
|
||||
{
|
||||
sleep_signal (user_data, FALSE);
|
||||
}
|
||||
|
||||
#else /* USE_UPOWER */
|
||||
|
||||
static void
|
||||
drop_inhibitor (NMSleepMonitor *self)
|
||||
{
|
||||
if (self->inhibit_fd >= 0) {
|
||||
_LOGD ("Dropping systemd sleep inhibitor %d", self->inhibit_fd);
|
||||
_LOGD ("inhibit: dropping sleep inhibitor %d", self->inhibit_fd);
|
||||
close (self->inhibit_fd);
|
||||
self->inhibit_fd = -1;
|
||||
}
|
||||
|
|
@ -126,17 +138,17 @@ inhibit_done (GObject *source,
|
|||
GAsyncResult *result,
|
||||
gpointer user_data)
|
||||
{
|
||||
GDBusProxy *sd_proxy = G_DBUS_PROXY (source);
|
||||
GDBusProxy *proxy = G_DBUS_PROXY (source);
|
||||
NMSleepMonitor *self = user_data;
|
||||
gs_free_error GError *error = NULL;
|
||||
gs_unref_variant GVariant *res = NULL;
|
||||
gs_unref_object GUnixFDList *fd_list = NULL;
|
||||
|
||||
res = g_dbus_proxy_call_with_unix_fd_list_finish (sd_proxy, &fd_list, result, &error);
|
||||
res = g_dbus_proxy_call_with_unix_fd_list_finish (proxy, &fd_list, result, &error);
|
||||
if (!res) {
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) {
|
||||
g_clear_object (&self->cancellable);
|
||||
_LOGW ("Inhibit failed: %s", error->message);
|
||||
_LOGW ("inhibit: failed (%s)", error->message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
|
@ -144,25 +156,25 @@ inhibit_done (GObject *source,
|
|||
g_clear_object (&self->cancellable);
|
||||
|
||||
if (!fd_list || g_unix_fd_list_get_length (fd_list) != 1) {
|
||||
_LOGW ("Didn't get a single fd back");
|
||||
_LOGW ("inhibit: didn't get a single fd back");
|
||||
return;
|
||||
}
|
||||
|
||||
self->inhibit_fd = g_unix_fd_list_get (fd_list, 0, NULL);
|
||||
_LOGD ("Inhibitor fd is %d", self->inhibit_fd);
|
||||
_LOGD ("inhibit: inhibitor fd is %d", self->inhibit_fd);
|
||||
}
|
||||
|
||||
static void
|
||||
take_inhibitor (NMSleepMonitor *self)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SLEEP_MONITOR (self));
|
||||
g_return_if_fail (G_IS_DBUS_PROXY (self->sd_proxy));
|
||||
g_return_if_fail (G_IS_DBUS_PROXY (self->proxy));
|
||||
|
||||
drop_inhibitor (self);
|
||||
|
||||
_LOGD ("Taking systemd sleep inhibitor");
|
||||
_LOGD ("inhibit: taking sleep inhibitor...");
|
||||
self->cancellable = g_cancellable_new ();
|
||||
g_dbus_proxy_call_with_unix_fd_list (self->sd_proxy,
|
||||
g_dbus_proxy_call_with_unix_fd_list (self->proxy,
|
||||
"Inhibit",
|
||||
g_variant_new ("(ssss)",
|
||||
"sleep",
|
||||
|
|
@ -182,17 +194,7 @@ prepare_for_sleep_cb (GDBusProxy *proxy,
|
|||
gboolean is_about_to_suspend,
|
||||
gpointer data)
|
||||
{
|
||||
NMSleepMonitor *self = data;
|
||||
|
||||
_LOGD ("Received PrepareForSleep signal: %d", is_about_to_suspend);
|
||||
|
||||
if (is_about_to_suspend) {
|
||||
g_signal_emit (self, signals[SLEEPING], 0);
|
||||
drop_inhibitor (self);
|
||||
} else {
|
||||
take_inhibitor (self);
|
||||
g_signal_emit (self, signals[RESUMING], 0);
|
||||
}
|
||||
sleep_signal (data, is_about_to_suspend);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -204,7 +206,7 @@ name_owner_cb (GObject *object,
|
|||
NMSleepMonitor *self = NM_SLEEP_MONITOR (user_data);
|
||||
char *owner;
|
||||
|
||||
g_assert (proxy == self->sd_proxy);
|
||||
g_assert (proxy == self->proxy);
|
||||
|
||||
owner = g_dbus_proxy_get_name_owner (proxy);
|
||||
if (owner)
|
||||
|
|
@ -213,6 +215,28 @@ name_owner_cb (GObject *object,
|
|||
drop_inhibitor (self);
|
||||
g_free (owner);
|
||||
}
|
||||
#endif /* USE_UPOWER */
|
||||
|
||||
static void
|
||||
sleep_signal (NMSleepMonitor *self,
|
||||
gboolean is_about_to_suspend)
|
||||
{
|
||||
g_return_if_fail (NM_IS_SLEEP_MONITOR (self));
|
||||
|
||||
_LOGD ("received %s signal", is_about_to_suspend ? "SLEEP" : "RESUME");
|
||||
|
||||
#if !USE_UPOWER
|
||||
if (!is_about_to_suspend)
|
||||
take_inhibitor (self);
|
||||
#endif
|
||||
|
||||
g_signal_emit (self, signals[SLEEPING], 0, is_about_to_suspend);
|
||||
|
||||
#if !USE_UPOWER
|
||||
if (is_about_to_suspend)
|
||||
drop_inhibitor (self);
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
on_proxy_acquired (GObject *object,
|
||||
|
|
@ -220,29 +244,37 @@ on_proxy_acquired (GObject *object,
|
|||
NMSleepMonitor *self)
|
||||
{
|
||||
GError *error = NULL;
|
||||
char *owner;
|
||||
GDBusProxy *sd_proxy;
|
||||
GDBusProxy *proxy;
|
||||
|
||||
sd_proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
||||
if (!sd_proxy) {
|
||||
proxy = g_dbus_proxy_new_for_bus_finish (res, &error);
|
||||
if (!proxy) {
|
||||
if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
|
||||
_LOGW ("Failed to acquire logind proxy: %s", error->message);
|
||||
_LOGW ("failed to acquire D-Bus proxy: %s", error->message);
|
||||
g_clear_error (&error);
|
||||
return;
|
||||
}
|
||||
self->sd_proxy = sd_proxy;
|
||||
self->proxy = proxy;
|
||||
g_clear_object (&self->cancellable);
|
||||
|
||||
self->sig_id_1 = g_signal_connect (self->sd_proxy, "notify::g-name-owner",
|
||||
#if USE_UPOWER
|
||||
self->sig_id_1 = _nm_dbus_signal_connect (self->proxy, "Sleeping", NULL,
|
||||
G_CALLBACK (upower_sleeping_cb), self);
|
||||
self->sig_id_2 = _nm_dbus_signal_connect (self->proxy, "Resuming", NULL,
|
||||
G_CALLBACK (upower_resuming_cb), self);
|
||||
#else
|
||||
self->sig_id_1 = g_signal_connect (self->proxy, "notify::g-name-owner",
|
||||
G_CALLBACK (name_owner_cb), self);
|
||||
self->sig_id_2 = _nm_dbus_signal_connect (self->sd_proxy, "PrepareForSleep",
|
||||
self->sig_id_2 = _nm_dbus_signal_connect (self->proxy, "PrepareForSleep",
|
||||
G_VARIANT_TYPE ("(b)"),
|
||||
G_CALLBACK (prepare_for_sleep_cb), self);
|
||||
{
|
||||
gs_free char *owner = NULL;
|
||||
|
||||
owner = g_dbus_proxy_get_name_owner (self->sd_proxy);
|
||||
if (owner)
|
||||
take_inhibitor (self);
|
||||
g_free (owner);
|
||||
owner = g_dbus_proxy_get_name_owner (self->proxy);
|
||||
if (owner)
|
||||
take_inhibitor (self);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -259,18 +291,27 @@ nm_sleep_monitor_init (NMSleepMonitor *self)
|
|||
(GAsyncReadyCallback) on_proxy_acquired, self);
|
||||
}
|
||||
|
||||
NMSleepMonitor *
|
||||
nm_sleep_monitor_new (void)
|
||||
{
|
||||
return g_object_new (NM_TYPE_SLEEP_MONITOR, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose (GObject *object)
|
||||
{
|
||||
NMSleepMonitor *self = NM_SLEEP_MONITOR (object);
|
||||
|
||||
/* drop_inhibitor() also clears our "cancellable" */
|
||||
#if !USE_UPOWER
|
||||
drop_inhibitor (self);
|
||||
#endif
|
||||
|
||||
if (self->sd_proxy) {
|
||||
nm_clear_g_signal_handler (self->sd_proxy, &self->sig_id_1);
|
||||
nm_clear_g_signal_handler (self->sd_proxy, &self->sig_id_2);
|
||||
g_clear_object (&self->sd_proxy);
|
||||
nm_clear_g_cancellable (&self->cancellable);
|
||||
|
||||
if (self->proxy) {
|
||||
nm_clear_g_signal_handler (self->proxy, &self->sig_id_1);
|
||||
nm_clear_g_signal_handler (self->proxy, &self->sig_id_2);
|
||||
g_clear_object (&self->proxy);
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (nm_sleep_monitor_parent_class)->dispose (object);
|
||||
|
|
@ -289,13 +330,7 @@ nm_sleep_monitor_class_init (NMSleepMonitorClass *klass)
|
|||
NM_TYPE_SLEEP_MONITOR,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
signals[RESUMING] = g_signal_new (NM_SLEEP_MONITOR_RESUMING,
|
||||
NM_TYPE_SLEEP_MONITOR,
|
||||
G_SIGNAL_RUN_LAST,
|
||||
0, NULL, NULL,
|
||||
g_cclosure_marshal_VOID__VOID,
|
||||
G_TYPE_NONE, 0);
|
||||
g_cclosure_marshal_VOID__BOOLEAN,
|
||||
G_TYPE_NONE, 1, G_TYPE_BOOLEAN);
|
||||
}
|
||||
|
||||
|
|
@ -13,16 +13,13 @@
|
|||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* (C) Copyright 2012 Red Hat, Inc.
|
||||
* (C) Copyright 2012-2016 Red Hat, Inc.
|
||||
* Author: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_SLEEP_MONITOR_H__
|
||||
#define __NETWORKMANAGER_SLEEP_MONITOR_H__
|
||||
|
||||
|
||||
#include "nm-default.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define NM_TYPE_SLEEP_MONITOR (nm_sleep_monitor_get_type ())
|
||||
|
|
@ -33,12 +30,11 @@ G_BEGIN_DECLS
|
|||
#define NM_IS_SLEEP_MONITOR_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), NM_TYPE_SLEEP_MONITOR))
|
||||
|
||||
#define NM_SLEEP_MONITOR_SLEEPING "sleeping"
|
||||
#define NM_SLEEP_MONITOR_RESUMING "resuming"
|
||||
|
||||
typedef struct _NMSleepMonitorClass NMSleepMonitorClass;
|
||||
|
||||
GType nm_sleep_monitor_get_type (void) G_GNUC_CONST;
|
||||
NMSleepMonitor *nm_sleep_monitor_get (void);
|
||||
NMSleepMonitor *nm_sleep_monitor_new (void);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue