summaryrefslogtreecommitdiff
path: root/engine/dconf-engine-source-user.c
diff options
context:
space:
mode:
authorRyan Lortie <desrt@desrt.ca>2012-07-02 00:49:46 -0400
committerRyan Lortie <desrt@desrt.ca>2012-07-02 00:49:46 -0400
commit4eea8cb823c5a113d8209b04102f17f08df853d6 (patch)
tree5a8bb7d0c220e00981c0f0ba6e834ac8e1f6e584 /engine/dconf-engine-source-user.c
parent6a675a5bdef5949e2397b0d5ca9d0c8a36ccedfd (diff)
downloaddconf-4eea8cb823c5a113d8209b04102f17f08df853d6.tar.gz
Massively reorganise the client-side
This commit represents a rather complete rethinking of DConfEngine. - the different kinds of sources are now properly abstracted. This will make landing NFS support substantially easier. - there is now substantially more internal documentation - DConfEngineMessage is gone and replaced with ordinary function calls to be implemented by the D-Bus glue code - the GDBus glue has been factored out and is now shared between the client library and GSettings - the "outstanding" queue logic from the GSettings backend is now in the engine - all changes now go through a single API that accepts a (new) DConfChangeset object. Currently this only supports the current operations (ie: setting and resetting). In the future this object will also support the directory operations required by GSettingsList and will be the basis for the new approach to implementing the 'delayed' GSettingsBackend (which will be the method by which those two concepts can co-exist). The (internal) API of the engine changed substantially. This caused the following: - the libdconf client library has been rewritten in C. Most of the complicated aspects of it (that made it more convenience to use Vala) are now gone. - during the rewrite of libdconf, the DConfClient API changed a bit to look more like a proper GObject. It now makes GIO-style use of thread-default main contexts and uses GObject signals for notifications (instead of hand-rolled callbacks). - the GSettings backend has been substantially simplified (the "outstanding" logic is gone). No externally-visible changes. - the dbus-1 backend has taken a copy of the old engine code for now until it can be ported to the new engine and sufficiently tested. No externally-visible changes. - the dconf commandline tool and dconf-editor required minor changes to adjust to the DConfClient API changes There is a substantial amount of cleaning up and finishing of work to be done. There are many stubs remaining. There are likely still a large number of bugs.
Diffstat (limited to 'engine/dconf-engine-source-user.c')
-rw-r--r--engine/dconf-engine-source-user.c163
1 files changed, 163 insertions, 0 deletions
diff --git a/engine/dconf-engine-source-user.c b/engine/dconf-engine-source-user.c
new file mode 100644
index 0000000..dba655f
--- /dev/null
+++ b/engine/dconf-engine-source-user.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright © 2010 Codethink Limited
+ * Copyright © 2012 Canonical Limited
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the licence, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ * Author: Ryan Lortie <desrt@desrt.ca>
+ */
+
+#include "dconf-engine-source-private.h"
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+
+typedef struct
+{
+ DConfEngineSource source;
+
+ guint8 *shm;
+} DConfEngineSourceUser;
+
+static guint8 *
+dconf_engine_source_user_open_shm (const gchar *name)
+{
+ static gchar *shmdir;
+ gchar *filename;
+ void *memory;
+ gint fd;
+
+ if (shmdir == NULL)
+ shmdir = g_build_filename (g_get_user_runtime_dir (), "dconf", NULL);
+
+ filename = g_build_filename (shmdir, name, NULL);
+ memory = NULL;
+ fd = -1;
+
+ if (g_mkdir_with_parents (shmdir, 0700) != 0)
+ {
+ g_critical ("unable to create directory '%s': %s. dconf will not work properly.", shmdir, g_strerror (errno));
+ goto out;
+ }
+
+ fd = open (filename, O_RDWR | O_CREAT, 0600);
+ if (fd == -1)
+ {
+ g_critical ("unable to create file '%s': %s. dconf will not work properly.", filename, g_strerror (errno));
+ goto out;
+ }
+
+ if (ftruncate (fd, 1) != 0)
+ {
+ g_critical ("failed to allocate file '%s': %s. dconf will not work properly.", filename, g_strerror (errno));
+ goto out;
+ }
+
+ memory = mmap (NULL, 1, PROT_READ, MAP_SHARED, fd, 0);
+ g_assert (memory != NULL);
+
+ if (memory == MAP_FAILED)
+ {
+ g_critical ("failed to mmap file '%s': %s. dconf will not work properly.", filename, g_strerror (errno));
+ memory = NULL;
+ goto out;
+ }
+
+ out:
+ g_free (filename);
+ close (fd);
+
+ return memory;
+}
+
+static GvdbTable *
+dconf_engine_source_user_open_gvdb (const gchar *name)
+{
+ GvdbTable *table;
+ gchar *filename;
+
+ /* This can fail in the normal case of the user not having any
+ * settings. That's OK and it shouldn't be considered as an error.
+ */
+ filename = g_build_filename (g_get_user_config_dir (), "dconf", name, NULL);
+ table = gvdb_table_new (filename, FALSE, NULL);
+ g_free (filename);
+
+ return table;
+}
+
+static gboolean
+dconf_engine_source_user_init (DConfEngineSource *source)
+{
+ DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
+ guint8 *shm;
+
+ shm = dconf_engine_source_user_open_shm (source->name);
+
+ if (shm == NULL)
+ return FALSE;
+
+ source->bus_type = G_BUS_TYPE_SESSION;
+ source->bus_name = g_strdup ("ca.desrt.dconf");
+ source->object_path = g_strdup_printf ("/ca/desrt/dconf/Writer/%s", source->name);
+ source->writable = TRUE;
+ user_source->shm = shm;
+
+ source->values = dconf_engine_source_user_open_gvdb (source->name);
+
+ return TRUE;
+}
+
+static gboolean
+dconf_engine_source_user_needs_reopen (DConfEngineSource *source)
+{
+ DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
+
+ return user_source->shm && *user_source->shm;
+}
+
+static GvdbTable *
+dconf_engine_source_user_reopen (DConfEngineSource *source)
+{
+ DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
+
+ munmap (user_source->shm, 1);
+ user_source->shm = dconf_engine_source_user_open_shm (source->name);
+
+ if (user_source->shm)
+ return dconf_engine_source_user_open_gvdb (source->name);
+
+ return NULL;
+}
+
+static void
+dconf_engine_source_user_finalize (DConfEngineSource *source)
+{
+ DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
+
+ if (user_source->shm)
+ munmap (user_source->shm, 1);
+}
+
+G_GNUC_INTERNAL
+const DConfEngineSourceVTable dconf_engine_source_user_vtable = {
+ .instance_size = sizeof (DConfEngineSourceUser),
+ .init = dconf_engine_source_user_init,
+ .finalize = dconf_engine_source_user_finalize,
+ .needs_reopen = dconf_engine_source_user_needs_reopen,
+ .reopen = dconf_engine_source_user_reopen
+};