[dconf/wip/reorg: 461/498] service: introduce a new Changeset-based method



commit b132b06ef9a106332dbe5002ca42873ef1de8748
Author: Ryan Lortie <desrt desrt ca>
Date:   Sun Jul 1 13:31:49 2012 -0400

    service: introduce a new Changeset-based method
    
    Add a "Change" method to the service for writing DConfChangesets.

 service/dconf-interfaces.c |   11 +++++++-
 service/dconf-writer.c     |   23 +++++++++++++++++
 service/dconf-writer.h     |    5 ++++
 service/service.c          |   57 +++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 94 insertions(+), 2 deletions(-)
---
diff --git a/service/dconf-interfaces.c b/service/dconf-interfaces.c
index c3c57c0..e824aca 100644
--- a/service/dconf-interfaces.c
+++ b/service/dconf-interfaces.c
@@ -21,6 +21,7 @@
 
 #include "dconf-interfaces.h"
 
+static const GDBusArgInfo payload_arg = { -1, (gchar *) "payload", (gchar *) "ay" };
 static const GDBusArgInfo name_arg = { -1, (gchar *) "name", (gchar *) "s" };
 static const GDBusArgInfo path_arg = { -1, (gchar *) "path", (gchar *) "s" };
 static const GDBusArgInfo names_arg = { -1, (gchar *) "names", (gchar *) "as" };
@@ -28,6 +29,8 @@ static const GDBusArgInfo tag_arg = { -1, (gchar *) "tag", (gchar *) "s" };
 static const GDBusArgInfo value_arg = { -1, (gchar *) "value", (gchar *) "av" };
 static const GDBusArgInfo values_arg = { -1, (gchar *) "values", (gchar *) "a(sav)" };
 
+static const GDBusArgInfo *change_in[] = { &payload_arg, NULL };
+static const GDBusArgInfo *change_out[] = { &tag_arg, NULL };
 static const GDBusArgInfo *write_in[] = { &name_arg, &value_arg, NULL };
 static const GDBusArgInfo *write_out[] = { &tag_arg, NULL };
 static const GDBusArgInfo *many_in[] = { &path_arg, &values_arg, NULL };
@@ -35,6 +38,12 @@ static const GDBusArgInfo *many_out[] = { &tag_arg, NULL };
 static const GDBusArgInfo *blame_out[] = { &tag_arg, NULL };
 static const GDBusArgInfo *notify_args[] = { &path_arg, &names_arg, &tag_arg, NULL };
 
