[gnome-power-manager] Migrate from dbus-glib to GDBus, based on a patch from Giovanni Campagna, many thanks
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-power-manager] Migrate from dbus-glib to GDBus, based on a patch from Giovanni Campagna, many thanks
- Date: Tue, 26 Oct 2010 09:13:08 +0000 (UTC)
commit 7568769fb1e46de1b8ed8601fe106df9b367bb45
Author: Richard Hughes <richard hughsie com>
Date: Tue Oct 26 11:13:04 2010 +0100
Migrate from dbus-glib to GDBus, based on a patch from Giovanni Campagna, many thanks
configure.ac | 5 -
src/Makefile.am | 80 +----
src/cc-power-panel.c | 8 +-
src/gpm-backlight.c | 156 ++++++++-
src/gpm-backlight.h | 4 +-
src/gpm-control.c | 2 -
src/gpm-control.h | 1 -
src/gpm-disks.c | 73 +++--
src/gpm-dpms.c | 2 -
src/gpm-engine.c | 2 -
src/gpm-idle.c | 201 ++++++++---
src/gpm-main.c | 259 ++++++++------
src/gpm-manager.c | 219 ++++++++++---
src/gpm-manager.h | 2 -
src/gpm-phone.c | 98 ++++---
src/gpm-screensaver.c | 149 +++++----
src/gpm-session.c | 551 ------------------------------
src/gpm-session.h | 79 -----
src/gpm-statistics.c | 4 -
src/org.gnome.PowerManager.Backlight.xml | 15 -
src/org.gnome.PowerManager.xml | 6 -
21 files changed, 834 insertions(+), 1082 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index d6a091c..6dca0de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -102,11 +102,6 @@ PKG_CHECK_MODULES(GLIB, glib-2.0 >= 2.13.0 gobject-2.0 gio-2.0 >= 2.25.9)
PKG_CHECK_MODULES(CANBERRA, libcanberra-gtk3 >= 0.10)
-PKG_CHECK_MODULES(DBUS,[
- dbus-glib-1 >= 0.70
- dbus-1 >= 1.0
- gthread-2.0])
-
PKG_CHECK_MODULES(GNOME, [
gtk+-3.0 >= 2.91.0
gconf-2.0 >= 2.31.1
diff --git a/src/Makefile.am b/src/Makefile.am
index 2380380..04e2cec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,24 +1,17 @@
## We require new-style dependency handling.
AUTOMAKE_OPTIONS = 1.7
-NULL =
-
EXTRA_DIST = \
- org.gnome.PowerManager.xml \
- org.gnome.PowerManager.Backlight.xml \
- gpm-marshal.list \
- $(NULL)
+ gpm-marshal.list
INCLUDES = \
$(GLIB_CFLAGS) \
- $(DBUS_CFLAGS) \
$(GNOME_CFLAGS) \
$(X11_CFLAGS) \
$(NOTIFY_CFLAGS) \
$(CANBERRA_CFLAGS) \
$(GSTREAMER_CFLAGS) \
$(CONTROL_CENTER_CFLAGS) \
- -DI_KNOW_THE_DEVICEKIT_POWER_API_IS_SUBJECT_TO_CHANGE \
$(UPOWER_CFLAGS) \
-DBINDIR=\"$(bindir)\" \
-DSBINDIR=\"$(sbindir)\" \
@@ -35,16 +28,14 @@ INCLUDES = \
-DEGG_VERBOSE="\"GPM_VERBOSE\"" \
-DEGG_LOGGING="\"GPM_LOGGING\"" \
-DEGG_CONSOLE="\"GPM_CONSOLE\"" \
- -I$(top_srcdir) \
- $(NULL)
+ -I$(top_srcdir)
ccpanelsdir = $(PANELS_DIR)
ccpanels_LTLIBRARIES = libpower.la
bin_PROGRAMS = \
gnome-power-manager \
- gnome-power-statistics \
- $(NULL)
+ gnome-power-statistics
sbin_PROGRAMS = \
gnome-power-backlight-helper \
@@ -70,12 +61,10 @@ libgpmshared_a_SOURCES = \
gpm-marshal.h \
gpm-marshal.c \
gpm-upower.c \
- gpm-upower.h \
- $(NULL)
+ gpm-upower.h
gnome_power_backlight_helper_SOURCES = \
- gpm-backlight-helper.c \
- $(NULL)
+ gpm-backlight-helper.c
gnome_power_backlight_helper_LDADD = \
libgpmshared.a \
@@ -83,16 +72,14 @@ gnome_power_backlight_helper_LDADD = \
-lm
gnome_power_backlight_helper_CFLAGS = \
- $(WARNINGFLAGS) \
- $(NULL)
+ $(WARNINGFLAGS)
gnome_power_statistics_SOURCES = \
gpm-statistics.c \
gpm-point-obj.c \
gpm-point-obj.h \
gpm-graph-widget.h \
- gpm-graph-widget.c \
- $(NULL)
+ gpm-graph-widget.c
gnome_power_statistics_LDADD = \
libgpmshared.a \
@@ -100,12 +87,10 @@ gnome_power_statistics_LDADD = \
$(X11_LIBS) \
$(UPOWER_LIBS) \
$(GNOME_LIBS) \
- $(DBUS_LIBS) \
-lm
gnome_power_statistics_CFLAGS = \
- $(WARNINGFLAGS) \
- $(NULL)
+ $(WARNINGFLAGS)
libpower_la_SOURCES = \
egg-console-kit.h \
@@ -117,15 +102,13 @@ libpower_la_SOURCES = \
gpm-common.h \
gpm-common.c \
cc-power-panel.c \
- cc-power-panel.h \
- $(NULL)
+ cc-power-panel.h
libpower_la_LIBADD = \
$(GLIB_LIBS) \
$(CONTROL_CENTER_LIBS) \
$(X11_LIBS) \
$(GNOME_LIBS) \
- $(DBUS_LIBS) \
$(GPM_EXTRA_LIBS) \
$(UPOWER_LIBS) \
-lm
@@ -157,40 +140,33 @@ gnome_power_manager_SOURCES = \
gpm-tray-icon.c \
gpm-screensaver.h \
gpm-screensaver.c \
- gpm-session.h \
- gpm-session.c \
gpm-stock-icons.h \
gsd-media-keys-window.h \
gsd-media-keys-window.c \
gpm-engine.h \
- gpm-engine.c \
- $(NULL)
+ gpm-engine.c
gnome_power_manager_LDADD = \
libgpmshared.a \
$(GLIB_LIBS) \
- $(X11_LIBS) \
+ $(X11_LIBS) \
$(GSTREAMER_LIBS) \
$(GNOME_LIBS) \
- $(DBUS_LIBS) \
- $(X11_LIBS) \
+ $(X11_LIBS) \
$(CANBERRA_LIBS) \
- $(NOTIFY_LIBS) \
+ $(NOTIFY_LIBS) \
$(GPM_EXTRA_LIBS) \
$(UPOWER_LIBS) \
-lm
gnome_power_manager_CFLAGS = \
- $(WARNINGFLAGS) \
- $(NULL)
+ $(WARNINGFLAGS)
gnome_power_self_test_SOURCES = \
gpm-dpms.h \
gpm-dpms.c \
gpm-idle.h \
gpm-idle.c \
- gpm-session.h \
- gpm-session.c \
gpm-common.h \
gpm-common.c \
gpm-load.h \
@@ -203,8 +179,7 @@ gnome_power_self_test_SOURCES = \
gpm-idletime.c \
gpm-array-float.h \
gpm-array-float.c \
- gpm-self-test.c \
- $(NULL)
+ gpm-self-test.c
gnome_power_self_test_LDADD = \
libgpmshared.a \
@@ -213,20 +188,16 @@ gnome_power_self_test_LDADD = \
$(GNOME_LIBS) \
$(GSTREAMER_LIBS) \
$(UPOWER_LIBS) \
- $(DBUS_LIBS) \
$(X11_LIBS) \
- $(NOTIFY_LIBS) \
+ $(NOTIFY_LIBS) \
$(GPM_EXTRA_LIBS) \
-lm
gnome_power_self_test_CFLAGS = -DEGG_TEST $(AM_CFLAGS) $(WARNINGFLAGS)
BUILT_SOURCES = \
- org.gnome.PowerManager.h \
- org.gnome.PowerManager.Backlight.h \
gpm-marshal.c \
- gpm-marshal.h \
- $(NULL)
+ gpm-marshal.h
gpm-marshal.c: gpm-marshal.list
echo "#include \"gpm-marshal.h\"" > $@ && \
@@ -235,20 +206,6 @@ gpm-marshal.c: gpm-marshal.list
gpm-marshal.h: gpm-marshal.list
@GLIB_GENMARSHAL@ $< --prefix=gpm_marshal --header > $@
-org.gnome.PowerManager.h: org.gnome.PowerManager.xml
- libtool --mode=execute dbus-binding-tool \
- --prefix=gpm_manager \
- --mode=glib-server \
- --output=org.gnome.PowerManager.h \
- $(srcdir)/org.gnome.PowerManager.xml
-
-org.gnome.PowerManager.Backlight.h: org.gnome.PowerManager.Backlight.xml
- libtool --mode=execute dbus-binding-tool \
- --prefix=gpm_backlight \
- --mode=glib-server \
- --output=org.gnome.PowerManager.Backlight.h \
- $(srcdir)/org.gnome.PowerManager.Backlight.xml
-
clean-local:
rm -f *~
rm -f gpm-marshal.c gpm-marshal.h
@@ -259,6 +216,5 @@ TESTS = gnome-power-self-test
MAINTAINERCLEANFILES = \
*~ \
- Makefile.in \
- $(NULL)
+ Makefile.in
diff --git a/src/cc-power-panel.c b/src/cc-power-panel.c
index 5e3f5e6..fd56d7b 100644
--- a/src/cc-power-panel.c
+++ b/src/cc-power-panel.c
@@ -531,8 +531,8 @@ cc_power_panel_setup_general (CcPowerPanel *panel)
static void
cc_power_panel_set_defaults_cb (GtkWidget *widget, CcPowerPanel *panel)
{
- DBusGProxy *proxy;
- DBusGConnection *connection;
+ GDBusProxy *proxy;
+ GDBusConnection *connection;
GError *error = NULL;
const gchar *keys[5] = {
"/apps/gnome-power-manager/actions",
@@ -542,7 +542,7 @@ cc_power_panel_set_defaults_cb (GtkWidget *widget, CcPowerPanel *panel)
"/apps/gnome-power-manager/timeout"
};
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (error != NULL) {
g_warning ("failed to get system bus connection: %s", error->message);
g_error_free (error);
@@ -558,7 +558,7 @@ cc_power_panel_set_defaults_cb (GtkWidget *widget, CcPowerPanel *panel)
return;
}
- dbus_g_proxy_call (proxy, "SetSystem", &error,
+ g_dbus_proxy_call (proxy, "SetSystem", &error,
G_TYPE_STRV, keys,
G_TYPE_STRV, NULL,
G_TYPE_INVALID, G_TYPE_INVALID);
diff --git a/src/gpm-backlight.c b/src/gpm-backlight.c
index dba2823..00bf709 100644
--- a/src/gpm-backlight.c
+++ b/src/gpm-backlight.c
@@ -38,7 +38,6 @@
#endif /* HAVE_UNISTD_H */
#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
#include <libupower-glib/upower.h>
#include "gpm-button.h"
@@ -54,6 +53,22 @@
#include "gpm-stock-icons.h"
#include "egg-console-kit.h"
+static const gchar *backlight_introspection = ""
+"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<node name=\"/\">"
+ "<interface name=\"org.gnome.PowerManager.Backlight\">"
+ "<method name=\"GetBrightness\">"
+ "<arg type=\"u\" name=\"percentage_brightness\" direction=\"out\"/>"
+ "</method>"
+ "<method name=\"SetBrightness\">"
+ "<arg type=\"u\" name=\"percentage_brightness\" direction=\"in\"/>"
+ "</method>"
+ "<signal name=\"BrightnessChanged\">"
+ "<arg type=\"u\" name=\"percentage_brightness\" direction=\"out\"/>"
+ "</signal>"
+ "</interface>"
+"</node>";
+
#define GPM_BACKLIGHT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_BACKLIGHT, GpmBacklightPrivate))
struct GpmBacklightPrivate
@@ -72,6 +87,8 @@ struct GpmBacklightPrivate
GTimer *idle_timer;
guint idle_dim_timeout;
guint master_percentage;
+ GDBusConnection *bus_connection;
+ guint bus_object_id;
};
enum {
@@ -385,10 +402,10 @@ gpm_settings_key_changed_cb (GSettings *settings, const gchar *key, GpmBacklight
gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);
} else if (g_strcmp0 (key, GPM_SETTINGS_IDLE_DIM_AC) == 0 ||
- g_strcmp0 (key, GPM_SETTINGS_BACKLIGHT_ENABLE) == 0 ||
- g_strcmp0 (key, GPM_SETTINGS_SLEEP_DISPLAY_BATT) == 0 ||
- g_strcmp0 (key, GPM_SETTINGS_BACKLIGHT_BATTERY_REDUCE) == 0 ||
- g_strcmp0 (key, GPM_SETTINGS_IDLE_BRIGHTNESS) == 0) {
+ g_strcmp0 (key, GPM_SETTINGS_BACKLIGHT_ENABLE) == 0 ||
+ g_strcmp0 (key, GPM_SETTINGS_SLEEP_DISPLAY_BATT) == 0 ||
+ g_strcmp0 (key, GPM_SETTINGS_BACKLIGHT_BATTERY_REDUCE) == 0 ||
+ g_strcmp0 (key, GPM_SETTINGS_IDLE_BRIGHTNESS) == 0) {
gpm_backlight_brightness_evaluate_and_set (backlight, FALSE);
} else if (g_strcmp0 (key, GPM_SETTINGS_IDLE_DIM_TIME) == 0) {
@@ -529,7 +546,7 @@ gpm_backlight_notify_system_idle_changed (GpmBacklight *backlight, gboolean is_i
}
/**
- * idle_changed_cb:
+ * gpm_backlight_idle_changed_cb:
* @idle: The idle class instance
* @mode: The idle mode, e.g. GPM_IDLE_MODE_BLANK
* @manager: This class instance
@@ -540,7 +557,7 @@ gpm_backlight_notify_system_idle_changed (GpmBacklight *backlight, gboolean is_i
* session timeout has elapsed for the idle action.
**/
static void
-idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
+gpm_backlight_idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
{
gboolean ret;
gboolean is_active;
@@ -619,7 +636,7 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
}
/**
- * brightness_changed_cb:
+ * gpm_backlight_brightness_changed_cb:
* @brightness: The GpmBrightness class instance
* @percentage: The new percentage brightness
* @brightness: This class instance
@@ -627,7 +644,7 @@ idle_changed_cb (GpmIdle *idle, GpmIdleMode mode, GpmBacklight *backlight)
* This callback is called when the brightness value changes.
**/
static void
-brightness_changed_cb (GpmBrightness *brightness, guint percentage, GpmBacklight *backlight)
+gpm_backlight_brightness_changed_cb (GpmBrightness *brightness, guint percentage, GpmBacklight *backlight)
{
/* save the new percentage */
backlight->priv->master_percentage = percentage;
@@ -635,17 +652,26 @@ brightness_changed_cb (GpmBrightness *brightness, guint percentage, GpmBacklight
/* we emit a signal for the brightness applet */
egg_debug ("emitting brightness-changed : %i", percentage);
g_signal_emit (backlight, signals [BRIGHTNESS_CHANGED], 0, percentage);
+
+ /* and one for Dbus users */
+ g_dbus_connection_emit_signal (backlight->priv->bus_connection,
+ NULL,
+ GPM_DBUS_PATH_BACKLIGHT,
+ GPM_DBUS_INTERFACE_BACKLIGHT,
+ "BrightnessChanged",
+ g_variant_new ("(u)", percentage),
+ NULL);
}
/**
- * control_resume_cb:
+ * gpm_backlight_control_resume_cb:
* @control: The control class instance
* @power: This power class instance
*
* We have to update the caches on resume
**/
static void
-control_resume_cb (GpmControl *control, GpmControlAction action, GpmBacklight *backlight)
+gpm_backlight_control_resume_cb (GpmControl *control, GpmControlAction action, GpmBacklight *backlight)
{
gboolean ret;
GError *error = NULL;
@@ -659,6 +685,100 @@ control_resume_cb (GpmControl *control, GpmControlAction action, GpmBacklight *b
}
/**
+ * gpm_backlight_dbus_method_call:
+ **/
+static void
+gpm_backlight_dbus_method_call (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *method_name,
+ GVariant *parameters, GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ GError *error;
+ guint value;
+ gboolean ret;
+ GpmBacklight *backlight = GPM_BACKLIGHT (user_data);
+
+ if (g_strcmp0 (method_name, "GetBrightness") == 0) {
+ ret = gpm_backlight_get_brightness (backlight, &value, &error);
+ if (!ret) {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ } else {
+ g_dbus_method_invocation_return_value (invocation, g_variant_new ("(u)", value));
+ }
+ return;
+ }
+ if (g_strcmp0 (method_name, "SetBrightness") == 0) {
+ g_variant_get (parameters, "(u)", &value);
+ ret = gpm_backlight_set_brightness (backlight, value, &error);
+ if (!ret) {
+ g_dbus_method_invocation_return_gerror (invocation, error);
+ g_error_free (error);
+ } else {
+ g_dbus_method_invocation_return_value (invocation, NULL);
+ }
+ return;
+ }
+ g_assert_not_reached ();
+}
+
+/**
+ * gpm_backlight_dbus_property_get:
+ **/
+static GVariant *
+gpm_backlight_dbus_property_get (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name,
+ GError **error, gpointer user_data)
+{
+ /* do nothing, no properties defined */
+ return NULL;
+}
+
+/**
+ * gpm_backlight_dbus_property_set:
+ **/
+static gboolean
+gpm_backlight_dbus_property_set (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name,
+ GVariant *value,
+ GError**invocation, gpointer user_data)
+{
+ /* do nothing, no properties defined */
+ return FALSE;
+}
+
+/**
+ * gpm_backlight_register_dbus:
+ **/
+void
+gpm_backlight_register_dbus (GpmBacklight *backlight, GDBusConnection *connection)
+{
+ GDBusNodeInfo *node_info;
+ GDBusInterfaceInfo *interface_info;
+ GDBusInterfaceVTable interface_vtable = {
+ gpm_backlight_dbus_method_call,
+ gpm_backlight_dbus_property_get,
+ gpm_backlight_dbus_property_set
+ };
+
+ node_info = g_dbus_node_info_new_for_xml (backlight_introspection, NULL);
+ interface_info = g_dbus_node_info_lookup_interface (node_info, GPM_DBUS_INTERFACE_BACKLIGHT);
+
+ backlight->priv->bus_connection = g_object_ref (connection);
+ backlight->priv->bus_object_id =
+ g_dbus_connection_register_object (connection,
+ GPM_DBUS_PATH_BACKLIGHT,
+ interface_info,
+ &interface_vtable,
+ backlight,
+ NULL, NULL);
+ g_dbus_node_info_unref (node_info);
+}
+
+/**
* gpm_backlight_finalize:
**/
static void
@@ -669,6 +789,12 @@ gpm_backlight_finalize (GObject *object)
g_return_if_fail (GPM_IS_BACKLIGHT (object));
backlight = GPM_BACKLIGHT (object);
+ if (backlight->priv->bus_connection != NULL) {
+ g_dbus_connection_unregister_object (backlight->priv->bus_connection,
+ backlight->priv->bus_object_id);
+ g_object_unref (backlight->priv->bus_connection);
+ }
+
g_timer_destroy (backlight->priv->idle_timer);
gtk_widget_destroy (backlight->priv->popup);
@@ -725,7 +851,7 @@ gpm_backlight_init (GpmBacklight *backlight)
/* watch for manual brightness changes (for the popup widget) */
backlight->priv->brightness = gpm_brightness_new ();
g_signal_connect (backlight->priv->brightness, "brightness-changed",
- G_CALLBACK (brightness_changed_cb), backlight);
+ G_CALLBACK (gpm_backlight_brightness_changed_cb), backlight);
/* we use up_client for the ac-adapter-changed signal */
backlight->priv->client = up_client_new ();
@@ -751,7 +877,7 @@ gpm_backlight_init (GpmBacklight *backlight)
/* watch for idle mode changes */
backlight->priv->idle = gpm_idle_new ();
g_signal_connect (backlight->priv->idle, "idle-changed",
- G_CALLBACK (idle_changed_cb), backlight);
+ G_CALLBACK (gpm_backlight_idle_changed_cb), backlight);
/* assumption */
backlight->priv->system_is_idle = FALSE;
@@ -763,7 +889,7 @@ gpm_backlight_init (GpmBacklight *backlight)
gsd_media_keys_window_set_action_custom (GSD_MEDIA_KEYS_WINDOW (backlight->priv->popup),
"gpm-brightness-lcd",
TRUE);
- gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);
+ gtk_window_set_position (GTK_WINDOW (backlight->priv->popup), GTK_WIN_POS_NONE);
/* DPMS mode poll class */
backlight->priv->dpms = gpm_dpms_new ();
@@ -771,7 +897,7 @@ gpm_backlight_init (GpmBacklight *backlight)
/* we refresh DPMS on resume */
backlight->priv->control = gpm_control_new ();
g_signal_connect (backlight->priv->control, "resume",
- G_CALLBACK (control_resume_cb), backlight);
+ G_CALLBACK (gpm_backlight_control_resume_cb), backlight);
/* Don't do dimming on inactive console */
backlight->priv->consolekit = egg_console_kit_new ();
diff --git a/src/gpm-backlight.h b/src/gpm-backlight.h
index 1060587..bf0c6a9 100644
--- a/src/gpm-backlight.h
+++ b/src/gpm-backlight.h
@@ -38,7 +38,7 @@ typedef struct GpmBacklightPrivate GpmBacklightPrivate;
typedef struct
{
- GObject parent;
+ GObject parent;
GpmBacklightPrivate *priv;
} GpmBacklight;
@@ -66,6 +66,8 @@ gboolean gpm_backlight_get_brightness (GpmBacklight *backlight,
gboolean gpm_backlight_set_brightness (GpmBacklight *backlight,
guint brightness,
GError **error);
+void gpm_backlight_register_dbus (GpmBacklight *backlight,
+ GDBusConnection *connection);
G_END_DECLS
diff --git a/src/gpm-control.c b/src/gpm-control.c
index 816f6ef..1371699 100644
--- a/src/gpm-control.c
+++ b/src/gpm-control.c
@@ -37,8 +37,6 @@
#endif /* HAVE_UNISTD_H */
#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <gnome-keyring.h>
#include <gconf/gconf-client.h>
#include <libupower-glib/upower.h>
diff --git a/src/gpm-control.h b/src/gpm-control.h
index f4b36d7..d7d9f9a 100644
--- a/src/gpm-control.h
+++ b/src/gpm-control.h
@@ -24,7 +24,6 @@
#define __GPM_CONTROL_H
#include <glib-object.h>
-#include <dbus/dbus-glib.h>
G_BEGIN_DECLS
diff --git a/src/gpm-disks.c b/src/gpm-disks.c
index eec3358..6bcada1 100644
--- a/src/gpm-disks.c
+++ b/src/gpm-disks.c
@@ -22,7 +22,7 @@
#include "config.h"
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include "egg-debug.h"
#include "gpm-disks.h"
@@ -33,7 +33,7 @@ static void gpm_disks_finalize (GObject *object);
struct GpmDisksPrivate
{
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
gchar *cookie;
};
@@ -48,6 +48,7 @@ static gboolean
gpm_disks_unregister (GpmDisks *disks)
{
gboolean ret = FALSE;
+ GVariant *retval = NULL;
GError *error = NULL;
/* no UDisks */
@@ -56,21 +57,25 @@ gpm_disks_unregister (GpmDisks *disks)
goto out;
}
- /* clear spindown timeouts */
- ret = dbus_g_proxy_call (disks->priv->proxy, "DriveUnsetAllSpindownTimeouts", &error,
- G_TYPE_STRING, disks->priv->cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (!ret) {
+ /* set spindown timeouts */
+ retval = g_dbus_proxy_call_sync (disks->priv->proxy,
+ "DriveUnsetAllSpindownTimeouts",
+ g_variant_new ("(s)",
+ disks->priv->cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (retval == NULL) {
+ /* abort as the DBUS method failed */
egg_warning ("failed to clear spindown timeout: %s", error->message);
g_error_free (error);
goto out;
}
-out:
- /* reset */
- g_free (disks->priv->cookie);
- disks->priv->cookie = NULL;
+ /* sucess */
+ ret = TRUE;
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
return ret;
}
@@ -81,6 +86,7 @@ static gboolean
gpm_disks_register (GpmDisks *disks, gint timeout)
{
gboolean ret = FALSE;
+ GVariant *retval = NULL;
GError *error = NULL;
const gchar **options = {NULL};
@@ -91,18 +97,26 @@ gpm_disks_register (GpmDisks *disks, gint timeout)
}
/* set spindown timeouts */
- ret = dbus_g_proxy_call (disks->priv->proxy, "DriveSetAllSpindownTimeouts", &error,
- G_TYPE_INT, timeout,
- G_TYPE_STRV, options,
- G_TYPE_INVALID,
- G_TYPE_STRING, &disks->priv->cookie,
- G_TYPE_INVALID);
- if (!ret) {
+ retval = g_dbus_proxy_call_sync (disks->priv->proxy,
+ "DriveSetAllSpindownTimeouts",
+ g_variant_new ("(ias)",
+ timeout,
+ options),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (retval == NULL) {
+ /* abort as the DBUS method failed */
egg_warning ("failed to set spindown timeout: %s", error->message);
g_error_free (error);
goto out;
}
+
+ /* sucess */
+ ret = TRUE;
+ g_variant_get (retval, "(s)", &disks->priv->cookie);
out:
+ if (retval != NULL)
+ g_variant_unref (retval);
return ret;
}
@@ -141,20 +155,23 @@ static void
gpm_disks_init (GpmDisks *disks)
{
GError *error = NULL;
- DBusGConnection *connection;
+ GDBusConnection *connection;
disks->priv = GPM_DISKS_GET_PRIVATE (disks);
- disks->priv->cookie = NULL;
-
/* get proxy to interface */
- connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);
- disks->priv->proxy = dbus_g_proxy_new_for_name_owner (connection,
- "org.freedesktop.UDisks",
- "/org/freedesktop/UDisks",
- "org.freedesktop.UDisks", &error);
+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
+ disks->priv->proxy =
+ g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.freedesktop.UDisks",
+ "/org/freedesktop/UDisks",
+ "org.freedesktop.UDisks",
+ NULL, &error);
if (disks->priv->proxy == NULL) {
- egg_warning ("DBUS error: %s", error->message);
+ egg_warning ("failed to setup disks proxy: %s", error->message);
g_error_free (error);
}
}
diff --git a/src/gpm-dpms.c b/src/gpm-dpms.c
index fa4faf6..a3668d5 100644
--- a/src/gpm-dpms.c
+++ b/src/gpm-dpms.c
@@ -348,9 +348,7 @@ gpm_dpms_init (GpmDpms *dpms)
dpms->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default());
dpms->priv->dpms_capable = DPMSCapable (dpms->priv->display);
dpms->priv->timer_id = g_timeout_add_seconds (GPM_DPMS_POLL_TIME, (GSourceFunc)gpm_dpms_poll_mode_cb, dpms);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (dpms->priv->timer_id, "[GpmDpms] poll");
-#endif
/* ensure we clear the default timeouts (Standby: 1200s, Suspend: 1800s, Off: 2400s) */
gpm_dpms_clear_timeouts (dpms);
diff --git a/src/gpm-engine.c b/src/gpm-engine.c
index 7cbfce9..dd439b8 100644
--- a/src/gpm-engine.c
+++ b/src/gpm-engine.c
@@ -1156,9 +1156,7 @@ gpm_engine_init (GpmEngine *engine)
egg_debug ("Using percentage notification policy");
idle_id = g_idle_add ((GSourceFunc) gpm_engine_coldplug_idle_cb, engine);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (idle_id, "[GpmEngine] coldplug");
-#endif
}
/**
diff --git a/src/gpm-idle.c b/src/gpm-idle.c
index cfe4bb4..7bdca27 100644
--- a/src/gpm-idle.c
+++ b/src/gpm-idle.c
@@ -37,13 +37,13 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
+#include <gio/gio.h>
#include "egg-debug.h"
#include "gpm-idletime.h"
#include "gpm-idle.h"
#include "gpm-load.h"
-#include "gpm-session.h"
#define GPM_IDLE_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GPM_TYPE_IDLE, GpmIdlePrivate))
@@ -54,17 +54,18 @@
struct GpmIdlePrivate
{
- GpmIdletime *idletime;
- GpmLoad *load;
- GpmSession *session;
- GpmIdleMode mode;
- guint timeout_dim; /* in seconds */
- guint timeout_blank; /* in seconds */
- guint timeout_sleep; /* in seconds */
- guint timeout_blank_id;
- guint timeout_sleep_id;
- gboolean x_idle;
- gboolean check_type_cpu;
+ GpmIdletime *idletime;
+ GpmLoad *load;
+ GDBusProxy *proxy;
+ GDBusProxy *proxy_presence;
+ GpmIdleMode mode;
+ guint timeout_dim; /* in seconds */
+ guint timeout_blank; /* in seconds */
+ guint timeout_sleep; /* in seconds */
+ guint timeout_blank_id;
+ guint timeout_sleep_id;
+ gboolean x_idle;
+ gboolean check_type_cpu;
};
enum {
@@ -171,6 +172,75 @@ out:
return ret;
}
+typedef enum {
+ GPM_IDLE_STATUS_ENUM_AVAILABLE = 0,
+ GPM_IDLE_STATUS_ENUM_INVISIBLE,
+ GPM_IDLE_STATUS_ENUM_BUSY,
+ GPM_IDLE_STATUS_ENUM_IDLE,
+ GPM_IDLE_STATUS_ENUM_UNKNOWN
+} GpmIdleStatusEnum;
+
+/**
+ * gpm_idle_is_session_idle:
+ **/
+static gboolean
+gpm_idle_is_session_idle (GpmIdle *idle)
+{
+ gboolean ret = FALSE;
+ GVariant *result;
+ guint status;
+
+ /* get the session status */
+ result = g_dbus_proxy_get_cached_property (idle->priv->proxy_presence, "status");
+ if (result == NULL)
+ goto out;
+
+ g_variant_get (result, "u", &status);
+ ret = (status == GPM_IDLE_STATUS_ENUM_IDLE);
+ g_variant_unref (result);
+out:
+ return ret;
+}
+
+typedef enum {
+ GPM_IDLE_INHIBIT_MASK_LOGOUT = 1,
+ GPM_IDLE_INHIBIT_MASK_SWITCH = 2,
+ GPM_IDLE_INHIBIT_MASK_SUSPEND = 4,
+ GPM_IDLE_INHIBIT_MASK_IDLE = 8
+} GpmIdleInhibitMask;
+
+/**
+ * gpm_idle_is_session_inhibited:
+ **/
+static gboolean
+gpm_idle_is_session_inhibited (GpmIdle *idle, guint mask)
+{
+ gboolean ret = FALSE;
+ GVariant *retval = NULL;
+ GError *error = NULL;
+
+ retval = g_dbus_proxy_call_sync (idle->priv->proxy,
+ "IsInhibited",
+ g_variant_new ("(u)",
+ mask),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ if (retval == NULL) {
+ /* abort as the DBUS method failed */
+ egg_warning ("IsInhibited failed: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* success */
+ g_variant_get (retval, "(b)", &ret);
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ return ret;
+}
+
/**
* gpm_idle_evaluate:
**/
@@ -181,11 +251,6 @@ gpm_idle_evaluate (GpmIdle *idle)
gboolean is_idle_inhibited;
gboolean is_suspend_inhibited;
- is_idle = gpm_session_get_idle (idle->priv->session);
- is_idle_inhibited = gpm_session_get_idle_inhibited (idle->priv->session);
- is_suspend_inhibited = gpm_session_get_suspend_inhibited (idle->priv->session);
- egg_debug ("session_idle=%i, idle_inhibited=%i, suspend_inhibited=%i, x_idle=%i", is_idle, is_idle_inhibited, is_suspend_inhibited, idle->priv->x_idle);
-
/* check we are really idle */
if (!idle->priv->x_idle) {
gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
@@ -202,6 +267,7 @@ gpm_idle_evaluate (GpmIdle *idle)
}
/* are we inhibited from going idle */
+ is_idle_inhibited = gpm_idle_is_session_inhibited (idle, GPM_IDLE_INHIBIT_MASK_IDLE);
if (is_idle_inhibited) {
egg_debug ("inhibited, so using normal state");
gpm_idle_set_mode (idle, GPM_IDLE_MODE_NORMAL);
@@ -229,12 +295,12 @@ gpm_idle_evaluate (GpmIdle *idle)
egg_debug ("setting up blank callback for %is", idle->priv->timeout_blank);
idle->priv->timeout_blank_id = g_timeout_add_seconds (idle->priv->timeout_blank,
(GSourceFunc) gpm_idle_blank_cb, idle);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (idle->priv->timeout_blank_id, "[GpmIdle] blank");
-#endif
}
/* are we inhibited from sleeping */
+ is_idle = gpm_idle_is_session_idle (idle);
+ is_suspend_inhibited = gpm_idle_is_session_inhibited (idle, GPM_IDLE_INHIBIT_MASK_SUSPEND);
if (is_suspend_inhibited) {
egg_debug ("suspend inhibited");
if (idle->priv->timeout_sleep_id != 0) {
@@ -242,15 +308,13 @@ gpm_idle_evaluate (GpmIdle *idle)
idle->priv->timeout_sleep_id = 0;
}
} else if (is_idle) {
- /* only do the sleep timeout when the session is idle and we aren't inhibited from sleeping */
+ /* only do the sleep timeout when the session is idle and we aren't inhibited from sleeping */
if (idle->priv->timeout_sleep_id == 0 &&
idle->priv->timeout_sleep != 0) {
egg_debug ("setting up sleep callback %is", idle->priv->timeout_sleep);
idle->priv->timeout_sleep_id = g_timeout_add_seconds (idle->priv->timeout_sleep,
(GSourceFunc) gpm_idle_sleep_cb, idle);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (idle->priv->timeout_sleep_id, "[GpmIdle] sleep");
-#endif
}
}
out:
@@ -351,29 +415,6 @@ gpm_idle_set_timeout_sleep (GpmIdle *idle, guint timeout)
}
/**
- * gpm_idle_session_idle_changed_cb:
- * @is_idle: If the session is idle
- *
- * The SessionIdleChanged callback from gnome-session.
- **/
-static void
-gpm_idle_session_idle_changed_cb (GpmSession *session, gboolean is_idle, GpmIdle *idle)
-{
- egg_debug ("Received gnome session idle changed: %i", is_idle);
- gpm_idle_evaluate (idle);
-}
-
-/**
- * gpm_idle_session_inhibited_changed_cb:
- **/
-static void
-gpm_idle_session_inhibited_changed_cb (GpmSession *session, gboolean is_idle_inhibited, gboolean is_suspend_inhibited, GpmIdle *idle)
-{
- egg_debug ("Received gnome session inhibited changed: idle=(%i), suspend=(%i)", is_idle_inhibited, is_suspend_inhibited);
- gpm_idle_evaluate (idle);
-}
-
-/**
* gpm_idle_idletime_alarm_expired_cb:
*
* We're idle, something timed out
@@ -403,6 +444,27 @@ gpm_idle_idletime_reset_cb (GpmIdletime *idletime, GpmIdle *idle)
}
/**
+ * gpm_idle_dbus_signal_cb:
+ **/
+static void
+gpm_idle_dbus_signal_cb (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
+{
+ GpmIdle *idle = GPM_IDLE (user_data);
+
+ if (g_strcmp0 (signal_name, "InhibitorAdded") == 0 ||
+ g_strcmp0 (signal_name, "InhibitorRemoved") == 0) {
+ egg_debug ("Received gnome session inhibitor change");
+ gpm_idle_evaluate (idle);
+ return;
+ }
+ if (g_strcmp0 (signal_name, "StatusChanged") == 0) {
+ egg_debug ("Received gnome session status change");
+ gpm_idle_evaluate (idle);
+ return;
+ }
+}
+
+/**
* gpm_idle_finalize:
* @object: This class instance
**/
@@ -424,7 +486,10 @@ gpm_idle_finalize (GObject *object)
g_source_remove (idle->priv->timeout_sleep_id);
g_object_unref (idle->priv->load);
- g_object_unref (idle->priv->session);
+ if (idle->priv->proxy != NULL)
+ g_object_unref (idle->priv->proxy);
+ if (idle->priv->proxy_presence != NULL)
+ g_object_unref (idle->priv->proxy_presence);
gpm_idletime_alarm_remove (idle->priv->idletime, GPM_IDLE_IDLETIME_ID);
g_object_unref (idle->priv->idletime);
@@ -464,6 +529,9 @@ gpm_idle_class_init (GpmIdleClass *klass)
static void
gpm_idle_init (GpmIdle *idle)
{
+ GDBusConnection *connection;
+ GError *error = NULL;
+
idle->priv = GPM_IDLE_GET_PRIVATE (idle);
idle->priv->timeout_dim = G_MAXUINT;
@@ -473,14 +541,49 @@ gpm_idle_init (GpmIdle *idle)
idle->priv->timeout_sleep_id = 0;
idle->priv->x_idle = FALSE;
idle->priv->load = gpm_load_new ();
- idle->priv->session = gpm_session_new ();
- g_signal_connect (idle->priv->session, "idle-changed", G_CALLBACK (gpm_idle_session_idle_changed_cb), idle);
- g_signal_connect (idle->priv->session, "inhibited-changed", G_CALLBACK (gpm_idle_session_inhibited_changed_cb), idle);
idle->priv->idletime = gpm_idletime_new ();
g_signal_connect (idle->priv->idletime, "reset", G_CALLBACK (gpm_idle_idletime_reset_cb), idle);
g_signal_connect (idle->priv->idletime, "alarm-expired", G_CALLBACK (gpm_idle_idletime_alarm_expired_cb), idle);
+ /* get connection */
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ egg_warning ("Failed to get session connection: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+
+ /* get org.gnome.Session main interface */
+ idle->priv->proxy =
+ g_dbus_proxy_new_sync (connection,
+ 0, NULL,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ NULL, &error);
+ if (idle->priv->proxy == NULL) {
+ egg_warning ("Cannot connect to session manager: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ g_signal_connect (idle->priv->proxy, "g-signal", G_CALLBACK (gpm_idle_dbus_signal_cb), idle);
+
+ /* get org.gnome.Session.Presence interface */
+ idle->priv->proxy_presence =
+ g_dbus_proxy_new_sync (connection,
+ 0, NULL,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager/Presence",
+ "org.gnome.SessionManager.Presence",
+ NULL, &error);
+ if (idle->priv->proxy_presence == NULL) {
+ egg_warning ("Cannot connect to session manager: %s", error->message);
+ g_error_free (error);
+ return;
+ }
+ g_signal_connect (idle->priv->proxy_presence, "g-signal", G_CALLBACK (gpm_idle_dbus_signal_cb), idle);
+
gpm_idle_evaluate (idle);
}
diff --git a/src/gpm-main.c b/src/gpm-main.c
index 02001c5..092c583 100644
--- a/src/gpm-main.c
+++ b/src/gpm-main.c
@@ -33,72 +33,16 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include "gpm-stock-icons.h"
#include "gpm-common.h"
#include "gpm-manager.h"
-#include "gpm-session.h"
-
-#include "org.gnome.PowerManager.h"
#include "egg-debug.h"
-/**
- * gpm_object_register:
- * @connection: What we want to register to
- * @object: The GObject we want to register
- *
- * Register org.gnome.PowerManager on the session bus.
- * This function MUST be called before DBUS service will work.
- *
- * Return value: success
- **/
-static gboolean
-gpm_object_register (DBusGConnection *connection,
- GObject *object)
-{
- DBusGProxy *bus_proxy = NULL;
- GError *error = NULL;
- guint request_name_result;
- gboolean ret;
-
- bus_proxy = dbus_g_proxy_new_for_name (connection,
- DBUS_SERVICE_DBUS,
- DBUS_PATH_DBUS,
- DBUS_INTERFACE_DBUS);
-
- ret = dbus_g_proxy_call (bus_proxy, "RequestName", &error,
- G_TYPE_STRING, GPM_DBUS_SERVICE,
- G_TYPE_UINT, 0,
- G_TYPE_INVALID,
- G_TYPE_UINT, &request_name_result,
- G_TYPE_INVALID);
- if (error) {
- egg_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- if (!ret) {
- /* abort as the DBUS method failed */
- egg_warning ("RequestName failed!");
- return FALSE;
- }
-
- /* free the bus_proxy */
- g_object_unref (G_OBJECT (bus_proxy));
-
- /* already running */
- if (request_name_result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
- return FALSE;
- }
-
- dbus_g_object_type_install_info (GPM_TYPE_MANAGER, &dbus_glib_gpm_manager_object_info);
- dbus_g_error_domain_register (GPM_MANAGER_ERROR, NULL, GPM_MANAGER_TYPE_ERROR);
- dbus_g_connection_register_g_object (connection, GPM_DBUS_PATH, object);
-
- return TRUE;
-}
+static GDBusProxy *session_proxy = NULL;
+static GDBusProxy *session_proxy_client = NULL;
+static GMainLoop *loop = NULL;
/**
* timed_exit_cb:
@@ -109,42 +53,157 @@ gpm_object_register (DBusGConnection *connection,
* Return value: FALSE, as we don't want to repeat this action.
**/
static gboolean
-timed_exit_cb (GMainLoop *loop)
+timed_exit_cb (GMainLoop *_loop)
{
g_main_loop_quit (loop);
return FALSE;
}
/**
- * gpm_main_stop_cb:
+ * gpm_main_session_end_session_response:
**/
-static void
-gpm_main_stop_cb (GpmSession *session, GMainLoop *loop)
+static gboolean
+gpm_main_session_end_session_response (gboolean is_okay, const gchar *reason)
{
- g_main_loop_quit (loop);
+ gboolean ret = FALSE;
+ GVariant *retval = NULL;
+ GError *error = NULL;
+
+ g_return_val_if_fail (session_proxy_client != NULL, FALSE);
+
+ /* no gnome-session */
+ if (session_proxy == NULL) {
+ egg_warning ("no gnome-session");
+ goto out;
+ }
+
+ retval = g_dbus_proxy_call_sync (session_proxy,
+ "EndSessionResponse",
+ g_variant_new ("(bs)",
+ is_okay,
+ reason),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (retval == NULL) {
+ egg_debug ("ERROR: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* success */
+ ret = TRUE;
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ return ret;
}
/**
- * gpm_main_query_end_session_cb:
+ * gpm_main_session_dbus_signal_cb:
**/
static void
-gpm_main_query_end_session_cb (GpmSession *session, guint flags, GMainLoop *loop)
+gpm_main_session_dbus_signal_cb (GDBusProxy *proxy, const gchar *sender_name, const gchar *signal_name, GVariant *parameters, gpointer user_data)
{
- /* just send response */
- gpm_session_end_session_response (session, TRUE, NULL);
+ if (g_strcmp0 (signal_name, "Stop") == 0) {
+ g_main_loop_quit (loop);
+ return;
+ }
+ if (g_strcmp0 (signal_name, "QueryEndSession") == 0) {
+ /* just send response */
+ gpm_main_session_end_session_response (TRUE, NULL);
+ return;
+ }
+ if (g_strcmp0 (signal_name, "EndSession") == 0) {
+ /* send response */
+ gpm_main_session_end_session_response (TRUE, NULL);
+
+ /* exit loop, will unref manager */
+ g_main_loop_quit (loop);
+ return;
+ }
}
/**
- * gpm_main_end_session_cb:
+ * gpm_main_session_register_client:
**/
-static void
-gpm_main_end_session_cb (GpmSession *session, guint flags, GMainLoop *loop)
+static gboolean
+gpm_main_session_register_client (const gchar *app_id, const gchar *client_startup_id)
{
- /* send response */
- gpm_session_end_session_response (session, TRUE, NULL);
+ gboolean ret = FALSE;
+ gchar *client_id = NULL;
+ GError *error = NULL;
+ GDBusConnection *connection;
+ GVariant *retval = NULL;
- /* exit loop, will unref manager */
- g_main_loop_quit (loop);
+ /* fallback for local running */
+ if (client_startup_id == NULL)
+ client_startup_id = "";
+
+ /* get connection */
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ egg_warning ("Failed to get session connection: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ /* get org.gnome.Session interface */
+ session_proxy =
+ g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ NULL, &error);
+ if (session_proxy == NULL) {
+ egg_warning ("Failed to get gnome-session: %s", error->message);
+ g_error_free (error);
+ return FALSE;
+ }
+
+ /* register ourselves */
+ retval = g_dbus_proxy_call_sync (session_proxy,
+ "RegisterClient",
+ g_variant_new ("(ss)",
+ app_id,
+ client_startup_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (retval == NULL) {
+ egg_warning ("failed to register client '%s': %s", client_startup_id, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* get client id */
+ g_variant_get (retval, "(o)", &client_id);
+
+ /* get org.gnome.Session.ClientPrivate interface */
+ session_proxy_client =
+ g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ "org.gnome.SessionManager",
+ client_id,
+ "org.gnome.SessionManager.ClientPrivate",
+ NULL, &error);
+ if (session_proxy_client == NULL) {
+ egg_warning ("failed to setup private proxy: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ g_signal_connect (session_proxy_client, "g-signal", G_CALLBACK (gpm_main_session_dbus_signal_cb), NULL);
+
+ /* success */
+ ret = TRUE;
+ egg_debug ("registered startup '%s' to client id '%s'", client_startup_id, client_id);
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ g_free (client_id);
+ return ret;
}
/**
@@ -153,18 +212,16 @@ gpm_main_end_session_cb (GpmSession *session, guint flags, GMainLoop *loop)
int
main (int argc, char *argv[])
{
- GMainLoop *loop;
- DBusGConnection *system_connection;
- DBusGConnection *session_connection;
+ GDBusConnection *system_connection;
+ GDBusConnection *session_connection;
gboolean verbose = FALSE;
gboolean version = FALSE;
gboolean timed_exit = FALSE;
gboolean immediate_exit = FALSE;
- GpmSession *session = NULL;
GpmManager *manager = NULL;
GError *error = NULL;
GOptionContext *context;
- gint ret;
+ gint policy_owner_id;
guint timer_id;
const GOptionEntry options[] = {
@@ -186,7 +243,6 @@ main (int argc, char *argv[])
if (! g_thread_supported ())
g_thread_init (NULL);
- dbus_g_thread_init ();
g_type_init ();
context = g_option_context_new (N_("GNOME Power Manager"));
@@ -203,7 +259,6 @@ main (int argc, char *argv[])
if (!g_thread_supported ())
g_thread_init (NULL);
- dbus_g_thread_init ();
gtk_init (&argc, &argv);
egg_debug_init (verbose);
@@ -211,7 +266,7 @@ main (int argc, char *argv[])
egg_debug ("GNOME %s %s", GPM_NAME, VERSION);
/* check dbus connections, exit if not valid */
- system_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
+ system_connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
if (error) {
egg_warning ("%s", error->message);
g_error_free (error);
@@ -221,7 +276,7 @@ main (int argc, char *argv[])
"your computer after starting this service.");
}
- session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ session_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (error) {
egg_warning ("%s", error->message);
g_error_free (error);
@@ -233,47 +288,26 @@ main (int argc, char *argv[])
/* add application specific icons to search path */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
- GPM_DATA G_DIR_SEPARATOR_S "icons");
+ GPM_DATA G_DIR_SEPARATOR_S "icons");
loop = g_main_loop_new (NULL, FALSE);
/* optionally register with the session */
- session = gpm_session_new ();
- g_signal_connect (session, "stop", G_CALLBACK (gpm_main_stop_cb), loop);
- g_signal_connect (session, "query-end-session", G_CALLBACK (gpm_main_query_end_session_cb), loop);
- g_signal_connect (session, "end-session", G_CALLBACK (gpm_main_end_session_cb), loop);
- gpm_session_register_client (session, "gnome-power-manager", getenv ("DESKTOP_AUTOSTART_ID"));
+ gpm_main_session_register_client ("gnome-power-manager", getenv ("DESKTOP_AUTOSTART_ID"));
/* create a new gui object */
manager = gpm_manager_new ();
- if (!gpm_object_register (session_connection, G_OBJECT (manager))) {
- egg_error ("%s is already running in this session.", GPM_NAME);
- return 0;
- }
-
- /* register to be a policy agent, just like kpackagekit does */
- ret = dbus_bus_request_name(dbus_g_connection_get_connection(system_connection),
+ /* register to be a policy agent, just like kpowersave does */
+ policy_owner_id = g_bus_own_name_on_connection (system_connection,
"org.freedesktop.Policy.Power",
- DBUS_NAME_FLAG_REPLACE_EXISTING, NULL);
- switch (ret) {
- case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER:
- egg_debug ("Successfully acquired interface org.freedesktop.Policy.Power.");
- break;
- case DBUS_REQUEST_NAME_REPLY_IN_QUEUE:
- egg_debug ("Queued for interface org.freedesktop.Policy.Power.");
- break;
- default:
- break;
- };
+ G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, NULL, NULL, NULL);
/* Only timeout and close the mainloop if we have specified it
* on the command line */
if (timed_exit) {
timer_id = g_timeout_add_seconds (20, (GSourceFunc) timed_exit_cb, loop);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (timer_id, "[GpmMain] timed-exit");
-#endif
}
if (immediate_exit == FALSE) {
@@ -282,7 +316,10 @@ main (int argc, char *argv[])
g_main_loop_unref (loop);
- g_object_unref (session);
+ if (session_proxy != NULL)
+ g_object_unref (session_proxy);
+ if (session_proxy_client != NULL)
+ g_object_unref (session_proxy_client);
g_object_unref (manager);
unref_program:
g_option_context_free (context);
diff --git a/src/gpm-manager.c b/src/gpm-manager.c
index 0dbb76d..1790df2 100644
--- a/src/gpm-manager.c
+++ b/src/gpm-manager.c
@@ -36,8 +36,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
-#include <dbus/dbus-glib-lowlevel.h>
#include <canberra-gtk.h>
#include <libupower-glib/upower.h>
#include <libnotify/notify.h>
@@ -53,14 +51,18 @@
#include "gpm-manager.h"
#include "gpm-screensaver.h"
#include "gpm-backlight.h"
-#include "gpm-session.h"
#include "gpm-stock-icons.h"
#include "gpm-tray-icon.h"
#include "gpm-engine.h"
#include "gpm-upower.h"
#include "gpm-disks.h"
-#include "org.gnome.PowerManager.Backlight.h"
+static const gchar *power_manager_introspection = ""
+"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
+"<node name=\"/org/gnome/PowerManager\">"
+ "<interface name=\"org.gnome.PowerManager\">"
+ "</interface>"
+"</node>";
static void gpm_manager_finalize (GObject *object);
@@ -98,6 +100,9 @@ struct GpmManagerPrivate
NotifyNotification *notification_warning_low;
NotifyNotification *notification_discharging;
NotifyNotification *notification_fully_charged;
+ GDBusConnection *bus_connection;
+ guint bus_owner_id;
+ guint bus_object_id;
};
typedef enum {
@@ -235,9 +240,7 @@ gpm_manager_play_loop_start (GpmManager *manager, GpmManagerSound action, gboole
manager->priv->critical_alert_timeout_id = g_timeout_add_seconds (timeout,
(GSourceFunc) gpm_manager_play_loop_timeout_cb,
manager);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (manager->priv->critical_alert_timeout_id, "[GpmManager] play-loop");
-#endif
/* play the sound, using sounds from the naming spec */
context = ca_gtk_context_get_for_screen (gdk_screen_get_default ());
@@ -523,7 +526,6 @@ out:
return ret;
}
-
/**
* gpm_manager_sleep_failure_response_cb:
**/
@@ -664,6 +666,60 @@ gpm_manager_action_hibernate (GpmManager *manager, const gchar *reason)
}
/**
+ * gpm_manager_logout:
+ **/
+static gboolean
+gpm_manager_logout (GpmManager *manager)
+{
+ gboolean ret = FALSE;
+ GVariant *retval = NULL;
+ GError *error = NULL;
+ GDBusProxy *proxy = NULL;
+ GDBusConnection *connection;
+
+ /* connect to gnome-session */
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
+ egg_warning ("Failed to connect to the session: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+ proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ "org.gnome.SessionManager",
+ "/org/gnome/SessionManager",
+ "org.gnome.SessionManager",
+ NULL, &error);
+ if (proxy == NULL) {
+ egg_warning ("Failed to shutdown session: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* ask to shut it down */
+ retval = g_dbus_proxy_call_sync (proxy,
+ "Shutdown",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (retval == NULL) {
+ egg_debug ("Failed to shutdown session: %s", error->message);
+ g_error_free (error);
+ goto out;
+ }
+
+ /* success */
+ ret = TRUE;
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ if (proxy != NULL)
+ g_object_unref (proxy);
+ return ret;
+}
+
+/**
* gpm_manager_perform_policy:
* @manager: This class instance
* @policy: The policy that we should do, e.g. "suspend"
@@ -698,11 +754,8 @@ gpm_manager_perform_policy (GpmManager *manager, const gchar *policy_key, const
gpm_control_shutdown (manager->priv->control, NULL);
} else if (policy == GPM_ACTION_POLICY_INTERACTIVE) {
- GpmSession *session;
egg_debug ("logout, reason: %s", reason);
- session = gpm_session_new ();
- gpm_session_logout (session);
- g_object_unref (session);
+ gpm_manager_logout (manager);
} else {
egg_warning ("unknown action %i", policy);
}
@@ -1242,9 +1295,7 @@ gpm_manager_engine_perhaps_recall_cb (GpmEngine *engine, UpDevice *device, gchar
/* delay by a few seconds so the panel can load */
timer_id = g_timeout_add_seconds (GPM_MANAGER_RECALL_DELAY,
(GSourceFunc) gpm_manager_perhaps_recall_delay_cb, manager);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (timer_id, "[GpmManager] perhaps-recall");
-#endif
}
/**
@@ -1825,9 +1876,7 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan
/* wait 20 seconds for user-panic */
timer_id = g_timeout_add_seconds (20, (GSourceFunc) manager_critical_action_do, manager);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (timer_id, "[GpmManager] battery critical-action");
-#endif
} else if (kind == UP_DEVICE_KIND_UPS) {
/* TRANSLATORS: UPS is really, really, low */
@@ -1840,25 +1889,23 @@ gpm_manager_engine_charge_action_cb (GpmEngine *engine, UpDevice *device, GpmMan
if (policy == GPM_ACTION_POLICY_NOTHING) {
/* TRANSLATORS: computer will shutdown without saving data */
message = g_strdup (_("UPS is below the critical level and "
- "this computer will <b>power-off</b> when the "
- "UPS becomes completely empty."));
+ "this computer will <b>power-off</b> when the "
+ "UPS becomes completely empty."));
} else if (policy == GPM_ACTION_POLICY_HIBERNATE) {
/* TRANSLATORS: computer will hibernate */
message = g_strdup (_("UPS is below the critical level and "
- "this computer is about to hibernate."));
+ "this computer is about to hibernate."));
} else if (policy == GPM_ACTION_POLICY_SHUTDOWN) {
/* TRANSLATORS: computer will just shutdown */
message = g_strdup (_("UPS is below the critical level and "
- "this computer is about to shutdown."));
+ "this computer is about to shutdown."));
}
/* wait 20 seconds for user-panic */
timer_id = g_timeout_add_seconds (20, (GSourceFunc) manager_critical_action_do, manager);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (timer_id, "[GpmManager] ups critical-action");
-#endif
}
/* not all types have actions */
@@ -1901,9 +1948,9 @@ gpm_manager_dpms_mode_changed_cb (GpmDpms *dpms, GpmDpmsMode mode, GpmManager *m
gpm_manager_update_dpms_throttle (manager);
}
-/*
- * gpm_manager_reset_just_resumed_cb
- */
+/**
+ * gpm_manager_reset_just_resumed_cb:
+ **/
static gboolean
gpm_manager_reset_just_resumed_cb (gpointer user_data)
{
@@ -1923,7 +1970,7 @@ gpm_manager_reset_just_resumed_cb (gpointer user_data)
}
/**
- * gpm_manager_control_resume_cb
+ * gpm_manager_control_resume_cb:
**/
static void
gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, GpmManager *manager)
@@ -1931,9 +1978,97 @@ gpm_manager_control_resume_cb (GpmControl *control, GpmControlAction action, Gpm
guint timer_id;
manager->priv->just_resumed = TRUE;
timer_id = g_timeout_add_seconds (1, gpm_manager_reset_just_resumed_cb, manager);
-#if GLIB_CHECK_VERSION(2,25,8)
g_source_set_name_by_id (timer_id, "[GpmManager] just-resumed");
-#endif
+}
+
+/**
+ * gpm_manager_dbus_method_call:
+ **/
+static void
+gpm_manager_dbus_method_call (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ /* GpmManager *manager = GPM_MANAGER (user_data); */
+
+ /* do nothing, no methods defined (yet) */
+}
+
+/**
+ * gpm_manager_dbus_property_get:
+ **/
+static GVariant *
+gpm_manager_dbus_property_get (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name,
+ GError **error, gpointer user_data)
+{
+ /* GpmManager *manager = GPM_MANAGER (user_data); */
+ /* do nothing, no properties defined (yet) */
+ return NULL;
+}
+
+/**
+ * gpm_manager_dbus_property_set:
+ **/
+static gboolean
+gpm_manager_dbus_property_set (GDBusConnection *connection,
+ const gchar *sender, const gchar *object_path,
+ const gchar *interface_name, const gchar *property_name,
+ GVariant *value,
+ GError **invocation, gpointer user_data)
+{
+ /* GpmManager *manager = GPM_MANAGER (user_data); */
+ /* do nothing, no properties defined (yet) */
+ return FALSE;
+}
+
+/**
+ * gpm_manager_bus_acquired_cb:
+ **/
+static void
+gpm_manager_bus_acquired_cb (GDBusConnection *connection,
+ const gchar *name, gpointer user_data)
+{
+ GDBusNodeInfo *node_info;
+ GDBusInterfaceInfo *interface_info;
+ GpmManager *manager = GPM_MANAGER (user_data);
+ GDBusInterfaceVTable interface_vtable = {
+ gpm_manager_dbus_method_call,
+ gpm_manager_dbus_property_get,
+ gpm_manager_dbus_property_set
+ };
+
+ node_info = g_dbus_node_info_new_for_xml (power_manager_introspection, NULL);
+ interface_info = g_dbus_node_info_lookup_interface (node_info, GPM_DBUS_INTERFACE);
+
+ manager->priv->bus_connection = (GDBusConnection*) g_object_ref ((GObject*) connection);
+ manager->priv->bus_object_id = g_dbus_connection_register_object (connection,
+ GPM_DBUS_PATH,
+ interface_info,
+ &interface_vtable,
+ manager,
+ NULL,
+ NULL);
+ g_dbus_node_info_unref (node_info);
+
+ if (manager->priv->backlight != NULL) {
+ gpm_backlight_register_dbus (manager->priv->backlight, connection);
+ }
+}
+
+/**
+ * gpm_manager_name_lost_cb:
+ **/
+static void
+gpm_manager_name_lost_cb (GDBusConnection *connection,
+ const gchar *name,
+ gpointer user_data)
+{
+ egg_warning ("name lost %s", name);
}
/**
@@ -1945,12 +2080,9 @@ gpm_manager_init (GpmManager *manager)
{
gboolean check_type_cpu;
gint timeout;
- DBusGConnection *connection;
- GError *error = NULL;
guint version;
manager->priv = GPM_MANAGER_GET_PRIVATE (manager);
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
/* init to unthrottled */
manager->priv->screensaver_ac_throttle_id = 0;
@@ -2007,20 +2139,9 @@ gpm_manager_init (GpmManager *manager)
/* try and start an interactive service */
manager->priv->screensaver = gpm_screensaver_new ();
-#if 0
- g_signal_connect (manager->priv->screensaver, "auth-request",
- G_CALLBACK (gpm_manager_screensaver_auth_request_cb), manager);
-#endif
/* try an start an interactive service */
manager->priv->backlight = gpm_backlight_new ();
- if (manager->priv->backlight != NULL) {
- /* add the new brightness lcd DBUS interface */
- dbus_g_object_type_install_info (GPM_TYPE_BACKLIGHT,
- &dbus_glib_gpm_backlight_object_info);
- dbus_g_connection_register_g_object (connection, GPM_DBUS_PATH_BACKLIGHT,
- G_OBJECT (manager->priv->backlight));
- }
manager->priv->idle = gpm_idle_new ();
g_signal_connect (manager->priv->idle, "idle-changed",
@@ -2074,6 +2195,18 @@ gpm_manager_init (GpmManager *manager)
/* update ac throttle */
gpm_manager_update_ac_throttle (manager);
+
+ /* finally, register on the bus, exporting the objects */
+ manager->priv->bus_object_id = -1;
+ manager->priv->bus_owner_id =
+ g_bus_own_name (G_BUS_TYPE_SESSION,
+ GPM_DBUS_SERVICE,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ gpm_manager_bus_acquired_cb,
+ NULL,
+ gpm_manager_name_lost_cb,
+ g_object_ref (manager),
+ g_object_unref);
}
/**
@@ -2120,6 +2253,10 @@ gpm_manager_finalize (GObject *object)
g_object_unref (manager->priv->client);
g_object_unref (manager->priv->status_icon);
+ g_dbus_connection_unregister_object (manager->priv->bus_connection, manager->priv->bus_object_id);
+ g_object_unref (manager->priv->bus_connection);
+ g_bus_unown_name (manager->priv->bus_owner_id);
+
G_OBJECT_CLASS (gpm_manager_parent_class)->finalize (object);
}
diff --git a/src/gpm-manager.h b/src/gpm-manager.h
index a78509a..92a433e 100644
--- a/src/gpm-manager.h
+++ b/src/gpm-manager.h
@@ -24,7 +24,6 @@
#define __GPM_MANAGER_H
#include <glib-object.h>
-#include <dbus/dbus-glib.h>
G_BEGIN_DECLS
@@ -57,7 +56,6 @@ typedef enum
GPM_MANAGER_ERROR_LAST
} GpmManagerError;
-
GQuark gpm_manager_error_quark (void);
GType gpm_manager_error_get_type (void);
GType gpm_manager_get_type (void);
diff --git a/src/gpm-phone.c b/src/gpm-phone.c
index 7abe45e..166ddaa 100644
--- a/src/gpm-phone.c
+++ b/src/gpm-phone.c
@@ -25,7 +25,6 @@
#include <glib.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
-#include <dbus/dbus-glib.h>
#include "gpm-phone.h"
#include "egg-debug.h"
@@ -37,8 +36,8 @@ static void gpm_phone_finalize (GObject *object);
struct GpmPhonePrivate
{
- DBusGProxy *proxy;
- DBusGConnection *connection;
+ GDBusProxy *proxy;
+ GDBusConnection *connection;
guint watch_id;
gboolean present;
guint percentage;
@@ -65,6 +64,7 @@ gboolean
gpm_phone_coldplug (GpmPhone *phone)
{
GError *error = NULL;
+ GVariant *reply;
gboolean ret;
g_return_val_if_fail (phone != NULL, FALSE);
@@ -75,18 +75,24 @@ gpm_phone_coldplug (GpmPhone *phone)
return FALSE;
}
- ret = dbus_g_proxy_call (phone->priv->proxy, "Coldplug", &error,
- G_TYPE_INVALID, G_TYPE_INVALID);
+ reply = g_dbus_proxy_call_sync (phone->priv->proxy, "Coldplug",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error);
if (error != NULL) {
egg_warning ("DEBUG: ERROR: %s", error->message);
g_error_free (error);
}
+ if (reply != NULL) {
+ ret = TRUE;
+ g_variant_unref (reply);
+ } else
+ ret = FALSE;
+
return ret;
}
/**
- * gpm_phone_coldplug:
+ * gpm_phone_get_present:
* Return value: if present
**/
gboolean
@@ -98,7 +104,7 @@ gpm_phone_get_present (GpmPhone *phone, guint idx)
}
/**
- * gpm_phone_coldplug:
+ * gpm_phone_get_percentage:
* Return value: if present
**/
guint
@@ -110,7 +116,7 @@ gpm_phone_get_percentage (GpmPhone *phone, guint idx)
}
/**
- * gpm_phone_coldplug:
+ * gpm_phone_get_on_ac:
* Return value: if present
**/
gboolean
@@ -139,7 +145,7 @@ gpm_phone_get_num_batteries (GpmPhone *phone)
/** Invoked when we get the BatteryStateChanged
*/
static void
-gpm_phone_battery_state_changed (DBusGProxy *proxy, guint idx, guint percentage, gboolean on_ac, GpmPhone *phone)
+gpm_phone_battery_state_changed (GDBusProxy *proxy, guint idx, guint percentage, gboolean on_ac, GpmPhone *phone)
{
g_return_if_fail (GPM_IS_PHONE (phone));
@@ -154,7 +160,7 @@ gpm_phone_battery_state_changed (DBusGProxy *proxy, guint idx, guint percentage,
/** Invoked when we get NumberBatteriesChanged
*/
static void
-gpm_phone_num_batteries_changed (DBusGProxy *proxy, guint number, GpmPhone *phone)
+gpm_phone_num_batteries_changed (GDBusProxy *proxy, guint number, GpmPhone *phone)
{
g_return_if_fail (GPM_IS_PHONE (phone));
@@ -188,6 +194,36 @@ gpm_phone_num_batteries_changed (DBusGProxy *proxy, guint number, GpmPhone *phon
}
/**
+ * gpm_phone_generic_signal_cb:
+ */
+static void
+gpm_phone_generic_signal_cb (GDBusProxy *proxy,
+ gchar *sender_name, gchar *signal_name,
+ GVariant *parameters, gpointer user_data) {
+
+ GpmPhone *self = GPM_PHONE (user_data);
+
+ if (!g_strcmp0 (signal_name, "BatteryStateChanged")) {
+ guint idx, percentage;
+ gboolean on_ac;
+
+ g_variant_get (parameters, "(uub)", &idx, &percentage, &on_ac);
+ gpm_phone_battery_state_changed (proxy, idx, percentage, on_ac, self);
+ return;
+ }
+
+ if (!g_strcmp0 (signal_name, "NumberBatteriesChanged")) {
+ guint number;
+
+ g_variant_get (parameters, "(u)", &number);
+ gpm_phone_num_batteries_changed (proxy, number, self);
+ return;
+ }
+
+ /* not a signal we're interested in */
+}
+
+/**
* gpm_phone_class_init:
* @klass: This class instance
**/
@@ -238,8 +274,8 @@ gpm_phone_service_appeared_cb (GDBusConnection *connection,
if (phone->priv->connection == NULL) {
egg_debug ("get connection");
g_clear_error (&error);
- phone->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error != NULL) {
+ phone->priv->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (phone->priv->connection == NULL) {
egg_warning ("Could not connect to DBUS daemon: %s", error->message);
g_error_free (error);
phone->priv->connection = NULL;
@@ -249,37 +285,21 @@ gpm_phone_service_appeared_cb (GDBusConnection *connection,
if (phone->priv->proxy == NULL) {
egg_debug ("get proxy");
g_clear_error (&error);
- phone->priv->proxy = dbus_g_proxy_new_for_name_owner (phone->priv->connection,
- GNOME_PHONE_MANAGER_DBUS_SERVICE,
- GNOME_PHONE_MANAGER_DBUS_PATH,
- GNOME_PHONE_MANAGER_DBUS_INTERFACE,
- &error);
- if (error != NULL) {
+ phone->priv->proxy = g_dbus_proxy_new_sync (phone->priv->connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES,
+ NULL,
+ GNOME_PHONE_MANAGER_DBUS_SERVICE,
+ GNOME_PHONE_MANAGER_DBUS_PATH,
+ GNOME_PHONE_MANAGER_DBUS_INTERFACE,
+ NULL, &error);
+ if (phone->priv->proxy == NULL) {
egg_warning ("Cannot connect, maybe the daemon is not running: %s", error->message);
g_error_free (error);
phone->priv->proxy = NULL;
return;
}
- /* complicated type. ick */
- dbus_g_object_register_marshaller(gpm_marshal_VOID__UINT_UINT_BOOLEAN,
- G_TYPE_NONE, G_TYPE_UINT, G_TYPE_UINT,
- G_TYPE_BOOLEAN, G_TYPE_INVALID);
-
- /* get BatteryStateChanged */
- dbus_g_proxy_add_signal (phone->priv->proxy, "BatteryStateChanged",
- G_TYPE_UINT, G_TYPE_UINT, G_TYPE_BOOLEAN, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (phone->priv->proxy, "BatteryStateChanged",
- G_CALLBACK (gpm_phone_battery_state_changed),
- phone, NULL);
-
- /* get NumberBatteriesChanged */
- dbus_g_proxy_add_signal (phone->priv->proxy, "NumberBatteriesChanged",
- G_TYPE_UINT, G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (phone->priv->proxy, "NumberBatteriesChanged",
- G_CALLBACK (gpm_phone_num_batteries_changed),
- phone, NULL);
-
+ g_signal_connect (phone->priv->proxy, "g-signal", G_CALLBACK(gpm_phone_generic_signal_cb), phone);
}
}
@@ -288,8 +308,8 @@ gpm_phone_service_appeared_cb (GDBusConnection *connection,
*/
static void
gpm_phone_service_vanished_cb (GDBusConnection *connection,
- const gchar *name,
- GpmPhone *phone)
+ const gchar *name,
+ GpmPhone *phone)
{
g_return_if_fail (GPM_IS_PHONE (phone));
diff --git a/src/gpm-screensaver.c b/src/gpm-screensaver.c
index cafc4a7..63401d3 100644
--- a/src/gpm-screensaver.c
+++ b/src/gpm-screensaver.c
@@ -24,7 +24,7 @@
#include <string.h>
#include <glib.h>
#include <glib/gi18n.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include <gconf/gconf-client.h>
#include "gpm-screensaver.h"
@@ -41,7 +41,7 @@ static void gpm_screensaver_finalize (GObject *object);
struct GpmScreensaverPrivate
{
- DBusGProxy *proxy;
+ GDBusProxy *proxy;
GConfClient *conf;
};
@@ -86,8 +86,9 @@ gpm_screensaver_lock (GpmScreensaver *screensaver)
}
egg_debug ("doing gnome-screensaver lock");
- dbus_g_proxy_call_no_reply (screensaver->priv->proxy,
- "Lock", G_TYPE_INVALID);
+ g_dbus_proxy_call (screensaver->priv->proxy,
+ "Lock",
+ NULL, G_DBUS_CALL_FLAGS_NONE, -1, NULL, NULL, NULL);
/* When we send the Lock signal to g-ss it takes maybe a second
or so to fade the screen and lock. If we suspend mid fade then on
@@ -112,43 +113,45 @@ gpm_screensaver_lock (GpmScreensaver *screensaver)
/**
* gpm_screensaver_add_throttle:
* @screensaver: This class instance
- * @reason: The reason for throttling
+ * @reason: The reason for throttling
* Return value: Success value, or zero for failure
**/
guint
-gpm_screensaver_add_throttle (GpmScreensaver *screensaver,
- const char *reason)
+gpm_screensaver_add_throttle (GpmScreensaver *screensaver, const char *reason)
{
- GError *error = NULL;
- gboolean ret;
- guint32 cookie;
+ GError *error = NULL;
+ GVariant *retval = NULL;
+ guint32 cookie = 0;
g_return_val_if_fail (GPM_IS_SCREENSAVER (screensaver), 0);
g_return_val_if_fail (reason != NULL, 0);
if (screensaver->priv->proxy == NULL) {
- egg_warning ("not connected");
- return 0;
+ egg_warning ("not connected to the screensaver");
+ goto out;
}
- ret = dbus_g_proxy_call (screensaver->priv->proxy,
- "Throttle", &error,
- G_TYPE_STRING, "Power screensaver",
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_UINT, &cookie,
- G_TYPE_INVALID);
- if (error) {
- egg_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- if (!ret) {
+ retval = g_dbus_proxy_call_sync (screensaver->priv->proxy,
+ "Throttle",
+ g_variant_new ("(ss)",
+ "Power screensaver",
+ reason),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ if (retval == NULL) {
/* abort as the DBUS method failed */
- egg_warning ("Throttle failed!");
- return 0;
+ egg_warning ("Throttle failed: %s", error->message);
+ g_error_free (error);
+ goto out;
}
+ /* success */
+ g_variant_get (retval, "(s)", &cookie);
egg_debug ("adding throttle reason: '%s': id %u", reason, cookie);
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
return cookie;
}
@@ -158,33 +161,37 @@ gpm_screensaver_add_throttle (GpmScreensaver *screensaver,
gboolean
gpm_screensaver_remove_throttle (GpmScreensaver *screensaver, guint cookie)
{
- gboolean ret;
+ gboolean ret = FALSE;
+ GVariant *retval = NULL;
GError *error = NULL;
g_return_val_if_fail (GPM_IS_SCREENSAVER (screensaver), FALSE);
if (screensaver->priv->proxy == NULL) {
- egg_warning ("not connected");
- return FALSE;
+ egg_warning ("not connected to the screensaver");
+ goto out;
}
egg_debug ("removing throttle: id %u", cookie);
- ret = dbus_g_proxy_call (screensaver->priv->proxy,
- "UnThrottle", &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (error) {
- egg_debug ("ERROR: %s", error->message);
- g_error_free (error);
- }
- if (!ret) {
+ retval = g_dbus_proxy_call_sync (screensaver->priv->proxy,
+ "UnThrottle",
+ g_variant_new ("(s)", cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL,
+ &error);
+ if (retval == NULL) {
/* abort as the DBUS method failed */
- egg_warning ("UnThrottle failed!");
+ egg_warning ("UnThrottle failed!: %s", error->message);
+ g_error_free (error);
return FALSE;
}
- return TRUE;
+ /* success */
+ ret = TRUE;
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ return ret;
}
/**
@@ -195,28 +202,34 @@ gpm_screensaver_remove_throttle (GpmScreensaver *screensaver, guint cookie)
gboolean
gpm_screensaver_check_running (GpmScreensaver *screensaver)
{
- gboolean ret;
- gboolean temp = TRUE;
+ GVariant *retval = NULL;
+ gboolean active = FALSE;
GError *error = NULL;
g_return_val_if_fail (GPM_IS_SCREENSAVER (screensaver), FALSE);
if (screensaver->priv->proxy == NULL) {
- egg_warning ("not connected");
- return FALSE;
+ egg_warning ("not connected to screensaver");
+ goto out;
}
- ret = dbus_g_proxy_call (screensaver->priv->proxy,
- "GetActive", &error,
- G_TYPE_INVALID,
- G_TYPE_BOOLEAN, &temp,
- G_TYPE_INVALID);
- if (error) {
+ retval = g_dbus_proxy_call_sync (screensaver->priv->proxy,
+ "GetActive",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (retval == NULL) {
egg_debug ("ERROR: %s", error->message);
g_error_free (error);
+ goto out;
}
- return ret;
+ /* success */
+ g_variant_get (retval, "(b)", &active);
+out:
+ if (retval != NULL)
+ g_variant_unref (retval);
+ return active;
}
/**
@@ -238,9 +251,11 @@ gpm_screensaver_poke (GpmScreensaver *screensaver)
}
egg_debug ("poke");
- dbus_g_proxy_call_no_reply (screensaver->priv->proxy,
- "SimulateUserActivity",
- G_TYPE_INVALID);
+ g_dbus_proxy_call (screensaver->priv->proxy,
+ "SimulateUserActivity",
+ NULL, G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, NULL, NULL);
+
return TRUE;
}
@@ -263,17 +278,25 @@ gpm_screensaver_class_init (GpmScreensaverClass *klass)
static void
gpm_screensaver_init (GpmScreensaver *screensaver)
{
- DBusGConnection *connection;
+ GDBusConnection *connection;
+ GError *error = NULL;
screensaver->priv = GPM_SCREENSAVER_GET_PRIVATE (screensaver);
- connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
-
- screensaver->priv->proxy = dbus_g_proxy_new_for_name (connection,
- GS_LISTENER_SERVICE,
- GS_LISTENER_PATH,
- GS_LISTENER_INTERFACE);
-
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, NULL);
+ screensaver->priv->proxy =
+ g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES |
+ G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ GS_LISTENER_SERVICE,
+ GS_LISTENER_PATH,
+ GS_LISTENER_INTERFACE,
+ NULL, &error);
+ if (screensaver->priv->proxy == NULL) {
+ egg_warning ("failed to setup screensaver proxy: %s", error->message);
+ g_error_free (error);
+ }
screensaver->priv->conf = gconf_client_get_default ();
}
diff --git a/src/gpm-statistics.c b/src/gpm-statistics.c
index fda1bae..4671a37 100644
--- a/src/gpm-statistics.c
+++ b/src/gpm-statistics.c
@@ -27,7 +27,6 @@
#include <glib/gi18n.h>
#include <gtk/gtk.h>
-#include <dbus/dbus-glib.h>
#include <gconf/gconf-client.h>
#include <libupower-glib/upower.h>
@@ -776,7 +775,6 @@ gpm_stats_update_info_data (UpDevice *device)
"has-statistics", &has_statistics,
NULL);
-
notebook = GTK_NOTEBOOK (gtk_builder_get_object (builder, "notebook1"));
/* show info page */
@@ -1755,7 +1753,6 @@ gpm_stats_startup_cb (GApplication *application,
g_signal_connect (G_OBJECT (widget), "changed",
G_CALLBACK (gpm_stats_range_combo_changed), NULL);
-
wakeups = up_wakeups_new ();
g_signal_connect (wakeups, "data-changed", G_CALLBACK (gpm_stats_data_changed_cb), NULL);
@@ -1832,7 +1829,6 @@ main (int argc, char *argv[])
if (! g_thread_supported ())
g_thread_init (NULL);
- dbus_g_thread_init ();
g_type_init ();
gtk_init (&argc, &argv);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]