aboutsummaryrefslogtreecommitdiffstats
path: root/meta-gnome/recipes-gnome/gconf/gconf/0001-Port-gconfd-2-to-GDBus.patch
blob: 01cbdbcf9e00e29f804a328436626c1cd5bf7c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
From 979bfb2448c3895a303041c1d422daf7930f3a51 Mon Sep 17 00:00:00 2001
From: Christian Persch <chpe@gnome.org>
Date: Sat, 8 May 2010 02:13:43 +0200
Subject: [PATCH] Port gconfd-2 to GDBus

Bug #618039.
---
 gconf/gconfd.c |  328 +++++++++++++++++++++++++++++---------------------------
 1 files changed, 170 insertions(+), 158 deletions(-)

diff --git a/gconf/gconfd.c b/gconf/gconfd.c
index b89e7a1..ee9d6ad 100644
--- a/gconf/gconfd.c
+++ b/gconf/gconfd.c
@@ -55,7 +55,7 @@
 #endif
 #include <locale.h>
 
-#include <dbus/dbus-glib-lowlevel.h>
+#include <gio/gio.h>
 
 #ifdef G_OS_WIN32
 #include <io.h>
@@ -518,152 +518,144 @@ gconf_get_poa (void)
   return the_poa;
 }
 
-static const char *
-get_introspection_xml (void)
-{
-  return "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n"
-         "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
-         "<node>\n"
-         "  <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
-         "    <method name=\"Introspect\">\n"
-         "      <arg name=\"introspection_xml\" direction=\"out\" type=\"s\"/>\n"
-         "    </method>\n"
-         "  </interface>\n"
-         "  <interface name=\"org.gnome.GConf\">\n"
-         "    <method name=\"GetIOR\">\n"
-         "      <arg name=\"ior\" direction=\"out\" type=\"s\"/>\n"
-         "    </method>\n"
-         "  </interface>\n"
-         "</node>\n";
-}
-
-static DBusHandlerResult
-bus_message_handler (DBusConnection *connection,
-                     DBusMessage    *message,
-                     void           *user_data)
+static void
+handle_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)
 {
-  DBusMessage *reply;
-
-  reply = NULL;
-
-  if (dbus_message_is_signal (message,
-                              DBUS_INTERFACE_LOCAL,
-                              "Disconnected"))
+  if (g_strcmp0 (method_name, "GetIOR") == 0)
     {
-      gconf_main_quit ();
-      return DBUS_HANDLER_RESULT_HANDLED;
+      g_dbus_method_invocation_return_value (invocation,
+                                             g_variant_new ("(s)", gconf_get_daemon_ior ()));
     }
-  else if (dbus_message_is_method_call (message,
-                                        "org.freedesktop.DBus.Introspectable",
-                                        "Introspect"))
-    {
-      const char *introspection_xml;
-
-      introspection_xml = get_introspection_xml ();
-
-      reply = dbus_message_new_method_return (message);
-      dbus_message_append_args (reply, DBUS_TYPE_STRING, &introspection_xml,
-                                DBUS_TYPE_INVALID);
-
-    }
-  else if (dbus_message_is_method_call (message,
-                                        "org.gnome.GConf",
-                                        "GetIOR"))
-    {
-      const char *ior;
+}
 
-      ior = gconf_get_daemon_ior ();
+static void
+on_name_acquired (GDBusConnection *connection,
+                  const gchar     *name,
+                  gpointer         user_data)
+{
+  * (gboolean *) user_data = TRUE;
+  gconf_main_quit ();
+}
 
-      reply = dbus_message_new_method_return (message);
-      dbus_message_append_args (reply, DBUS_TYPE_STRING, &ior, DBUS_TYPE_INVALID);
-    }
+static void
+on_name_lost (GDBusConnection *connection,
+              const gchar     *name,
+              gpointer         user_data)
+{
+  * (gboolean *) user_data = FALSE;
 
-  if (reply != NULL)
-    {
-      dbus_connection_send (connection, reply, NULL);
-      dbus_message_unref (reply);
-      return DBUS_HANDLER_RESULT_HANDLED;
-    }
+  gconf_log (GCL_WARNING,
+             _("Failed to get bus name for daemon, exiting."));
 
-  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+  gconf_main_quit ();
 }
 
-static DBusConnection *
-get_on_d_bus (void)
+static GDBusConnection *
+own_org_gnome_GConf (void)
 {
-  DBusConnection *connection;
-  DBusError bus_error;
-  int result;
-
-  dbus_error_init (&bus_error);
-  connection = dbus_bus_get (DBUS_BUS_SESSION, &bus_error);
-
-  if (dbus_error_is_set (&bus_error))
+  static const char introspection_xml[] =
+    "<node>"
+      "<interface name='org.gnome.GConf'>"
+        "<method name='GetIOR'>"
+          "<arg name='ior' direction='out' type='s'/>"
+        "</method>"
+      "</interface>"
+    "</node>";
+  static const GDBusInterfaceVTable interface_vtable =
+  {
+    handle_method_call,
+    NULL,
+    NULL
+  };
+
+  GDBusConnection *connection;
+  GDBusNodeInfo *introspection_data;
+  guint registration_id;
+  guint owner_id;
+  gboolean *do_own_ptr;
+  GError *error = NULL;
+
+  connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error);
+  if (connection == NULL)
     {
-      gconf_log (GCL_ERR, _("Could not connect to session bus: %s"), bus_error.message);
-      dbus_error_free (&bus_error);
+      gconf_log (GCL_ERR, _("Could not connect to session bus: %s"), error->message);
+      g_error_free (error);
       return NULL;
     }
 
