2
* Copyright (C) 1999, 2000 Red Hat Inc.
4
* This library is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Library General Public
6
* License as published by the Free Software Foundation; either
7
* version 2 of the License, or (at your option) any later version.
9
* This library is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Library General Public License for more details.
14
* You should have received a copy of the GNU Library General Public
15
* License along with this library; if not, write to the
16
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17
* Boston, MA 02111-1307, USA.
20
#include "gconf-database.h"
21
#include "gconf-listeners.h"
22
#include "gconf-sources.h"
23
#include "gconf-locale.h"
26
#include <liboaf/liboaf.h>
30
/* This makes hash table safer when debugging */
31
#ifndef GCONF_ENABLE_DEBUG
32
#define safe_g_hash_table_insert g_hash_table_insert
35
safe_g_hash_table_insert(GHashTable* ht, gpointer key, gpointer value)
37
gpointer oldkey = NULL, oldval = NULL;
39
if (g_hash_table_lookup_extended(ht, key, &oldkey, &oldval))
41
gconf_log(GCL_WARNING, "Hash key `%s' is already in the table!",
47
g_hash_table_insert(ht, key, value);
56
static GConfLocaleList* locale_cache_lookup(const gchar* locale);
58
typedef struct _Listener Listener;
64
static Listener* listener_new(ConfigListener obj);
65
static void listener_destroy(Listener* l);
68
* CORBA implementation of ConfigDatabase
71
static CORBA_unsigned_long
72
impl_ConfigDatabase_add_listener(PortableServer_Servant servant,
73
const CORBA_char * where,
74
const ConfigListener who,
75
CORBA_Environment * ev)
77
GConfDatabase *db = (GConfDatabase*) servant;
79
if (gconfd_check_in_shutdown (ev))
82
return gconf_database_add_listener (db, who, where);
86
impl_ConfigDatabase_remove_listener(PortableServer_Servant servant,
87
CORBA_unsigned_long cnxn,
88
CORBA_Environment * ev)
90
GConfDatabase *db = (GConfDatabase*) servant;
92
if (gconfd_check_in_shutdown (ev))
95
gconf_database_remove_listener (db, cnxn);
99
impl_ConfigDatabase_lookup_with_locale(PortableServer_Servant servant,
100
const CORBA_char * key,
101
const CORBA_char * locale,
102
CORBA_boolean use_schema_default,
103
CORBA_boolean * value_is_default,
104
CORBA_boolean * value_is_writable,
105
CORBA_Environment * ev)
107
GConfDatabase *db = (GConfDatabase*) servant;
109
GError* error = NULL;
110
GConfLocaleList* locale_list;
111
gboolean is_default = FALSE;
112
gboolean is_writable = TRUE;
114
if (gconfd_check_in_shutdown (ev))
115
return invalid_corba_value ();
117
locale_list = locale_cache_lookup(locale);
119
val = gconf_database_query_value(db, key, locale_list->list,
126
*value_is_default = is_default;
127
*value_is_writable = is_writable;
129
gconf_locale_list_unref(locale_list);
133
ConfigValue* cval = corba_value_from_gconf_value(val);
135
gconf_value_free(val);
137
g_return_val_if_fail(error == NULL, cval);
143
gconf_set_exception(&error, ev);
145
return invalid_corba_value();
150
impl_ConfigDatabase_lookup(PortableServer_Servant servant,
151
const CORBA_char * key,
152
CORBA_Environment * ev)
154
if (gconfd_check_in_shutdown (ev))
155
return invalid_corba_value ();
157
return impl_ConfigDatabase_lookup_with_locale (servant, key,
163
impl_ConfigDatabase_lookup_default_value(PortableServer_Servant servant,
164
const CORBA_char * key,
165
const CORBA_char * locale,
166
CORBA_Environment * ev)
168
GConfDatabase *db = (GConfDatabase*) servant;
170
GError* error = NULL;
171
GConfLocaleList* locale_list;
173
if (gconfd_check_in_shutdown (ev))
174
return invalid_corba_value ();
176
locale_list = locale_cache_lookup(locale);
178
val = gconf_database_query_default_value(db, key,
183
gconf_locale_list_unref(locale_list);
187
ConfigValue* cval = corba_value_from_gconf_value(val);
189
gconf_value_free(val);
191
g_return_val_if_fail(error == NULL, cval);
197
gconf_set_exception(&error, ev);
199
return invalid_corba_value();
204
impl_ConfigDatabase_batch_lookup(PortableServer_Servant servant,
205
const ConfigDatabase_KeyList * keys,
206
const CORBA_char * locale,
207
ConfigDatabase_ValueList ** values,
208
ConfigDatabase_IsDefaultList ** is_defaults,
209
ConfigDatabase_IsWritableList ** is_writables,
210
CORBA_Environment * ev)
212
if (gconfd_check_in_shutdown (ev))
217
impl_ConfigDatabase_set(PortableServer_Servant servant,
218
const CORBA_char * key,
219
const ConfigValue * value,
220
CORBA_Environment * ev)
222
GConfDatabase *db = (GConfDatabase*) servant;
225
GError* error = NULL;
227
if (gconfd_check_in_shutdown (ev))
230
if (value->_d == InvalidVal)
232
gconf_log(GCL_ERR, _("Received invalid value in set request"));
236
val = gconf_value_from_corba_value(value);
240
gconf_log(GCL_ERR, _("Couldn't make sense of CORBA value received in set request for key `%s'"), key);
244
str = gconf_value_to_string(val);
247
/* reduce traffice to the logfile */
248
gconf_log(GCL_DEBUG, "Received request to set key `%s' to `%s'", key, str);
254
gconf_database_set(db, key, val, value, &error);
256
gconf_set_exception(&error, ev);
258
gconf_value_free(val);
262
impl_ConfigDatabase_unset_with_locale(PortableServer_Servant servant,
263
const CORBA_char * key,
264
const CORBA_char * locale,
265
CORBA_Environment * ev)
267
GConfDatabase *db = (GConfDatabase*) servant;
268
GError* error = NULL;
270
if (gconfd_check_in_shutdown (ev))
273
gconf_database_unset(db, key, locale, &error);
275
gconf_set_exception(&error, ev);
279
impl_ConfigDatabase_unset(PortableServer_Servant servant,
280
const CORBA_char * key,
281
CORBA_Environment * ev)
283
if (gconfd_check_in_shutdown (ev))
286
/* This is a cheat, since const CORBA_char* isn't normally NULL */
287
impl_ConfigDatabase_unset_with_locale (servant, key, NULL, ev);
291
impl_ConfigDatabase_batch_change (PortableServer_Servant servant,
292
const CORBA_char * locale,
293
const ConfigDatabase_KeyList * keys,
294
const ConfigDatabase_ValueList * values,
295
CORBA_Environment * ev)
297
if (gconfd_check_in_shutdown (ev))
302
impl_ConfigDatabase_dir_exists(PortableServer_Servant servant,
303
const CORBA_char * dir,
304
CORBA_Environment * ev)
306
GConfDatabase *db = (GConfDatabase*) servant;
307
CORBA_boolean retval;
308
GError* error = NULL;
310
if (gconfd_check_in_shutdown (ev))
314
gconf_database_dir_exists (db, dir, &error) ? CORBA_TRUE : CORBA_FALSE;
316
gconf_set_exception(&error, ev);
322
impl_ConfigDatabase_remove_dir(PortableServer_Servant servant,
323
const CORBA_char * dir,
324
CORBA_Environment * ev)
326
GConfDatabase *db = (GConfDatabase*) servant;
327
GError* error = NULL;
329
if (gconfd_check_in_shutdown (ev))
332
gconf_database_remove_dir(db, dir, &error);
334
gconf_set_exception(&error, ev);
338
impl_ConfigDatabase_all_entries(PortableServer_Servant servant,
339
const CORBA_char * dir,
340
const CORBA_char * locale,
341
ConfigDatabase_KeyList ** keys,
342
ConfigDatabase_ValueList ** values,
343
ConfigDatabase_IsDefaultList ** is_defaults,
344
ConfigDatabase_IsWritableList ** is_writables,
345
CORBA_Environment * ev)
347
GConfDatabase *db = (GConfDatabase*) servant;
352
GError* error = NULL;
353
GConfLocaleList* locale_list;
355
if (gconfd_check_in_shutdown (ev))
358
locale_list = locale_cache_lookup(locale);
360
pairs = gconf_database_all_entries(db, dir, locale_list->list, &error);
362
gconf_locale_list_unref(locale_list);
366
gconf_set_exception(&error, ev);
370
n = g_slist_length(pairs);
372
*keys= ConfigDatabase_KeyList__alloc();
373
(*keys)->_buffer = CORBA_sequence_CORBA_string_allocbuf(n);
374
(*keys)->_length = n;
375
(*keys)->_maximum = n;
376
(*keys)->_release = CORBA_TRUE; /* free buffer */
378
*values= ConfigDatabase_ValueList__alloc();
379
(*values)->_buffer = CORBA_sequence_ConfigValue_allocbuf(n);
380
(*values)->_length = n;
381
(*values)->_maximum = n;
382
(*values)->_release = CORBA_TRUE; /* free buffer */
384
*is_defaults = ConfigDatabase_IsDefaultList__alloc();
385
(*is_defaults)->_buffer = CORBA_sequence_CORBA_boolean_allocbuf(n);
386
(*is_defaults)->_length = n;
387
(*is_defaults)->_maximum = n;
388
(*is_defaults)->_release = CORBA_TRUE; /* free buffer */
390
*is_writables = ConfigDatabase_IsWritableList__alloc();
391
(*is_writables)->_buffer = CORBA_sequence_CORBA_boolean_allocbuf(n);
392
(*is_writables)->_length = n;
393
(*is_writables)->_maximum = n;
394
(*is_writables)->_release = CORBA_TRUE; /* free buffer */
401
GConfEntry* p = tmp->data;
404
g_assert(p->key != NULL);
406
(*keys)->_buffer[i] = CORBA_string_dup(p->key);
407
fill_corba_value_from_gconf_value(p->value, &((*values)->_buffer[i]));
408
(*is_defaults)->_buffer[i] = gconf_entry_get_is_default(p);
409
(*is_writables)->_buffer[i] = gconf_entry_get_is_writable(p);
414
tmp = g_slist_next(tmp);
423
impl_ConfigDatabase_all_dirs(PortableServer_Servant servant,
424
const CORBA_char * dir,
425
ConfigDatabase_KeyList ** keys,
426
CORBA_Environment * ev)
428
GConfDatabase *db = (GConfDatabase*) servant;
433
GError* error = NULL;
435
if (gconfd_check_in_shutdown (ev))
438
subdirs = gconf_database_all_dirs (db, dir, &error);
442
/* I think this is right anyway... */
443
gconf_set_exception (&error, ev);
448
n = g_slist_length (subdirs);
450
*keys = ConfigDatabase_KeyList__alloc();
451
(*keys)->_buffer = CORBA_sequence_CORBA_string_allocbuf(n);
452
(*keys)->_length = n;
453
(*keys)->_maximum = n;
454
(*keys)->_release = CORBA_TRUE; /* free buffer */
461
gchar* subdir = tmp->data;
463
(*keys)->_buffer[i] = CORBA_string_dup (subdir);
468
tmp = g_slist_next (tmp);
473
g_slist_free (subdirs);
477
impl_ConfigDatabase_set_schema(PortableServer_Servant servant,
478
const CORBA_char * key,
479
const CORBA_char * schema_key,
480
CORBA_Environment * ev)
482
GConfDatabase *db = (GConfDatabase*) servant;
483
GError* error = NULL;
485
if (gconfd_check_in_shutdown (ev))
488
gconf_database_set_schema(db, key, schema_key, &error);
490
gconf_set_exception(&error, ev);
494
impl_ConfigDatabase_sync(PortableServer_Servant servant,
495
CORBA_Environment * ev)
497
GConfDatabase *db = (GConfDatabase*) servant;
498
GError* error = NULL;
500
if (gconfd_check_in_shutdown (ev))
503
gconf_database_sync(db, &error);
505
gconf_set_exception(&error, ev);
509
impl_ConfigDatabase_clear_cache(PortableServer_Servant servant,
510
CORBA_Environment * ev)
512
GConfDatabase *db = (GConfDatabase*) servant;
513
GError* error = NULL;
515
if (gconfd_check_in_shutdown (ev))
518
gconf_log(GCL_DEBUG, _("Received request to drop all cached data"));
520
gconf_database_clear_cache(db, &error);
522
gconf_set_exception(&error, ev);
526
impl_ConfigDatabase_synchronous_sync(PortableServer_Servant servant,
527
CORBA_Environment * ev)
529
GConfDatabase *db = (GConfDatabase*) servant;
530
GError* error = NULL;
532
if (gconfd_check_in_shutdown (ev))
535
gconf_log(GCL_DEBUG, _("Received request to sync synchronously"));
538
gconf_database_synchronous_sync(db, &error);
540
gconf_set_exception(&error, ev);
545
impl_ConfigDatabase2_lookup_with_schema_name(PortableServer_Servant servant,
546
const CORBA_char * key,
547
const CORBA_char * locale,
548
CORBA_boolean use_schema_default,
549
CORBA_char **schema_name,
550
CORBA_boolean * value_is_default,
551
CORBA_boolean * value_is_writable,
552
CORBA_Environment * ev)
554
GConfDatabase *db = (GConfDatabase*) servant;
556
GError* error = NULL;
557
GConfLocaleList* locale_list;
558
gboolean is_default = FALSE;
559
gboolean is_writable = TRUE;
563
if (gconfd_check_in_shutdown (ev))
564
return invalid_corba_value ();
566
locale_list = locale_cache_lookup(locale);
569
val = gconf_database_query_value(db, key, locale_list->list,
576
*value_is_default = is_default;
577
*value_is_writable = is_writable;
580
*schema_name = CORBA_string_dup (s);
582
*schema_name = CORBA_string_dup ("");
586
gconf_locale_list_unref(locale_list);
590
cval = corba_value_from_gconf_value(val);
591
gconf_value_free(val);
592
g_return_val_if_fail(error == NULL, cval);
596
cval = invalid_corba_value();
599
gconf_log (GCL_DEBUG, "In lookup_with_schema_name returning schema name '%s' error '%s'",
600
*schema_name, error ? error->message : "none");
604
gconf_set_exception (&error, ev);
611
impl_ConfigDatabase2_all_entries_with_schema_name(PortableServer_Servant servant,
612
const CORBA_char * dir,
613
const CORBA_char * locale,
614
ConfigDatabase_KeyList ** keys,
615
ConfigDatabase_ValueList ** values,
616
ConfigDatabase2_SchemaNameList **schema_names,
617
ConfigDatabase_IsDefaultList **is_defaults,
618
ConfigDatabase_IsWritableList **is_writables,
619
CORBA_Environment * ev)
621
GConfDatabase *db = (GConfDatabase*) servant;
626
GError* error = NULL;
627
GConfLocaleList* locale_list;
629
if (gconfd_check_in_shutdown (ev))
632
locale_list = locale_cache_lookup(locale);
634
pairs = gconf_database_all_entries(db, dir, locale_list->list, &error);
636
gconf_locale_list_unref(locale_list);
640
gconf_set_exception(&error, ev);
644
n = g_slist_length(pairs);
646
*keys= ConfigDatabase_KeyList__alloc();
647
(*keys)->_buffer = CORBA_sequence_CORBA_string_allocbuf(n);
648
(*keys)->_length = n;
649
(*keys)->_maximum = n;
650
(*keys)->_release = CORBA_TRUE; /* free buffer */
652
*values= ConfigDatabase_ValueList__alloc();
653
(*values)->_buffer = CORBA_sequence_ConfigValue_allocbuf(n);
654
(*values)->_length = n;
655
(*values)->_maximum = n;
656
(*values)->_release = CORBA_TRUE; /* free buffer */
658
*schema_names = ConfigDatabase2_SchemaNameList__alloc();
659
(*schema_names)->_buffer = CORBA_sequence_CORBA_string_allocbuf(n);
660
(*schema_names)->_length = n;
661
(*schema_names)->_maximum = n;
662
(*schema_names)->_release = CORBA_TRUE; /* free buffer */
664
*is_defaults = ConfigDatabase_IsDefaultList__alloc();
665
(*is_defaults)->_buffer = CORBA_sequence_CORBA_boolean_allocbuf(n);
666
(*is_defaults)->_length = n;
667
(*is_defaults)->_maximum = n;
668
(*is_defaults)->_release = CORBA_TRUE; /* free buffer */
670
*is_writables = ConfigDatabase_IsWritableList__alloc();
671
(*is_writables)->_buffer = CORBA_sequence_CORBA_boolean_allocbuf(n);
672
(*is_writables)->_length = n;
673
(*is_writables)->_maximum = n;
674
(*is_writables)->_release = CORBA_TRUE; /* free buffer */
681
GConfEntry* p = tmp->data;
684
g_assert(p->key != NULL);
686
(*keys)->_buffer[i] = CORBA_string_dup(p->key);
687
fill_corba_value_from_gconf_value(p->value, &((*values)->_buffer[i]));
688
(*schema_names)->_buffer[i] = CORBA_string_dup (gconf_entry_get_schema_name (p));
689
if ((*schema_names)->_buffer[i] == NULL)
690
(*schema_names)->_buffer[i] = CORBA_string_dup ("");
691
(*is_defaults)->_buffer[i] = gconf_entry_get_is_default(p);
692
(*is_writables)->_buffer[i] = gconf_entry_get_is_writable(p);
697
tmp = g_slist_next(tmp);
705
static PortableServer_ServantBase__epv base_epv = {
711
static POA_ConfigDatabase__epv server_epv = {
713
impl_ConfigDatabase_add_listener,
714
impl_ConfigDatabase_remove_listener,
715
impl_ConfigDatabase_lookup,
716
impl_ConfigDatabase_lookup_with_locale,
717
impl_ConfigDatabase_lookup_default_value,
718
impl_ConfigDatabase_batch_lookup,
719
impl_ConfigDatabase_set,
720
impl_ConfigDatabase_unset,
721
impl_ConfigDatabase_unset_with_locale,
722
impl_ConfigDatabase_batch_change,
723
impl_ConfigDatabase_dir_exists,
724
impl_ConfigDatabase_remove_dir,
725
impl_ConfigDatabase_all_entries,
726
impl_ConfigDatabase_all_dirs,
727
impl_ConfigDatabase_set_schema,
728
impl_ConfigDatabase_sync,
729
impl_ConfigDatabase_clear_cache,
730
impl_ConfigDatabase_synchronous_sync
733
static POA_ConfigDatabase2__epv server2_epv = {
735
impl_ConfigDatabase2_lookup_with_schema_name,
736
impl_ConfigDatabase2_all_entries_with_schema_name
739
static POA_ConfigDatabase2__vepv poa_server_vepv = { &base_epv, &server_epv, &server2_epv };
741
static void gconf_database_really_sync(GConfDatabase* db);
744
gconf_database_new (GConfSources *sources)
747
CORBA_Environment ev;
748
PortableServer_ObjectId* objid;
750
db = g_new0 (GConfDatabase, 1);
752
db->servant._private = NULL;
753
db->servant.vepv = &poa_server_vepv;
755
CORBA_exception_init (&ev);
757
POA_ConfigDatabase2__init (&db->servant, &ev);
760
PortableServer_POA_activate_object(gconf_get_poa (),
764
db->objref = PortableServer_POA_servant_to_reference(gconf_get_poa (),
767
if (CORBA_Object_is_nil(db->objref, &ev))
770
_("Fatal error: failed to get object reference for ConfigDatabase"));
777
db->listeners = gconf_listeners_new();
779
db->sources = sources;
781
db->last_access = time(NULL);
784
db->sync_timeout = 0;
786
db->persistent_name = NULL;
792
gconf_database_free (GConfDatabase *db)
794
PortableServer_ObjectId *oid;
795
CORBA_Environment ev;
797
CORBA_exception_init (&ev);
799
CORBA_Object_release (db->objref, &ev);
801
CORBA_exception_free (&ev);
803
oid = PortableServer_POA_servant_to_id (gconf_get_poa(), &db->servant, &ev);
805
CORBA_exception_free (&ev);
807
PortableServer_POA_deactivate_object (gconf_get_poa (), oid, &ev);
809
CORBA_exception_free (&ev);
811
POA_ConfigDatabase2__fini (&db->servant, &ev);
815
CORBA_exception_free (&ev);
817
if (db->listeners != NULL)
819
gboolean need_sync = FALSE;
821
g_assert(db->sources != NULL);
823
if (db->sync_idle != 0)
825
g_source_remove(db->sync_idle);
830
if (db->sync_timeout != 0)
832
g_source_remove(db->sync_timeout);
833
db->sync_timeout = 0;
838
gconf_database_really_sync(db);
840
gconf_listeners_free(db->listeners);
841
gconf_sources_free(db->sources);
844
g_free (db->persistent_name);
850
client_alive_predicate (const gchar* location,
852
gpointer listener_data,
855
Listener *l = listener_data;
856
CORBA_Environment ev;
858
CORBA_exception_init (&ev);
860
ConfigListener_ping (l->obj, &ev);
862
if (ev._major != CORBA_NO_EXCEPTION)
864
gconf_log (GCL_DEBUG, "Removing stale listener %u, client not alive",
867
CORBA_exception_free (&ev);
876
gconf_database_drop_dead_listeners (GConfDatabase *db)
880
gconf_listeners_remove_if (db->listeners,
881
client_alive_predicate,
887
gconf_database_sync_idle (GConfDatabase* db)
891
/* could have been added before reaching the
893
if (db->sync_timeout != 0)
895
g_source_remove (db->sync_timeout);
896
db->sync_timeout = 0;
899
gconf_database_really_sync (db);
901
/* Remove the idle function by returning FALSE */
906
gconf_database_sync_timeout(GConfDatabase* db)
908
db->sync_timeout = 0;
910
/* Install the sync idle */
911
if (db->sync_idle == 0)
912
db->sync_idle = g_idle_add((GSourceFunc)gconf_database_sync_idle, db);
914
gconf_log(GCL_DEBUG, "Sync queued one minute after changes occurred");
916
/* Remove the timeout function by returning FALSE */
921
gconf_database_really_sync(GConfDatabase* db)
923
GError* error = NULL;
925
if (!gconf_database_synchronous_sync(db, &error))
927
g_return_if_fail(error != NULL);
929
gconf_log(GCL_ERR, _("Failed to sync one or more sources: %s"),
935
gconf_log(GCL_DEBUG, "Sync completed without errors");
940
gconf_database_sync_nowish(GConfDatabase* db)
942
/* Go ahead and sync as soon as the event loop quiets down */
944
/* remove the scheduled sync */
945
if (db->sync_timeout != 0)
947
g_source_remove(db->sync_timeout);
948
db->sync_timeout = 0;
951
/* Schedule immediate post-quietdown sync */
952
if (db->sync_idle == 0)
953
db->sync_idle = g_idle_add((GSourceFunc)gconf_database_sync_idle, db);
957
gconf_database_schedule_sync(GConfDatabase* db)
959
/* Plan to sync within a minute or so */
960
if (db->sync_idle != 0)
962
else if (db->sync_timeout != 0)
966
/* 1 minute timeout */
967
db->sync_timeout = g_timeout_add(60000, (GSourceFunc)gconf_database_sync_timeout, db);
972
gconf_database_readd_listener (GConfDatabase *db,
979
gconfd_need_log_cleanup ();
981
g_assert(db->listeners != NULL);
983
db->last_access = time(NULL);
985
l = listener_new(who);
987
cnxn = gconf_listeners_add (db->listeners, where, l,
988
(GFreeFunc)listener_destroy);
990
gconf_log (GCL_DEBUG, "Added listener %u", cnxn);
996
gconf_database_add_listener (GConfDatabase *db,
1001
CORBA_unsigned_long cnxn;
1003
gconfd_need_log_cleanup ();
1005
cnxn = gconf_database_readd_listener (db, who, where);
1008
if (!gconfd_logfile_change_listener (db, TRUE, cnxn,
1011
/* This error is not fatal; we basically ignore it.
1012
* Because it's likely the right thing for the client
1013
* app to simply continue.
1015
gconf_log (GCL_WARNING, _("Failed to log addition of listener (%s); will not be able to restore this listener on gconfd restart, resulting in unreliable notification of configuration changes."), err->message);
1023
gconf_database_remove_listener (GConfDatabase *db,
1024
CORBA_unsigned_long cnxn)
1028
const gchar *location = NULL;
1030
gconfd_need_log_cleanup ();
1032
g_assert(db->listeners != NULL);
1034
db->last_access = time(NULL);
1036
gconf_log(GCL_DEBUG, "Removing listener %u", (guint)cnxn);
1038
if (!gconf_listeners_get_data (db->listeners, cnxn,
1042
gconf_log (GCL_WARNING, _("Listener ID %lu doesn't exist"),
1048
if (!gconfd_logfile_change_listener (db, FALSE, cnxn,
1049
l->obj, location, &err))
1051
gconf_log (GCL_WARNING, _("Failed to log removal of listener to logfile (most likely harmless, may result in a notification weirdly reappearing): %s"),
1056
/* calls destroy notify */
1057
gconf_listeners_remove(db->listeners, cnxn);
1060
typedef struct _ListenerNotifyClosure ListenerNotifyClosure;
1062
struct _ListenerNotifyClosure {
1064
const ConfigValue* value;
1065
gboolean is_default;
1066
gboolean is_writable;
1068
CORBA_Environment ev;
1072
notify_listeners_cb(GConfListeners* listeners,
1073
const gchar* all_above_key,
1075
gpointer listener_data,
1078
Listener* l = listener_data;
1079
ListenerNotifyClosure* closure = user_data;
1081
ConfigListener_notify(l->obj,
1082
closure->db->objref,
1084
(gchar*)all_above_key,
1086
closure->is_default,
1087
closure->is_writable,
1090
if(closure->ev._major != CORBA_NO_EXCEPTION)
1092
gconf_log (GCL_DEBUG, "Failed to notify listener %u, removing: %s",
1093
cnxn_id, CORBA_exception_id (&closure->ev));
1094
CORBA_exception_free (&closure->ev);
1096
/* Dead listeners need to be forgotten */
1097
closure->dead = g_slist_prepend(closure->dead, GUINT_TO_POINTER(cnxn_id));
1101
gconf_log (GCL_DEBUG, "Notified listener %u of change to key `%s'",
1102
cnxn_id, all_above_key);
1107
gconf_database_notify_listeners (GConfDatabase *db,
1109
const ConfigValue *value,
1110
gboolean is_default,
1111
gboolean is_writable)
1113
ListenerNotifyClosure closure;
1116
g_return_if_fail(db != NULL);
1119
closure.value = value;
1120
closure.is_default = is_default;
1121
closure.is_writable = is_writable;
1122
closure.dead = NULL;
1124
CORBA_exception_init(&closure.ev);
1126
gconf_listeners_notify(db->listeners, key, notify_listeners_cb, &closure);
1131
gconfd_need_log_cleanup ();
1135
guint dead = GPOINTER_TO_UINT(tmp->data);
1137
gconf_listeners_remove(db->listeners, dead);
1139
tmp = g_slist_next(tmp);
1144
gconf_database_query_value (GConfDatabase *db,
1146
const gchar **locales,
1147
gboolean use_schema_default,
1149
gboolean *value_is_default,
1150
gboolean *value_is_writable,
1155
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
1156
g_assert(db->listeners != NULL);
1158
db->last_access = time(NULL);
1160
val = gconf_sources_query_value(db->sources, key, locales,
1167
if (err && *err != NULL)
1169
gconf_log(GCL_ERR, _("Error getting value for `%s': %s"),
1170
key, (*err)->message);
1177
gconf_database_query_default_value (GConfDatabase *db,
1179
const gchar **locales,
1180
gboolean *is_writable,
1183
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
1184
g_assert(db->listeners != NULL);
1186
db->last_access = time(NULL);
1188
return gconf_sources_query_default_value(db->sources, key, locales,
1194
gconf_database_set (GConfDatabase *db,
1197
const ConfigValue *cvalue,
1200
GError *error = NULL;
1202
g_assert(db->listeners != NULL);
1203
g_return_if_fail(err == NULL || *err == NULL);
1205
db->last_access = time(NULL);
1208
/* this really churns the logfile, so we avoid it */
1209
gconf_log(GCL_DEBUG, "Received request to set key `%s'", key);
1212
gconf_sources_set_value(db->sources, key, value, &error);
1216
gconf_log(GCL_ERR, _("Error setting value for `%s': %s"),
1217
key, error->message);
1219
g_propagate_error (err, error);
1225
gconf_database_schedule_sync(db);
1227
gconf_database_notify_listeners(db, key, cvalue,
1228
/* Can't possibly be the default,
1229
since we just set it,
1230
and must be writable since
1231
setting it succeeded.
1239
gconf_database_unset (GConfDatabase *db,
1241
const gchar *locale,
1245
GError* error = NULL;
1247
g_return_if_fail(err == NULL || *err == NULL);
1249
g_assert(db->listeners != NULL);
1251
db->last_access = time(NULL);
1253
gconf_log(GCL_DEBUG, "Received request to unset key `%s'", key);
1255
gconf_sources_unset_value(db->sources, key, locale, &error);
1259
gconf_log(GCL_ERR, _("Error unsetting `%s': %s"),
1260
key, error->message);
1265
g_error_free(error);
1271
GConfValue* def_value;
1272
const gchar* locale_list[] = { NULL, NULL };
1273
gboolean is_writable = TRUE;
1275
locale_list[0] = locale;
1276
def_value = gconf_database_query_default_value(db,
1283
gconf_log(GCL_ERR, _("Error getting default value for `%s': %s"),
1284
key, (*err)->message);
1286
if (def_value != NULL)
1288
val = corba_value_from_gconf_value(def_value);
1289
gconf_value_free(def_value);
1293
val = invalid_corba_value();
1296
gconf_database_schedule_sync(db);
1298
gconf_database_notify_listeners(db, key, val, TRUE, is_writable);
1305
gconf_database_dir_exists (GConfDatabase *db,
1311
g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
1313
g_assert(db->listeners != NULL);
1315
db->last_access = time(NULL);
1317
gconf_log(GCL_DEBUG, "Received dir_exists request for `%s'", dir);
1319
ret = gconf_sources_dir_exists(db->sources, dir, err);
1321
if (err && *err != NULL)
1323
gconf_log(GCL_ERR, _("Error checking existence of `%s': %s"),
1324
dir, (*err)->message);
1332
gconf_database_remove_dir (GConfDatabase *db,
1336
g_return_if_fail(err == NULL || *err == NULL);
1337
g_assert(db->listeners != NULL);
1339
db->last_access = time(NULL);
1341
gconf_log(GCL_DEBUG, "Received request to remove dir `%s'", dir);
1343
gconf_sources_remove_dir(db->sources, dir, err);
1345
if (err && *err != NULL)
1347
gconf_log(GCL_ERR, _("Error removing dir `%s': %s"),
1348
dir, (*err)->message);
1352
gconf_database_schedule_sync(db);
1357
gconf_database_all_entries (GConfDatabase *db,
1359
const gchar **locales,
1364
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
1366
g_assert(db->listeners != NULL);
1368
db->last_access = time(NULL);
1370
entries = gconf_sources_all_entries(db->sources, dir, locales, err);
1372
if (err && *err != NULL)
1374
gconf_log(GCL_ERR, _("Failed to get all entries in `%s': %s"),
1375
dir, (*err)->message);
1382
gconf_database_all_dirs (GConfDatabase *db,
1388
g_return_val_if_fail(err == NULL || *err == NULL, NULL);
1390
g_assert(db->listeners != NULL);
1392
db->last_access = time(NULL);
1394
gconf_log(GCL_DEBUG, "Received request to list all subdirs in `%s'", dir);
1396
subdirs = gconf_sources_all_dirs (db->sources, dir, err);
1398
if (err && *err != NULL)
1400
gconf_log(GCL_ERR, _("Error listing dirs in `%s': %s"),
1401
dir, (*err)->message);
1407
gconf_database_set_schema (GConfDatabase *db,
1409
const gchar *schema_key,
1412
g_return_if_fail(err == NULL || *err == NULL);
1413
g_assert(db->listeners != NULL);
1415
db->last_access = time(NULL);
1417
gconf_sources_set_schema(db->sources, key, schema_key, err);
1419
if (err && *err != NULL)
1421
gconf_log(GCL_ERR, _("Error setting schema for `%s': %s"),
1422
key, (*err)->message);
1426
gconf_database_schedule_sync(db);
1431
gconf_database_sync (GConfDatabase *db,
1434
g_assert(db->listeners != NULL);
1436
db->last_access = time(NULL);
1438
gconf_log(GCL_DEBUG, "Received suggestion to sync all config data");
1440
gconf_database_sync_nowish(db);
1444
gconf_database_synchronous_sync (GConfDatabase *db,
1447
/* remove the scheduled syncs */
1448
if (db->sync_timeout != 0)
1450
g_source_remove(db->sync_timeout);
1451
db->sync_timeout = 0;
1454
if (db->sync_idle != 0)
1456
g_source_remove(db->sync_idle);
1460
db->last_access = time(NULL);
1462
return gconf_sources_sync_all(db->sources, err);
1466
gconf_database_clear_cache (GConfDatabase *db,
1469
g_assert(db->listeners != NULL);
1471
db->last_access = time(NULL);
1473
gconf_sources_clear_cache(db->sources);
1477
gconf_database_get_persistent_name (GConfDatabase *db)
1479
if (db->persistent_name == NULL)
1481
if (db->sources->sources)
1482
db->persistent_name =
1483
g_strdup (((GConfSource*)db->sources->sources->data)->address);
1485
db->persistent_name = g_strdup ("empty");
1488
return db->persistent_name;
1498
listener_save_foreach (const gchar* location,
1500
gpointer listener_data,
1503
struct ForeachData *fd = user_data;
1504
Listener* l = listener_data;
1506
CORBA_Environment ev;
1510
s = g_strdup_printf ("ADD %u %s ", cnxn_id, fd->db_name);
1512
g_string_append (fd->str, s);
1516
s = gconf_quote_string (location);
1517
g_string_append (fd->str, s);
1519
g_string_append_c (fd->str, ' ');
1521
orb = gconf_orb_get ();
1523
CORBA_exception_init (&ev);
1525
ior = CORBA_ORB_object_to_string(orb, l->obj, &ev);
1527
s = gconf_quote_string (ior);
1529
g_string_append (fd->str, s);
1535
g_string_append_c (fd->str, '\n');
1539
gconf_database_log_listeners_to_string (GConfDatabase *db,
1540
gboolean is_default,
1543
struct ForeachData fd;
1548
fd.db_name = gconf_quote_string ("def");
1552
gconf_quote_string (gconf_database_get_persistent_name (db));
1555
gconf_listeners_foreach (db->listeners,
1556
listener_save_foreach,
1559
g_free (fd.db_name);
1566
static GConfLocaleCache* locale_cache = NULL;
1568
static GConfLocaleList*
1569
locale_cache_lookup(const gchar* locale)
1571
GConfLocaleList* locale_list;
1573
if (locale_cache == NULL)
1574
locale_cache = gconf_locale_cache_new();
1576
locale_list = gconf_locale_cache_get_list(locale_cache, locale);
1578
g_assert(locale_list != NULL);
1579
g_assert(locale_list->list != NULL);
1585
gconfd_locale_cache_expire(void)
1587
if (locale_cache != NULL)
1588
gconf_locale_cache_expire(locale_cache, 60 * 30); /* 60 sec * 30 min */
1592
gconfd_locale_cache_drop(void)
1594
if (locale_cache != NULL)
1596
gconf_locale_cache_free(locale_cache);
1597
locale_cache = NULL;
1602
* The listener object
1606
listener_new(ConfigListener obj)
1609
CORBA_Environment ev;
1611
CORBA_exception_init(&ev);
1613
l = g_new0(Listener, 1);
1615
l->obj = CORBA_Object_duplicate(obj, &ev);
1621
listener_destroy(Listener* l)
1624
CORBA_Environment ev;
1626
CORBA_exception_init(&ev);
1627
CORBA_Object_release(l->obj, &ev);