Skip to content

Commit f1427f0

Browse files
yetistmonsta
authored andcommitted
Migrate from dbus-glib to gdbus
- mate-session/Makefile.am - mate-session/test-client-dbus.c
1 parent 413050e commit f1427f0

File tree

2 files changed

+96
-92
lines changed

2 files changed

+96
-92
lines changed

‎mate-session/Makefile.am‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ test_inhibit_SOURCES = test-inhibit.c
9393
test_inhibit_LDADD = $(MATE_SESSION_LIBS)
9494

9595
test_client_dbus_SOURCES = test-client-dbus.c
96-
test_client_dbus_LDADD = $(DBUS_GLIB_LIBS)
96+
test_client_dbus_LDADD = $(MATE_SESSION_LIBS)
9797

9898
gsm-marshal.c: gsm-marshal.list
9999
$(AM_V_GEN)echo "#include \"gsm-marshal.h\"" > $@ && \

‎mate-session/test-client-dbus.c‎

Lines changed: 95 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,18 @@
2727
#include <unistd.h>
2828

2929
#include <glib.h>
30-
#include <dbus/dbus-glib.h>
30+
#include <gio/gio.h>
3131

3232
#define SM_DBUS_NAME "org.gnome.SessionManager"
3333
#define SM_DBUS_PATH "/org/gnome/SessionManager"
3434
#define SM_DBUS_INTERFACE "org.gnome.SessionManager"
3535

3636
#define SM_CLIENT_DBUS_INTERFACE "org.gnome.SessionManager.ClientPrivate"
3737

38-
#ifdef __GNUC__
39-
#define UNUSED_VARIABLE __attribute__ ((unused))
40-
#else
41-
#define UNUSED_VARIABLE
42-
#endif
43-
44-
static DBusGConnection *bus_connection = NULL;
45-
static DBusGProxy *sm_proxy = NULL;
38+
static GDBusConnection *bus_connection = NULL;
39+
static GDBusProxy *sm_proxy = NULL;
4640
static char *client_id = NULL;
47-
static DBusGProxy *client_proxy = NULL;
41+
static GDBusProxy *client_proxy = NULL;
4842
static GMainLoop *main_loop = NULL;
4943

5044
static gboolean
@@ -55,7 +49,7 @@ session_manager_connect (void)
5549
GError *error;
5650

5751
error = NULL;
58-
bus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
52+
bus_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
5953
if (bus_connection == NULL) {
6054
g_message ("Failed to connect to the session bus: %s",
6155
error->message);
@@ -64,129 +58,138 @@ session_manager_connect (void)
6458
}
6559
}
6660

67-
sm_proxy = dbus_g_proxy_new_for_name (bus_connection,
68-
SM_DBUS_NAME,
69-
SM_DBUS_PATH,
70-
SM_DBUS_INTERFACE);
61+
sm_proxy = g_dbus_proxy_new_sync (bus_connection,
62+
G_DBUS_PROXY_FLAGS_NONE,
63+
NULL,
64+
SM_DBUS_NAME,
65+
SM_DBUS_PATH,
66+
SM_DBUS_INTERFACE,
67+
NULL,
68+
NULL);
7169
return (sm_proxy != NULL);
7270
}
7371

7472
static void
75-
on_client_query_end_session (DBusGProxy *proxy,
76-
guint flags,
77-
gpointer data)
73+
on_client_query_end_session (GDBusProxy *proxy,
74+
GVariant *parameters)
7875
{
7976
GError *error;
8077
gboolean is_ok;
81-
gboolean UNUSED_VARIABLE res;
78+
GVariant *res;
79+
guint flags;
8280
const char *reason;
8381

8482
is_ok = FALSE;
8583
reason = "Unsaved files";
84+
g_variant_get (parameters, "(u)", &flags);
8685

8786
g_debug ("Got query end session signal flags=%u", flags);
8887

8988
error = NULL;
90-
res = dbus_g_proxy_call (proxy,
91-
"EndSessionResponse",
92-
&error,
93-
G_TYPE_BOOLEAN, is_ok,
94-
G_TYPE_STRING, reason,
95-
G_TYPE_INVALID,
96-
G_TYPE_INVALID);
89+
res = g_dbus_proxy_call_sync (proxy,
90+
"EndSessionResponse",
91+
g_variant_new ("(bs)",
92+
is_ok,
93+
reason),
94+
G_DBUS_CALL_FLAGS_NONE,
95+
-1,
96+
NULL,
97+
&error);
98+
if (res == NULL) {
99+
g_warning ("Failed to respond to EndSession: %s", error->message);
100+
g_error_free (error);
101+
} else {
102+
g_variant_unref (res);
103+
}
97104
}
98105

99106
static void
100-
on_client_end_session (DBusGProxy *proxy,
101-
guint flags,
102-
gpointer data)
107+
on_client_end_session (GVariant *parameters)
103108
{
109+
guint flags;
110+
g_variant_get (parameters, "(u)", &flags);
104111
g_debug ("Got end session signal flags=%u", flags);
105112
}
106113

107114
static void
108-
on_client_cancel_end_session (DBusGProxy *proxy,
109-
gpointer data)
115+
on_client_cancel_end_session (void)
110116
{
111117
g_debug ("Got end session cancelled signal");
112118
}
113119

114120
static void
115-
on_client_stop (DBusGProxy *proxy,
116-
gpointer data)
121+
on_client_stop (void)
117122
{
118123
g_debug ("Got client stop signal");
119124
g_main_loop_quit (main_loop);
120125
}
121126