-  dbus_connection_setup_with_g_main (connection, NULL);
+  introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL);
+  g_assert (introspection_data != NULL);
 
-  if (!dbus_connection_add_filter (connection, (DBusHandleMessageFunction)
-                                  bus_message_handler, NULL, NULL))
+  registration_id = g_dbus_connection_register_object (connection,
+                                                       "/org/gnome/GConf",
+                                                       introspection_data->interfaces[0],
+                                                       &interface_vtable,
+                                                       introspection_data,
+                                                       (GDestroyNotify) g_dbus_node_info_unref,
+                                                       &error);
+  if (registration_id == 0)
     {
-      dbus_connection_unref (connection);
+      gconf_log (GCL_ERR, "Failed to register object: %s", error->message);
+      g_error_free (error);
+      g_object_unref (connection);
       return NULL;
     }
 
-  dbus_connection_set_exit_on_disconnect (connection, FALSE);
+  g_dbus_connection_set_exit_on_close (connection, FALSE);
+  g_signal_connect (connection, "closed", G_CALLBACK (gconf_main_quit), NULL);
 
-  result = dbus_bus_request_name (connection, "org.gnome.GConf",
-                                  0, &bus_error);
+  do_own_ptr = g_new (gboolean, 1);
+  *do_own_ptr = FALSE;
 
-  if (dbus_error_is_set (&bus_error))
-    {
-      gconf_log (GCL_WARNING,
-                 _("Failed to get bus name for daemon, exiting: %s"),
-                 bus_error.message);
-      dbus_error_free (&bus_error);
-    }
+  owner_id = g_bus_own_name_on_connection (connection,
+                                           "org.gnome.GConf",
+                                           G_BUS_NAME_OWNER_FLAGS_NONE,
+                                           on_name_acquired,
+                                           on_name_lost,
+                                           do_own_ptr, (GDestroyNotify) g_free);
 
-  if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      dbus_connection_unref (connection);
-      return NULL;
-    }
+  gconf_main ();
 
-  return connection;
+  if (*do_own_ptr)
+    return connection;
+
+  g_object_unref (connection);
+  return NULL;
 }
 
 #ifdef ENABLE_DEFAULTS_SERVICE
 /* listen on system bus for defaults changes */
 
