[dconf] flesh out the APIs a bit
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] flesh out the APIs a bit
- Date: Sun, 23 May 2010 04:11:56 +0000 (UTC)
commit 26b6477e9a9b2730b082dd9fec4df1b645d375c6
Author: Ryan Lortie <desrt desrt ca>
Date: Sun May 23 00:11:14 2010 -0400
flesh out the APIs a bit
- add a sync set() call to client API
- GCancellable/GErrorify some APIs
bin/dconf.c | 38 ++++++++++++----
client/dconf-client.c | 88 ++++++++++++++++++++++++++++++++++++--
client/dconf-client.h | 2 +
engine/dconf-engine.c | 17 ++++---
engine/dconf-engine.h | 22 ++++++----
gsettings/dconfsettingsbackend.c | 4 +-
6 files changed, 139 insertions(+), 32 deletions(-)
---
diff --git a/bin/dconf.c b/bin/dconf.c
index 318d42f..3a5e230 100644
--- a/bin/dconf.c
+++ b/bin/dconf.c
@@ -4,23 +4,41 @@ int
main (int argc, char **argv)
{
DConfClient *client;
- GVariant *value;
g_type_init ();
client = dconf_client_new (NULL, NULL, NULL, NULL);
- value = dconf_client_read (client, argv[1], DCONF_READ_NORMAL);
+ if (g_strcmp0 (argv[1], "get") == 0)
+ {
+ GVariant *value;
+
+ value = dconf_client_read (client, argv[2], DCONF_READ_NORMAL);
+
+ if (value == NULL)
+ g_print ("(null)\n");
+ else
+ {
+ gchar *printed;
+ printed = g_variant_print (value, TRUE);
+ g_print ("%s\n", printed);
+ g_variant_unref (value);
+ g_free (printed);
+ }
+ }
- if (value == NULL)
- g_print ("(null)\n");
- else
+ else if (g_strcmp0 (argv[1], "set") == 0)
{
- gchar *printed;
- printed = g_variant_print (value, TRUE);
- g_print ("%s\n", printed);
- g_variant_unref (value);
- g_free (printed);
+ GError *error = NULL;
+ GVariant *value;
+
+ value = g_variant_parse (NULL, argv[3], NULL, NULL, &error);
+
+ if (value == NULL)
+ g_error ("%s\n", error->message);
+
+ if (!dconf_client_write (client, argv[2], value, NULL, NULL, &error))
+ g_error ("%s\n", error->message);
}
return 0;
diff --git a/client/dconf-client.c b/client/dconf-client.c
index 0e7af27..9d0088b 100644
--- a/client/dconf-client.c
+++ b/client/dconf-client.c
@@ -61,6 +61,90 @@ dconf_client_read (DConfClient *client,
return dconf_engine_read (client->engine, key, type);
}
+static GDBusConnection *
+dconf_client_get_connection (guint bus_type,
+ GError **error)
+{
+}
+
+static GBusType
+dconf_client_bus_type (DConfEngineMessage *dcem)
+{
+ switch (dcem->bus_type)
+ {
+ case 'e':
+ return G_BUS_TYPE_SESSION;
+
+ case 'y':
+ return G_BUS_TYPE_SYSTEM;
+
+ default:
+ g_assert_not_reached ();
+ }
+}
+
+static gboolean
+dconf_client_call_sync (DConfClient *client,
+ DConfEngineMessage *dcem,
+ guint64 *sequence,
+ GCancellable *cancellable,
+ GError **error)
+{
+ GDBusConnection *connection;
+
+ connection = g_bus_get_sync (dconf_client_bus_type (dcem),
+ cancellable, error);
+
+ if (connection == NULL)
+ return FALSE;
+
+ if (dcem->body)
+ {
+ GVariant *reply;
+
+ reply = g_dbus_connection_call_sync (connection, dcem->destination,
+ dcem->object_path, dcem->interface,
+ dcem->method, dcem->body,
+ G_DBUS_CALL_FLAGS_NONE, -1,
+ cancellable, error);
+
+ if (reply == NULL)
+ return FALSE;
+
+ if (!g_variant_is_of_type (reply, dcem->reply_type))
+ {
+ g_set_error (error, G_DBUS_ERROR, G_DBUS_ERROR_INVALID_ARGS,
+ "incorrect return type for '%s' method call",
+ dcem->method);
+ g_variant_unref (reply);
+ return FALSE;
+ }
+
+ if (sequence)
+ g_variant_get (reply, "(t)", sequence);
+
+ g_variant_unref (reply);
+ }
+
+ return TRUE;
+}
+
+gboolean
+dconf_client_write (DConfClient *client,
+ const gchar *key,
+ GVariant *value,
+ guint64 *sequence,
+ GCancellable *cancellable,
+ GError **error)
+{
+ DConfEngineMessage dcem;
+
+ if (!dconf_engine_write (client->engine, &dcem, key, value, error))
+ return FALSE;
+
+ return dconf_client_call_sync (client, &dcem, sequence, cancellable, error);
+}
+
#if 0
GVariant * dconf_client_read (DConfClient *client,
@@ -75,10 +159,6 @@ gboolean dconf_client_is_writable (DConfCl
const gchar *prefix,
GError **error);
-gboolean dconf_client_write (DConfClient *client,
- const gchar *key,
- GVariant *value,
- GError **error);
void dconf_client_write_async (DConfClient *client,
const gchar *key,
GVariant *value,
diff --git a/client/dconf-client.h b/client/dconf-client.h
index d8afc2f..108d7a8 100644
--- a/client/dconf-client.h
+++ b/client/dconf-client.h
@@ -39,6 +39,8 @@ gboolean dconf_client_is_writable (DConfCl
gboolean dconf_client_write (DConfClient *client,
const gchar *key,
GVariant *value,
+ guint64 *sequence,
+ GCancellable *cancellable,
GError **error);
void dconf_client_write_async (DConfClient *client,
const gchar *key,
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index de28190..dbb22ed 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -91,9 +91,10 @@ dconf_engine_unwatch (DConfEngine *engine,
}
gboolean
-dconf_engine_is_writable (DConfEngine *engine,
- DConfEngineMessage *dcem,
- const gchar *name)
+dconf_engine_is_writable (DConfEngine *engine,
+ DConfEngineMessage *dcem,
+ const gchar *name,
+ GError **error)
{
dcem->bus_type = 'e';
dcem->body = NULL;
@@ -127,6 +128,7 @@ dconf_engine_dcem (DConfEngine *engine,
dcem->destination = "ca.desrt.dconf";
dcem->object_path = "/";
dcem->interface = "ca.desrt.dconf.Writer";
+ dcem->reply_type = G_VARIANT_TYPE ("(t)");
dcem->method = method;
va_start (ap, format_string);
@@ -136,10 +138,11 @@ dconf_engine_dcem (DConfEngine *engine,
}
gboolean
-dconf_engine_write (DConfEngine *engine,
- DConfEngineMessage *dcem,
- const gchar *name,
- GVariant *value)
+dconf_engine_write (DConfEngine *engine,
+ DConfEngineMessage *dcem,
+ const gchar *name,
+ GVariant *value,
+ GError **error)
{
dconf_engine_dcem (engine, dcem,
"Write", "(s av)",
diff --git a/engine/dconf-engine.h b/engine/dconf-engine.h
index f766f0b..9d9a77f 100644
--- a/engine/dconf-engine.h
+++ b/engine/dconf-engine.h
@@ -9,12 +9,13 @@ typedef struct _DConfEngineResetList DConfEngineResetList;
typedef struct
{
- gint bus_type;
- const gchar *destination;
- const gchar *object_path;
- const gchar *interface;
- const gchar *method;
- GVariant *body;
+ gint bus_type;
+ const gchar *destination;
+ const gchar *object_path;
+ const gchar *interface;
+ const gchar *method;
+ const GVariantType *reply_type;
+ GVariant *body;
} DConfEngineMessage;
@@ -39,14 +40,17 @@ void dconf_engine_get_service_info (DConfEn
const gchar **object_path);
gboolean dconf_engine_is_writable (DConfEngine *engine,
DConfEngineMessage *message,
- const gchar *name);
+ const gchar *name,
+ GError **error);
gboolean dconf_engine_write (DConfEngine *engine,
DConfEngineMessage *message,
const gchar *key,
- GVariant *value);
+ GVariant *value,
+ GError **error);
gboolean dconf_engine_write_tree (DConfEngine *engine,
DConfEngineMessage *message,
- GTree *tree);
+ GTree *tree,
+ GError **error);
void dconf_engine_watch (DConfEngine *engine,
DConfEngineMessage *message,
const gchar *name);
diff --git a/gsettings/dconfsettingsbackend.c b/gsettings/dconfsettingsbackend.c
index c15da74..b1e01e3 100644
--- a/gsettings/dconfsettingsbackend.c
+++ b/gsettings/dconfsettingsbackend.c
@@ -323,7 +323,7 @@ dconf_settings_backend_write (GSettingsBackend *backend,
volatile guint32 *serial;
GDBusConnection *bus;
- if (!dconf_engine_write (dcsb->engine, &message, path_or_key, value))
+ if (!dconf_engine_write (dcsb->engine, &message, path_or_key, value, NULL))
return FALSE;
if (!dconf_settings_backend_get_bus (&bus, &message))
@@ -397,7 +397,7 @@ dconf_settings_backend_get_writable (GSettingsBackend *backend,
DConfEngineMessage message;
GDBusConnection *bus;
- if (!dconf_engine_is_writable (dcsb->engine, &message, name))
+ if (!dconf_engine_is_writable (dcsb->engine, &message, name, NULL))
return FALSE;
return dconf_settings_backend_get_bus (&bus, &message);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]