Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
openSUSE:13.2:Update
urfkill
urfkill-support-nfc-and-logind.patch
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File urfkill-support-nfc-and-logind.patch of Package urfkill
From 114b41c5fe056341ca5d274509234f424a234688 Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin <chingpang@gmail.com> Date: Fri, 28 Sep 2012 12:50:33 +0800 Subject: [PATCH 01/14] Add gcc warnings to urfkilld and adjust warning types --- configure.ac | 8 ++++---- src/Makefile.am | 1 + 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 47ce756..179b086 100644 --- a/configure.ac +++ b/configure.ac @@ -113,25 +113,25 @@ fi if test "$GCC" = "yes"; then WARNINGFLAGS_C="$WARNINGFLAGS_C -Wall" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wcast-align -Wno-uninitialized" - WARNINGFLAGS_C="$WARNINGFLAGS_C -Wmissing-declarations" +# WARNINGFLAGS_C="$WARNINGFLAGS_C -Wmissing-declarations" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wredundant-decls" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wpointer-arith" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wcast-align" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wwrite-strings" WARNINGFLAGS_C="$WARNINGFLAGS_C -Winit-self" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wreturn-type" - WARNINGFLAGS_C="$WARNINGFLAGS_C -Wformat-nonliteral" +# WARNINGFLAGS_C="$WARNINGFLAGS_C -Wformat-nonliteral" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wformat-security" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wmissing-include-dirs" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wmissing-format-attribute" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wclobbered" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wempty-body" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wignored-qualifiers" - WARNINGFLAGS_C="$WARNINGFLAGS_C -Wsign-compare" +# WARNINGFLAGS_C="$WARNINGFLAGS_C -Wsign-compare" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wtype-limits" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wuninitialized" WARNINGFLAGS_C="$WARNINGFLAGS_C -Waggregate-return" - WARNINGFLAGS_C="$WARNINGFLAGS_C -Wdeclaration-after-statement" +# WARNINGFLAGS_C="$WARNINGFLAGS_C -Wdeclaration-after-statement" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Wshadow" WARNINGFLAGS_C="$WARNINGFLAGS_C -Wno-strict-aliasing" # WARNINGFLAGS_C="$WARNINGFLAGS_C -Winline" diff --git a/src/Makefile.am b/src/Makefile.am index f462e09..8726e02 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -48,6 +48,7 @@ urfkilld_SOURCES = \ urfkilld_CPPFLAGS = \ -I$(top_srcdir)/src \ -DG_LOG_DOMAIN=\"URfkill\" \ + $(WARNINGFLAGS_C) \ $(AM_CPPFLAGS) urfkilld_LDADD = \ -- 1.8.4 From 638549e03efa22857322b690c3beef366d8f1d9c Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin <chingpang@gmail.com> Date: Tue, 10 Dec 2013 10:07:52 +0800 Subject: [PATCH 02/14] Don't crash for missing DMI Some systems don't have DMI devices Patch from Tony Espy <tony.espy@canonical.com> --- src/urf-config.c | 2 +- src/urf-utils.c | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/urf-config.c b/src/urf-config.c index 7bbf088..adb7c1b 100644 --- a/src/urf-config.c +++ b/src/urf-config.c @@ -357,7 +357,7 @@ parse_xml_start_element (void *data, } match_key = get_match_key (info->hardware_info, key); - if (!match_rule (match_key, operator, match_body)) + if (match_key && !match_rule (match_key, operator, match_body)) return; } else if (g_strcmp0 (name, "option") == 0) { for (i = 0; atts[i]; i++) { diff --git a/src/urf-utils.c b/src/urf-utils.c index fe6d817..45fa592 100644 --- a/src/urf-utils.c +++ b/src/urf-utils.c @@ -21,13 +21,18 @@ get_dmi_info () return NULL; } - info = g_new0 (DmiInfo, 1); - enumerate = udev_enumerate_new (udev); udev_enumerate_add_match_subsystem (enumerate, "dmi"); udev_enumerate_scan_devices (enumerate); devices = udev_enumerate_get_list_entry (enumerate); + if (devices == NULL) { + g_warning("No dmi devices found."); + return NULL; + } + + info = g_new0 (DmiInfo, 1); + udev_list_entry_foreach (dev_list_entry, devices) { const char *path; const char *attribute; -- 1.8.4 From d751302b003d0df792f2f83ceb693584ad6bc980 Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin <chingpang@gmail.com> Date: Tue, 10 Dec 2013 10:22:26 +0800 Subject: [PATCH 03/14] Add new rfkill type: NFC Patch from Tony Espy <tony.espy@canonical.com> --- src/urf-utils.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/urf-utils.c b/src/urf-utils.c index 45fa592..3b73b8a 100644 --- a/src/urf-utils.c +++ b/src/urf-utils.c @@ -169,6 +169,8 @@ type_to_string (guint type) return "GPS"; case RFKILL_TYPE_FM: return "FM"; + case RFKILL_TYPE_NFC: + return "NFC"; default: g_assert_not_reached (); } -- 1.8.4 From ec771fdd23034f368403e461617a0f8427e8e709 Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin <chingpang@gmail.com> Date: Tue, 10 Dec 2013 10:42:58 +0800 Subject: [PATCH 04/14] Add NFC to glib and docs --- data/org.freedesktop.URfkill.Device.xml | 3 +++ data/org.freedesktop.URfkill.Killswitch.xml | 4 ++-- liburfkill-glib/urf-enum.h | 2 ++ liburfkill-glib/urf-killswitch.c | 5 ++++- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/data/org.freedesktop.URfkill.Device.xml b/data/org.freedesktop.URfkill.Device.xml index 14fd743..15d5436 100644 --- a/data/org.freedesktop.URfkill.Device.xml +++ b/data/org.freedesktop.URfkill.Device.xml @@ -91,6 +91,9 @@ $ gdbus call -y \ <doc:item> <doc:term>7</doc:term><doc:definition>FM</doc:definition> </doc:item> + <doc:item> + <doc:term>8</doc:term><doc:definition>NFC</doc:definition> + </doc:item> </doc:list> </doc:description> </doc:doc> diff --git a/data/org.freedesktop.URfkill.Killswitch.xml b/data/org.freedesktop.URfkill.Killswitch.xml index cc185d7..a113152 100644 --- a/data/org.freedesktop.URfkill.Killswitch.xml +++ b/data/org.freedesktop.URfkill.Killswitch.xml @@ -15,8 +15,8 @@ name <doc:tt>org.freedesktop.URfkill</doc:tt>. The TYPENAME could be <doc:tt>"WLAN"</doc:tt>, <doc:tt>"BLUETOOTH"</doc:tt>, <doc:tt>"UWB"</doc:tt>, <doc:tt>"WIMAX"</doc:tt>, - <doc:tt>"WWAN"</doc:tt>, <doc:tt>"GPS"</doc:tt>, or - <doc:tt>"FM"</doc:tt>. + <doc:tt>"WWAN"</doc:tt>, <doc:tt>"GPS"</doc:tt>, + <doc:tt>"FM"</doc:tt>, or <doc:tt>"NFC"</doc:tt>. </doc:para> <doc:para> <doc:example language="shell" title="simple example"> diff --git a/liburfkill-glib/urf-enum.h b/liburfkill-glib/urf-enum.h index 7672c48..d152e83 100644 --- a/liburfkill-glib/urf-enum.h +++ b/liburfkill-glib/urf-enum.h @@ -46,6 +46,7 @@ * @URF_ENUM_TYPE_WWAN: switch is on a wireless WAN device. * @URF_ENUM_TYPE_GPS: switch is on a GPS device. * @URF_ENUM_TYPE_FM: switch is on a FM radio device. + * @URF_ENUM_TYPE_NFC: switch is on a NFC device. * @URF_ENUM_TYPE_NUM: number of defined rfkill types * * The type of the rfkill device following the definition in <linux/rfkill.h> @@ -59,6 +60,7 @@ typedef enum { URF_ENUM_TYPE_WWAN, URF_ENUM_TYPE_GPS, URF_ENUM_TYPE_FM, + URF_ENUM_TYPE_NFC, URF_ENUM_TYPE_NUM, } UrfEnumType; diff --git a/liburfkill-glib/urf-killswitch.c b/liburfkill-glib/urf-killswitch.c index 5a45668..c88f5fb 100644 --- a/liburfkill-glib/urf-killswitch.c +++ b/liburfkill-glib/urf-killswitch.c @@ -162,7 +162,7 @@ out: } /** - * urf_killswitch_startup + * urf_killswitch_startup: **/ static gboolean urf_killswitch_startup (UrfKillswitch *killswitch) @@ -193,6 +193,9 @@ urf_killswitch_startup (UrfKillswitch *killswitch) case URF_ENUM_TYPE_FM: object_path = BASE_OBJECT_PATH"FM"; break; + case URF_ENUM_TYPE_NFC: + object_path = BASE_OBJECT_PATH"NFC"; + break; default: object_path = NULL; break; -- 1.8.4 From 87438b2a0640acdaf8ca21f1f29313e68cdb254d Mon Sep 17 00:00:00 2001 From: Gary Ching-Pang Lin <chingpang@gmail.com> Date: Tue, 10 Dec 2013 11:01:39 +0800 Subject: [PATCH 05/14] Check glib version for g_type_init() g_type_init() is deprecated since glib 2.36 --- src/urf-main.c | 2 ++ tests/catch-signal.c | 2 ++ tests/device-write.c | 2 ++ tests/enumerate-devices.c | 2 ++ tests/inhibit-keycontrol.c | 2 ++ tests/killswitch-write.c | 2 ++ tests/monitor-killswitch.c | 4 ++++ tests/test-urfkill-client.c | 2 ++ 8 files changed, 18 insertions(+) diff --git a/src/urf-main.c b/src/urf-main.c index 507dd24..1613ba3 100644 --- a/src/urf-main.c +++ b/src/urf-main.c @@ -112,7 +112,9 @@ main (gint argc, gchar **argv) { NULL } }; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init (); +#endif context = g_option_context_new ("urfkill daemon"); g_option_context_add_main_entries (context, options, NULL); diff --git a/tests/catch-signal.c b/tests/catch-signal.c index f1cfa55..3d9aa0c 100644 --- a/tests/catch-signal.c +++ b/tests/catch-signal.c @@ -71,7 +71,9 @@ main () { UrfClient *client = NULL; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif client = urf_client_new (); urf_client_enumerate_devices_sync (client, NULL, NULL); diff --git a/tests/device-write.c b/tests/device-write.c index 5a9644e..af0558d 100644 --- a/tests/device-write.c +++ b/tests/device-write.c @@ -19,7 +19,9 @@ main () GList *devices, *item; gboolean soft; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif client = urf_client_new (); urf_client_enumerate_devices_sync (client, NULL, NULL); diff --git a/tests/enumerate-devices.c b/tests/enumerate-devices.c index a4e5820..2c1ca6c 100644 --- a/tests/enumerate-devices.c +++ b/tests/enumerate-devices.c @@ -34,7 +34,9 @@ main () UrfDevice *device; GList *devices, *item; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif client = urf_client_new (); urf_client_enumerate_devices_sync (client, NULL, NULL); diff --git a/tests/inhibit-keycontrol.c b/tests/inhibit-keycontrol.c index c2a6690..a1dd441 100644 --- a/tests/inhibit-keycontrol.c +++ b/tests/inhibit-keycontrol.c @@ -11,7 +11,9 @@ main () UrfClient *client = NULL; guint cookie; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif client = urf_client_new (); diff --git a/tests/killswitch-write.c b/tests/killswitch-write.c index 8f932e0..83b794b 100644 --- a/tests/killswitch-write.c +++ b/tests/killswitch-write.c @@ -16,7 +16,9 @@ main () { UrfKillswitch *wlan = NULL; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif wlan = urf_killswitch_new (URF_ENUM_TYPE_WLAN); diff --git a/tests/monitor-killswitch.c b/tests/monitor-killswitch.c index f81456d..479112c 100644 --- a/tests/monitor-killswitch.c +++ b/tests/monitor-killswitch.c @@ -22,6 +22,8 @@ type_to_name (UrfEnumType type) return "GPS"; case URF_ENUM_TYPE_FM: return "FM"; + case URF_ENUM_TYPE_NFC: + return "NFC"; default: return NULL; } @@ -65,7 +67,9 @@ main () UrfKillswitch *bluetooth = NULL; UrfKillswitch *wwan = NULL; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif wlan = urf_killswitch_new (URF_ENUM_TYPE_WLAN); bluetooth = urf_killswitch_new (URF_ENUM_TYPE_BLUETOOTH); diff --git a/tests/test-urfkill-client.c b/tests/test-urfkill-client.c index 38b2b3f..b66ae77 100644 --- a/tests/test-urfkill-client.c +++ b/tests/test-urfkill-client.c @@ -66,7 +66,9 @@ main () GList *devices, *item; UrfDevice *device; +#if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); +#endif client = urf_client_new (); urf_client_enumerate_devices_sync (client, NULL, NULL); -- 1.8.4 From 7cbcf1e87c4f320214f9b11034e9d6cc9a83ca3e Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 15:50:37 -0500 Subject: [PATCH 06/14] Rename urf-seat and urf-consolekit for generalization --- src/Makefile.am | 8 +- src/urf-consolekit.c | 592 ----------------------------------- src/urf-consolekit.h | 68 ---- src/urf-seat-consolekit.c | 213 +++++++++++++ src/urf-seat-consolekit.h | 66 ++++ src/urf-seat.c | 213 ------------- src/urf-seat.h | 66 ---- src/urf-session-checker-consolekit.c | 592 +++++++++++++++++++++++++++++++++++ src/urf-session-checker-consolekit.h | 68 ++++ 9 files changed, 943 insertions(+), 943 deletions(-) delete mode 100644 src/urf-consolekit.c delete mode 100644 src/urf-consolekit.h create mode 100644 src/urf-seat-consolekit.c create mode 100644 src/urf-seat-consolekit.h delete mode 100644 src/urf-seat.c delete mode 100644 src/urf-seat.h create mode 100644 src/urf-session-checker-consolekit.c create mode 100644 src/urf-session-checker-consolekit.h diff --git a/src/Makefile.am b/src/Makefile.am index 8726e02..6c141fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,10 +36,10 @@ urfkilld_SOURCES = \ urf-polkit.c \ urf-utils.h \ urf-utils.c \ - urf-consolekit.h \ - urf-consolekit.c \ - urf-seat.h \ - urf-seat.c \ + urf-session-checker-consolekit.h \ + urf-session-checker-consolekit.c \ + urf-seat-consolekit.h \ + urf-seat-consolekit.c \ urf-daemon.h \ urf-daemon.c \ urf-main.c \ diff --git a/src/urf-consolekit.c b/src/urf-consolekit.c deleted file mode 100644 index 013b610..0000000 --- a/src/urf-consolekit.c +++ /dev/null @@ -1,592 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> - * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <glib.h> -#include <string.h> -#include <gio/gio.h> - -#include "urf-consolekit.h" - -typedef struct { - guint cookie; - char *session_id; - char *bus_name; - char *reason; -} UrfInhibitor; - -struct UrfConsolekitPrivate { - GDBusProxy *proxy; - GDBusProxy *bus_proxy; - GList *seats; - GList *inhibitors; - gboolean inhibit; -}; - -G_DEFINE_TYPE (UrfConsolekit, urf_consolekit, G_TYPE_OBJECT) - -#define URF_CONSOLEKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitPrivate)) - -/** - * urf_consolekit_is_inhibited: - **/ -gboolean -urf_consolekit_is_inhibited (UrfConsolekit *consolekit) -{ - return consolekit->priv->inhibit; -} - -/** - * urf_consolekit_find_seat: - **/ -static UrfSeat * -urf_consolekit_find_seat (UrfConsolekit *consolekit, - const char *object_path) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfSeat *seat; - GList *item; - - for (item = priv->seats; item; item = item->next) { - seat = URF_SEAT (item->data); - if (g_strcmp0 (urf_seat_get_object_path (seat), object_path) == 0) - return seat; - } - - return NULL; -} - -static UrfInhibitor * -find_inhibitor_by_sid (UrfConsolekit *consolekit, - const char *session_id) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfInhibitor *inhibitor; - GList *item; - - for (item = priv->inhibitors; item; item = item->next) { - inhibitor = (UrfInhibitor *)item->data; - if (g_strcmp0 (inhibitor->session_id, session_id) == 0) - return inhibitor; - } - return NULL; -} - -static UrfInhibitor * -find_inhibitor_by_bus_name (UrfConsolekit *consolekit, - const char *bus_name) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfInhibitor *inhibitor; - GList *item; - - for (item = priv->inhibitors; item; item = item->next) { - inhibitor = (UrfInhibitor *)item->data; - if (g_strcmp0 (inhibitor->bus_name, bus_name) == 0) - return inhibitor; - } - return NULL; -} - -static UrfInhibitor * -find_inhibitor_by_cookie (UrfConsolekit *consolekit, - const guint cookie) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfInhibitor *inhibitor; - GList *item; - - if (cookie == 0) - return NULL; - - for (item = priv->inhibitors; item; item = item->next) { - inhibitor = (UrfInhibitor *)item->data; - if (inhibitor->cookie == cookie) - return inhibitor; - } - return NULL; -} - -static gboolean -is_inhibited (UrfConsolekit *consolekit) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfSeat *seat; - const char *active_id; - GList *item; - - for (item = priv->seats; item; item = item->next) { - seat = URF_SEAT (item->data); - active_id = urf_seat_get_active (seat); - if (find_inhibitor_by_sid (consolekit, active_id)) - return TRUE; - } - - return FALSE; -} - -static void -free_inhibitor (UrfInhibitor *inhibitor) -{ - g_free (inhibitor->session_id); - g_free (inhibitor->bus_name); - g_free (inhibitor->reason); - g_free (inhibitor); -} - -/** - * urf_consolekit_seat_active_changed: - **/ -static void -urf_consolekit_seat_active_changed (UrfSeat *seat, - const char *session_id, - UrfConsolekit *consolekit) -{ - consolekit->priv->inhibit = is_inhibited (consolekit); - g_debug ("Active Session changed: %s", session_id); -} - -static char * -get_session_id (UrfConsolekit *consolekit, - const char *bus_name) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - pid_t calling_pid; - char *session_id = NULL; - GVariant *retval; - GError *error; - - error = NULL; - retval = g_dbus_proxy_call_sync (priv->bus_proxy, "GetConnectionUnixProcessID", - g_variant_new ("(s)", bus_name), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (error) { - g_warning("GetConnectionUnixProcessID() failed: %s", error->message); - g_error_free (error); - goto out; - } - g_variant_get (retval, "(u)", &calling_pid); - g_variant_unref (retval); - - error = NULL; - retval = g_dbus_proxy_call_sync (priv->proxy, "GetSessionForUnixProcess", - g_variant_new ("(u)", (guint)calling_pid), - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (error) { - g_warning ("Couldn't sent GetSessionForUnixProcess: %s", error->message); - g_error_free (error); - session_id = NULL; - goto out; - } - - g_variant_get (retval, "(s)", &session_id); - session_id = g_strdup (session_id); - g_variant_unref (retval); -out: - return session_id; -} - -static guint -generate_unique_cookie (UrfConsolekit *consolekit) -{ - UrfInhibitor *inhibitor; - guint cookie; - - do { - cookie = g_random_int_range (1, G_MAXINT); - inhibitor = find_inhibitor_by_cookie (consolekit, cookie); - } while (inhibitor != NULL); - - return cookie; -} - -/** - * urf_consolekit_inhibit: - **/ -guint -urf_consolekit_inhibit (UrfConsolekit *consolekit, - const char *bus_name, - const char *reason) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfInhibitor *inhibitor; - - g_return_val_if_fail (priv->proxy != NULL, 0); - - inhibitor = find_inhibitor_by_bus_name (consolekit, bus_name); - if (inhibitor) - return inhibitor->cookie; - - inhibitor = g_new0 (UrfInhibitor, 1); - inhibitor->session_id = get_session_id (consolekit, bus_name); - if (inhibitor->session_id == NULL) { - g_free (inhibitor); - return 0; - } - - inhibitor->reason = g_strdup (reason); - inhibitor->bus_name = g_strdup (bus_name); - inhibitor->cookie = generate_unique_cookie (consolekit); - - priv->inhibitors = g_list_prepend (priv->inhibitors, inhibitor); - - consolekit->priv->inhibit = is_inhibited (consolekit); - g_debug ("Inhibit: %s for %s", bus_name, reason); - - return inhibitor->cookie; -} - -static void -remove_inhibitor (UrfConsolekit *consolekit, - UrfInhibitor *inhibitor) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - - g_return_if_fail (priv->proxy != NULL); - - priv->inhibitors = g_list_remove (priv->inhibitors, inhibitor); - consolekit->priv->inhibit = is_inhibited (consolekit); - g_debug ("Remove inhibitor: %s", inhibitor->bus_name); - free_inhibitor (inhibitor); -} - -/** - * urf_consolekit_uninhibit: - **/ -void -urf_consolekit_uninhibit (UrfConsolekit *consolekit, - const guint cookie) -{ - UrfInhibitor *inhibitor; - - inhibitor = find_inhibitor_by_cookie (consolekit, cookie); - if (inhibitor == NULL) { - g_debug ("Cookie outdated"); - return; - } - remove_inhibitor (consolekit, inhibitor); -} - -/** - * urf_consolekit_add_seat: - **/ -static void -urf_consolekit_add_seat (UrfConsolekit *consolekit, - const char *object_path) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfSeat *seat = urf_seat_new (); - gboolean ret; - - ret = urf_seat_object_path_sync (seat, object_path); - - if (!ret) { - g_warning ("Failed to sync %s", object_path); - return; - } - - priv->seats = g_list_prepend (priv->seats, seat); - - /* connect signal */ - g_signal_connect (seat, "active-changed", - G_CALLBACK (urf_consolekit_seat_active_changed), - consolekit); -} - -/** - * urf_consolekit_seat_added: - **/ -static void -urf_consolekit_seat_added (UrfConsolekit *consolekit, - const char *object_path) -{ - if (urf_consolekit_find_seat (consolekit, object_path) != NULL) { - g_debug ("Already added seat: %s", object_path); - return; - } - - urf_consolekit_add_seat (consolekit, object_path); - g_debug ("Monitor seat: %s", object_path); -} - -/** - * urf_consolekit_seat_removed: - **/ -static void -urf_consolekit_seat_removed (UrfConsolekit *consolekit, - const char *object_path) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - UrfSeat *seat; - - seat = urf_consolekit_find_seat (consolekit, object_path); - if (seat == NULL) - return; - - priv->seats = g_list_remove (priv->seats, seat); - - g_object_unref (seat); - g_debug ("Removed seat: %s", object_path); -} - -/** - * urf_consolekit_proxy_signal_cb - **/ -static void -urf_consolekit_proxy_signal_cb (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); - char *seat_path; - - if (g_strcmp0 (signal_name, "SeatAdded") == 0) { - g_variant_get (parameters, "(o)", &seat_path); - urf_consolekit_seat_added (consolekit, seat_path); - } else if (g_strcmp0 (signal_name, "SeatRemoved") == 0) { - g_variant_get (parameters, "(o)", &seat_path); - urf_consolekit_seat_removed (consolekit, seat_path); - } -} - -/** - * urf_consolekit_bus_owner_changed: - **/ -static void -urf_consolekit_bus_owner_changed (UrfConsolekit *consolekit, - const char *old_owner, - const char *new_owner) -{ - UrfInhibitor *inhibitor; - - if (strlen (new_owner) == 0 && - strlen (old_owner) > 0) { - /* A process disconnected from the bus */ - inhibitor = find_inhibitor_by_bus_name (consolekit, old_owner); - if (inhibitor == NULL) - return; - remove_inhibitor (consolekit, inhibitor); - } -} - -/** - * urf_consolekit_bus_proxy_signal_cb - **/ -static void -urf_consolekit_bus_proxy_signal_cb (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); - char *name; - char *old_owner; - char *new_owner; - - if (g_strcmp0 (signal_name, "NameOwnerChanged") == 0) { - g_variant_get (parameters, "(sss)", &name, &old_owner, &new_owner); - urf_consolekit_bus_owner_changed (consolekit, old_owner, new_owner); - } -} - -/** - * urf_consolekit_get_seats: - **/ -static gboolean -urf_consolekit_get_seats (UrfConsolekit *consolekit) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - GError *error = NULL; - const char *seat_name; - GVariant *retval; - GVariantIter *iter; - - retval = g_dbus_proxy_call_sync (priv->proxy, "GetSeats", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (error) { - g_warning ("GetSeats Failed: %s", error->message); - g_error_free (error); - return FALSE; - } - - if (retval == NULL) { - g_debug ("No Seat exists"); - return FALSE; - } - - g_variant_get (retval, "(ao)", &iter); - while (g_variant_iter_loop (iter, "o", &seat_name)) { - urf_consolekit_add_seat (consolekit, seat_name); - g_debug ("Added seat: %s", seat_name); - } - g_variant_iter_free (iter); - g_variant_unref (retval); - - return TRUE; -} - -/** - * urf_consolekit_startup: - **/ -gboolean -urf_consolekit_startup (UrfConsolekit *consolekit) -{ - UrfConsolekitPrivate *priv = consolekit->priv; - GError *error; - gboolean ret; - - error = NULL; - priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.ConsoleKit", - "/org/freedesktop/ConsoleKit/Manager", - "org.freedesktop.ConsoleKit.Manager", - NULL, - &error); - if (error) { - g_error ("failed to setup proxy for consolekit: %s", error->message); - g_error_free (error); - return FALSE; - } - - error = NULL; - priv->bus_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.DBus", - "/org/freedesktop/DBus", - "org.freedesktop.DBus", - NULL, - &error); - if (error) { - g_error ("failed to setup proxy for consolekit: %s", error->message); - g_error_free (error); - return FALSE; - } - - /* Get seats */ - ret = urf_consolekit_get_seats (consolekit); - if (!ret) - return FALSE; - - /* connect signals */ - g_signal_connect (G_OBJECT (priv->proxy), "g-signal", - G_CALLBACK (urf_consolekit_proxy_signal_cb), consolekit); - g_signal_connect (G_CALLBACK (priv->bus_proxy), "g-signal", - G_CALLBACK (urf_consolekit_bus_proxy_signal_cb), consolekit); - - return TRUE; -} - -/** - * urf_consolekit_dispose: - **/ -static void -urf_consolekit_dispose (GObject *object) -{ - UrfConsolekit *consolekit = URF_CONSOLEKIT(object); - - if (consolekit->priv->proxy) { - g_object_unref (consolekit->priv->proxy); - consolekit->priv->proxy = NULL; - } - if (consolekit->priv->bus_proxy) { - g_object_unref (consolekit->priv->bus_proxy); - consolekit->priv->bus_proxy = NULL; - } - - G_OBJECT_CLASS (urf_consolekit_parent_class)->dispose (object); -} - -/** - * urf_consolekit_finalize: - **/ -static void -urf_consolekit_finalize (GObject *object) -{ - UrfConsolekit *consolekit = URF_CONSOLEKIT (object); - GList *item; - - if (consolekit->priv->seats) { - for (item = consolekit->priv->seats; item; item = item->next) - g_object_unref (item->data); - g_list_free (consolekit->priv->seats); - consolekit->priv->seats = NULL; - } - if (consolekit->priv->inhibitors) { - for (item = consolekit->priv->inhibitors; item; item = item->next) - free_inhibitor (item->data); - g_list_free (consolekit->priv->inhibitors); - consolekit->priv->inhibitors = NULL; - } - - G_OBJECT_CLASS (urf_consolekit_parent_class)->finalize (object); -} - -/** - * urf_consolekit_class_init: - **/ -static void -urf_consolekit_class_init (UrfConsolekitClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = urf_consolekit_dispose; - object_class->finalize = urf_consolekit_finalize; - - g_type_class_add_private (klass, sizeof (UrfConsolekitPrivate)); -} - -/** - * urf_consolekit_init: - **/ -static void -urf_consolekit_init (UrfConsolekit *consolekit) -{ - consolekit->priv = URF_CONSOLEKIT_GET_PRIVATE (consolekit); - consolekit->priv->seats = NULL; - consolekit->priv->inhibitors = NULL; - consolekit->priv->inhibit = FALSE; - consolekit->priv->proxy = NULL; - consolekit->priv->bus_proxy = NULL; -} - -/** - * urf_consolekit_new: - **/ -UrfConsolekit * -urf_consolekit_new (void) -{ - UrfConsolekit *consolekit; - consolekit = URF_CONSOLEKIT (g_object_new (URF_TYPE_CONSOLEKIT, NULL)); - return consolekit; -} diff --git a/src/urf-consolekit.h b/src/urf-consolekit.h deleted file mode 100644 index b9f1e02..0000000 --- a/src/urf-consolekit.h +++ /dev/null @@ -1,68 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> - * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __URF_CONSOLEKIT_H__ -#define __URF_CONSOLEKIT_H__ - -#include <glib-object.h> - -#include "urf-seat.h" - -G_BEGIN_DECLS - -#define URF_TYPE_CONSOLEKIT (urf_consolekit_get_type()) -#define URF_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - URF_TYPE_CONSOLEKIT, UrfConsolekit)) -#define URF_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) -#define URF_IS_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - URF_TYPE_CONSOLEKIT)) -#define URF_IS_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ - URF_TYPE_CONSOLEKIT)) -#define URF_GET_CONSOLEKIT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) - -typedef struct UrfConsolekitPrivate UrfConsolekitPrivate; - -typedef struct { - GObject parent; - UrfConsolekitPrivate *priv; -} UrfConsolekit; - -typedef struct { - GObjectClass parent_class; -} UrfConsolekitClass; - -GType urf_consolekit_get_type (void); - -UrfConsolekit *urf_consolekit_new (void); - -gboolean urf_consolekit_startup (UrfConsolekit *consolekit); - -gboolean urf_consolekit_is_inhibited (UrfConsolekit *consolekit); -guint urf_consolekit_inhibit (UrfConsolekit *consolekit, - const char *bus_name, - const char *reason); -void urf_consolekit_uninhibit (UrfConsolekit *consolekit, - const guint cookie); - -G_END_DECLS - -#endif /* __URF_CONSOLEKIT_H__ */ diff --git a/src/urf-seat-consolekit.c b/src/urf-seat-consolekit.c new file mode 100644 index 0000000..99fcb51 --- /dev/null +++ b/src/urf-seat-consolekit.c @@ -0,0 +1,213 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <gio/gio.h> + +#include "urf-seat.h" + +enum { + SIGNAL_ACTIVE_CHANGED, + SIGNAL_LAST +}; + +static guint signals[SIGNAL_LAST] = { 0 }; + + +struct UrfSeatPrivate { + GDBusConnection *connection; + GDBusProxy *proxy; + char *object_path; + char *active; +}; + +G_DEFINE_TYPE (UrfSeat, urf_seat, G_TYPE_OBJECT) + +#define URF_SEAT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_SEAT, UrfSeatPrivate)) + +/** + * urf_seat_get_object_path: + **/ +const char * +urf_seat_get_object_path (UrfSeat *seat) +{ + return seat->priv->object_path; +} + +/** + * urf_seat_get_active: + **/ +const char * +urf_seat_get_active (UrfSeat *seat) +{ + return seat->priv->active; +} + +/** + * urf_seat_proxy_signal_cb: + **/ +static void +urf_seat_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + UrfSeat *seat = URF_SEAT (user_data); + char *session_id; + + if (g_strcmp0 (signal_name, "ActiveSessionChanged") == 0) { + g_variant_get (parameters, "(s)", &session_id); + + g_free (seat->priv->active); + seat->priv->active = g_strdup (session_id); + + g_signal_emit (seat, signals[SIGNAL_ACTIVE_CHANGED], 0, session_id); + } +} + +/** + * urf_seat_object_path_sync: + **/ +gboolean +urf_seat_object_path_sync (UrfSeat *seat, + const char *object_path) +{ + UrfSeatPrivate *priv = seat->priv; + GVariant *retval; + char *session; + GError *error; + + priv->object_path = g_strdup (object_path); + + error = NULL; + priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.ConsoleKit", + priv->object_path, + "org.freedesktop.ConsoleKit.Seat", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for consolekit seat: %s", error->message); + g_error_free (error); + return FALSE; + } + + error = NULL; + retval = g_dbus_proxy_call_sync (priv->proxy, "GetActiveSession", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning ("Failed to get Active Session: %s", error->message); + g_error_free (error); + return FALSE; + } + + g_variant_get (retval, "(o)", &session); + priv->active = g_strdup (session); + g_variant_unref (retval); + + /* connect signals */ + g_signal_connect (G_OBJECT (priv->proxy), "g-signal", + G_CALLBACK (urf_seat_proxy_signal_cb), seat); + + return TRUE; +} + +/** + * urf_seat_dispose: + **/ +static void +urf_seat_dispose (GObject *object) +{ + UrfSeat *seat = URF_SEAT (object); + + if (seat->priv->proxy) { + g_object_unref (seat->priv->proxy); + seat->priv->proxy = NULL; + } + + G_OBJECT_CLASS (urf_seat_parent_class)->dispose (object); +} + +/** + * urf_seat_finalize: + **/ +static void +urf_seat_finalize (GObject *object) +{ + UrfSeat *seat = URF_SEAT (object); + + g_free (seat->priv->object_path); + g_free (seat->priv->active); + + G_OBJECT_CLASS (urf_seat_parent_class)->finalize (object); +} + +/** + * urf_seat_class_init: + **/ +static void +urf_seat_class_init (UrfSeatClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = urf_seat_dispose; + object_class->finalize = urf_seat_finalize; + + signals[SIGNAL_ACTIVE_CHANGED] = + g_signal_new ("active-changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UrfSeatClass, active_changed), + NULL, NULL, g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); + + g_type_class_add_private (klass, sizeof (UrfSeatPrivate)); +} + +/** + * urf_seat_init: + **/ +static void +urf_seat_init (UrfSeat *seat) +{ + seat->priv = URF_SEAT_GET_PRIVATE (seat); + seat->priv->object_path = NULL; + seat->priv->active = NULL; +} + +/** + * urf_seat_new: + **/ +UrfSeat * +urf_seat_new (void) +{ + UrfSeat *seat; + seat = URF_SEAT (g_object_new (URF_TYPE_SEAT, NULL)); + return seat; +} diff --git a/src/urf-seat-consolekit.h b/src/urf-seat-consolekit.h new file mode 100644 index 0000000..195649d --- /dev/null +++ b/src/urf-seat-consolekit.h @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __URF_SEAT_H__ +#define __URF_SEAT_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define URF_TYPE_SEAT (urf_seat_get_type()) +#define URF_SEAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_SEAT, UrfSeat)) +#define URF_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_SEAT, UrfSeatClass)) +#define URF_IS_SEAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_SEAT)) +#define URF_IS_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_SEAT)) +#define URF_GET_SEAT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_SEAT, UrfSeatClass)) + +typedef struct UrfSeatPrivate UrfSeatPrivate; + +typedef struct { + GObject parent; + UrfSeatPrivate *priv; +} UrfSeat; + +typedef struct { + GObjectClass parent_class; + void (*active_changed) (UrfSeat *seat, + const char *session_id); + void (*session_removed) (UrfSeat *seat, + const char *session_id); +} UrfSeatClass; + +GType urf_seat_get_type (void); + +UrfSeat *urf_seat_new (void); +gboolean urf_seat_object_path_sync (UrfSeat *seat, + const char *object_path); + +const char *urf_seat_get_object_path (UrfSeat *seat); +const char *urf_seat_get_active (UrfSeat *seat); + +G_END_DECLS + +#endif /* __URF_SEAT_H__ */ diff --git a/src/urf-seat.c b/src/urf-seat.c deleted file mode 100644 index 99fcb51..0000000 --- a/src/urf-seat.c +++ /dev/null @@ -1,213 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> - * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifdef HAVE_CONFIG_H -# include "config.h" -#endif - -#include <glib.h> -#include <gio/gio.h> - -#include "urf-seat.h" - -enum { - SIGNAL_ACTIVE_CHANGED, - SIGNAL_LAST -}; - -static guint signals[SIGNAL_LAST] = { 0 }; - - -struct UrfSeatPrivate { - GDBusConnection *connection; - GDBusProxy *proxy; - char *object_path; - char *active; -}; - -G_DEFINE_TYPE (UrfSeat, urf_seat, G_TYPE_OBJECT) - -#define URF_SEAT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - URF_TYPE_SEAT, UrfSeatPrivate)) - -/** - * urf_seat_get_object_path: - **/ -const char * -urf_seat_get_object_path (UrfSeat *seat) -{ - return seat->priv->object_path; -} - -/** - * urf_seat_get_active: - **/ -const char * -urf_seat_get_active (UrfSeat *seat) -{ - return seat->priv->active; -} - -/** - * urf_seat_proxy_signal_cb: - **/ -static void -urf_seat_proxy_signal_cb (GDBusProxy *proxy, - gchar *sender_name, - gchar *signal_name, - GVariant *parameters, - gpointer user_data) -{ - UrfSeat *seat = URF_SEAT (user_data); - char *session_id; - - if (g_strcmp0 (signal_name, "ActiveSessionChanged") == 0) { - g_variant_get (parameters, "(s)", &session_id); - - g_free (seat->priv->active); - seat->priv->active = g_strdup (session_id); - - g_signal_emit (seat, signals[SIGNAL_ACTIVE_CHANGED], 0, session_id); - } -} - -/** - * urf_seat_object_path_sync: - **/ -gboolean -urf_seat_object_path_sync (UrfSeat *seat, - const char *object_path) -{ - UrfSeatPrivate *priv = seat->priv; - GVariant *retval; - char *session; - GError *error; - - priv->object_path = g_strdup (object_path); - - error = NULL; - priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, - G_DBUS_PROXY_FLAGS_NONE, - NULL, - "org.freedesktop.ConsoleKit", - priv->object_path, - "org.freedesktop.ConsoleKit.Seat", - NULL, - &error); - if (error) { - g_error ("failed to setup proxy for consolekit seat: %s", error->message); - g_error_free (error); - return FALSE; - } - - error = NULL; - retval = g_dbus_proxy_call_sync (priv->proxy, "GetActiveSession", - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &error); - if (error) { - g_warning ("Failed to get Active Session: %s", error->message); - g_error_free (error); - return FALSE; - } - - g_variant_get (retval, "(o)", &session); - priv->active = g_strdup (session); - g_variant_unref (retval); - - /* connect signals */ - g_signal_connect (G_OBJECT (priv->proxy), "g-signal", - G_CALLBACK (urf_seat_proxy_signal_cb), seat); - - return TRUE; -} - -/** - * urf_seat_dispose: - **/ -static void -urf_seat_dispose (GObject *object) -{ - UrfSeat *seat = URF_SEAT (object); - - if (seat->priv->proxy) { - g_object_unref (seat->priv->proxy); - seat->priv->proxy = NULL; - } - - G_OBJECT_CLASS (urf_seat_parent_class)->dispose (object); -} - -/** - * urf_seat_finalize: - **/ -static void -urf_seat_finalize (GObject *object) -{ - UrfSeat *seat = URF_SEAT (object); - - g_free (seat->priv->object_path); - g_free (seat->priv->active); - - G_OBJECT_CLASS (urf_seat_parent_class)->finalize (object); -} - -/** - * urf_seat_class_init: - **/ -static void -urf_seat_class_init (UrfSeatClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = urf_seat_dispose; - object_class->finalize = urf_seat_finalize; - - signals[SIGNAL_ACTIVE_CHANGED] = - g_signal_new ("active-changed", - G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (UrfSeatClass, active_changed), - NULL, NULL, g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, 1, G_TYPE_STRING); - - g_type_class_add_private (klass, sizeof (UrfSeatPrivate)); -} - -/** - * urf_seat_init: - **/ -static void -urf_seat_init (UrfSeat *seat) -{ - seat->priv = URF_SEAT_GET_PRIVATE (seat); - seat->priv->object_path = NULL; - seat->priv->active = NULL; -} - -/** - * urf_seat_new: - **/ -UrfSeat * -urf_seat_new (void) -{ - UrfSeat *seat; - seat = URF_SEAT (g_object_new (URF_TYPE_SEAT, NULL)); - return seat; -} diff --git a/src/urf-seat.h b/src/urf-seat.h deleted file mode 100644 index 195649d..0000000 --- a/src/urf-seat.h +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> - * - * 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 St, Fifth Floor, Boston, MA 02110-1301 USA - * - */ - -#ifndef __URF_SEAT_H__ -#define __URF_SEAT_H__ - -#include <glib-object.h> - -G_BEGIN_DECLS - -#define URF_TYPE_SEAT (urf_seat_get_type()) -#define URF_SEAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - URF_TYPE_SEAT, UrfSeat)) -#define URF_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ - URF_TYPE_SEAT, UrfSeatClass)) -#define URF_IS_SEAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - URF_TYPE_SEAT)) -#define URF_IS_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ - URF_TYPE_SEAT)) -#define URF_GET_SEAT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ - URF_TYPE_SEAT, UrfSeatClass)) - -typedef struct UrfSeatPrivate UrfSeatPrivate; - -typedef struct { - GObject parent; - UrfSeatPrivate *priv; -} UrfSeat; - -typedef struct { - GObjectClass parent_class; - void (*active_changed) (UrfSeat *seat, - const char *session_id); - void (*session_removed) (UrfSeat *seat, - const char *session_id); -} UrfSeatClass; - -GType urf_seat_get_type (void); - -UrfSeat *urf_seat_new (void); -gboolean urf_seat_object_path_sync (UrfSeat *seat, - const char *object_path); - -const char *urf_seat_get_object_path (UrfSeat *seat); -const char *urf_seat_get_active (UrfSeat *seat); - -G_END_DECLS - -#endif /* __URF_SEAT_H__ */ diff --git a/src/urf-session-checker-consolekit.c b/src/urf-session-checker-consolekit.c new file mode 100644 index 0000000..013b610 --- /dev/null +++ b/src/urf-session-checker-consolekit.c @@ -0,0 +1,592 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <string.h> +#include <gio/gio.h> + +#include "urf-consolekit.h" + +typedef struct { + guint cookie; + char *session_id; + char *bus_name; + char *reason; +} UrfInhibitor; + +struct UrfConsolekitPrivate { + GDBusProxy *proxy; + GDBusProxy *bus_proxy; + GList *seats; + GList *inhibitors; + gboolean inhibit; +}; + +G_DEFINE_TYPE (UrfConsolekit, urf_consolekit, G_TYPE_OBJECT) + +#define URF_CONSOLEKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_CONSOLEKIT, UrfConsolekitPrivate)) + +/** + * urf_consolekit_is_inhibited: + **/ +gboolean +urf_consolekit_is_inhibited (UrfConsolekit *consolekit) +{ + return consolekit->priv->inhibit; +} + +/** + * urf_consolekit_find_seat: + **/ +static UrfSeat * +urf_consolekit_find_seat (UrfConsolekit *consolekit, + const char *object_path) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfSeat *seat; + GList *item; + + for (item = priv->seats; item; item = item->next) { + seat = URF_SEAT (item->data); + if (g_strcmp0 (urf_seat_get_object_path (seat), object_path) == 0) + return seat; + } + + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_sid (UrfConsolekit *consolekit, + const char *session_id) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfInhibitor *inhibitor; + GList *item; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (g_strcmp0 (inhibitor->session_id, session_id) == 0) + return inhibitor; + } + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_bus_name (UrfConsolekit *consolekit, + const char *bus_name) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfInhibitor *inhibitor; + GList *item; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (g_strcmp0 (inhibitor->bus_name, bus_name) == 0) + return inhibitor; + } + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_cookie (UrfConsolekit *consolekit, + const guint cookie) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfInhibitor *inhibitor; + GList *item; + + if (cookie == 0) + return NULL; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (inhibitor->cookie == cookie) + return inhibitor; + } + return NULL; +} + +static gboolean +is_inhibited (UrfConsolekit *consolekit) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfSeat *seat; + const char *active_id; + GList *item; + + for (item = priv->seats; item; item = item->next) { + seat = URF_SEAT (item->data); + active_id = urf_seat_get_active (seat); + if (find_inhibitor_by_sid (consolekit, active_id)) + return TRUE; + } + + return FALSE; +} + +static void +free_inhibitor (UrfInhibitor *inhibitor) +{ + g_free (inhibitor->session_id); + g_free (inhibitor->bus_name); + g_free (inhibitor->reason); + g_free (inhibitor); +} + +/** + * urf_consolekit_seat_active_changed: + **/ +static void +urf_consolekit_seat_active_changed (UrfSeat *seat, + const char *session_id, + UrfConsolekit *consolekit) +{ + consolekit->priv->inhibit = is_inhibited (consolekit); + g_debug ("Active Session changed: %s", session_id); +} + +static char * +get_session_id (UrfConsolekit *consolekit, + const char *bus_name) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + pid_t calling_pid; + char *session_id = NULL; + GVariant *retval; + GError *error; + + error = NULL; + retval = g_dbus_proxy_call_sync (priv->bus_proxy, "GetConnectionUnixProcessID", + g_variant_new ("(s)", bus_name), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning("GetConnectionUnixProcessID() failed: %s", error->message); + g_error_free (error); + goto out; + } + g_variant_get (retval, "(u)", &calling_pid); + g_variant_unref (retval); + + error = NULL; + retval = g_dbus_proxy_call_sync (priv->proxy, "GetSessionForUnixProcess", + g_variant_new ("(u)", (guint)calling_pid), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning ("Couldn't sent GetSessionForUnixProcess: %s", error->message); + g_error_free (error); + session_id = NULL; + goto out; + } + + g_variant_get (retval, "(s)", &session_id); + session_id = g_strdup (session_id); + g_variant_unref (retval); +out: + return session_id; +} + +static guint +generate_unique_cookie (UrfConsolekit *consolekit) +{ + UrfInhibitor *inhibitor; + guint cookie; + + do { + cookie = g_random_int_range (1, G_MAXINT); + inhibitor = find_inhibitor_by_cookie (consolekit, cookie); + } while (inhibitor != NULL); + + return cookie; +} + +/** + * urf_consolekit_inhibit: + **/ +guint +urf_consolekit_inhibit (UrfConsolekit *consolekit, + const char *bus_name, + const char *reason) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfInhibitor *inhibitor; + + g_return_val_if_fail (priv->proxy != NULL, 0); + + inhibitor = find_inhibitor_by_bus_name (consolekit, bus_name); + if (inhibitor) + return inhibitor->cookie; + + inhibitor = g_new0 (UrfInhibitor, 1); + inhibitor->session_id = get_session_id (consolekit, bus_name); + if (inhibitor->session_id == NULL) { + g_free (inhibitor); + return 0; + } + + inhibitor->reason = g_strdup (reason); + inhibitor->bus_name = g_strdup (bus_name); + inhibitor->cookie = generate_unique_cookie (consolekit); + + priv->inhibitors = g_list_prepend (priv->inhibitors, inhibitor); + + consolekit->priv->inhibit = is_inhibited (consolekit); + g_debug ("Inhibit: %s for %s", bus_name, reason); + + return inhibitor->cookie; +} + +static void +remove_inhibitor (UrfConsolekit *consolekit, + UrfInhibitor *inhibitor) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + + g_return_if_fail (priv->proxy != NULL); + + priv->inhibitors = g_list_remove (priv->inhibitors, inhibitor); + consolekit->priv->inhibit = is_inhibited (consolekit); + g_debug ("Remove inhibitor: %s", inhibitor->bus_name); + free_inhibitor (inhibitor); +} + +/** + * urf_consolekit_uninhibit: + **/ +void +urf_consolekit_uninhibit (UrfConsolekit *consolekit, + const guint cookie) +{ + UrfInhibitor *inhibitor; + + inhibitor = find_inhibitor_by_cookie (consolekit, cookie); + if (inhibitor == NULL) { + g_debug ("Cookie outdated"); + return; + } + remove_inhibitor (consolekit, inhibitor); +} + +/** + * urf_consolekit_add_seat: + **/ +static void +urf_consolekit_add_seat (UrfConsolekit *consolekit, + const char *object_path) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfSeat *seat = urf_seat_new (); + gboolean ret; + + ret = urf_seat_object_path_sync (seat, object_path); + + if (!ret) { + g_warning ("Failed to sync %s", object_path); + return; + } + + priv->seats = g_list_prepend (priv->seats, seat); + + /* connect signal */ + g_signal_connect (seat, "active-changed", + G_CALLBACK (urf_consolekit_seat_active_changed), + consolekit); +} + +/** + * urf_consolekit_seat_added: + **/ +static void +urf_consolekit_seat_added (UrfConsolekit *consolekit, + const char *object_path) +{ + if (urf_consolekit_find_seat (consolekit, object_path) != NULL) { + g_debug ("Already added seat: %s", object_path); + return; + } + + urf_consolekit_add_seat (consolekit, object_path); + g_debug ("Monitor seat: %s", object_path); +} + +/** + * urf_consolekit_seat_removed: + **/ +static void +urf_consolekit_seat_removed (UrfConsolekit *consolekit, + const char *object_path) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + UrfSeat *seat; + + seat = urf_consolekit_find_seat (consolekit, object_path); + if (seat == NULL) + return; + + priv->seats = g_list_remove (priv->seats, seat); + + g_object_unref (seat); + g_debug ("Removed seat: %s", object_path); +} + +/** + * urf_consolekit_proxy_signal_cb + **/ +static void +urf_consolekit_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); + char *seat_path; + + if (g_strcmp0 (signal_name, "SeatAdded") == 0) { + g_variant_get (parameters, "(o)", &seat_path); + urf_consolekit_seat_added (consolekit, seat_path); + } else if (g_strcmp0 (signal_name, "SeatRemoved") == 0) { + g_variant_get (parameters, "(o)", &seat_path); + urf_consolekit_seat_removed (consolekit, seat_path); + } +} + +/** + * urf_consolekit_bus_owner_changed: + **/ +static void +urf_consolekit_bus_owner_changed (UrfConsolekit *consolekit, + const char *old_owner, + const char *new_owner) +{ + UrfInhibitor *inhibitor; + + if (strlen (new_owner) == 0 && + strlen (old_owner) > 0) { + /* A process disconnected from the bus */ + inhibitor = find_inhibitor_by_bus_name (consolekit, old_owner); + if (inhibitor == NULL) + return; + remove_inhibitor (consolekit, inhibitor); + } +} + +/** + * urf_consolekit_bus_proxy_signal_cb + **/ +static void +urf_consolekit_bus_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); + char *name; + char *old_owner; + char *new_owner; + + if (g_strcmp0 (signal_name, "NameOwnerChanged") == 0) { + g_variant_get (parameters, "(sss)", &name, &old_owner, &new_owner); + urf_consolekit_bus_owner_changed (consolekit, old_owner, new_owner); + } +} + +/** + * urf_consolekit_get_seats: + **/ +static gboolean +urf_consolekit_get_seats (UrfConsolekit *consolekit) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + GError *error = NULL; + const char *seat_name; + GVariant *retval; + GVariantIter *iter; + + retval = g_dbus_proxy_call_sync (priv->proxy, "GetSeats", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning ("GetSeats Failed: %s", error->message); + g_error_free (error); + return FALSE; + } + + if (retval == NULL) { + g_debug ("No Seat exists"); + return FALSE; + } + + g_variant_get (retval, "(ao)", &iter); + while (g_variant_iter_loop (iter, "o", &seat_name)) { + urf_consolekit_add_seat (consolekit, seat_name); + g_debug ("Added seat: %s", seat_name); + } + g_variant_iter_free (iter); + g_variant_unref (retval); + + return TRUE; +} + +/** + * urf_consolekit_startup: + **/ +gboolean +urf_consolekit_startup (UrfConsolekit *consolekit) +{ + UrfConsolekitPrivate *priv = consolekit->priv; + GError *error; + gboolean ret; + + error = NULL; + priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.ConsoleKit", + "/org/freedesktop/ConsoleKit/Manager", + "org.freedesktop.ConsoleKit.Manager", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for consolekit: %s", error->message); + g_error_free (error); + return FALSE; + } + + error = NULL; + priv->bus_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for consolekit: %s", error->message); + g_error_free (error); + return FALSE; + } + + /* Get seats */ + ret = urf_consolekit_get_seats (consolekit); + if (!ret) + return FALSE; + + /* connect signals */ + g_signal_connect (G_OBJECT (priv->proxy), "g-signal", + G_CALLBACK (urf_consolekit_proxy_signal_cb), consolekit); + g_signal_connect (G_CALLBACK (priv->bus_proxy), "g-signal", + G_CALLBACK (urf_consolekit_bus_proxy_signal_cb), consolekit); + + return TRUE; +} + +/** + * urf_consolekit_dispose: + **/ +static void +urf_consolekit_dispose (GObject *object) +{ + UrfConsolekit *consolekit = URF_CONSOLEKIT(object); + + if (consolekit->priv->proxy) { + g_object_unref (consolekit->priv->proxy); + consolekit->priv->proxy = NULL; + } + if (consolekit->priv->bus_proxy) { + g_object_unref (consolekit->priv->bus_proxy); + consolekit->priv->bus_proxy = NULL; + } + + G_OBJECT_CLASS (urf_consolekit_parent_class)->dispose (object); +} + +/** + * urf_consolekit_finalize: + **/ +static void +urf_consolekit_finalize (GObject *object) +{ + UrfConsolekit *consolekit = URF_CONSOLEKIT (object); + GList *item; + + if (consolekit->priv->seats) { + for (item = consolekit->priv->seats; item; item = item->next) + g_object_unref (item->data); + g_list_free (consolekit->priv->seats); + consolekit->priv->seats = NULL; + } + if (consolekit->priv->inhibitors) { + for (item = consolekit->priv->inhibitors; item; item = item->next) + free_inhibitor (item->data); + g_list_free (consolekit->priv->inhibitors); + consolekit->priv->inhibitors = NULL; + } + + G_OBJECT_CLASS (urf_consolekit_parent_class)->finalize (object); +} + +/** + * urf_consolekit_class_init: + **/ +static void +urf_consolekit_class_init (UrfConsolekitClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = urf_consolekit_dispose; + object_class->finalize = urf_consolekit_finalize; + + g_type_class_add_private (klass, sizeof (UrfConsolekitPrivate)); +} + +/** + * urf_consolekit_init: + **/ +static void +urf_consolekit_init (UrfConsolekit *consolekit) +{ + consolekit->priv = URF_CONSOLEKIT_GET_PRIVATE (consolekit); + consolekit->priv->seats = NULL; + consolekit->priv->inhibitors = NULL; + consolekit->priv->inhibit = FALSE; + consolekit->priv->proxy = NULL; + consolekit->priv->bus_proxy = NULL; +} + +/** + * urf_consolekit_new: + **/ +UrfConsolekit * +urf_consolekit_new (void) +{ + UrfConsolekit *consolekit; + consolekit = URF_CONSOLEKIT (g_object_new (URF_TYPE_CONSOLEKIT, NULL)); + return consolekit; +} diff --git a/src/urf-session-checker-consolekit.h b/src/urf-session-checker-consolekit.h new file mode 100644 index 0000000..b9f1e02 --- /dev/null +++ b/src/urf-session-checker-consolekit.h @@ -0,0 +1,68 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2011 Gary Ching-Pang Lin <glin@suse.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __URF_CONSOLEKIT_H__ +#define __URF_CONSOLEKIT_H__ + +#include <glib-object.h> + +#include "urf-seat.h" + +G_BEGIN_DECLS + +#define URF_TYPE_CONSOLEKIT (urf_consolekit_get_type()) +#define URF_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_CONSOLEKIT, UrfConsolekit)) +#define URF_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) +#define URF_IS_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_CONSOLEKIT)) +#define URF_IS_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_CONSOLEKIT)) +#define URF_GET_CONSOLEKIT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) + +typedef struct UrfConsolekitPrivate UrfConsolekitPrivate; + +typedef struct { + GObject parent; + UrfConsolekitPrivate *priv; +} UrfConsolekit; + +typedef struct { + GObjectClass parent_class; +} UrfConsolekitClass; + +GType urf_consolekit_get_type (void); + +UrfConsolekit *urf_consolekit_new (void); + +gboolean urf_consolekit_startup (UrfConsolekit *consolekit); + +gboolean urf_consolekit_is_inhibited (UrfConsolekit *consolekit); +guint urf_consolekit_inhibit (UrfConsolekit *consolekit, + const char *bus_name, + const char *reason); +void urf_consolekit_uninhibit (UrfConsolekit *consolekit, + const guint cookie); + +G_END_DECLS + +#endif /* __URF_CONSOLEKIT_H__ */ -- 1.8.4 From 5590ae43aed52d35e167c9e9a08afe482a20b93e Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 15:55:56 -0500 Subject: [PATCH 07/14] Rename UrfConsolekit to UrfSessionChecker --- src/urf-daemon.c | 42 +++++------ src/urf-session-checker-consolekit.c | 142 +++++++++++++++++------------------ src/urf-session-checker-consolekit.h | 52 ++++++------- 3 files changed, 118 insertions(+), 118 deletions(-) diff --git a/src/urf-daemon.c b/src/urf-daemon.c index ca37119..d510f8a 100644 --- a/src/urf-daemon.c +++ b/src/urf-daemon.c @@ -36,7 +36,7 @@ #include "urf-input.h" #include "urf-utils.h" #include "urf-config.h" -#include "urf-consolekit.h" +#include "urf-session-checker-consolekit.h" #define URFKILL_DBUS_INTERFACE "org.freedesktop.URfkill" #define URFKILL_OBJECT_PATH "/org/freedesktop/URfkill" @@ -110,15 +110,15 @@ static guint signals[SIGNAL_LAST] = { 0 }; struct UrfDaemonPrivate { - UrfConfig *config; - UrfPolkit *polkit; - UrfArbitrator *arbitrator; - UrfInput *input; - UrfConsolekit *consolekit; - gboolean key_control; - gboolean master_key; - GDBusConnection *connection; - GDBusNodeInfo *introspection_data; + UrfConfig *config; + UrfPolkit *polkit; + UrfArbitrator *arbitrator; + UrfInput *input; + UrfSessionChecker *session_checker; + gboolean key_control; + gboolean master_key; + GDBusConnection *connection; + GDBusNodeInfo *introspection_data; }; static void urf_daemon_dispose (GObject *object); @@ -143,7 +143,7 @@ urf_daemon_input_event_cb (UrfInput *input, gboolean block = FALSE; GError *error = NULL; - if (urf_consolekit_is_inhibited (priv->consolekit)) + if (urf_session_checker_is_inhibited (priv->session_checker)) goto out; switch (code) { @@ -311,7 +311,7 @@ urf_daemon_is_inhibited (UrfDaemon *daemon, UrfDaemonPrivate *priv = daemon->priv; GVariant *value; - value = g_variant_new ("(b)", urf_consolekit_is_inhibited (priv->consolekit)); + value = g_variant_new ("(b)", urf_session_checker_is_inhibited (priv->session_checker)); g_dbus_method_invocation_return_value (invocation, value); return TRUE; @@ -330,7 +330,7 @@ urf_daemon_inhibit (UrfDaemon *daemon, guint cookie = 0; bus_name = g_dbus_method_invocation_get_sender (invocation); - cookie = urf_consolekit_inhibit (priv->consolekit, bus_name, reason); + cookie = urf_session_checker_inhibit (priv->session_checker, bus_name, reason); g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", cookie)); @@ -345,7 +345,7 @@ urf_daemon_uninhibit (UrfDaemon *daemon, const guint cookie, GDBusMethodInvocation *invocation) { - urf_consolekit_uninhibit (daemon->priv->consolekit, cookie); + urf_session_checker_uninhibit (daemon->priv->session_checker, cookie); } static void @@ -502,10 +502,10 @@ urf_daemon_startup (UrfDaemon *daemon) goto out; } - /* start up consolekit checker */ - ret = urf_consolekit_startup (priv->consolekit); + /* start up session checker */ + ret = urf_session_checker_startup (priv->session_checker); if (!ret) { - g_warning ("failed to setup consolekit session checker"); + g_warning ("failed to setup session checker"); goto out; } } @@ -628,7 +628,7 @@ urf_daemon_init (UrfDaemon *daemon) g_signal_connect (daemon->priv->input, "rf-key-pressed", G_CALLBACK (urf_daemon_input_event_cb), daemon); - daemon->priv->consolekit = urf_consolekit_new (); + daemon->priv->session_checker = urf_session_checker_new (); } /** @@ -760,9 +760,9 @@ urf_daemon_dispose (GObject *object) priv->arbitrator = NULL; } - if (priv->consolekit) { - g_object_unref (priv->consolekit); - priv->consolekit = NULL; + if (priv->session_checker) { + g_object_unref (priv->session_checker); + priv->session_checker = NULL; } G_OBJECT_CLASS (urf_daemon_parent_class)->dispose (object); diff --git a/src/urf-session-checker-consolekit.c b/src/urf-session-checker-consolekit.c index 013b610..1ed90eb 100644 --- a/src/urf-session-checker-consolekit.c +++ b/src/urf-session-checker-consolekit.c @@ -26,7 +26,7 @@ #include <string.h> #include <gio/gio.h> -#include "urf-consolekit.h" +#include "urf-session-checker-consolekit.h" typedef struct { guint cookie; @@ -43,25 +43,25 @@ struct UrfConsolekitPrivate { gboolean inhibit; }; -G_DEFINE_TYPE (UrfConsolekit, urf_consolekit, G_TYPE_OBJECT) +G_DEFINE_TYPE (UrfSessionChecker, urf_session_checker, G_TYPE_OBJECT) -#define URF_CONSOLEKIT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitPrivate)) +#define URF_SESSION_CHECKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_SESSION_CHECKER, UrfConsolekitPrivate)) /** - * urf_consolekit_is_inhibited: + * urf_session_checker_is_inhibited: **/ gboolean -urf_consolekit_is_inhibited (UrfConsolekit *consolekit) +urf_session_checker_is_inhibited (UrfSessionChecker *consolekit) { return consolekit->priv->inhibit; } /** - * urf_consolekit_find_seat: + * urf_session_checker_find_seat: **/ static UrfSeat * -urf_consolekit_find_seat (UrfConsolekit *consolekit, +urf_session_checker_find_seat (UrfSessionChecker *consolekit, const char *object_path) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -78,7 +78,7 @@ urf_consolekit_find_seat (UrfConsolekit *consolekit, } static UrfInhibitor * -find_inhibitor_by_sid (UrfConsolekit *consolekit, +find_inhibitor_by_sid (UrfSessionChecker *consolekit, const char *session_id) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -94,7 +94,7 @@ find_inhibitor_by_sid (UrfConsolekit *consolekit, } static UrfInhibitor * -find_inhibitor_by_bus_name (UrfConsolekit *consolekit, +find_inhibitor_by_bus_name (UrfSessionChecker *consolekit, const char *bus_name) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -110,7 +110,7 @@ find_inhibitor_by_bus_name (UrfConsolekit *consolekit, } static UrfInhibitor * -find_inhibitor_by_cookie (UrfConsolekit *consolekit, +find_inhibitor_by_cookie (UrfSessionChecker *consolekit, const guint cookie) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -129,7 +129,7 @@ find_inhibitor_by_cookie (UrfConsolekit *consolekit, } static gboolean -is_inhibited (UrfConsolekit *consolekit) +is_inhibited (UrfSessionChecker *consolekit) { UrfConsolekitPrivate *priv = consolekit->priv; UrfSeat *seat; @@ -156,19 +156,19 @@ free_inhibitor (UrfInhibitor *inhibitor) } /** - * urf_consolekit_seat_active_changed: + * urf_session_checker_seat_active_changed: **/ static void -urf_consolekit_seat_active_changed (UrfSeat *seat, +urf_session_checker_seat_active_changed (UrfSeat *seat, const char *session_id, - UrfConsolekit *consolekit) + UrfSessionChecker *consolekit) { consolekit->priv->inhibit = is_inhibited (consolekit); g_debug ("Active Session changed: %s", session_id); } static char * -get_session_id (UrfConsolekit *consolekit, +get_session_id (UrfSessionChecker *consolekit, const char *bus_name) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -210,7 +210,7 @@ out: } static guint -generate_unique_cookie (UrfConsolekit *consolekit) +generate_unique_cookie (UrfSessionChecker *consolekit) { UrfInhibitor *inhibitor; guint cookie; @@ -224,10 +224,10 @@ generate_unique_cookie (UrfConsolekit *consolekit) } /** - * urf_consolekit_inhibit: + * urf_session_checker_inhibit: **/ guint -urf_consolekit_inhibit (UrfConsolekit *consolekit, +urf_session_checker_inhibit (UrfSessionChecker *consolekit, const char *bus_name, const char *reason) { @@ -260,7 +260,7 @@ urf_consolekit_inhibit (UrfConsolekit *consolekit, } static void -remove_inhibitor (UrfConsolekit *consolekit, +remove_inhibitor (UrfSessionChecker *consolekit, UrfInhibitor *inhibitor) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -274,10 +274,10 @@ remove_inhibitor (UrfConsolekit *consolekit, } /** - * urf_consolekit_uninhibit: + * urf_session_checker_uninhibit: **/ void -urf_consolekit_uninhibit (UrfConsolekit *consolekit, +urf_session_checker_uninhibit (UrfSessionChecker *consolekit, const guint cookie) { UrfInhibitor *inhibitor; @@ -291,10 +291,10 @@ urf_consolekit_uninhibit (UrfConsolekit *consolekit, } /** - * urf_consolekit_add_seat: + * urf_session_checker_add_seat: **/ static void -urf_consolekit_add_seat (UrfConsolekit *consolekit, +urf_session_checker_add_seat (UrfSessionChecker *consolekit, const char *object_path) { UrfConsolekitPrivate *priv = consolekit->priv; @@ -312,37 +312,37 @@ urf_consolekit_add_seat (UrfConsolekit *consolekit, /* connect signal */ g_signal_connect (seat, "active-changed", - G_CALLBACK (urf_consolekit_seat_active_changed), + G_CALLBACK (urf_session_checker_seat_active_changed), consolekit); } /** - * urf_consolekit_seat_added: + * urf_session_checker_seat_added: **/ static void -urf_consolekit_seat_added (UrfConsolekit *consolekit, +urf_session_checker_seat_added (UrfSessionChecker *consolekit, const char *object_path) { - if (urf_consolekit_find_seat (consolekit, object_path) != NULL) { + if (urf_session_checker_find_seat (consolekit, object_path) != NULL) { g_debug ("Already added seat: %s", object_path); return; } - urf_consolekit_add_seat (consolekit, object_path); + urf_session_checker_add_seat (consolekit, object_path); g_debug ("Monitor seat: %s", object_path); } /** - * urf_consolekit_seat_removed: + * urf_session_checker_seat_removed: **/ static void -urf_consolekit_seat_removed (UrfConsolekit *consolekit, +urf_session_checker_seat_removed (UrfSessionChecker *consolekit, const char *object_path) { UrfConsolekitPrivate *priv = consolekit->priv; UrfSeat *seat; - seat = urf_consolekit_find_seat (consolekit, object_path); + seat = urf_session_checker_find_seat (consolekit, object_path); if (seat == NULL) return; @@ -353,32 +353,32 @@ urf_consolekit_seat_removed (UrfConsolekit *consolekit, } /** - * urf_consolekit_proxy_signal_cb + * urf_session_checker_proxy_signal_cb **/ static void -urf_consolekit_proxy_signal_cb (GDBusProxy *proxy, +urf_session_checker_proxy_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { - UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); + UrfSessionChecker *consolekit = URF_SESSION_CHECKER (user_data); char *seat_path; if (g_strcmp0 (signal_name, "SeatAdded") == 0) { g_variant_get (parameters, "(o)", &seat_path); - urf_consolekit_seat_added (consolekit, seat_path); + urf_session_checker_seat_added (consolekit, seat_path); } else if (g_strcmp0 (signal_name, "SeatRemoved") == 0) { g_variant_get (parameters, "(o)", &seat_path); - urf_consolekit_seat_removed (consolekit, seat_path); + urf_session_checker_seat_removed (consolekit, seat_path); } } /** - * urf_consolekit_bus_owner_changed: + * urf_session_checker_bus_owner_changed: **/ static void -urf_consolekit_bus_owner_changed (UrfConsolekit *consolekit, +urf_session_checker_bus_owner_changed (UrfSessionChecker *consolekit, const char *old_owner, const char *new_owner) { @@ -395,31 +395,31 @@ urf_consolekit_bus_owner_changed (UrfConsolekit *consolekit, } /** - * urf_consolekit_bus_proxy_signal_cb + * urf_session_checker_bus_proxy_signal_cb **/ static void -urf_consolekit_bus_proxy_signal_cb (GDBusProxy *proxy, +urf_session_checker_bus_proxy_signal_cb (GDBusProxy *proxy, gchar *sender_name, gchar *signal_name, GVariant *parameters, gpointer user_data) { - UrfConsolekit *consolekit = URF_CONSOLEKIT (user_data); + UrfSessionChecker *consolekit = URF_SESSION_CHECKER (user_data); char *name; char *old_owner; char *new_owner; if (g_strcmp0 (signal_name, "NameOwnerChanged") == 0) { g_variant_get (parameters, "(sss)", &name, &old_owner, &new_owner); - urf_consolekit_bus_owner_changed (consolekit, old_owner, new_owner); + urf_session_checker_bus_owner_changed (consolekit, old_owner, new_owner); } } /** - * urf_consolekit_get_seats: + * urf_session_checker_get_seats: **/ static gboolean -urf_consolekit_get_seats (UrfConsolekit *consolekit) +urf_session_checker_get_seats (UrfSessionChecker *consolekit) { UrfConsolekitPrivate *priv = consolekit->priv; GError *error = NULL; @@ -444,7 +444,7 @@ urf_consolekit_get_seats (UrfConsolekit *consolekit) g_variant_get (retval, "(ao)", &iter); while (g_variant_iter_loop (iter, "o", &seat_name)) { - urf_consolekit_add_seat (consolekit, seat_name); + urf_session_checker_add_seat (consolekit, seat_name); g_debug ("Added seat: %s", seat_name); } g_variant_iter_free (iter); @@ -454,10 +454,10 @@ urf_consolekit_get_seats (UrfConsolekit *consolekit) } /** - * urf_consolekit_startup: + * urf_session_checker_startup: **/ gboolean -urf_consolekit_startup (UrfConsolekit *consolekit) +urf_session_checker_startup (UrfSessionChecker *consolekit) { UrfConsolekitPrivate *priv = consolekit->priv; GError *error; @@ -494,26 +494,26 @@ urf_consolekit_startup (UrfConsolekit *consolekit) } /* Get seats */ - ret = urf_consolekit_get_seats (consolekit); + ret = urf_session_checker_get_seats (consolekit); if (!ret) return FALSE; /* connect signals */ g_signal_connect (G_OBJECT (priv->proxy), "g-signal", - G_CALLBACK (urf_consolekit_proxy_signal_cb), consolekit); + G_CALLBACK (urf_session_checker_proxy_signal_cb), consolekit); g_signal_connect (G_CALLBACK (priv->bus_proxy), "g-signal", - G_CALLBACK (urf_consolekit_bus_proxy_signal_cb), consolekit); + G_CALLBACK (urf_session_checker_bus_proxy_signal_cb), consolekit); return TRUE; } /** - * urf_consolekit_dispose: + * urf_session_checker_dispose: **/ static void -urf_consolekit_dispose (GObject *object) +urf_session_checker_dispose (GObject *object) { - UrfConsolekit *consolekit = URF_CONSOLEKIT(object); + UrfSessionChecker *consolekit = URF_SESSION_CHECKER(object); if (consolekit->priv->proxy) { g_object_unref (consolekit->priv->proxy); @@ -524,16 +524,16 @@ urf_consolekit_dispose (GObject *object) consolekit->priv->bus_proxy = NULL; } - G_OBJECT_CLASS (urf_consolekit_parent_class)->dispose (object); + G_OBJECT_CLASS (urf_session_checker_parent_class)->dispose (object); } /** - * urf_consolekit_finalize: + * urf_session_checker_finalize: **/ static void -urf_consolekit_finalize (GObject *object) +urf_session_checker_finalize (GObject *object) { - UrfConsolekit *consolekit = URF_CONSOLEKIT (object); + UrfSessionChecker *consolekit = URF_SESSION_CHECKER (object); GList *item; if (consolekit->priv->seats) { @@ -549,30 +549,30 @@ urf_consolekit_finalize (GObject *object) consolekit->priv->inhibitors = NULL; } - G_OBJECT_CLASS (urf_consolekit_parent_class)->finalize (object); + G_OBJECT_CLASS (urf_session_checker_parent_class)->finalize (object); } /** - * urf_consolekit_class_init: + * urf_session_checker_class_init: **/ static void -urf_consolekit_class_init (UrfConsolekitClass *klass) +urf_session_checker_class_init (UrfSessionCheckerClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); - object_class->dispose = urf_consolekit_dispose; - object_class->finalize = urf_consolekit_finalize; + object_class->dispose = urf_session_checker_dispose; + object_class->finalize = urf_session_checker_finalize; g_type_class_add_private (klass, sizeof (UrfConsolekitPrivate)); } /** - * urf_consolekit_init: + * urf_session_checker_init: **/ static void -urf_consolekit_init (UrfConsolekit *consolekit) +urf_session_checker_init (UrfSessionChecker *consolekit) { - consolekit->priv = URF_CONSOLEKIT_GET_PRIVATE (consolekit); + consolekit->priv = URF_SESSION_CHECKER_GET_PRIVATE (consolekit); consolekit->priv->seats = NULL; consolekit->priv->inhibitors = NULL; consolekit->priv->inhibit = FALSE; @@ -581,12 +581,12 @@ urf_consolekit_init (UrfConsolekit *consolekit) } /** - * urf_consolekit_new: + * urf_session_checker_new: **/ -UrfConsolekit * -urf_consolekit_new (void) +UrfSessionChecker * +urf_session_checker_new (void) { - UrfConsolekit *consolekit; - consolekit = URF_CONSOLEKIT (g_object_new (URF_TYPE_CONSOLEKIT, NULL)); + UrfSessionChecker *consolekit; + consolekit = URF_SESSION_CHECKER (g_object_new (URF_TYPE_SESSION_CHECKER, NULL)); return consolekit; } diff --git a/src/urf-session-checker-consolekit.h b/src/urf-session-checker-consolekit.h index b9f1e02..6cafbd0 100644 --- a/src/urf-session-checker-consolekit.h +++ b/src/urf-session-checker-consolekit.h @@ -18,51 +18,51 @@ * */ -#ifndef __URF_CONSOLEKIT_H__ -#define __URF_CONSOLEKIT_H__ +#ifndef __URF_SESSION_CHECKER_CONSOLEKIT_H__ +#define __URF_SESSION_CHECKER_CONSOLEKIT_H__ #include <glib-object.h> -#include "urf-seat.h" +#include "urf-seat-consolekit.h" G_BEGIN_DECLS -#define URF_TYPE_CONSOLEKIT (urf_consolekit_get_type()) -#define URF_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ - URF_TYPE_CONSOLEKIT, UrfConsolekit)) -#define URF_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) -#define URF_IS_CONSOLEKIT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ - URF_TYPE_CONSOLEKIT)) -#define URF_IS_CONSOLEKIT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ - URF_TYPE_CONSOLEKIT)) -#define URF_GET_CONSOLEKIT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ - URF_TYPE_CONSOLEKIT, UrfConsolekitClass)) +#define URF_TYPE_SESSION_CHECKER (urf_session_checker_get_type()) +#define URF_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionChecker)) +#define URF_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) +#define URF_IS_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_IS_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_GET_SESSION_CHECKER_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) typedef struct UrfConsolekitPrivate UrfConsolekitPrivate; typedef struct { GObject parent; UrfConsolekitPrivate *priv; -} UrfConsolekit; +} UrfSessionChecker; typedef struct { GObjectClass parent_class; -} UrfConsolekitClass; +} UrfSessionCheckerClass; -GType urf_consolekit_get_type (void); +GType urf_session_checker_get_type (void); -UrfConsolekit *urf_consolekit_new (void); +UrfSessionChecker *urf_session_checker_new (void); -gboolean urf_consolekit_startup (UrfConsolekit *consolekit); +gboolean urf_session_checker_startup (UrfSessionChecker *consolekit); -gboolean urf_consolekit_is_inhibited (UrfConsolekit *consolekit); -guint urf_consolekit_inhibit (UrfConsolekit *consolekit, - const char *bus_name, - const char *reason); -void urf_consolekit_uninhibit (UrfConsolekit *consolekit, - const guint cookie); +gboolean urf_session_checker_is_inhibited (UrfSessionChecker *consolekit); +guint urf_session_checker_inhibit (UrfSessionChecker *consolekit, + const char *bus_name, + const char *reason); +void urf_session_checker_uninhibit (UrfSessionChecker *consolekit, + const guint cookie); G_END_DECLS -#endif /* __URF_CONSOLEKIT_H__ */ +#endif /* __URF_SESSION_CHECKER_CONSOLEKIT_H__ */ -- 1.8.4 From 3f1421b892fee6f40979e7e1ef88b8bd09711fc0 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 15:57:41 -0500 Subject: [PATCH 08/14] Fix include for UrfSeat --- src/urf-seat-consolekit.c | 2 +- src/urf-seat-consolekit.h | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/urf-seat-consolekit.c b/src/urf-seat-consolekit.c index 99fcb51..0ae4553 100644 --- a/src/urf-seat-consolekit.c +++ b/src/urf-seat-consolekit.c @@ -25,7 +25,7 @@ #include <glib.h> #include <gio/gio.h> -#include "urf-seat.h" +#include "urf-seat-consolekit.h" enum { SIGNAL_ACTIVE_CHANGED, diff --git a/src/urf-seat-consolekit.h b/src/urf-seat-consolekit.h index 195649d..e32dbcd 100644 --- a/src/urf-seat-consolekit.h +++ b/src/urf-seat-consolekit.h @@ -18,8 +18,8 @@ * */ -#ifndef __URF_SEAT_H__ -#define __URF_SEAT_H__ +#ifndef __URF_SEAT_CONSOLEKIT_H__ +#define __URF_SEAT_CONSOLEKIT_H__ #include <glib-object.h> @@ -63,4 +63,4 @@ const char *urf_seat_get_active (UrfSeat *seat); G_END_DECLS -#endif /* __URF_SEAT_H__ */ +#endif /* __URF_SEAT_CONSOLEKIT_H__ */ -- 1.8.4 From 0efe927659040acfa96d5526611bcaa0e4fe6d69 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 19:29:55 -0500 Subject: [PATCH 09/14] Simplistic port of UrfSessionChecker and UrfSeat to logind --- src/urf-seat-logind.c | 206 ++++++++++++++ src/urf-seat-logind.h | 66 +++++ src/urf-session-checker-logind.c | 595 +++++++++++++++++++++++++++++++++++++++ src/urf-session-checker-logind.h | 68 +++++ 4 files changed, 935 insertions(+) create mode 100644 src/urf-seat-logind.c create mode 100644 src/urf-seat-logind.h create mode 100644 src/urf-session-checker-logind.c create mode 100644 src/urf-session-checker-logind.h diff --git a/src/urf-seat-logind.c b/src/urf-seat-logind.c new file mode 100644 index 0000000..b4a950b --- /dev/null +++ b/src/urf-seat-logind.c @@ -0,0 +1,206 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <gio/gio.h> + +#include "urf-seat-logind.h" + +enum { + SIGNAL_ACTIVE_CHANGED, + SIGNAL_LAST +}; + +static guint signals[SIGNAL_LAST] = { 0 }; + + +struct UrfSeatPrivate { + GDBusConnection *connection; + GDBusProxy *proxy; + char *object_path; + char *active; +}; + +G_DEFINE_TYPE (UrfSeat, urf_seat, G_TYPE_OBJECT) + +#define URF_SEAT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_SEAT, UrfSeatPrivate)) + +/** + * urf_seat_get_object_path: + **/ +const char * +urf_seat_get_object_path (UrfSeat *seat) +{ + return seat->priv->object_path; +} + +/** + * urf_seat_get_active: + **/ +const char * +urf_seat_get_active (UrfSeat *seat) +{ + return seat->priv->active; +} + +/** + * urf_seat_proxy_signal_cb: + **/ +static void +urf_seat_proxy_property_changed_cb (GDBusProxy *proxy, + gchar *property, + GVariant *value) +{ + UrfSeat *seat = URF_SEAT (user_data); + char *session_name, *session_path; + + if (g_strcmp0 (property, "ActiveSession") == 0) { + g_variant_get (value, "(so)", &session_name, &session_path); + + g_free (seat->priv->active); + seat->priv->active = g_strdup (session_path); + + g_signal_emit (seat, signals[SIGNAL_ACTIVE_CHANGED], 0, session_path); + } +} + +/** + * urf_seat_object_path_sync: + **/ +gboolean +urf_seat_object_path_sync (UrfSeat *seat, + const char *object_path) +{ + UrfSeatPrivate *priv = seat->priv; + GVariant *retval; + char *session_name, *session_path; + GError *error; + + priv->object_path = g_strdup (object_path); + + error = NULL; + priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.login1", + priv->object_path, + "org.freedesktop.login1.Seat", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for logind seat: %s", error->message); + g_error_free (error); + return FALSE; + } + + retval = g_dbus_proxy_get_cached_property (priv->proxy, "ActiveSession"); + if (!retval) { + g_warning ("Failed to get Active Session"); + return FALSE; + } + + g_variant_get (retval, "(so)", &session_name, &session); + priv->active = g_strdup (session); + g_variant_unref (retval); + + /* connect signals */ + g_signal_connect (G_OBJECT (priv->proxy), "g-properties-changed", + G_CALLBACK (urf_seat_proxy_properties_changed), seat); + + return TRUE; +} + +/** + * urf_seat_dispose: + **/ +static void +urf_seat_dispose (GObject *object) +{ + UrfSeat *seat = URF_SEAT (object); + + if (seat->priv->proxy) { + g_object_unref (seat->priv->proxy); + seat->priv->proxy = NULL; + } + + G_OBJECT_CLASS (urf_seat_parent_class)->dispose (object); +} + +/** + * urf_seat_finalize: + **/ +static void +urf_seat_finalize (GObject *object) +{ + UrfSeat *seat = URF_SEAT (object); + + g_free (seat->priv->object_path); + g_free (seat->priv->active); + + G_OBJECT_CLASS (urf_seat_parent_class)->finalize (object); +} + +/** + * urf_seat_class_init: + **/ +static void +urf_seat_class_init (UrfSeatClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = urf_seat_dispose; + object_class->finalize = urf_seat_finalize; + + signals[SIGNAL_ACTIVE_CHANGED] = + g_signal_new ("active-changed", + G_TYPE_FROM_CLASS (object_class), G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (UrfSeatClass, active_changed), + NULL, NULL, g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, 1, G_TYPE_STRING); + + g_type_class_add_private (klass, sizeof (UrfSeatPrivate)); +} + +/** + * urf_seat_init: + **/ +static void +urf_seat_init (UrfSeat *seat) +{ + seat->priv = URF_SEAT_GET_PRIVATE (seat); + seat->priv->object_path = NULL; + seat->priv->active = NULL; +} + +/** + * urf_seat_new: + **/ +UrfSeat * +urf_seat_new (void) +{ + UrfSeat *seat; + seat = URF_SEAT (g_object_new (URF_TYPE_SEAT, NULL)); + return seat; +} diff --git a/src/urf-seat-logind.h b/src/urf-seat-logind.h new file mode 100644 index 0000000..17ba740 --- /dev/null +++ b/src/urf-seat-logind.h @@ -0,0 +1,66 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __URF_SEAT_LOGIND_H__ +#define __URF_SEAT_LOGIND_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define URF_TYPE_SEAT (urf_seat_get_type()) +#define URF_SEAT(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_SEAT, UrfSeat)) +#define URF_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_SEAT, UrfSeatClass)) +#define URF_IS_SEAT(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_SEAT)) +#define URF_IS_SEAT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_SEAT)) +#define URF_GET_SEAT_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_SEAT, UrfSeatClass)) + +typedef struct UrfSeatPrivate UrfSeatPrivate; + +typedef struct { + GObject parent; + UrfSeatPrivate *priv; +} UrfSeat; + +typedef struct { + GObjectClass parent_class; + void (*active_changed) (UrfSeat *seat, + const char *session_id); + void (*session_removed) (UrfSeat *seat, + const char *session_id); +} UrfSeatClass; + +GType urf_seat_get_type (void); + +UrfSeat *urf_seat_new (void); +gboolean urf_seat_object_path_sync (UrfSeat *seat, + const char *object_path); + +const char *urf_seat_get_object_path (UrfSeat *seat); +const char *urf_seat_get_active (UrfSeat *seat); + +G_END_DECLS + +#endif /* __URF_SEAT_LOGIND_H__ */ diff --git a/src/urf-session-checker-logind.c b/src/urf-session-checker-logind.c new file mode 100644 index 0000000..0b849d6 --- /dev/null +++ b/src/urf-session-checker-logind.c @@ -0,0 +1,595 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <string.h> +#include <gio/gio.h> + +#include "urf-session-checker-logind.h" + +typedef struct { + guint cookie; + char *session_id; + char *bus_name; + char *reason; +} UrfInhibitor; + +struct UrfLogindPrivate { + GDBusProxy *proxy; + GDBusProxy *bus_proxy; + GList *seats; + GList *inhibitors; + gboolean inhibit; +}; + +G_DEFINE_TYPE (UrfSessionChecker, urf_session_checker, G_TYPE_OBJECT) + +#define URF_SESSION_CHECKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_SESSION_CHECKER, UrfLogindPrivate)) + +/** + * urf_session_checker_is_inhibited: + **/ +gboolean +urf_session_checker_is_inhibited (UrfSessionChecker *logind) +{ + return logind->priv->inhibit; +} + +/** + * urf_session_checker_find_seat: + **/ +static UrfSeat * +urf_session_checker_find_seat (UrfSessionChecker *logind, + const char *object_path) +{ + UrfLogindPrivate *priv = logind->priv; + UrfSeat *seat; + GList *item; + + for (item = priv->seats; item; item = item->next) { + seat = URF_SEAT (item->data); + if (g_strcmp0 (urf_seat_get_object_path (seat), object_path) == 0) + return seat; + } + + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_sid (UrfSessionChecker *logind, + const char *session_id) +{ + UrfLogindPrivate *priv = logind->priv; + UrfInhibitor *inhibitor; + GList *item; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (g_strcmp0 (inhibitor->session_id, session_id) == 0) + return inhibitor; + } + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_bus_name (UrfSessionChecker *logind, + const char *bus_name) +{ + UrfLogindPrivate *priv = logind->priv; + UrfInhibitor *inhibitor; + GList *item; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (g_strcmp0 (inhibitor->bus_name, bus_name) == 0) + return inhibitor; + } + return NULL; +} + +static UrfInhibitor * +find_inhibitor_by_cookie (UrfSessionChecker *logind, + const guint cookie) +{ + UrfLogindPrivate *priv = logind->priv; + UrfInhibitor *inhibitor; + GList *item; + + if (cookie == 0) + return NULL; + + for (item = priv->inhibitors; item; item = item->next) { + inhibitor = (UrfInhibitor *)item->data; + if (inhibitor->cookie == cookie) + return inhibitor; + } + return NULL; +} + +static gboolean +is_inhibited (UrfSessionChecker *logind) +{ + UrfLogindPrivate *priv = logind->priv; + UrfSeat *seat; + const char *active_id; + GList *item; + + for (item = priv->seats; item; item = item->next) { + seat = URF_SEAT (item->data); + active_id = urf_seat_get_active (seat); + if (find_inhibitor_by_sid (logind, active_id)) + return TRUE; + } + + return FALSE; +} + +static void +free_inhibitor (UrfInhibitor *inhibitor) +{ + g_free (inhibitor->session_id); + g_free (inhibitor->bus_name); + g_free (inhibitor->reason); + g_free (inhibitor); +} + +/** + * urf_session_checker_seat_active_changed: + **/ +static void +urf_session_checker_seat_active_changed (UrfSeat *seat, + const char *session_id, + UrfSessionChecker *logind) +{ + logind->priv->inhibit = is_inhibited (logind); + g_debug ("Active Session changed: %s", session_id); +} + +static char * +get_session_id (UrfSessionChecker *logind, + const char *bus_name) +{ + UrfLogindPrivate *priv = logind->priv; + pid_t calling_pid; + char *session_id = NULL; + GVariant *retval; + GError *error; + + error = NULL; + retval = g_dbus_proxy_call_sync (priv->bus_proxy, "GetConnectionUnixProcessID", + g_variant_new ("(s)", bus_name), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning("GetConnectionUnixProcessID() failed: %s", error->message); + g_error_free (error); + goto out; + } + g_variant_get (retval, "(u)", &calling_pid); + g_variant_unref (retval); + + error = NULL; + retval = g_dbus_proxy_call_sync (priv->proxy, "GetSessionByPID", + g_variant_new ("(u)", (guint)calling_pid), + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning ("Couldn't send GetSessionByPID: %s", error->message); + g_error_free (error); + session_id = NULL; + goto out; + } + + g_variant_get (retval, "(s)", &session_id); + session_id = g_strdup (session_id); + g_variant_unref (retval); +out: + return session_id; +} + +static guint +generate_unique_cookie (UrfSessionChecker *logind) +{ + UrfInhibitor *inhibitor; + guint cookie; + + do { + cookie = g_random_int_range (1, G_MAXINT); + inhibitor = find_inhibitor_by_cookie (logind, cookie); + } while (inhibitor != NULL); + + return cookie; +} + +/** + * urf_session_checker_inhibit: + **/ +guint +urf_session_checker_inhibit (UrfSessionChecker *logind, + const char *bus_name, + const char *reason) +{ + UrfLogindPrivate *priv = logind->priv; + UrfInhibitor *inhibitor; + + g_return_val_if_fail (priv->proxy != NULL, 0); + + inhibitor = find_inhibitor_by_bus_name (logind, bus_name); + if (inhibitor) + return inhibitor->cookie; + + inhibitor = g_new0 (UrfInhibitor, 1); + inhibitor->session_id = get_session_id (logind, bus_name); + if (inhibitor->session_id == NULL) { + g_free (inhibitor); + return 0; + } + + inhibitor->reason = g_strdup (reason); + inhibitor->bus_name = g_strdup (bus_name); + inhibitor->cookie = generate_unique_cookie (logind); + + priv->inhibitors = g_list_prepend (priv->inhibitors, inhibitor); + + logind->priv->inhibit = is_inhibited (logind); + g_debug ("Inhibit: %s for %s", bus_name, reason); + + return inhibitor->cookie; +} + +static void +remove_inhibitor (UrfSessionChecker *logind, + UrfInhibitor *inhibitor) +{ + UrfLogindPrivate *priv = logind->priv; + + g_return_if_fail (priv->proxy != NULL); + + priv->inhibitors = g_list_remove (priv->inhibitors, inhibitor); + logind->priv->inhibit = is_inhibited (logind); + g_debug ("Remove inhibitor: %s", inhibitor->bus_name); + free_inhibitor (inhibitor); +} + +/** + * urf_session_checker_uninhibit: + **/ +void +urf_session_checker_uninhibit (UrfSessionChecker *logind, + const guint cookie) +{ + UrfInhibitor *inhibitor; + + inhibitor = find_inhibitor_by_cookie (logind, cookie); + if (inhibitor == NULL) { + g_debug ("Cookie outdated"); + return; + } + remove_inhibitor (logind, inhibitor); +} + +/** + * urf_session_checker_add_seat: + **/ +static void +urf_session_checker_add_seat (UrfSessionChecker *logind, + const char *object_path) +{ + UrfLogindPrivate *priv = logind->priv; + UrfSeat *seat = urf_seat_new (); + gboolean ret; + + ret = urf_seat_object_path_sync (seat, object_path); + + if (!ret) { + g_warning ("Failed to sync %s", object_path); + return; + } + + priv->seats = g_list_prepend (priv->seats, seat); + + /* connect signal */ + g_signal_connect (seat, "active-changed", + G_CALLBACK (urf_session_checker_seat_active_changed), + logind); +} + +/** + * urf_session_checker_seat_added: + **/ +static void +urf_session_checker_seat_added (UrfSessionChecker *logind, + const char *object_path) +{ + if (urf_session_checker_find_seat (logind, object_path) != NULL) { + g_debug ("Already added seat: %s", object_path); + return; + } + + urf_session_checker_add_seat (logind, object_path); + g_debug ("Monitor seat: %s", object_path); +} + +/** + * urf_session_checker_seat_removed: + **/ +static void +urf_session_checker_seat_removed (UrfSessionChecker *logind, + const char *object_path) +{ + UrfLogindPrivate *priv = logind->priv; + UrfSeat *seat; + + seat = urf_session_checker_find_seat (logind, object_path); + if (seat == NULL) + return; + + priv->seats = g_list_remove (priv->seats, seat); + + g_object_unref (seat); + g_debug ("Removed seat: %s", object_path); +} + +/** + * urf_session_checker_proxy_signal_cb + **/ +static void +urf_session_checker_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + UrfSessionChecker *logind = URF_SESSION_CHECKER (user_data); + const char *seat_string; + char *seat_path; + + if (g_strcmp0 (signal_name, "SeatNew") == 0) { + g_variant_get (parameters, "(so)", &seat_name, &seat_path); + g_debug ("got: %s", seat_name); + urf_session_checker_seat_added (logind, seat_path); + } else if (g_strcmp0 (signal_name, "SeatRemoved") == 0) { + g_variant_get (parameters, "(so)", &seat_name, &seat_path); + g_debug ("got: %s", seat_name); + urf_session_checker_seat_removed (logind, seat_path); + } +} + +/** + * urf_session_checker_bus_owner_changed: + **/ +static void +urf_session_checker_bus_owner_changed (UrfSessionChecker *logind, + const char *old_owner, + const char *new_owner) +{ + UrfInhibitor *inhibitor; + + if (strlen (new_owner) == 0 && + strlen (old_owner) > 0) { + /* A process disconnected from the bus */ + inhibitor = find_inhibitor_by_bus_name (logind, old_owner); + if (inhibitor == NULL) + return; + remove_inhibitor (logind, inhibitor); + } +} + +/** + * urf_session_checker_bus_proxy_signal_cb + **/ +static void +urf_session_checker_bus_proxy_signal_cb (GDBusProxy *proxy, + gchar *sender_name, + gchar *signal_name, + GVariant *parameters, + gpointer user_data) +{ + UrfSessionChecker *logind = URF_SESSION_CHECKER (user_data); + char *name; + char *old_owner; + char *new_owner; + + if (g_strcmp0 (signal_name, "NameOwnerChanged") == 0) { + g_variant_get (parameters, "(sss)", &name, &old_owner, &new_owner); + urf_session_checker_bus_owner_changed (logind, old_owner, new_owner); + } +} + +/** + * urf_session_checker_get_seats: + **/ +static gboolean +urf_session_checker_get_seats (UrfSessionChecker *logind) +{ + UrfLogindPrivate *priv = logind->priv; + GError *error = NULL; + const char *seat_name, *seat_path; + GVariant *retval; + GVariantIter *iter; + + retval = g_dbus_proxy_call_sync (priv->proxy, "ListSeats", + NULL, + G_DBUS_CALL_FLAGS_NONE, + -1, NULL, &error); + if (error) { + g_warning ("ListSeats Failed: %s", error->message); + g_error_free (error); + return FALSE; + } + + if (retval == NULL) { + g_debug ("No Seat exists"); + return FALSE; + } + + g_variant_get (retval, "(a(so))", &iter); + while (g_variant_iter_loop (iter, "so", &seat_name, &seat_path)) { + urf_session_checker_add_seat (logind, seat_path); + g_debug ("Added seat: %s", seat_name); + } + g_variant_iter_free (iter); + g_variant_unref (retval); + + return TRUE; +} + +/** + * urf_session_checker_startup: + **/ +gboolean +urf_session_checker_startup (UrfSessionChecker *logind) +{ + UrfLogindPrivate *priv = logind->priv; + GError *error; + gboolean ret; + + error = NULL; + priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.login1", + "/org/freedesktop/login1/Manager", + "org.freedesktop.login1.Manager", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for logind: %s", error->message); + g_error_free (error); + return FALSE; + } + + error = NULL; + priv->bus_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_NONE, + NULL, + "org.freedesktop.DBus", + "/org/freedesktop/DBus", + "org.freedesktop.DBus", + NULL, + &error); + if (error) { + g_error ("failed to setup proxy for logind: %s", error->message); + g_error_free (error); + return FALSE; + } + + /* Get seats */ + ret = urf_session_checker_get_seats (logind); + if (!ret) + return FALSE; + + /* connect signals */ + g_signal_connect (G_OBJECT (priv->proxy), "g-signal", + G_CALLBACK (urf_session_checker_proxy_signal_cb), logind); + g_signal_connect (G_CALLBACK (priv->bus_proxy), "g-signal", + G_CALLBACK (urf_session_checker_bus_proxy_signal_cb), logind); + + return TRUE; +} + +/** + * urf_session_checker_dispose: + **/ +static void +urf_session_checker_dispose (GObject *object) +{ + UrfSessionChecker *logind = URF_SESSION_CHECKER(object); + + if (logind->priv->proxy) { + g_object_unref (logind->priv->proxy); + logind->priv->proxy = NULL; + } + if (logind->priv->bus_proxy) { + g_object_unref (logind->priv->bus_proxy); + logind->priv->bus_proxy = NULL; + } + + G_OBJECT_CLASS (urf_session_checker_parent_class)->dispose (object); +} + +/** + * urf_session_checker_finalize: + **/ +static void +urf_session_checker_finalize (GObject *object) +{ + UrfSessionChecker *logind = URF_SESSION_CHECKER (object); + GList *item; + + if (logind->priv->seats) { + for (item = logind->priv->seats; item; item = item->next) + g_object_unref (item->data); + g_list_free (logind->priv->seats); + logind->priv->seats = NULL; + } + if (logind->priv->inhibitors) { + for (item = logind->priv->inhibitors; item; item = item->next) + free_inhibitor (item->data); + g_list_free (logind->priv->inhibitors); + logind->priv->inhibitors = NULL; + } + + G_OBJECT_CLASS (urf_session_checker_parent_class)->finalize (object); +} + +/** + * urf_session_checker_class_init: + **/ +static void +urf_session_checker_class_init (UrfSessionCheckerClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + + object_class->dispose = urf_session_checker_dispose; + object_class->finalize = urf_session_checker_finalize; + + g_type_class_add_private (klass, sizeof (UrfLogindPrivate)); +} + +/** + * urf_session_checker_init: + **/ +static void +urf_session_checker_init (UrfSessionChecker *logind) +{ + logind->priv = URF_SESSION_CHECKER_GET_PRIVATE (logind); + logind->priv->seats = NULL; + logind->priv->inhibitors = NULL; + logind->priv->inhibit = FALSE; + logind->priv->proxy = NULL; + logind->priv->bus_proxy = NULL; +} + +/** + * urf_session_checker_new: + **/ +UrfSessionChecker * +urf_session_checker_new (void) +{ + UrfSessionChecker *logind; + logind = URF_SESSION_CHECKER (g_object_new (URF_TYPE_SESSION_CHECKER, NULL)); + return logind; +} diff --git a/src/urf-session-checker-logind.h b/src/urf-session-checker-logind.h new file mode 100644 index 0000000..bbb6d9d --- /dev/null +++ b/src/urf-session-checker-logind.h @@ -0,0 +1,68 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __URF_SESSION_CHECKER_LOGIND_H__ +#define __URF_SESSION_CHECKER_LOGIND_H__ + +#include <glib-object.h> + +#include "urf-seat-logind.h" + +G_BEGIN_DECLS + +#define URF_TYPE_SESSION_CHECKER (urf_session_checker_get_type()) +#define URF_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionChecker)) +#define URF_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) +#define URF_IS_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_IS_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_GET_SESSION_CHECKER_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) + +typedef struct UrfLogindPrivate UrfLogindPrivate; + +typedef struct { + GObject parent; + UrfLogindPrivate *priv; +} UrfSessionChecker; + +typedef struct { + GObjectClass parent_class; +} UrfSessionCheckerClass; + +GType urf_session_checker_get_type (void); + +UrfSessionChecker *urf_session_checker_new (void); + +gboolean urf_session_checker_startup (UrfSessionChecker *logind); + +gboolean urf_session_checker_is_inhibited (UrfSessionChecker *logind); +guint urf_session_checker_inhibit (UrfSessionChecker *logind, + const char *bus_name, + const char *reason); +void urf_session_checker_uninhibit (UrfSessionChecker *logind, + const guint cookie); + +G_END_DECLS + +#endif /* __URF_SESSION_CHECKER_LOGIND_H__ */ -- 1.8.4 From 09d00265b685c887e73d5a7c02c4e2bba2a6eced Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 22:03:06 -0500 Subject: [PATCH 10/14] Add stubs for no session checking (breaks inhibit). --- src/urf-session-checker-none.c | 107 +++++++++++++++++++++++++++++++++++++++++ src/urf-session-checker-none.h | 63 ++++++++++++++++++++++++ 2 files changed, 170 insertions(+) create mode 100644 src/urf-session-checker-none.c create mode 100644 src/urf-session-checker-none.h diff --git a/src/urf-session-checker-none.c b/src/urf-session-checker-none.c new file mode 100644 index 0000000..cd5e7f1 --- /dev/null +++ b/src/urf-session-checker-none.c @@ -0,0 +1,107 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include <glib.h> +#include <string.h> +#include <gio/gio.h> + +#include "urf-session-checker-none.h" + +typedef struct { + guint cookie; + char *session_id; + char *bus_name; + char *reason; +} UrfInhibitor; + +struct UrfLogindPrivate { + GDBusProxy *proxy; + GDBusProxy *bus_proxy; + GList *seats; + GList *inhibitors; + gboolean inhibit; +}; + +G_DEFINE_TYPE (UrfSessionChecker, urf_session_checker, G_TYPE_OBJECT) + +#define URF_SESSION_CHECKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), \ + URF_TYPE_SESSION_CHECKER, UrfLogindPrivate)) + +/** + * urf_session_checker_is_inhibited: + **/ +gboolean +urf_session_checker_is_inhibited (UrfSessionChecker *logind) +{ + return FALSE; +} + +/** + * urf_session_checker_inhibit: + **/ +guint +urf_session_checker_inhibit (UrfSessionChecker *logind, + const char *bus_name, + const char *reason) +{ + return 0; +} + +/** + * urf_session_checker_uninhibit: + **/ +void +urf_session_checker_uninhibit (UrfSessionChecker *logind, + const guint cookie) +{ +} + +/** + * urf_session_checker_add_seat: + **/ +static void +urf_session_checker_add_seat (UrfSessionChecker *logind, + const char *object_path) +{ +} + +/** + * urf_session_checker_startup: + **/ +gboolean +urf_session_checker_startup (UrfSessionChecker *logind) +{ + return TRUE; +} + +/** + * urf_session_checker_new: + **/ +UrfSessionChecker * +urf_session_checker_new (void) +{ + UrfSessionChecker *logind; + logind = URF_SESSION_CHECKER (g_object_new (URF_TYPE_SESSION_CHECKER, NULL)); + return logind; +} diff --git a/src/urf-session-checker-none.h b/src/urf-session-checker-none.h new file mode 100644 index 0000000..a549e12 --- /dev/null +++ b/src/urf-session-checker-none.h @@ -0,0 +1,63 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- + * + * Copyright (C) 2013 Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> + * + * 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 St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#ifndef __URF_SESSION_CHECKER_NONE_H__ +#define __URF_SESSION_CHECKER_NONE_H__ + +#include <glib-object.h> + +G_BEGIN_DECLS + +#define URF_TYPE_SESSION_CHECKER (urf_session_checker_get_type()) +#define URF_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionChecker)) +#define URF_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) +#define URF_IS_SESSION_CHECKER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_IS_SESSION_CHECKER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), \ + URF_TYPE_SESSION_CHECKER)) +#define URF_GET_SESSION_CHECKER_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), \ + URF_TYPE_SESSION_CHECKER, UrfSessionCheckerClass)) + +typedef struct { + GObject parent; +} UrfSessionChecker; + +typedef struct { + GObjectClass parent_class; +} UrfSessionCheckerClass; + +GType urf_session_checker_get_type (void); + +UrfSessionChecker *urf_session_checker_new (void); + +gboolean urf_session_checker_startup (UrfSessionChecker *logind); + +gboolean urf_session_checker_is_inhibited (UrfSessionChecker *logind); +guint urf_session_checker_inhibit (UrfSessionChecker *logind, + const char *bus_name, + const char *reason); +void urf_session_checker_uninhibit (UrfSessionChecker *logind, + const guint cookie); + +G_END_DECLS + +#endif /* __URF_SESSION_CHECKER_NONE_H__ */ -- 1.8.4 From bc651f8ceeab918b161c43584b31144d97627471 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 22:27:49 -0500 Subject: [PATCH 11/14] Allow selecting the session tracking method at build time --- configure.ac | 22 ++++++++++++++++++++++ src/Makefile.am | 26 ++++++++++++++++++++++---- src/urf-daemon.c | 7 +++++++ 3 files changed, 51 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 179b086..9f862f9 100644 --- a/configure.ac +++ b/configure.ac @@ -174,6 +174,27 @@ else AC_DEFINE(USE_SECURITY_POLKIT_NEW, 1, [if we should use PolicyKit new API]) fi +# session tracking support +AC_MSG_CHECKING([Session tracking support]) +AC_ARG_WITH(session-tracking, AS_HELP_STRING([--with-session-tracking=systemd|consolekit|no], + [Select session tracking support (default: consolekit)])) +# default to consolekit +AS_IF([test -z "$with_session_tracking"], with_session_tracking=consolekit) +AS_IF([test "$with_session_tracking" = "ck"], with_session_tracking=consolekit) +AS_IF([test "$with_session_tracking" = "none"], with_session_tracking=no) +# check value +AS_IF([! (echo "$with_session_tracking" | grep -q -E "^(systemd|consolekit|no)$")], + AC_MSG_ERROR([--with-session-tracking must be systemd/consolekit/no, not $with_session_tracking])) +# add conditionals and subtitution +AM_CONDITIONAL(SESSION_TRACKING_CK, test "$with_session_tracking" = "consolekit") +AM_CONDITIONAL(SESSION_TRACKING_SYSTEMD, test "$with_session_tracking" = "systemd") +AC_DEFINE(SESSION_TRACKING_CK, + test "$with_session_tracking" = "consolekit", + [Define if you want to use consolekit for session tracking]) +AC_DEFINE(SESSION_TRACKING_SYSTEMD, + test "$with_session_tracking" = "systemd", + [Define if you want to use systemd/logind for session tracking]) + GOBJECT_INTROSPECTION_CHECK([0.6.7]) dnl --------------------------------------------------------------------------- @@ -236,6 +257,7 @@ echo " cppflags: ${CPPFLAGS}" echo " xsltproc: ${XSLTPROC}" echo "" echo " Maintainer mode: ${USE_MAINTAINER_MODE}" +echo " Session tracking using: ${with_session_tracking}" echo " Building api docs: ${enable_gtk_doc}" echo " Building man pages: ${enable_man_pages}" echo " Building unit tests: ${enable_tests}" diff --git a/src/Makefile.am b/src/Makefile.am index 6c141fd..c371902 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,15 +36,33 @@ urfkilld_SOURCES = \ urf-polkit.c \ urf-utils.h \ urf-utils.c \ - urf-session-checker-consolekit.h \ - urf-session-checker-consolekit.c \ - urf-seat-consolekit.h \ - urf-seat-consolekit.c \ urf-daemon.h \ urf-daemon.c \ urf-main.c \ $(NULL) +if SESSION_TRACKING_SYSTEMD +urfkilld_SOURCES += \ + urf-session-checker-logind.h \ + urf-session-checker-logind.c \ + urf-seat-logind.h \ + urf-seat-logind.c \ + $(NULL) +else +if SESSION_TRACKING_CK +urfkilld_SOURCES += \ + urf-session-checker-consolekit.h \ + urf-session-checker-consolekit.c \ + urf-seat-consolekit.h \ + urf-seat-consolekit.c \ + $(NULL) +else +urfkilld_SOURCES += \ + urf-session-checker-none.h \ + urf-session-checker-none.c \ + $(NULL) +endif +endif urfkilld_CPPFLAGS = \ -I$(top_srcdir)/src \ -DG_LOG_DOMAIN=\"URfkill\" \ diff --git a/src/urf-daemon.c b/src/urf-daemon.c index d510f8a..1808f28 100644 --- a/src/urf-daemon.c +++ b/src/urf-daemon.c @@ -36,7 +36,14 @@ #include "urf-input.h" #include "urf-utils.h" #include "urf-config.h" + +#if defined SESSION_TRACKING_CK #include "urf-session-checker-consolekit.h" +#elif defined SESSION_TRACKING_SYSTEMD +#include "urf-session-checker-logind.h" +#else +#include "urf-session-checker-none.h" +#endif #define URFKILL_DBUS_INTERFACE "org.freedesktop.URfkill" #define URFKILL_OBJECT_PATH "/org/freedesktop/URfkill" -- 1.8.4 From 310ebd43b398a4f9a47c6a1744ae72b6da470efc Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 22:28:48 -0500 Subject: [PATCH 12/14] Fix errors/typos in LoginD port. --- src/urf-seat-logind.c | 11 ++++++----- src/urf-session-checker-logind.c | 8 ++++---- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/urf-seat-logind.c b/src/urf-seat-logind.c index b4a950b..75a48d5 100644 --- a/src/urf-seat-logind.c +++ b/src/urf-seat-logind.c @@ -69,9 +69,10 @@ urf_seat_get_active (UrfSeat *seat) * urf_seat_proxy_signal_cb: **/ static void -urf_seat_proxy_property_changed_cb (GDBusProxy *proxy, - gchar *property, - GVariant *value) +urf_seat_proxy_properties_changed (GDBusProxy *proxy, + gchar *property, + GVariant *value, + gpointer user_data) { UrfSeat *seat = URF_SEAT (user_data); char *session_name, *session_path; @@ -121,8 +122,8 @@ urf_seat_object_path_sync (UrfSeat *seat, return FALSE; } - g_variant_get (retval, "(so)", &session_name, &session); - priv->active = g_strdup (session); + g_variant_get (retval, "(so)", &session_name, &session_path); + priv->active = g_strdup (session_path); g_variant_unref (retval); /* connect signals */ diff --git a/src/urf-session-checker-logind.c b/src/urf-session-checker-logind.c index 0b849d6..3243357 100644 --- a/src/urf-session-checker-logind.c +++ b/src/urf-session-checker-logind.c @@ -202,7 +202,7 @@ get_session_id (UrfSessionChecker *logind, goto out; } - g_variant_get (retval, "(s)", &session_id); + g_variant_get (retval, "(o)", &session_id); session_id = g_strdup (session_id); g_variant_unref (retval); out: @@ -363,7 +363,7 @@ urf_session_checker_proxy_signal_cb (GDBusProxy *proxy, gpointer user_data) { UrfSessionChecker *logind = URF_SESSION_CHECKER (user_data); - const char *seat_string; + const char *seat_name; char *seat_path; if (g_strcmp0 (signal_name, "SeatNew") == 0) { @@ -446,7 +446,7 @@ urf_session_checker_get_seats (UrfSessionChecker *logind) } g_variant_get (retval, "(a(so))", &iter); - while (g_variant_iter_loop (iter, "so", &seat_name, &seat_path)) { + while (g_variant_iter_loop (iter, "(so)", &seat_name, &seat_path)) { urf_session_checker_add_seat (logind, seat_path); g_debug ("Added seat: %s", seat_name); } @@ -471,7 +471,7 @@ urf_session_checker_startup (UrfSessionChecker *logind) G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.login1", - "/org/freedesktop/login1/Manager", + "/org/freedesktop/login1", "org.freedesktop.login1.Manager", NULL, &error); -- 1.8.4 From 8754138701d735765c48969d4ae8ed40fb979115 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Thu, 12 Dec 2013 23:14:37 -0500 Subject: [PATCH 13/14] Propagate/notify device state changes to UrfKillswitch objects --- src/urf-device.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/urf-device.c b/src/urf-device.c index 02f0afa..cafc422 100644 --- a/src/urf-device.c +++ b/src/urf-device.c @@ -138,6 +138,8 @@ urf_device_update_states (UrfDevice *device, priv->soft = soft; priv->hard = hard; priv->state = event_to_state (priv->soft, priv->hard); + + g_signal_emit (G_OBJECT (device), signals[SIGNAL_CHANGED], 0); emit_properites_changed (device); g_dbus_connection_emit_signal (priv->connection, NULL, -- 1.8.4 From 57c15bf4ecf55d1f1c6b249bebda64f7a23b3fc2 Mon Sep 17 00:00:00 2001 From: Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com> Date: Wed, 18 Dec 2013 14:37:21 -0500 Subject: [PATCH 14/14] Fix build for no session tracking. --- src/urf-session-checker-none.c | 35 +++++++++++++++++++++-------------- src/urf-session-checker-none.h | 8 ++++---- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/urf-session-checker-none.c b/src/urf-session-checker-none.c index cd5e7f1..922a154 100644 --- a/src/urf-session-checker-none.c +++ b/src/urf-session-checker-none.c @@ -52,7 +52,7 @@ G_DEFINE_TYPE (UrfSessionChecker, urf_session_checker, G_TYPE_OBJECT) * urf_session_checker_is_inhibited: **/ gboolean -urf_session_checker_is_inhibited (UrfSessionChecker *logind) +urf_session_checker_is_inhibited (UrfSessionChecker *session_checker) { return FALSE; } @@ -61,7 +61,7 @@ urf_session_checker_is_inhibited (UrfSessionChecker *logind) * urf_session_checker_inhibit: **/ guint -urf_session_checker_inhibit (UrfSessionChecker *logind, +urf_session_checker_inhibit (UrfSessionChecker *session_checker, const char *bus_name, const char *reason) { @@ -72,27 +72,34 @@ urf_session_checker_inhibit (UrfSessionChecker *logind, * urf_session_checker_uninhibit: **/ void -urf_session_checker_uninhibit (UrfSessionChecker *logind, +urf_session_checker_uninhibit (UrfSessionChecker *session_checker, const guint cookie) { } /** - * urf_session_checker_add_seat: + * urf_session_checker_startup: **/ +gboolean +urf_session_checker_startup (UrfSessionChecker *session_checker) +{ + return TRUE; +} + +/** + * urf_session_checker_init: + */ static void -urf_session_checker_add_seat (UrfSessionChecker *logind, - const char *object_path) +urf_session_checker_init (UrfSessionChecker *session_checker) { } /** - * urf_session_checker_startup: - **/ -gboolean -urf_session_checker_startup (UrfSessionChecker *logind) + * urf_session_checker_class_init + */ +static void +urf_session_checker_class_init (UrfSessionCheckerClass *klass) { - return TRUE; } /** @@ -101,7 +108,7 @@ urf_session_checker_startup (UrfSessionChecker *logind) UrfSessionChecker * urf_session_checker_new (void) { - UrfSessionChecker *logind; - logind = URF_SESSION_CHECKER (g_object_new (URF_TYPE_SESSION_CHECKER, NULL)); - return logind; + UrfSessionChecker *session_checker; + session_checker = URF_SESSION_CHECKER (g_object_new (URF_TYPE_SESSION_CHECKER, NULL)); + return session_checker; } diff --git a/src/urf-session-checker-none.h b/src/urf-session-checker-none.h index a549e12..4cf2482 100644 --- a/src/urf-session-checker-none.h +++ b/src/urf-session-checker-none.h @@ -49,13 +49,13 @@ GType urf_session_checker_get_type (void); UrfSessionChecker *urf_session_checker_new (void); -gboolean urf_session_checker_startup (UrfSessionChecker *logind); +gboolean urf_session_checker_startup (UrfSessionChecker *session_checker); -gboolean urf_session_checker_is_inhibited (UrfSessionChecker *logind); -guint urf_session_checker_inhibit (UrfSessionChecker *logind, +gboolean urf_session_checker_is_inhibited (UrfSessionChecker *session_checker); +guint urf_session_checker_inhibit (UrfSessionChecker *session_checker, const char *bus_name, const char *reason); -void urf_session_checker_uninhibit (UrfSessionChecker *logind, +void urf_session_checker_uninhibit (UrfSessionChecker *session_checker, const guint cookie); G_END_DECLS -- 1.8.4
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor