[dconf] bring service API in line with the client
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] bring service API in line with the client
- Date: Mon, 19 Jul 2010 17:53:05 +0000 (UTC)
commit 1e93f987b56bd157f74808e0d0eb4d274437ba68
Author: Ryan Lortie <desrt desrt ca>
Date: Mon Jul 19 13:52:33 2010 -0400
bring service API in line with the client
also, cache GDBusConnections in the client since GDBus doesn't keep them
alive for us.
client/dconf-client.vala | 48 ++++++++++++++++++++++++++++++-------------
engine/dconf-engine.c | 7 +++--
service/dconf-interfaces.c | 8 +++---
service/dconf-writer.c | 8 +++++++
service/dconf-writer.h | 1 +
service/service.c | 37 +++++++++++++++++++++------------
6 files changed, 73 insertions(+), 36 deletions(-)
---
diff --git a/client/dconf-client.vala b/client/dconf-client.vala
index 0e71b7c..5db8767 100644
--- a/client/dconf-client.vala
+++ b/client/dconf-client.vala
@@ -3,22 +3,26 @@ namespace DConf {
public delegate void WatchFunc (DConf.Client client, string path, string[] items, string tag);
public class Client : Object {
- Engine engine;
+ DBusConnection? session;
+ DBusConnection? system;
WatchFunc watch_func;
-
- static BusType get_bus_type (EngineMessage dcem) {
- switch (dcem.bus_type) {
- case 'e':
- return BusType.SESSION;
- case 'y':
- return BusType.SYSTEM;
- default:
- assert_not_reached ();
- }
- }
+ Engine engine;
void call_sync (EngineMessage dcem, out string tag, Cancellable? cancellable) throws Error {
- var connection = Bus.get_sync (get_bus_type (dcem), cancellable);
+ DBusConnection connection;
+
+ if (dcem.bus_type == 'e') {
+ if (session == null) {
+ session = Bus.get_sync (BusType.SESSION, cancellable);
+ }
+ connection = session;
+ } else {
+ assert (dcem.bus_type == 'y');
+ if (system == null) {
+ system = Bus.get_sync (BusType.SYSTEM, cancellable);
+ }
+ connection = system;
+ }
foreach (var message in dcem.body) {
var reply = connection.call_sync (dcem.destination, dcem.object_path, dcem interface, dcem.method,
@@ -30,7 +34,20 @@ namespace DConf {
}
async void call_async (EngineMessage dcem, out string tag, Cancellable? cancellable) throws Error {
- var connection = yield Bus.get (get_bus_type (dcem), cancellable);
+ DBusConnection connection;
+
+ if (dcem.bus_type == 'e') {
+ if (session == null) {
+ session = yield Bus.get (BusType.SESSION, cancellable);
+ }
+ connection = session;
+ } else {
+ assert (dcem.bus_type == 'y');
+ if (system == null) {
+ system = yield Bus.get (BusType.SYSTEM, cancellable);
+ }
+ connection = system;
+ }
foreach (var message in dcem.body) {
var reply = yield connection.call (dcem.destination, dcem.object_path, dcem interface, dcem.method,
@@ -104,7 +121,8 @@ namespace DConf {
static Variant? service_func (EngineMessage dcem) {
try {
- var connection = Bus.get_sync (get_bus_type (dcem), null);
+ assert (dcem.bus_type == 'e');
+ var connection = Bus.get_sync (BusType.SESSION, null);
return connection.call_sync (dcem.destination, dcem.object_path, dcem interface, dcem.method,
dcem.body, dcem.reply_type, DBusCallFlags.NONE, -1, null);
} catch {
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index 73aadc7..faaa5dc 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -435,11 +435,12 @@ dconf_engine_make_match_rule (DConfEngine *engine,
{
gchar *rule;
- rule = g_strdup_printf ("interface='ca.desrt.dconf.Writer',"
- "arg1path='%s'", name);
+ rule = g_strdup_printf ("type='signal',interface='ca.desrt.dconf.Writer',"
+ "path='%s',arg0path='%s'",
+ engine->object_paths[0], name);
dcem->bus_type = 'e';
dcem->destination = "org.freedesktop.DBus";
- dcem->object_path = engine->object_paths[0];
+ dcem->object_path = "/org/freedesktop/DBus";
dcem->interface = "org.freedesktop.DBus";
dcem->body = g_variant_ref_sink (g_variant_new ("((s))", rule));
g_free (rule);
diff --git a/service/dconf-interfaces.c b/service/dconf-interfaces.c
index c50232d..87ecad1 100644
--- a/service/dconf-interfaces.c
+++ b/service/dconf-interfaces.c
@@ -24,16 +24,16 @@
static const GDBusArgInfo name_arg = { -1, (gchar *) "name", (gchar *) "s" };
static const GDBusArgInfo path_arg = { -1, (gchar *) "path", (gchar *) "s" };
static const GDBusArgInfo names_arg = { -1, (gchar *) "names", (gchar *) "as" };
-static const GDBusArgInfo serial_arg = { -1, (gchar *) "serial", (gchar *) "t" };
+static const GDBusArgInfo tag_arg = { -1, (gchar *) "tag", (gchar *) "s" };
static const GDBusArgInfo value_arg = { -1, (gchar *) "value", (gchar *) "av" };
static const GDBusArgInfo values_arg = { -1, (gchar *) "values", (gchar *) "a(sav)" };
static const GDBusArgInfo locked_arg = { -1, (gchar *) "locked", (gchar *) "b" };
static const GDBusArgInfo *write_in[] = { &name_arg, &value_arg, NULL };
-static const GDBusArgInfo *write_out[] = { &serial_arg, NULL };
+static const GDBusArgInfo *write_out[] = { &tag_arg, NULL };
static const GDBusArgInfo *many_in[] = { &path_arg, &values_arg, NULL };
-static const GDBusArgInfo *many_out[] = { &serial_arg, NULL };
-static const GDBusArgInfo *notify_args[] = { &path_arg, &names_arg, NULL };
+static const GDBusArgInfo *many_out[] = { &tag_arg, NULL };
+static const GDBusArgInfo *notify_args[] = { &path_arg, &names_arg, &tag_arg, NULL };
static const GDBusArgInfo *setlock_in[] = { &name_arg, &locked_arg, NULL };
static const GDBusArgInfo *setlock_out[] = { NULL };
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index 00dac13..c4d21a7 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -35,6 +35,7 @@ static const gchar *dconf_writer_db_dir;
struct OPAQUE_TYPE__DConfWriter
{
+ gchar *name;
gchar *path;
gchar *shm;
};
@@ -134,6 +135,12 @@ dconf_writer_set_lock (DConfWriter *writer,
return TRUE;
}
+const gchar *
+dconf_writer_get_name (DConfWriter *writer)
+{
+ return writer->name;
+}
+
DConfWriter *
dconf_writer_new (const gchar *name)
{
@@ -142,6 +149,7 @@ dconf_writer_new (const gchar *name)
writer = g_slice_new (DConfWriter);
writer->path = g_build_filename (dconf_writer_db_dir, name, NULL);
writer->shm = g_build_filename (dconf_writer_shm_dir, name, NULL);
+ writer->name = g_strdup (name);
return writer;
}
diff --git a/service/dconf-writer.h b/service/dconf-writer.h
index 8dc1d9d..8c21f3b 100644
--- a/service/dconf-writer.h
+++ b/service/dconf-writer.h
@@ -30,6 +30,7 @@ const gchar * dconf_writer_get_shm_dir (void);
gchar ** dconf_writer_list_existing (void);
void dconf_writer_init (void);
DConfWriter * dconf_writer_new (const gchar *name);
+const gchar * dconf_writer_get_name (DConfWriter *writer);
gboolean dconf_writer_write (DConfWriter *writer,
const gchar *name,
GVariant *value,
diff --git a/service/service.c b/service/service.c
index cab18e8..2c08a8e 100644
--- a/service/service.c
+++ b/service/service.c
@@ -21,6 +21,7 @@
#include <gio/gio.h>
#include <string.h>
+#include <stdio.h>
#include "dconf-interfaces.h"
#include "dconf-writer.h"
@@ -29,7 +30,8 @@ static guint64 dconf_service_serial;
static void
emit_notify_signal (GDBusConnection *connection,
- guint64 serial,
+ DConfWriter *writer,
+ const gchar *tag,
const gchar *prefix,
const gchar **keys,
guint n_keys)
@@ -37,6 +39,7 @@ emit_notify_signal (GDBusConnection *connection,
GVariantBuilder builder;
GVariant *items;
gchar *path;
+ gchar *obj;
g_variant_builder_init (&builder, G_VARIANT_TYPE ("as"));
@@ -79,12 +82,15 @@ emit_notify_signal (GDBusConnection *connection,
else
path = g_strdup (prefix);
+ obj = g_strjoin (NULL, "/ca/desrt/dconf/Writer/",
+ dconf_writer_get_name (writer), NULL);
g_dbus_connection_emit_signal (connection, NULL, "/",
"ca.desrt.dconf.Writer", "Notify",
- g_variant_new ("(ts as)",
- serial, path, items),
+ g_variant_new ("(s ass)",
+ path, items, tag),
NULL);
g_free (path);
+ g_free (obj);
}
static void
@@ -122,8 +128,9 @@ method_call (GDBusConnection *connection,
const gchar *key;
gsize key_length;
GVariant *value;
- guint64 serial;
GVariant *none;
+ gchar tag[20];
+ gchar *path;
g_variant_get (parameters, "(@s av)", &keyvalue, &value);
key = g_variant_get_string (keyvalue, &key_length);
@@ -157,15 +164,18 @@ method_call (GDBusConnection *connection,
return;
}
- serial = dconf_service_serial++;
+ snprintf (tag, sizeof tag, "%"G_GUINT64_FORMAT, dconf_service_serial++);
g_dbus_method_invocation_return_value (invocation,
- g_variant_new ("(t)", serial));
+ g_variant_new ("(s)", tag));
none = g_variant_new_array (G_VARIANT_TYPE_STRING, NULL, 0);
- g_dbus_connection_emit_signal (connection, NULL, "/",
+ path = g_strjoin (NULL, "/ca/desrt/dconf/Writer/",
+ dconf_writer_get_name (writer), NULL);
+ g_dbus_connection_emit_signal (connection, NULL, path,
"ca.desrt.dconf.Writer", "Notify",
- g_variant_new ("(ts as)",
- serial, key, none),
+ g_variant_new ("(s ass)",
+ key, none, tag),
NULL);
+ g_free (path);
}
else if (strcmp (method_name, "Merge") == 0)
@@ -175,7 +185,7 @@ method_call (GDBusConnection *connection,
GVariantIter *iter;
const gchar **keys;
GVariant **values;
- guint64 serial;
+ gchar tag[20];
gsize length;
gint i = 0;
gint j;
@@ -218,11 +228,10 @@ method_call (GDBusConnection *connection,
return;
}
- serial = dconf_service_serial++;
-
+ snprintf (tag, sizeof tag, "%"G_GUINT64_FORMAT, dconf_service_serial++);
g_dbus_method_invocation_return_value (invocation,
- g_variant_new ("(t)", serial));
- emit_notify_signal (connection, serial, prefix, keys, i);
+ g_variant_new ("(s)", tag));
+ emit_notify_signal (connection, writer, tag, prefix, keys, i);
for (j = 0; j < i; j++)
if (values[j] != NULL)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]