-static DBusHandlerResult
-system_bus_message_handler (DBusConnection *connection,
-			    DBusMessage    *message,
-			    void           *user_data)
-{
-  DBusMessage *reply;
-
-  reply = NULL;
-
-  if (dbus_message_is_signal (message,
-			      "org.gnome.GConf.Defaults",
-                              "SystemSet"))
-    {
-      DBusError bus_error;
-      char **keys;
-      int n_keys;
+typedef struct {
+  guint watch_id;
+  guint subscription_id;
+} DefaultsData;
 
-      dbus_error_init (&bus_error);
-      if (dbus_message_get_args (message, &bus_error,
-				 DBUS_TYPE_ARRAY, DBUS_TYPE_STRING, &keys, &n_keys,
-				 DBUS_TYPE_INVALID))
+static void
+system_set_cb (GDBusConnection *connection,
+               const gchar *sender_name,
+               const gchar *object_path,
+               const gchar *interface_name,
+               const gchar *signal_name,
+               GVariant *parameters,
+               gpointer user_data)
+{
+  if (g_strcmp0 (interface_name, "org.gnome.GConf.Defaults") == 0 &&
+      g_strcmp0 (signal_name, "SystemSet") == 0)
+    {
+      if (g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(as)")))
 	{
-	  char **key;
 	  GConfSources *system_sources;
 	  GSList addresses;
+          GVariantIter *iter;
+          const char *key;
 
 	  gconf_log (GCL_DEBUG, "System defaults changed.  Notifying.");
 
@@ -673,61 +665,72 @@ system_bus_message_handler (DBusConnection *connection,
 
 	  gconfd_clear_cache_for_sources (system_sources);
 
-	  for (key = keys; *key; key++)
-	    gconfd_notify_other_listeners (NULL, system_sources, *key);
+          g_variant_get (parameters, "(as)", &iter);
+          while (g_variant_iter_loop (iter, "&s", &key))
+            gconfd_notify_other_listeners (NULL, system_sources, key);
+          g_variant_iter_free (iter);
 
 	  gconf_sources_free (system_sources);
-
-	  dbus_free_string_array (keys);
 	}
       else
         {
-	  gconf_log (GCL_DEBUG, "SystemSet signal received, but error getting message: %s", bus_error.message);
+	  gconf_log (GCL_DEBUG, "SystemSet signal received, but wrong paramters type '%s'",
+                     g_variant_get_type_string (parameters));
 	}
-      dbus_error_free (&bus_error);
-
-      return DBUS_HANDLER_RESULT_HANDLED;
     }
-
-  return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
 }
 
-static DBusConnection *
-get_on_system_bus (void)
+static void
+defaults_appeared_cb (GDBusConnection *connection,
+                      const gchar     *name,
+                      const gchar     *name_owner,
+                      gpointer         user_data)
 {
-  DBusConnection *connection;
-  DBusError bus_error;
+  DefaultsData *data = (DefaultsData *) user_data;
 
-  dbus_error_init (&bus_error);
-  connection = dbus_bus_get (DBUS_BUS_SYSTEM, &bus_error);
+  gconf_log (GCL_DEBUG, "Defaults service appeared with name '%s'", name_owner);
 
-  if (dbus_error_is_set (&bus_error))
-    {
-      gconf_log (GCL_ERR, _("Could not connect to system bus: %s"), bus_error.message);
-      dbus_error_free (&bus_error);
-      return NULL;
-    }
+  g_assert (data->subscription_id == 0);
+  data->subscription_id = g_dbus_connection_signal_subscribe (connection,
+                                                              name_owner,
+                                                              "org.gnome.GConf.Defaults",
+                                                              "SystemSet",
+                                                              "/" /* really? */,
+                                                              NULL,
+                                                              G_DBUS_SIGNAL_FLAGS_NONE,
+                                                              system_set_cb,
+                                                              user_data, NULL);
+}
 
-  dbus_connection_setup_with_g_main (connection, NULL);
+static void
+defaults_vanished_cb (GDBusConnection *connection,
+                      const gchar     *name,
+                      gpointer         user_data)
+{
+  DefaultsData *data = (DefaultsData *) user_data;
 
-  dbus_bus_add_match (connection, "type='signal',interface='org.gnome.GConf.Defaults'", &bus_error);
-  dbus_connection_flush(connection);
-  if (dbus_error_is_set (&bus_error))
-    {
-      gconf_log (GCL_DEBUG, "Failed to add signal match to system bus: %s", bus_error.message);
-      dbus_connection_unref (connection);
-      return NULL;
-    }
+  gconf_log (GCL_DEBUG, "Defaults service disappeared");
 
-  if (!dbus_connection_add_filter (connection, (DBusHandleMessageFunction)
-                                   system_bus_message_handler, NULL, NULL))
-    {
-      gconf_log (GCL_DEBUG, "Failed to add message filter to system bus.");
-      dbus_connection_unref (connection);
-      return NULL;
-    }
+  if (data->subscription_id != 0) {
+    g_dbus_connection_signal_unsubscribe (connection , data->subscription_id);
+    data->subscription_id = 0;
+  }
+}
 
-  return connection;
+static DefaultsData *
+get_on_system_bus (void)
+{
+  DefaultsData *data = g_new (DefaultsData, 1);
+
+  data->subscription_id = 0;
+  data->watch_id = g_bus_watch_name (G_BUS_TYPE_SYSTEM,
+                                     "org.gnome.GConf.Defaults",
+                                     G_BUS_NAME_WATCHER_FLAGS_NONE,
+                                     defaults_appeared_cb,
+                                     defaults_vanished_cb,
+                                     data, NULL);
+
+  return data;
 }
 #endif  /* ENABLE_DEFAULTS_SERVICE */
 
@@ -759,7 +762,8 @@ main(int argc, char** argv)
   GError *err;
   int dev_null_fd;
   int write_byte_fd;
-  DBusConnection *connection;
+  GDBusConnection *connection;
+  DefaultsData *defaults_data;
 
   _gconf_init_i18n ();
   setlocale (LC_ALL, "");
@@ -896,8 +900,7 @@ main(int argc, char** argv)
   gconf_set_daemon_ior (ior);
   CORBA_free (ior);
 
-  connection = get_on_d_bus ();
-
+  connection = own_org_gnome_GConf ();
   if (connection != NULL)
     {
       /* This loads backends and so on. It needs to be done before
@@ -934,11 +937,20 @@ main(int argc, char** argv)
   logfile_read ();
  
 #ifdef ENABLE_DEFAULTS_SERVICE 
-  get_on_system_bus ();
+  defaults_data = get_on_system_bus ();
 #endif
 
   gconf_main ();
 
+  g_object_unref (connection);
+  connection = NULL;
+
+  if (defaults_data->subscription_id != 0) {
+    g_dbus_connection_signal_unsubscribe (connection , defaults_data->subscription_id);
+  }
+  g_bus_unwatch_name (defaults_data->watch_id);
+  g_free (defaults_data);
+
   if (in_shutdown)
     exit_code = 1; /* means someone already called enter_shutdown() */
   
-- 
1.6.6.1