Change of mandatory keys user notification



Hello,

Last month I have some problem with one interesting task of using
GConf. It is remote change of user keys and its immediately apply. But
how to notify user daemon? We can use setuid() and gconf_engine_set()
for rw-keys. This decision will not work for ro-keys. I have great
research at this point and become for next results. Because we can not
change keys at user context, we can change backend at admin context
and only notify at user. It is a really problem to notify user daemon
of backend changing immediately, To avoid this problem I am added new
gconf_engine function: gconf_engine_notify ()

Patch in attachment add this function to current cvs tree.

--
Sin (Sinelnikov Evgeny)
diff -ur gconf/gconf/gconf.c gconf.copy/gconf/gconf.c
--- gconf/gconf/gconf.c	2005-12-08 16:00:58 +0300
+++ gconf.copy/gconf/gconf.c	2006-11-01 01:23:21 +0300
@@ -1355,6 +1355,73 @@
   return TRUE;
 }
 
+gboolean
+gconf_engine_notify (GConfEngine* conf, const gchar* key, GError** err)
+{
+  CORBA_Environment ev;
+  ConfigDatabase db;
+  gint tries = 0;
+
+  g_return_val_if_fail(conf != NULL, FALSE);
+  g_return_val_if_fail(key != NULL, FALSE);
+  g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+
+  CHECK_OWNER_USE (conf);
+  
+  if (!gconf_key_check(key, err))
+    return FALSE;
+
+  if (gconf_engine_is_local(conf))
+    {
+      if (err)
+        {
+          g_set_error (err,
+                      GCONF_ERROR,
+                      GCONF_ERROR_LOCAL_ENGINE,
+                      _("Unable to notify local engine"));
+        }
+      
+      return FALSE;
+    }
+
+  g_assert(!gconf_engine_is_local(conf));
+  
+  CORBA_exception_init(&ev);
+
+ RETRY:
+  
+  db = gconf_engine_get_database (conf, TRUE, err);
+
+  if (db == CORBA_OBJECT_NIL)
+    {
+      g_return_val_if_fail(err == NULL || *err != NULL, FALSE);
+
+      return FALSE;
+    }
+
+  ConfigDatabase_notify(db,
+                        (gchar*)key,
+                        &ev);
+
+  if (gconf_server_broken(&ev))
+    {
+      if (tries < MAX_RETRIES)
+        {
+          ++tries;
+          CORBA_exception_free(&ev);
+          gconf_engine_detach (conf);
+          goto RETRY;
+        }
+    }
+  
+  if (gconf_handle_corba_exception(&ev, err))
+    return FALSE;
+
+  g_return_val_if_fail(err == NULL || *err == NULL, FALSE);
+  
+  return TRUE;
+}
+
 /**
  * gconf_engine_recursive_unset:
  * @engine: a #GConfEngine
diff -ur gconf/gconf/gconf-database.c gconf.copy/gconf/gconf-database.c
--- gconf/gconf/gconf-database.c	2004-04-21 21:46:04 +0400
+++ gconf.copy/gconf/gconf-database.c	2006-11-01 01:23:21 +0300
@@ -239,6 +239,51 @@
 }
 
 static void
+impl_ConfigDatabase_notify(PortableServer_Servant servant,
+                           const CORBA_char * key,
+                           CORBA_Environment * ev)
+{
+  GConfDatabase *db = (GConfDatabase*) servant;
+  GConfValue* val;
+  GError* error = NULL;
+  gboolean is_default = FALSE;
+  gboolean is_writable = TRUE;
+
+  if (gconfd_check_in_shutdown (ev))
+    return;
+  
+  val = gconf_database_query_value(db, key, NULL,
+                                   TRUE,
+                                   NULL,
+                                   &is_default,
+                                   &is_writable,
+                                   &error);
+
+  if (val != NULL)
+    {
+      ConfigValue* cval = gconf_corba_value_from_gconf_value(val);
+
+      gconf_database_notify_listeners (db,
+				       NULL,
+				       key,
+				       cval,
+                                       is_default,
+				       is_writable,
+				       FALSE);
+
+      gconf_value_free(val);
+      
+      return;
+    }
+  else
+    {
+      gconf_set_exception(&error, ev);
+
+      return;
+    }
+}
+
+static void
 impl_ConfigDatabase_unset_with_locale (PortableServer_Servant servant,
                                        const CORBA_char * key,
                                        const CORBA_char * locale,
@@ -751,6 +796,7 @@
   impl_ConfigDatabase_lookup_default_value,
   impl_ConfigDatabase_batch_lookup,
   impl_ConfigDatabase_set,
+  impl_ConfigDatabase_notify,
   impl_ConfigDatabase_unset,
   impl_ConfigDatabase_unset_with_locale,
   impl_ConfigDatabase_batch_change,
diff -ur gconf/gconf/gconf-database.h gconf.copy/gconf/gconf-database.h
--- gconf/gconf/gconf-database.h	2006-05-05 16:30:18 +0400
+++ gconf.copy/gconf/gconf-database.h	2006-11-01 01:23:21 +0300
@@ -100,6 +100,9 @@
                            const gchar        *key,
                            const gchar        *locale,
                            GError        **err);
+void gconf_database_notify (GConfDatabase     *db,
+                           const gchar        *key,
+                           GError        **err);
 
 void gconf_database_recursive_unset (GConfDatabase      *db,
                                      const gchar        *key,
ТолÑ?ко в gconf.copy/gconf: gconf-database.h.orig
diff -ur gconf/gconf/gconf.h gconf.copy/gconf/gconf.h
--- gconf/gconf/gconf.h	2006-05-05 16:30:18 +0400
+++ gconf.copy/gconf/gconf.h	2006-11-01 01:23:21 +0300
@@ -85,6 +85,9 @@
 gboolean    gconf_engine_unset                   (GConfEngine  *conf,
                                                   const gchar  *key,
                                                   GError  **err);
+gboolean    gconf_engine_notify                  (GConfEngine  *conf,
+                                                  const gchar  *key,
+                                                  GError  **err);
 
 
 /*
ТолÑ?ко в gconf.copy/gconf: gconf.h.orig
diff -ur gconf/gconf/GConfX.idl gconf.copy/gconf/GConfX.idl
--- gconf/gconf/GConfX.idl	2006-06-14 19:14:17 +0400
+++ gconf.copy/gconf/GConfX.idl	2006-11-01 01:23:21 +0300
@@ -157,6 +157,9 @@
   
   void set(in string key, in ConfigValue value)
     raises (ConfigException);
+  
+  void notify(in string key)
+    raises (ConfigException);
   
   void unset(in string key)
     raises (ConfigException);


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