127+
static void
128+
on_client_dbus_signal (GDBusProxy *proxy,
129+
gchar *sender_name,
130+
gchar *signal_name,
131+
GVariant *parameters,
132+
gpointer user_data)
133+
{
134+
if (g_strcmp0 (signal_name, "Stop") == 0) {
135+
on_client_stop ();
136+
} else if (g_strcmp0 (signal_name, "CancelEndSession") == 0) {
137+
on_client_cancel_end_session ();
138+
} else if (g_strcmp0 (signal_name, "EndSession") == 0) {
139+
on_client_end_session (parameters);
140+
} else if (g_strcmp0 (signal_name, "QueryEndSession") == 0) {
141+
on_client_query_end_session (proxy, parameters);
142+
}
143+
}
144+
122145
static gboolean
123146
register_client (void)
124147
{
125148
GError *error;
126-
gboolean res;
149+
GVariant *res;
127150
const char *startup_id;
128151
const char *app_id;
129152

130153
startup_id = g_getenv ("DESKTOP_AUTOSTART_ID");
154+
if (!startup_id) {
155+
startup_id = "";
156+
}
131157
app_id = "gedit";
132158

133159
error = NULL;
134-
res = dbus_g_proxy_call (sm_proxy,
135-
"RegisterClient",
136-
&error,
137-
G_TYPE_STRING, app_id,
138-
G_TYPE_STRING, startup_id,
139-
G_TYPE_INVALID,
140-
DBUS_TYPE_G_OBJECT_PATH, &client_id,
141-
G_TYPE_INVALID);
142-
if (! res) {
160+
res = g_dbus_proxy_call_sync (sm_proxy,
161+
"RegisterClient",
162+
g_variant_new ("(ss)",
163+
app_id,
164+
startup_id),
165+
G_DBUS_CALL_FLAGS_NONE,
166+
-1,
167+
NULL,
168+
&error);
169+
if (res == NULL) {
143170
g_warning ("Failed to register client: %s", error->message);
144171
g_error_free (error);
145172
return FALSE;
146173
}
147174

175+
g_variant_get (res, "(o)", &client_id);
148176
g_debug ("Client registered with session manager: %s", client_id);
149-
client_proxy = dbus_g_proxy_new_for_name (bus_connection,
150-
SM_DBUS_NAME,
151-
client_id,
152-
SM_CLIENT_DBUS_INTERFACE);
153-
dbus_g_proxy_add_signal (client_proxy,
154-
"QueryEndSession",
155-
G_TYPE_UINT,
156-
G_TYPE_INVALID);
157-
dbus_g_proxy_add_signal (client_proxy,
158-
"EndSession",
159-
G_TYPE_UINT,
160-
G_TYPE_INVALID);
161-
dbus_g_proxy_add_signal (client_proxy,
162-
"CancelEndSession",
163-
G_TYPE_UINT,
164-
G_TYPE_INVALID);
165-
dbus_g_proxy_add_signal (client_proxy,
166-
"Stop",
167-
G_TYPE_INVALID);
168-
dbus_g_proxy_connect_signal (client_proxy,
169-
"QueryEndSession",
170-
G_CALLBACK (on_client_query_end_session),
171-
NULL,
172-
NULL);
173-
dbus_g_proxy_connect_signal (client_proxy,
174-
"EndSession",
175-
G_CALLBACK (on_client_end_session),
176-
NULL,
177-
NULL);
178-
dbus_g_proxy_connect_signal (client_proxy,
179-
"CancelEndSession",
180-
G_CALLBACK (on_client_cancel_end_session),
181-
NULL,
182-
NULL);
183-
dbus_g_proxy_connect_signal (client_proxy,
184-
"Stop",
185-
G_CALLBACK (on_client_stop),
186-
NULL,
187-
NULL);
188177

189-
return TRUE;
178+
client_proxy = g_dbus_proxy_new_sync (bus_connection,
179+
G_DBUS_PROXY_FLAGS_NONE,
180+
NULL,
181+
SM_DBUS_NAME,
182+
client_id,
183+
SM_CLIENT_DBUS_INTERFACE,
184+
NULL, NULL);
185+
if (client_proxy != NULL) {
186+
g_signal_connect (client_proxy, "g-signal",
187+
G_CALLBACK (on_client_dbus_signal), NULL);
188+
}
189+
190+
g_variant_unref (res);
191+
192+
return (client_proxy != NULL);
190193
}
191194

192195
static gboolean
@@ -204,16 +207,15 @@ static gboolean
204207
unregister_client (void)
205208
{
206209
GError *error;
207-
gboolean res;
210+
GVariant *res;
208211

209212
error = NULL;
210-
res = dbus_g_proxy_call (sm_proxy,
211-
"UnregisterClient",
212-
&error,
213-
DBUS_TYPE_G_OBJECT_PATH, client_id,
214-
G_TYPE_INVALID,
215-
G_TYPE_INVALID);
216-
if (! res) {
213+
res = g_dbus_proxy_call_sync (sm_proxy,
214+
"UnregisterClient",
215+
g_variant_new ("(o)", client_id),
216+
G_DBUS_CALL_FLAGS_NONE,
217+
-1, NULL, &error);
218+
if (res == NULL) {
217219
g_warning ("Failed to unregister client: %s", error->message);
218220
g_error_free (error);
219221
return FALSE;
@@ -222,6 +224,8 @@ unregister_client (void)
222224
g_free (client_id);
223225
client_id = NULL;
224226

227+
g_variant_unref (res);
228+
225229
return TRUE;
226230
}
227231

0 commit comments

Comments
 (0)