service: add new 'string set' utility pseudoclass
[dconf.git] / engine / dconf-engine-source-user.c
blob982bbdf577ea3c248e5696238bdd2618b9b1d2fb
1 /*
2 * Copyright © 2010 Codethink Limited
3 * Copyright © 2012 Canonical Limited
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the licence, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
20 * Author: Ryan Lortie <desrt@desrt.ca>
23 #include "dconf-engine-source-private.h"
25 #include "../shm/dconf-shm.h"
26 #include <sys/mman.h>
27 #include <fcntl.h>
28 #include <errno.h>
30 typedef struct
32 DConfEngineSource source;
34 guint8 *shm;
35 } DConfEngineSourceUser;
37 static GvdbTable *
38 dconf_engine_source_user_open_gvdb (const gchar *name)
40 GvdbTable *table;
41 gchar *filename;
43 /* This can fail in the normal case of the user not having any
44 * settings. That's OK and it shouldn't be considered as an error.
46 filename = g_build_filename (g_get_user_config_dir (), "dconf", name, NULL);
47 table = gvdb_table_new (filename, FALSE, NULL);
48 g_free (filename);
50 return table;
53 static void
54 dconf_engine_source_user_init (DConfEngineSource *source)
56 source->bus_type = G_BUS_TYPE_SESSION;
57 source->bus_name = g_strdup ("ca.desrt.dconf");
58 source->object_path = g_strdup_printf ("/ca/desrt/dconf/Writer/%s", source->name);
59 source->writable = TRUE;
62 static gboolean
63 dconf_engine_source_user_needs_reopen (DConfEngineSource *source)
65 DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
67 return dconf_shm_is_flagged (user_source->shm);
70 static GvdbTable *
71 dconf_engine_source_user_reopen (DConfEngineSource *source)
73 DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
75 dconf_shm_close (user_source->shm);
76 user_source->shm = dconf_shm_open (source->name);
78 return dconf_engine_source_user_open_gvdb (source->name);
81 static void
82 dconf_engine_source_user_finalize (DConfEngineSource *source)
84 DConfEngineSourceUser *user_source = (DConfEngineSourceUser *) source;
86 dconf_shm_close (user_source->shm);
89 G_GNUC_INTERNAL
90 const DConfEngineSourceVTable dconf_engine_source_user_vtable = {
91 .instance_size = sizeof (DConfEngineSourceUser),
92 .init = dconf_engine_source_user_init,
93 .finalize = dconf_engine_source_user_finalize,
94 .needs_reopen = dconf_engine_source_user_needs_reopen,
95 .reopen = dconf_engine_source_user_reopen