[gnome-session] tests: port to GDBus
- From: Ray Strode <halfline src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-session] tests: port to GDBus
- Date: Fri, 12 Dec 2014 15:16:42 +0000 (UTC)
commit b47a3a3c4001dbc8743880c27dab371ba0494c5d
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Oct 25 19:55:33 2014 -0700
tests: port to GDBus
https://bugzilla.gnome.org/show_bug.cgi?id=622924
gnome-session/Makefile.am | 2 +-
gnome-session/test-client-dbus.c | 185 +++++++++++++++++++-------------------
gnome-session/test-inhibit.c | 71 ++++++++-------
3 files changed, 132 insertions(+), 126 deletions(-)
---
diff --git a/gnome-session/Makefile.am b/gnome-session/Makefile.am
index 64342bc..c70c542 100644
--- a/gnome-session/Makefile.am
+++ b/gnome-session/Makefile.am
@@ -127,7 +127,7 @@ test_inhibit_SOURCES = test-inhibit.c
test_inhibit_LDADD = $(GTK3_LIBS) $(GNOME_SESSION_LIBS)
test_client_dbus_SOURCES = test-client-dbus.c
-test_client_dbus_LDADD = $(DBUS_GLIB_LIBS)
+test_client_dbus_LDADD = $(GIO_LIBS)
test_process_helper_SOURCES = test-process-helper.c gsm-process-helper.c gsm-process-helper.h
test_process_helper_CFLAGS = $(AM_CFLAGS) $(GIO_CFLAGS)
diff --git a/gnome-session/test-client-dbus.c b/gnome-session/test-client-dbus.c
index e646a37..7d6f9e4 100644
--- a/gnome-session/test-client-dbus.c
+++ b/gnome-session/test-client-dbus.c
@@ -25,7 +25,7 @@
#include <unistd.h>
#include <glib.h>
-#include <dbus/dbus-glib.h>
+#include <gio/gio.h>
#define SM_DBUS_NAME "org.gnome.SessionManager"
#define SM_DBUS_PATH "/org/gnome/SessionManager"
@@ -33,22 +33,22 @@
#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
-static DBusGConnection *bus_connection = NULL;
-static DBusGProxy *sm_proxy = NULL;
+static GDBusConnection *connection = NULL;
+static GDBusProxy *sm_proxy = NULL;
static char *client_id = NULL;
-static DBusGProxy *client_proxy = NULL;
+static GDBusProxy *client_proxy = NULL;
static GMainLoop *main_loop = NULL;
static gboolean
session_manager_connect (void)
{
- if (bus_connection == NULL) {
+ if (connection == NULL) {
GError *error;
error = NULL;
- bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (bus_connection == NULL) {
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
g_message ("Failed to connect to the session bus: %s",
error->message);
g_error_free (error);
@@ -56,134 +56,136 @@ session_manager_connect (void)
}
}
- sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
- SM_DBUS_NAME,
- SM_DBUS_PATH,
- SM_DBUS_INTERFACE);
+ sm_proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ SM_DBUS_NAME,
+ SM_DBUS_PATH,
+ SM_DBUS_INTERFACE,
+ NULL, NULL);
return (sm_proxy != NULL);
}
static void
-on_client_query_end_session (DBusGProxy *proxy,
- guint flags,
- gpointer data)
+on_client_query_end_session (GDBusProxy *proxy,
+ GVariant *parameters)
{
GError *error;
gboolean is_ok;
- gboolean res;
const char *reason;
+ guint flags;
+ GVariant *reply;
is_ok = FALSE;
reason = "Unsaved files";
+ g_variant_get (parameters, "(u)", &flags);
g_debug ("Got query end session signal flags=%u", flags);
error = NULL;
- res = dbus_g_proxy_call (proxy,
- "EndSessionResponse",
- &error,
- G_TYPE_BOOLEAN, is_ok,
- G_TYPE_STRING, reason,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
-
- if (! res) {
+ reply = g_dbus_proxy_call_sync (proxy,
+ "EndSessionResponse",
+ g_variant_new ("(bs)",
+ is_ok,
+ reason),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error != NULL) {
g_warning ("Failed to respond to EndSession: %s", error->message);
g_error_free (error);
+ } else {
+ g_variant_unref (reply);
}
}
static void
-on_client_end_session (DBusGProxy *proxy,
- guint flags,
- gpointer data)
+on_client_end_session (GVariant *parameters)
{
+ guint flags;
+ g_variant_get (parameters, "(u)", &flags);
g_debug ("Got end session signal flags=%u", flags);
}
static void
-on_client_cancel_end_session (DBusGProxy *proxy,
- gpointer data)
+on_client_cancel_end_session (void)
{
g_debug ("Got end session cancelled signal");
}
static void
-on_client_stop (DBusGProxy *proxy,
- gpointer data)
+on_client_stop (void)
{
g_debug ("Got client stop signal");
g_main_loop_quit (main_loop);
}
+static void
+on_client_dbus_signal (GDBusProxy *proxy,
+ gchar *sender_name,
+ gchar *signal_name,
+ GVariant *parameters,
+ gpointer user_data)
+{
+ if (g_strcmp0 (signal_name, "Stop") == 0) {
+ on_client_stop ();
+ } else if (g_strcmp0 (signal_name, "CancelEndSession") == 0) {
+ on_client_cancel_end_session ();
+ } else if (g_strcmp0 (signal_name, "EndSession") == 0) {
+ on_client_end_session (parameters);
+ } else if (g_strcmp0 (signal_name, "QueryEndSession") == 0) {
+ on_client_query_end_session (proxy, parameters);
+ }
+}
+
static gboolean
register_client (void)
{
GError *error;
- gboolean res;
+ GVariant *object_path_variant;
const char *startup_id;
const char *app_id;
- startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
app_id = "gedit";
+ startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+ if (!startup_id) {
+ startup_id = "";
+ }
+
error = NULL;
- res = dbus_g_proxy_call (sm_proxy,
- "RegisterClient",
- &error,
- G_TYPE_STRING, app_id,
- G_TYPE_STRING, startup_id,
- G_TYPE_INVALID,
- DBUS_TYPE_G_OBJECT_PATH, &client_id,
- G_TYPE_INVALID);
- if (! res) {
+ object_path_variant = g_dbus_proxy_call_sync (sm_proxy,
+ "RegisterClient",
+ g_variant_new ("(ss)",
+ app_id,
+ startup_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error != NULL) {
g_warning ("Failed to register client: %s", error->message);
g_error_free (error);
return FALSE;
}
+ g_variant_get (object_path_variant, "(o)", &client_id);
g_debug ("Client registered with session manager: %s", client_id);
- client_proxy = dbus_g_proxy_new_for_name (bus_connection,
- SM_DBUS_NAME,
- client_id,
- SM_CLIENT_DBUS_INTERFACE);
- dbus_g_proxy_add_signal (client_proxy,
- "QueryEndSession",
- G_TYPE_UINT,
- G_TYPE_INVALID);
- dbus_g_proxy_add_signal (client_proxy,
- "EndSession",
- G_TYPE_UINT,
- G_TYPE_INVALID);
- dbus_g_proxy_add_signal (client_proxy,
- "CancelEndSession",
- G_TYPE_UINT,
- G_TYPE_INVALID);
- dbus_g_proxy_add_signal (client_proxy,
- "Stop",
- G_TYPE_INVALID);
- dbus_g_proxy_connect_signal (client_proxy,
- "QueryEndSession",
- G_CALLBACK (on_client_query_end_session),
- NULL,
- NULL);
- dbus_g_proxy_connect_signal (client_proxy,
- "EndSession",
- G_CALLBACK (on_client_end_session),
- NULL,
- NULL);
- dbus_g_proxy_connect_signal (client_proxy,
- "CancelEndSession",
- G_CALLBACK (on_client_cancel_end_session),
- NULL,
- NULL);
- dbus_g_proxy_connect_signal (client_proxy,
- "Stop",
- G_CALLBACK (on_client_stop),
- NULL,
- NULL);
- return TRUE;
+ client_proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ SM_DBUS_NAME,
+ client_id,
+ SM_CLIENT_DBUS_INTERFACE,
+ NULL, NULL);
+ if (client_proxy != NULL) {
+ g_signal_connect (client_proxy, "g-signal",
+ G_CALLBACK (on_client_dbus_signal), NULL);
+ }
+
+ g_variant_unref (object_path_variant);
+
+ return (client_proxy != NULL);
}
static gboolean
@@ -200,17 +202,16 @@ session_manager_disconnect (void)
static gboolean
unregister_client (void)
{
- GError *error;
- gboolean res;
+ GError *error;
+ GVariant *reply;
error = NULL;
- res = dbus_g_proxy_call (sm_proxy,
- "UnregisterClient",
- &error,
- DBUS_TYPE_G_OBJECT_PATH, client_id,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (! res) {
+ reply = g_dbus_proxy_call_sync (sm_proxy,
+ "UnregisterClient",
+ g_variant_new ("(o)", client_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error != NULL) {
g_warning ("Failed to unregister client: %s", error->message);
g_error_free (error);
return FALSE;
@@ -219,6 +220,8 @@ unregister_client (void)
g_free (client_id);
client_id = NULL;
+ g_variant_unref (reply);
+
return TRUE;
}
diff --git a/gnome-session/test-inhibit.c b/gnome-session/test-inhibit.c
index 6029d38..0a8417e 100644
--- a/gnome-session/test-inhibit.c
+++ b/gnome-session/test-inhibit.c
@@ -26,26 +26,25 @@
#include <gtk/gtk.h>
#include <gdk/gdkx.h>
-#include <dbus/dbus-glib.h>
#define SM_DBUS_NAME "org.gnome.SessionManager"
#define SM_DBUS_PATH "/org/gnome/SessionManager"
#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
-static DBusGConnection *bus_connection = NULL;
-static DBusGProxy *sm_proxy = NULL;
+static GDBusConnection *connection = NULL;
+static GDBusProxy *sm_proxy = NULL;
static guint cookie = 0;
static gboolean
session_manager_connect (void)
{
- if (bus_connection == NULL) {
+ if (connection == NULL) {
GError *error;
error = NULL;
- bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
- if (bus_connection == NULL) {
+ connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+ if (connection == NULL) {
g_message ("Failed to connect to the session bus: %s",
error->message);
g_error_free (error);
@@ -53,10 +52,13 @@ session_manager_connect (void)
}
}
- sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
- SM_DBUS_NAME,
- SM_DBUS_PATH,
- SM_DBUS_INTERFACE);
+ sm_proxy = g_dbus_proxy_new_sync (connection,
+ G_DBUS_PROXY_FLAGS_NONE,
+ NULL,
+ SM_DBUS_NAME,
+ SM_DBUS_PATH,
+ SM_DBUS_INTERFACE,
+ NULL, NULL);
return (sm_proxy != NULL);
}
@@ -70,7 +72,7 @@ static gboolean
do_inhibit_for_window (GdkWindow *window)
{
GError *error;
- gboolean res;
+ GVariant *cookie_variant;
const char *app_id;
const char *reason;
guint toplevel_xid;
@@ -89,33 +91,33 @@ do_inhibit_for_window (GdkWindow *window)
| GSM_INHIBITOR_FLAG_SUSPEND;
error = NULL;
- res = dbus_g_proxy_call (sm_proxy,
- "Inhibit",
- &error,
- G_TYPE_STRING, app_id,
- G_TYPE_UINT, toplevel_xid,
- G_TYPE_STRING, reason,
- G_TYPE_UINT, flags,
- G_TYPE_INVALID,
- G_TYPE_UINT, &cookie,
- G_TYPE_INVALID);
- if (! res) {
+ cookie_variant = g_dbus_proxy_call_sync (sm_proxy,
+ "Inhibit",
+ g_variant_new ("(susu)",
+ app_id,
+ toplevel_xid,
+ reason,
+ flags),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+
+ if (error != NULL) {
g_warning ("Failed to inhibit: %s", error->message);
g_error_free (error);
return FALSE;
}
+ g_variant_get (cookie_variant, "(u)", &cookie);
g_debug ("Inhibiting session manager: %u", cookie);
+ g_variant_unref (cookie_variant);
return TRUE;
}
static gboolean
session_manager_disconnect (void)
{
- if (sm_proxy != NULL) {
- g_object_unref (sm_proxy);
- sm_proxy = NULL;
- }
+ g_clear_object (&sm_proxy);
+ g_clear_object (&connection);
return TRUE;
}
@@ -124,21 +126,22 @@ static gboolean
do_uninhibit (void)
{
GError *error;
- gboolean res;
+ GVariant *reply;
error = NULL;
- res = dbus_g_proxy_call (sm_proxy,
- "Uninhibit",
- &error,
- G_TYPE_UINT, cookie,
- G_TYPE_INVALID,
- G_TYPE_INVALID);
- if (! res) {
+ reply = g_dbus_proxy_call_sync (sm_proxy,
+ "Uninhibit",
+ g_variant_new ("(u)", cookie),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (error != NULL) {
g_warning ("Failed to uninhibit: %s", error->message);
g_error_free (error);
return FALSE;
}
+ g_variant_unref (reply);
+
cookie = 0;
return TRUE;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]