summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mate-session/Makefile.am2
-rw-r--r--mate-session/test-client-dbus.c186
2 files changed, 96 insertions, 92 deletions
diff --git a/mate-session/Makefile.am b/mate-session/Makefile.am
index 4b2e3f1..093c908 100644
--- a/mate-session/Makefile.am
+++ b/mate-session/Makefile.am
@@ -93,7 +93,7 @@ test_inhibit_SOURCES = test-inhibit.c
test_inhibit_LDADD = $(MATE_SESSION_LIBS)
test_client_dbus_SOURCES = test-client-dbus.c
-test_client_dbus_LDADD = $(DBUS_GLIB_LIBS)
+test_client_dbus_LDADD = $(MATE_SESSION_LIBS)
gsm-marshal.c: gsm-marshal.list
$(AM_V_GEN)echo "#include \"gsm-marshal.h\"" > $@ && \
diff --git a/mate-session/test-client-dbus.c b/mate-session/test-client-dbus.c
index 70f7d3a..ccb40b1 100644
--- a/mate-session/test-client-dbus.c
+++ b/mate-session/test-client-dbus.c
@@ -27,7 +27,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"
@@ -35,16 +35,10 @@
#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
-#ifdef __GNUC__
-#define UNUSED_VARIABLE __attribute__ ((unused))
-#else
-#define UNUSED_VARIABLE
-#endif
-
-static DBusGConnection *bus_connection = NULL;
-static DBusGProxy *sm_proxy = NULL;
+static GDBusConnection *bus_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
@@ -55,7 +49,7 @@ session_manager_connect (void)
GError *error;
error = NULL;
- bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+ bus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
if (bus_connection == NULL) {
g_message ("Failed to connect to the session bus: %s",
error->message);
@@ -64,129 +58,138 @@ 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 (bus_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 UNUSED_VARIABLE res;
+ GVariant *res;
+ guint flags;
const char *reason;
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);
+ res = g_dbus_proxy_call_sync (proxy,
+ "EndSessionResponse",
+ g_variant_new ("(bs)",
+ is_ok,
+ reason),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ &error);
+ if (res == NULL) {
+ g_warning ("Failed to respond to EndSession: %s", error->message);
+ g_error_free (error);
+ } else {
+ g_variant_unref (res);
+ }
}
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 *res;
const char *startup_id;
const char *app_id;
startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
+ if (!startup_id) {
+ startup_id = "";
+ }
app_id = "gedit";
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) {
+ res = 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 (res == NULL) {
g_warning ("Failed to register client: %s", error->message);
g_error_free (error);
return FALSE;
}
+ g_variant_get (res, "(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 (bus_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 (res);
+
+ return (client_proxy != NULL);
}
static gboolean
@@ -204,16 +207,15 @@ static gboolean
unregister_client (void)
{
GError *error;
- gboolean res;
+ GVariant *res;
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) {
+ res = g_dbus_proxy_call_sync (sm_proxy,
+ "UnregisterClient",
+ g_variant_new ("(o)", client_id),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1, NULL, &error);
+ if (res == NULL) {
g_warning ("Failed to unregister client: %s", error->message);
g_error_free (error);
return FALSE;
@@ -222,6 +224,8 @@ unregister_client (void)
g_free (client_id);
client_id = NULL;
+ g_variant_unref (res);
+
return TRUE;
}