+static const GDBusMethodInfo change_method = {
+  -1, (gchar *) "Change",
+  (GDBusArgInfo **) change_in,
+  (GDBusArgInfo **) change_out
+};
+
 static const GDBusMethodInfo write_method = {
   -1, (gchar *) "Write",
   (GDBusArgInfo **) write_in,
@@ -63,7 +72,7 @@ static const GDBusPropertyInfo shmdir_property = {
 };
 
 static const GDBusMethodInfo *writer_methods[] = {
-  &write_method, &writemany_method, NULL
+  &change_method, &write_method, &writemany_method, NULL
 };
 
 static const GDBusSignalInfo *writer_signals[] = {
diff --git a/service/dconf-writer.c b/service/dconf-writer.c
index 3f2aeee..4218977 100644
--- a/service/dconf-writer.c
+++ b/service/dconf-writer.c
@@ -128,6 +128,29 @@ dconf_writer_write_many (DConfWriter          *writer,
   return TRUE;
 }
 
+gboolean
+dconf_writer_change (DConfWriter     *writer,
+                     DConfChangeset  *change,
+                     GError         **error)
+{
+  const gchar * const *keys;
+  GVariant * const *values;
+  const gchar *prefix;
+  gint n_items;
+
+  n_items = dconf_changeset_describe (change, &prefix, &keys, &values);
+
+  if (!n_items)
+    return TRUE;
+
+  if (!dconf_rebuilder_rebuild (writer->path, prefix, keys, values, n_items, error))
+    return FALSE;
+
+  dconf_writer_touch_shm (writer);
+
+  return TRUE;
+}
+
 const gchar *
 dconf_writer_get_name (DConfWriter *writer)
 {
diff --git a/service/dconf-writer.h b/service/dconf-writer.h
index c469d1b..cbabadb 100644
--- a/service/dconf-writer.h
+++ b/service/dconf-writer.h
@@ -22,6 +22,7 @@
 #ifndef __dconf_writer_h__
 #define __dconf_writer_h__
 
+#include "dconf-changeset.h"
 #include "dconf-state.h"
 
 typedef struct OPAQUE_TYPE__DConfWriter DConfWriter;
@@ -42,4 +43,8 @@ gboolean                dconf_writer_write_many                         (DConfWr
                                                                          gsize n_items,
                                                                          GError              **error);
 
+gboolean                dconf_writer_change                             (DConfWriter          *writer,
+                                                                         DConfChangeset       *change,
+                                                                         GError              **error);
+
 #endif /* __dconf_writer_h__ */
diff --git a/service/service.c b/service/service.c
index 3a87b63..13dcc88 100644
--- a/service/service.c
+++ b/service/service.c
@@ -26,6 +26,7 @@
 #include <stdio.h>
 
 #include "dconf-interfaces.h"
+#include "dconf-changeset.h"
 #include "dconf-writer.h"
 #include "dconf-state.h"
 
@@ -95,6 +96,28 @@ emit_notify_signal (GDBusConnection  *connection,
 }
 
 static void
+emit_notify_signal_change (GDBusConnection *connection,
+                           DConfWriter     *writer,
+                           gchar           *tag,
+                           DConfChangeset  *change)
+{
+  const gchar *path;
+  const gchar * const *names;
+
+  if (dconf_changeset_describe (change, &path, &names, NULL))
+    {
+      gchar *obj;
+
+      obj = g_strjoin (NULL, "/ca/desrt/dconf/Writer/", dconf_writer_get_name (writer), NULL);
+      g_dbus_connection_emit_signal (connection, NULL, obj,
+                                     "ca.desrt.dconf.Writer", "Notify",
+                                     g_variant_new ("(s^ass)", path, names, tag),
+                                     NULL);
+      g_free (obj);
+    }
+}
+
+static void
 unwrap_maybe_and_variant (GVariant **ptr)
 {
   GVariant *array, *child;
@@ -233,7 +256,39 @@ method_call (GDBusConnection       *connection,
   if G_UNLIKELY (state->blame_mode)
     gather_blame_info (state, connection, sender, object_path, method_name, parameters);
 
-  if (strcmp (method_name, "Write") == 0)
+  if (strcmp (method_name, "Change") == 0)
+    {
+      DConfChangeset *change;
+      GError *error = NULL;
+      GVariant *args;
+      GVariant *tmp;
+      gchar *tag;
+
+      tmp = g_variant_new_from_data (G_VARIANT_TYPE ("a{smv}"),
+                                     g_variant_get_data (parameters), g_variant_get_size (parameters), FALSE,
+                                     (GDestroyNotify) g_variant_unref, g_variant_ref (parameters));
+      g_variant_ref_sink (tmp);
+      args = g_variant_get_normal_form (tmp);
+      g_variant_unref (tmp);
+
+      change = dconf_changeset_deserialise (args);
+      g_variant_unref (args);
+
+      if (!dconf_writer_change (writer, change, &error))
+        {
+          g_dbus_method_invocation_return_gerror (invocation, error);
+          g_error_free (error);
+          return;
+        }
+
+      tag = dconf_state_get_tag (state);
+      g_dbus_method_invocation_return_value (invocation, g_variant_new ("(s)", tag));
+      emit_notify_signal_change (connection, writer, tag, change);
+      dconf_changeset_unref (change);
+      g_free (tag);
+    }
+
+  else if (strcmp (method_name, "Write") == 0)
     {
       GError *error = NULL;
       GVariant *keyvalue;



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