[sound-juicer] Port inhibit from GDbus to gio
- From: Ross Burton <rburton src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [sound-juicer] Port inhibit from GDbus to gio
- Date: Fri, 9 Dec 2011 14:21:57 +0000 (UTC)
commit 265a47a6fb58da2a0358ccbb981f0424993643ee
Author: Michael Wood <michael g wood linux intel com>
Date: Thu Dec 8 18:48:08 2011 +0000
Port inhibit from GDbus to gio
configure.in | 6 +--
src/sj-inhibit.c | 160 +++++++++++++++++++++++++-----------------------------
2 files changed, 75 insertions(+), 91 deletions(-)
---
diff --git a/configure.in b/configure.in
index 2eb8ec0..63bd52b 100644
--- a/configure.in
+++ b/configure.in
@@ -56,7 +56,7 @@ LIBS="$LIBS $BURN_LIBS"
# LIBS="$oldlibs"
# Find the UI libraries
-PKG_CHECK_MODULES(UI, gtk+-3.0 >= $GTK_REQUIRED gconf-2.0 gio-2.0 gmodule-export-2.0 dbus-glib-1 libcanberra-gtk3)
+PKG_CHECK_MODULES(UI, gtk+-3.0 >= $GTK_REQUIRED gconf-2.0 gio-2.0 gmodule-export-2.0 libcanberra-gtk3)
AC_SUBST(UI_CFLAGS)
AC_SUBST(UI_LIBS)
@@ -91,10 +91,6 @@ PKG_CHECK_MODULES(GIO, gio-2.0)
AC_SUBST(GIO_CFLAGS)
AC_SUBST(GIO_LIBS)
-PKG_CHECK_MODULES(DBUS, dbus-1)
-AC_SUBST(DBUS_CFLAGS)
-AC_SUBST(DBUS_LIBS)
-
# Find how and where to put the GConf schemas
AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
if test "$GCONFTOOL" = "no"; then
diff --git a/src/sj-inhibit.c b/src/sj-inhibit.c
index 7edc28a..6685af7 100644
--- a/src/sj-inhibit.c
+++ b/src/sj-inhibit.c
@@ -25,7 +25,7 @@
#include <config.h>
#endif
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#include "sj-inhibit.h"
@@ -38,106 +38,94 @@
guint
sj_inhibit (const gchar * appname, const gchar * reason, guint xid)
{
- gboolean res;
guint cookie;
GError *error = NULL;
- DBusGProxy *proxy = NULL;
- DBusGConnection *session_connection = NULL;
-
- /* get the DBUS session connection */
- session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error != NULL) {
- g_warning ("DBUS cannot connect : %s", error->message);
- g_error_free (error);
+ GDBusProxy *proxy = NULL;
+ GVariant *variant;
+
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ PM_DBUS_SERVICE,
+ PM_DBUS_INHIBIT_PATH,
+ PM_DBUS_INHIBIT_INTERFACE,
+ NULL,
+ &error);
+
+ if (!proxy)
+ {
+ g_warning ("Could not get DBUS proxy: %s", error->message);
+ g_clear_error (&error);
return 0;
}
- /* get the proxy for PowerManagement */
- proxy = dbus_g_proxy_new_for_name (session_connection,
- PM_DBUS_SERVICE,
- PM_DBUS_INHIBIT_PATH,
- PM_DBUS_INHIBIT_INTERFACE);
- if (proxy == NULL) {
- g_warning ("Could not get DBUS proxy: %s", PM_DBUS_SERVICE);
- return 0;
- }
-
- res = dbus_g_proxy_call (proxy,
- "Inhibit", &error,
- G_TYPE_STRING, appname, /* app-id */
- G_TYPE_UINT, xid,
- G_TYPE_STRING, reason,
- G_TYPE_UINT, 4+8, /* flags, inhibit being marked idle and allowing suspend */
- G_TYPE_INVALID,
- G_TYPE_UINT, &cookie,
- G_TYPE_INVALID);
-
- /* check the return value */
- if (!res) {
- cookie = 0;
- g_warning ("Inhibit method failed");
- }
- /* check the error value */
- if (error != NULL) {
- g_warning ("Inhibit problem : %s", error->message);
- g_error_free (error);
- cookie = 0;
- }
+ variant = g_dbus_proxy_call_sync (proxy,
+ "Inhibit",
+ g_variant_new ("(susu)",
+ appname,
+ xid,
+ reason,
+ 4+8),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ &error);
+ if (variant)
+ {
+ g_variant_get (variant, "(u)", &cookie);
+ g_variant_unref (variant);
+ }
+ else
+ {
+ g_warning ("Problem calling inhibit %s", error->message);
+ }
+
+ g_object_unref (proxy);
- g_object_unref (G_OBJECT (proxy));
return cookie;
}
void
sj_uninhibit (guint cookie)
{
- gboolean res;
GError *error = NULL;
- DBusGProxy *proxy = NULL;
- DBusGConnection *session_connection = NULL;
+ GDBusProxy *proxy = NULL;
/* check if the cookie is valid */
- if (cookie <= 0) {
- g_warning ("Invalid cookie");
- return;
- }
-
- /* get the DBUS session connection */
- session_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (error) {
- g_warning ("DBUS cannot connect : %s", error->message);
- g_error_free (error);
- return;
- }
-
- /* get the proxy for PowerManagement */
- proxy = dbus_g_proxy_new_for_name (session_connection,
- PM_DBUS_SERVICE,
- PM_DBUS_INHIBIT_PATH,
- PM_DBUS_INHIBIT_INTERFACE);
- if (proxy == NULL) {
- g_warning ("Could not get DBUS proxy: %s", PM_DBUS_SERVICE);
- return;
- }
-
- res = dbus_g_proxy_call (proxy,
- "Uninhibit",
- &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
-
- /* check the return value */
- if (!res) {
- g_warning ("Uninhibit method failed");
- }
-
- /* check the error value */
- if (error != NULL) {
- g_warning ("Inhibit problem : %s", error->message);
- g_error_free (error);
- }
- g_object_unref (G_OBJECT (proxy));
+ if (cookie <= 0)
+ {
+ g_warning ("Invalid cookie");
+ return;
+ }
+
+
+ proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SESSION,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ PM_DBUS_SERVICE,
+ PM_DBUS_INHIBIT_PATH,
+ PM_DBUS_INHIBIT_INTERFACE,
+ NULL,
+ &error);
+
+ if (!proxy)
+ {
+ g_warning ("Could not get DBUS proxy: %s", error->message);
+ g_clear_error (&error);
+ return;
+ }
+
+ g_dbus_proxy_call_sync (proxy, "Uninhibit",
+ g_variant_new ("(u)", cookie),
+ G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+ &error);
+
+ if (error)
+ {
+ g_warning ("Problem uninhibiting: %s", error->message);
+ g_clear_error (&error);
+ }
+
+ g_object_unref (proxy);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]