[dconf] assorted client API cleanups, vala port of 'dconf'
- From: Ryan Lortie <ryanl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf] assorted client API cleanups, vala port of 'dconf'
- Date: Mon, 19 Jul 2010 03:24:55 +0000 (UTC)
commit 67cb6fa67a608ba5b778e6e0bba9578a0a6ab075
Author: Ryan Lortie <desrt desrt ca>
Date: Sun Jul 18 23:23:54 2010 -0400
assorted client API cleanups, vala port of 'dconf'
bin/.gitignore | 2 +-
bin/Makefile.am | 4 +
bin/dconf.c | 242 --------------------------------------
bin/dconf.vala | 56 +++++++++
client/dconf-client.c | 39 +++---
client/dconf-client.h | 23 +---
{editor => client}/dconf.vapi | 37 ++++--
common/dconf-paths.c | 80 ++++++++++---
common/dconf-paths.h | 18 ++-
editor/Makefile.am | 2 +-
editor/dconf-model.vala | 4 +-
engine/dconf-engine.c | 16 ++--
engine/dconf-engine.h | 4 +-
gsettings/dconfsettingsbackend.c | 2 +-
tests/paths.c | 12 +-
15 files changed, 211 insertions(+), 330 deletions(-)
---
diff --git a/bin/.gitignore b/bin/.gitignore
index 08c4537..b9cdeb5 100644
--- a/bin/.gitignore
+++ b/bin/.gitignore
@@ -1,4 +1,4 @@
dconf
dconf-update
-dconf-update.c
+*.c
*.stamp
diff --git a/bin/Makefile.am b/bin/Makefile.am
index 5544f82..2f77617 100644
--- a/bin/Makefile.am
+++ b/bin/Makefile.am
@@ -8,3 +8,7 @@ dconf_LDADD = ../client/libdconf.la $(gio_LIBS)
dconf_update_VALAFLAGS = --pkg=posix --pkg=gio-2.0
dconf_update_LDADD = $(gio_LIBS)
dconf_update_SOURCES = dconf-update.vala ../gvdb/gvdb-builder.c gvdb.vapi fixes.vapi
+
+dconf_VALAFLAGS = --pkg=gio-2.0 ../client/dconf.vapi
+dconf_LDADD = $(gio_LIBS) ../client/libdconf.la
+dconf_SOURCES = dconf.vala
diff --git a/bin/dconf.vala b/bin/dconf.vala
new file mode 100644
index 0000000..6276ba7
--- /dev/null
+++ b/bin/dconf.vala
@@ -0,0 +1,56 @@
+
+
+void do_read (DConf.Client client, string key) throws Error {
+ DConf.verify_key (key);
+
+ var result = client.read (key);
+ if (result != null) {
+ stdout.puts (result.print (true));
+ stdout.putc ('\n');
+ }
+}
+
+void do_list (DConf.Client client, string dir) throws Error {
+ DConf.verify_dir (dir);
+
+ foreach (var item in client.list (dir)) {
+ stdout.puts (item);
+ stdout.putc ('\n');
+ }
+}
+
+void do_write (DConf.Client client, string key, string val) throws Error {
+ DConf.verify_key (key);
+
+ client.write (key, Variant.parse (null, val));
+}
+
+void main (string[] args) {
+ try {
+ var client = new DConf.Client ();
+
+ Environment.set_prgname (args[0]);
+
+ switch (args[1]) {
+ case "read":
+ do_read (client, args[2]);
+ break;
+
+ case "list":
+ do_list (client, args[2]);
+ break;
+
+ case "write":
+ do_write (client, args[2], args[3]);
+ break;
+
+ default:
+ error ("unknown command");
+ break;
+ }
+ } catch (Error e) {
+ stderr.printf ("error: %s\n", e.message);
+ }
+}
+
+// vim:noet sw=4 ts=4
diff --git a/client/dconf-client.c b/client/dconf-client.c
index 9b44397..de6fbba 100644
--- a/client/dconf-client.c
+++ b/client/dconf-client.c
@@ -31,7 +31,6 @@ struct _DConfClient
GDBusConnection *system_bus;
DConfEngine *engine;
- gboolean will_write;
DConfWatchFunc watch_func;
gpointer user_data;
@@ -256,7 +255,7 @@ dconf_client_service_func (DConfEngineMessage *dcem)
/**
* dconf_client_new:
- * @context: the context string (must by %NULL for now)
+ * @profile: the dconf profile to use, or %NULL
* @will_write: %TRUE if you intend to use the client to write
* @watch_func: the function to call when changes occur
* @user_data: the user_data to pass to @watch_func
@@ -265,23 +264,23 @@ dconf_client_service_func (DConfEngineMessage *dcem)
*
* Creates a new #DConfClient for the given context.
*
- * If @will_write is %FALSE then you will not be able to use the created
- * client to write. The benefit of this is that when combined with
- * @watch_func being %NULL, no connection to D-Bus is required.
+ * If @profile is non-%NULL then it specifies the name of the profile to
+ * use. If @profile is %NULL then the DCONF_PROFILE environment
+ * variable is consulted. If that is unset then the default profile of
+ * "user" is used. If a profile named "user" is not installed then
+ * the dconf client is setup to access ~/.config/dconf/user.
**/
DConfClient *
-dconf_client_new (const gchar *context,
- gboolean will_write,
- DConfWatchFunc watch_func,
- gpointer user_data,
- GDestroyNotify notify)
+dconf_client_new (const gchar *profile,
+ DConfWatchFunc watch_func,
+ gpointer user_data,
+ GDestroyNotify notify)
{
DConfClient *client = g_object_new (DCONF_TYPE_CLIENT, NULL);
dconf_engine_set_service_func (dconf_client_service_func);
- client->engine = dconf_engine_new ();
- client->will_write = will_write;
+ client->engine = dconf_engine_new (profile);
client->watch_func = watch_func;
client->user_data = user_data;
client->notify = notify;
@@ -503,7 +502,7 @@ dconf_client_list (DConfClient *client,
}
/**
- * dconf_client_set_locked:
+ * dconf_client_set_lock:
* @client: a #DConfClient
* @path: a dconf path
* @locked: %TRUE to lock, %FALSE to unlock
@@ -522,15 +521,15 @@ dconf_client_list (DConfClient *client,
* this database as its defaults.
**/
gboolean
-dconf_client_set_locked (DConfClient *client,
- const gchar *path,
- gboolean locked,
- GCancellable *cancellable,
- GError **error)
+dconf_client_set_lock (DConfClient *client,
+ const gchar *path,
+ gboolean locked,
+ GCancellable *cancellable,
+ GError **error)
{
DConfEngineMessage dcem;
- dconf_engine_set_locked (client->engine, &dcem, path, locked);
+ dconf_engine_set_lock (client->engine, &dcem, path, locked);
return dconf_client_call_sync (client, &dcem, NULL, cancellable, error);
}
@@ -553,6 +552,7 @@ dconf_client_write_many (DConfClient *client,
const gchar *prefix,
const gchar * const *rels,
GVariant **values,
+ gsize n_values,
gchar **tag,
GCancellable *cancellable,
GError **error)
@@ -570,6 +570,7 @@ dconf_client_write_many_async (DConfClient *client,
const gchar *prefix,
const gchar * const *rels,
GVariant **values,
+ gsize n_values,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
diff --git a/client/dconf-client.h b/client/dconf-client.h
index ba79044..d4d3eab 100644
--- a/client/dconf-client.h
+++ b/client/dconf-client.h
@@ -41,22 +41,11 @@ typedef void (*DConfWatchFunc) (DConfCl
GType dconf_client_get_type (void);
-DConfClient * dconf_client_new (const gchar *context,
- gboolean will_write,
+DConfClient * dconf_client_new (const gchar *profile,
DConfWatchFunc watch_func,
gpointer user_data,
GDestroyNotify notify);
-void dconf_client_new_async (const gchar *context,
- gboolean will_write,
- DConfWatchFunc watch_func,
- gpointer watch_func_data,
- GDestroyNotify notify,
- GAsyncReadyCallback callback,
- gpointer user_data);
-
-DConfClient * dconf_client_new_finish (GAsyncResult *result);
-
GVariant * dconf_client_read (DConfClient *client,
const gchar *key);
GVariant * dconf_client_read_default (DConfClient *client,
@@ -69,7 +58,7 @@ gchar ** dconf_client_list (DConfCl
gsize *length);
gboolean dconf_client_is_writable (DConfClient *client,
- const gchar *path,
+ const gchar *key,
GError **error);
gboolean dconf_client_write (DConfClient *client,
@@ -89,18 +78,18 @@ gboolean dconf_client_write_finish (DConfCl
gchar **tag,
GError **error);
-gboolean dconf_client_set_locked (DConfClient *client,
+gboolean dconf_client_set_lock (DConfClient *client,
const gchar *path,
gboolean locked,
GCancellable *cancellable,
GError **error);
-void dconf_client_set_locked_async (DConfClient *client,
+void dconf_client_set_lock_async (DConfClient *client,
const gchar *path,
gboolean locked,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
-gboolean dconf_client_set_locked_finish (DConfClient *client,
+gboolean dconf_client_set_lock_finish (DConfClient *client,
GAsyncResult *result,
GError **error);
@@ -108,6 +97,7 @@ gboolean dconf_client_write_many (DConfCl
const gchar *prefix,
const gchar * const *keys,
GVariant **values,
+ gsize n_values,
gchar **tag,
GCancellable *cancellable,
GError **error);
@@ -115,6 +105,7 @@ void dconf_client_write_many_async (DConfCl
const gchar *prefix,
const gchar * const *keys,
GVariant **values,
+ gsize n_values,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
diff --git a/editor/dconf.vapi b/client/dconf.vapi
similarity index 53%
rename from editor/dconf.vapi
rename to client/dconf.vapi
index 52a49b4..75fd7b2 100644
--- a/editor/dconf.vapi
+++ b/client/dconf.vapi
@@ -5,7 +5,7 @@ namespace DConf {
[CCode (cheader_filename = "dconf.h")]
public class Client : GLib.Object {
[CCode (has_construct_function = false)]
- public Client (string context, bool can_write, DConf.WatchFunc? watch_func, GLib.DestroyNotify? notify);
+ public Client (string? profile = null, owned DConf.WatchFunc? watch_func = null);
public bool is_writable (string prefix) throws GLib.Error;
[CCode (array_length_type = "gsize")]
public string[] list (string prefix);
@@ -19,25 +19,42 @@ namespace DConf {
public bool watch (string name) throws GLib.Error;
public async bool watch_async (string name);
public bool watch_finish (GLib.AsyncResult _result);
- public bool write (string key, GLib.Variant value, uint64 sequence, GLib.Cancellable? cancellable) throws GLib.Error;
+ public bool write (string key, GLib.Variant? value, out string? tag = null, GLib.Cancellable? cancellable = null) throws GLib.Error;
public async bool write_async (string key, GLib.Variant value, GLib.Cancellable? cancellable) throws GLib.Error;
- public bool write_finish (GLib.AsyncResult _result, uint64 sequence) throws GLib.Error;
- public bool write_many (string prefix, string keys, out unowned GLib.Variant values, uint64 sequence, GLib.Cancellable? cancellable) throws GLib.Error;
+ public bool write_finish (GLib.AsyncResult _result, out string? tag = null) throws GLib.Error;
+ public bool write_many (string prefix, string[] keys, GLib.Variant?[] values, out string? tag = null, GLib.Cancellable? cancellable = null) throws GLib.Error;
public async bool write_many_async (string prefix, string keys, out unowned GLib.Variant values, GLib.Cancellable? cancellable) throws GLib.Error;
public bool write_many_finish (GLib.AsyncResult _result, uint64 sequence) throws GLib.Error;
}
+
[CCode (cheader_filename = "dconf.h")]
public delegate void WatchFunc (DConf.Client client, string path, string items);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_dir (string str);
+ public bool is_dir (string str, void *error = null);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_key (string str);
+ public bool is_key (string str, void *error = null);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_path (string str);
+ public bool is_path (string str, void *error = null);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_rel (string str);
+ public bool is_rel (string str, void *error = null);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_rel_dir (string str);
+ public bool is_rel_dir (string str, void *error = null);
[CCode (cheader_filename = "dconf.h")]
- public static bool is_rel_key (string str);
+ public bool is_rel_key (string str, void *error = null);
+
+
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_dir")]
+ public void verify_dir (string str) throws GLib.Error;
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_key")]
+ public void verify_key (string str) throws GLib.Error;
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_path")]
+ public void verify_path (string str) throws GLib.Error;
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_rel")]
+ public void verify_rel (string str) throws GLib.Error;
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_rel_dir")]
+ public void verify_rel_dir (string str) throws GLib.Error;
+ [CCode (cheader_filename = "dconf.h", cname="dconf_is_rel_key")]
+ public void verify_rel_key (string str) throws GLib.Error;
}
+
+// vim:noet ts=4 sw=4
diff --git a/common/dconf-paths.c b/common/dconf-paths.c
index de1e837..f31bab3 100644
--- a/common/dconf-paths.c
+++ b/common/dconf-paths.c
@@ -24,29 +24,59 @@
#define vars gchar c, l
+#define DCONF_ERROR 0
+#define DCONF_ERROR_PATH 0
+
#define absolute \
- if ((l = *string++) != '/') \
- return FALSE \
+ if ((l = *string++) != '/') \
+ { \
+ g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
+ "dconf %s must begin with a slash", type); \
+ return FALSE; \
+ }
#define relative \
+ if (*string == '/') \
+ { \
+ g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
+ "dconf %s must not begin with a slash", type); \
+ return FALSE; \
+ } \
l = '/'
#define no_double_slash \
- while ((c = *string++)) \
- { \
- if (c == '/' && l == '/') \
- return FALSE; \
- l = c; \
- } \
+ while ((c = *string++)) \
+ { \
+ if (c == '/' && l == '/') \
+ { \
+ g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
+ "dconf %s must not contain two " \
+ "consecutive slashes", type); \
+ return FALSE; \
+ } \
+ l = c; \
+ } \
#define path \
return TRUE
#define key \
- return l != '/'
+ if (l == '/') \
+ { \
+ g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
+ "dconf %s must not end with a slash", type); \
+ return FALSE; \
+ } \
+ return TRUE
#define dir \
- return l == '/'
+ if (l != '/') \
+ { \
+ g_set_error (error, DCONF_ERROR, DCONF_ERROR_PATH, \
+ "dconf %s must end with a slash", type); \
+ return FALSE; \
+ } \
+ return TRUE
@@ -62,9 +92,12 @@
* dconf_is_dir() for examples of each.
**/
gboolean
-dconf_is_path (const gchar *string)
+dconf_is_path (const gchar *string,
+ GError **error)
{
+#define type "path"
vars; absolute; no_double_slash; path;
+#undef type
}
/**
@@ -83,9 +116,12 @@ dconf_is_path (const gchar *string)
* keys.
**/
gboolean
-dconf_is_key (const gchar *string)
+dconf_is_key (const gchar *string,
+ GError **error)
{
+#define type "key"
vars; absolute; no_double_slash; key;
+#undef type
}
/**
@@ -105,9 +141,12 @@ dconf_is_key (const gchar *string)
* dirs.
**/
gboolean
-dconf_is_dir (const gchar *string)
+dconf_is_dir (const gchar *string,
+ GError **error)
{
+#define type "dir"
vars; absolute; no_double_slash; dir;
+#undef type
}
/**
@@ -123,9 +162,12 @@ dconf_is_dir (const gchar *string)
* dconf_is_rel_key() and dconf_is_rel_dir() for examples of each.
**/
gboolean
-dconf_is_rel (const gchar *string)
+dconf_is_rel (const gchar *string,
+ GError **error)
{
+#define type "relative path"
vars; relative; no_double_slash; path;
+#undef type
}
@@ -144,9 +186,12 @@ dconf_is_rel (const gchar *string)
* not relative keys.
**/
gboolean
-dconf_is_rel_key (const gchar *string)
+dconf_is_rel_key (const gchar *string,
+ GError **error)
{
+#define type "relative key"
vars; relative; no_double_slash; key;
+#undef type
}
/**
@@ -166,7 +211,10 @@ dconf_is_rel_key (const gchar *string)
* not relative dirs.
**/
gboolean
-dconf_is_rel_dir (const gchar *string)
+dconf_is_rel_dir (const gchar *string,
+ GError **error)
{
+#define type "relative dir"
vars; relative; no_double_slash; dir;
+#undef type
}
diff --git a/common/dconf-paths.h b/common/dconf-paths.h
index c9f3609..6697a86 100644
--- a/common/dconf-paths.h
+++ b/common/dconf-paths.h
@@ -25,12 +25,18 @@
#include <glib.h>
-gboolean dconf_is_path (const gchar *string);
-gboolean dconf_is_key (const gchar *string);
-gboolean dconf_is_dir (const gchar *string);
+gboolean dconf_is_path (const gchar *string,
+ GError **error);
+gboolean dconf_is_key (const gchar *string,
+ GError **error);
+gboolean dconf_is_dir (const gchar *string,
+ GError **error);
-gboolean dconf_is_rel (const gchar *string);
-gboolean dconf_is_rel_key (const gchar *string);
-gboolean dconf_is_rel_dir (const gchar *string);
+gboolean dconf_is_rel (const gchar *string,
+ GError **error);
+gboolean dconf_is_rel_key (const gchar *string,
+ GError **error);
+gboolean dconf_is_rel_dir (const gchar *string,
+ GError **error);
#endif /* _dconf_common_h_ */
diff --git a/editor/Makefile.am b/editor/Makefile.am
index e2e77a6..a5ec825 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -3,4 +3,4 @@ bin_PROGRAMS = dconf-editor
AM_CFLAGS = $(gtk_CFLAGS) $(gee_CFLAGS) $(libxml_CFLAGS) -I$(top_srcdir)/common -I$(top_srcdir)/client
AM_VALAFLAGS = --pkg gee-1.0 --pkg gtk+-2.0 --pkg libxml-2.0
dconf_editor_LDADD = ../client/libdconf.la $(gtk_LIBS) $(gee_LIBS) $(libxml_LIBS)
-dconf_editor_SOURCES = dconf-editor.vala dconf-model.vala dconf-schema.vala dconf-view.vala dconf.vapi
+dconf_editor_SOURCES = dconf-editor.vala dconf-model.vala dconf-schema.vala dconf-view.vala ../client/dconf.vapi
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 42f5b3a..4762720 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -51,7 +51,7 @@ public class Key : GLib.Object
_value = value;
try
{
- model.client.write(full_name, value, 0, null);
+ model.client.write(full_name, value);
}
catch (GLib.Error e)
{
@@ -459,7 +459,7 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
public SettingsModel()
{
- client = new DConf.Client("", true, null, null);
+ client = new DConf.Client ();
root = new Directory(this, null, 0, "/", "/");
schemas = new SchemaList();
diff --git a/engine/dconf-engine.c b/engine/dconf-engine.c
index 3efa5f1..02e5bf3 100644
--- a/engine/dconf-engine.c
+++ b/engine/dconf-engine.c
@@ -262,9 +262,8 @@ dconf_engine_load_profile (const gchar *profile,
}
DConfEngine *
-dconf_engine_new (void)
+dconf_engine_new (const gchar *profile)
{
- const gchar *profile;
DConfEngine *engine;
gint i;
@@ -272,7 +271,8 @@ dconf_engine_new (void)
engine->ref_count = 1;
engine->shm = NULL;
- profile = getenv ("DCONF_PROFILE");
+ if (profile == NULL)
+ profile = getenv ("DCONF_PROFILE");
if (profile)
{
@@ -477,12 +477,12 @@ dconf_engine_write_many (DConfEngine *engine,
}
void
-dconf_engine_set_locked (DConfEngine *engine,
- DConfEngineMessage *dcem,
- const gchar *path,
- gboolean locked)
+dconf_engine_set_lock (DConfEngine *engine,
+ DConfEngineMessage *dcem,
+ const gchar *path,
+ gboolean locked)
{
- dconf_engine_dcem (engine, dcem, "SetLocked", "(sb)", path, locked);
+ dconf_engine_dcem (engine, dcem, "SetLock", "(sb)", path, locked);
}
gchar **
diff --git a/engine/dconf-engine.h b/engine/dconf-engine.h
index a8e7474..2beda07 100644
--- a/engine/dconf-engine.h
+++ b/engine/dconf-engine.h
@@ -23,7 +23,7 @@ typedef struct
typedef GVariant * (*DConfEngineServiceFunc) (DConfEngineMessage *message);
void dconf_engine_set_service_func (DConfEngineServiceFunc func);
-DConfEngine * dconf_engine_new (void);
+DConfEngine * dconf_engine_new (const gchar *profile);
DConfEngine * dconf_engine_new_for_db (DConfEngineServiceFunc *service,
const gchar *db_name);
guint64 dconf_engine_get_state (DConfEngine *engine);
@@ -73,7 +73,7 @@ gboolean dconf_engine_decode_notify (DConfEn
const gchar *interface,
const gchar *member,
GVariant *body);
-void dconf_engine_set_locked (DConfEngine *engine,
+void dconf_engine_set_lock (DConfEngine *engine,
DConfEngineMessage *message,
const gchar *path,
gboolean locked);
diff --git a/gsettings/dconfsettingsbackend.c b/gsettings/dconfsettingsbackend.c
index 66c0881..3ed35f3 100644
--- a/gsettings/dconfsettingsbackend.c
+++ b/gsettings/dconfsettingsbackend.c
@@ -611,7 +611,7 @@ static void
dconf_settings_backend_init (DConfSettingsBackend *dcsb)
{
dconf_engine_set_service_func (dconf_settings_backend_service_func);
- dcsb->engine = dconf_engine_new ();
+ dcsb->engine = dconf_engine_new (NULL);
}
static void
diff --git a/tests/paths.c b/tests/paths.c
index 0b6b0ce..a95530e 100644
--- a/tests/paths.c
+++ b/tests/paths.c
@@ -75,12 +75,12 @@ test_paths (void)
const gchar *string = cases[i].string;
guint flags;
- flags = (dconf_is_path (string) ? 001 : 000) |
- (dconf_is_key (string) ? 002 : 000) |
- (dconf_is_dir (string) ? 004 : 000) |
- (dconf_is_rel (string) ? 010 : 000) |
- (dconf_is_rel_key (string) ? 020 : 000) |
- (dconf_is_rel_dir (string) ? 040 : 000);
+ flags = (dconf_is_path (string, NULL) ? 001 : 000) |
+ (dconf_is_key (string, NULL) ? 002 : 000) |
+ (dconf_is_dir (string, NULL) ? 004 : 000) |
+ (dconf_is_rel (string, NULL) ? 010 : 000) |
+ (dconf_is_rel_key (string, NULL) ? 020 : 000) |
+ (dconf_is_rel_dir (string, NULL) ? 040 : 000);
if (flags != cases[i].flags)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]