[dconf] engine: add a new database type: "service-db"



commit c15a1e3970e7c1567f6022bd85d9ab3267b08129
Author: Ryan Lortie <desrt desrt ca>
Date:   Wed Jan 9 13:50:13 2013 -0500

    engine: add a new database type: "service-db"
    
    service-db databases are based on a gvdb in the user runtime dir
    maintained by the dconf-service.
    
    On startup, the client will send an Init message to the service to
    ensure that the database is properly initialised.  After that, things
    are pretty much the same except that the values are read from the file
    in the runtime dir instead of from the home directory.
    
    We also drop the "shm" signalling mechanism for this case and instead
    use the same invalidation trick that system databases use (ie:
    overwriting the old gvdb header after writing the new file).

 engine/Makefile.am                   |    1 +
 engine/dconf-engine-source-private.h |    1 +
 engine/dconf-engine-source-service.c |   87 ++++++++++++++++++++++++++++++++++
 engine/dconf-engine-source.c         |    6 ++-
 4 files changed, 94 insertions(+), 1 deletions(-)
---
diff --git a/engine/Makefile.am b/engine/Makefile.am
index b69c70c..8061ba9 100644
--- a/engine/Makefile.am
+++ b/engine/Makefile.am
@@ -9,6 +9,7 @@ libdconf_engine_a_SOURCES = \
 	dconf-engine-source-private.h	\
 	dconf-engine-source.h		\
 	dconf-engine-source-user.c	\
+	dconf-engine-source-service.c	\
 	dconf-engine-source-system.c	\
 	dconf-engine-source.c		\
 	dconf-engine.h			\
diff --git a/engine/dconf-engine-source-private.h b/engine/dconf-engine-source-private.h
index 822354a..e0b943d 100644
--- a/engine/dconf-engine-source-private.h
+++ b/engine/dconf-engine-source-private.h
@@ -26,6 +26,7 @@
 #include "dconf-engine-source.h"
 
 G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_user_vtable;
+G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_service_vtable;
 G_GNUC_INTERNAL extern const DConfEngineSourceVTable dconf_engine_source_system_vtable;
 
 #endif /* __dconf_engine_source_private_h__ */
diff --git a/engine/dconf-engine-source-service.c b/engine/dconf-engine-source-service.c
new file mode 100644
index 0000000..a65be7b
--- /dev/null
+++ b/engine/dconf-engine-source-service.c
@@ -0,0 +1,87 @@
+/*
+ * 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 "dconf-engine.h"
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <errno.h>
+
+static void
+dconf_engine_source_service_init (DConfEngineSource *source)
+{
+  source->bus_type = G_BUS_TYPE_SESSION;
+  source->bus_name = g_strdup ("ca.desrt.dconf");
+  source->object_path = g_strdup_printf ("/ca/desrt/dconf/%s", source->name);
+  source->writable = TRUE;
+
+  dconf_engine_dbus_call_sync_func (source->bus_type, source->bus_name, source->object_path,
+                                    "ca.desrt.dconf.Writer", "Init", NULL, NULL, NULL);
+}
+
+static gboolean
+dconf_engine_source_service_needs_reopen (DConfEngineSource *source)
+{
+  return !source->values || !gvdb_table_is_valid (source->values);
+}
+
+static GvdbTable *
+dconf_engine_source_service_reopen (DConfEngineSource *source)
+{
+  static gboolean did_warn;
+  GError *error = NULL;
+  GvdbTable *table;
+  gchar *filename;
+
+  filename = g_build_filename (g_get_user_runtime_dir (), "dconf-service", source->name, NULL);
+  table = gvdb_table_new (filename, FALSE, &error);
+
+  if (table == NULL)
+    {
+      if (!did_warn)
+        {
+          g_critical ("unable to open file '%s': %s; expect degraded performance", filename, error->message);
+          did_warn = TRUE;
+        }
+
+      g_error_free (error);
+    }
+
+  g_free (filename);
+
+  return table;
+}
+
+static void
+dconf_engine_source_service_finalize (DConfEngineSource *source)
+{
+}
+
+G_GNUC_INTERNAL
+const DConfEngineSourceVTable dconf_engine_source_service_vtable = {
+  .instance_size    = sizeof (DConfEngineSource),
+  .init             = dconf_engine_source_service_init,
+  .finalize         = dconf_engine_source_service_finalize,
+  .needs_reopen     = dconf_engine_source_service_needs_reopen,
+  .reopen           = dconf_engine_source_service_reopen
+};
diff --git a/engine/dconf-engine-source.c b/engine/dconf-engine-source.c
index 4eb7faa..7cf30bf 100644
--- a/engine/dconf-engine-source.c
+++ b/engine/dconf-engine-source.c
@@ -96,11 +96,15 @@ dconf_engine_source_new (const gchar *description)
   if ((colon == description + 7) && memcmp (description, "user-db", 7) == 0)
     vtable = &dconf_engine_source_user_vtable;
 
+  /* ...or "service-db" */
+  else if ((colon == description + 10) && memcmp (description, "service-db", 10) == 0)
+    vtable = &dconf_engine_source_service_vtable;
+
   /* ...or "system-db" */
   else if ((colon == description + 9) && memcmp (description, "system-db", 9) == 0)
     vtable = &dconf_engine_source_system_vtable;
 
-  /* If it's not either of those, we have failed. */
+  /* If it's not any of those, we have failed. */
   else
     return NULL;
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]