1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* 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 <string.h>
void
dconf_engine_source_free (DConfEngineSource *source)
{
if (source->values)
gvdb_table_unref (source->values);
if (source->locks)
gvdb_table_unref (source->locks);
source->vtable->finalize (source);
g_free (source->bus_name);
g_free (source->object_path);
g_free (source->name);
g_free (source);
}
gboolean
dconf_engine_source_refresh (DConfEngineSource *source)
{
if (source->vtable->needs_reopen (source))
{
gboolean was_open;
gboolean is_open;
/* Record if we had a gvdb before or not. */
was_open = source->values != NULL;
g_clear_pointer (&source->values, gvdb_table_unref);
g_clear_pointer (&source->locks, gvdb_table_unref);
source->values = source->vtable->reopen (source);
if (source->values)
source->locks = gvdb_table_get_table (source->values, ".locks");
/* Check if we ended up with a gvdb. */
is_open = source->values != NULL;
/* Only return TRUE in the case that we either had a database
* before or ended up with one after. In the case that we just go
* from NULL to NULL, return FALSE.
*/
return was_open || is_open;
}
return FALSE;
}
DConfEngineSource *
dconf_engine_source_new (const gchar *description)
{
const DConfEngineSourceVTable *vtable;
DConfEngineSource *source;
switch (description[0])
{
case 's':
vtable = &dconf_engine_source_system_vtable;
break;
case 'u':
vtable = &dconf_engine_source_user_vtable;
break;
default:
g_warning ("unknown dconf database description: %s", description);
return NULL;
}
source = g_malloc0 (vtable->instance_size);
source->vtable = vtable;
source->name = strchr (description, ':');
if (source->name)
source->name = g_strdup (source->name + 1);
source->vtable->init (source);
return source;
}
DConfEngineSource *
dconf_engine_source_new_default (void)
{
DConfEngineSource *source;
source = g_malloc0 (dconf_engine_source_user_vtable.instance_size);
source->vtable = &dconf_engine_source_user_vtable;
source->name = g_strdup ("user");
source->vtable->init (source);
return source;
}
|