[Pkg-telepathy-commits] [telepathy-mission-control-6] 80/90: McpAccountStorage: use GVariant instead of dbus-glib types

Simon McVittie smcv at debian.org
Wed May 14 12:09:08 UTC 2014


This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to branch debian
in repository telepathy-mission-control-6.

commit ba5600cf7eded9e5838807a87eeacce6d56fe9e2
Author: Simon McVittie <simon.mcvittie at collabora.co.uk>
Date:   Mon Apr 7 16:18:20 2014 +0100

    McpAccountStorage: use GVariant instead of dbus-glib types
    
    Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77139
---
 mission-control-plugins/account-storage.c | 101 ++++++++++++------------------
 mission-control-plugins/account-storage.h |  15 ++---
 src/mcd-account.c                         |  20 +++---
 tests/twisted/dbus-account-plugin.c       |  31 ++++-----
 4 files changed, 68 insertions(+), 99 deletions(-)

diff --git a/mission-control-plugins/account-storage.c b/mission-control-plugins/account-storage.c
index c8ce282..d246e32 100644
--- a/mission-control-plugins/account-storage.c
+++ b/mission-control-plugins/account-storage.c
@@ -61,8 +61,8 @@
  *   iface->delete_finish = foo_plugin_delete_finish;
  *   iface->commit = foo_plugin_commit;
  *   iface->list = foo_plugin_list;
- *   iface->get_identifier = foo_plugin_get_identifier;
- *   iface->get_additional_info = foo_plugin_get_additional_info;
+ *   iface->dup_identifier = foo_plugin_dup_identifier;
+ *   iface->dup_additional_info = foo_plugin_dup_additional_info;
  *   iface->get_restrictions = foo_plugin_get_restrictions;
  *   iface->create = foo_plugin_create;
  *   iface->get_attribute = foo_plugin_get_attribute;
@@ -164,20 +164,18 @@ default_create (McpAccountStorage *storage,
   return NULL;
 }
 
-static void
-default_get_identifier (McpAccountStorage *storage,
-    const gchar *account,
-    GValue *identifier)
+static GVariant *
+default_dup_identifier (McpAccountStorage *storage,
+    const gchar *account)
 {
-  g_value_init (identifier, G_TYPE_STRING);
-  g_value_set_string (identifier, account);
+  return g_variant_new_string (account);
 }
 
-static GHashTable *
-default_get_additional_info (McpAccountStorage *storage,
+static GVariant *
+default_dup_additional_info (McpAccountStorage *storage,
     const gchar *account)
 {
-  return g_hash_table_new (g_str_hash, g_str_equal);
+  return g_variant_new ("a{sv}", NULL);
 }
 
 static TpStorageRestrictionFlags
@@ -236,8 +234,8 @@ class_init (gpointer klass,
   iface->delete_async = default_delete_async;
   iface->delete_finish = default_delete_finish;
   iface->commit = default_commit;
-  iface->get_identifier = default_get_identifier;
-  iface->get_additional_info = default_get_additional_info;
+  iface->dup_identifier = default_dup_identifier;
+  iface->dup_additional_info = default_dup_additional_info;
   iface->get_restrictions = default_get_restrictions;
   iface->set_attribute = default_set_attribute;
   iface->set_parameter = default_set_parameter;
@@ -384,9 +382,9 @@ mcp_account_storage_get_type (void)
  * @delete_finish: implementation of mcp_account_storage_delete_finish()
  * @commit: implementation of mcp_account_storage_commit()
  * @list: implementation of mcp_account_storage_list()
- * @get_identifier: implementation of mcp_account_storage_get_identifier()
- * @get_additional_info: implementation of
- *  mcp_account_storage_get_additional_info()
+ * @dup_identifier: implementation of mcp_account_storage_dup_identifier()
+ * @dup_additional_info: implementation of
+ *  mcp_account_storage_dup_additional_info()
  * @get_restrictions: implementation of mcp_account_storage_get_restrictions()
  * @create: implementation of mcp_account_storage_create()
  * @get_attribute: implementation of mcp_account_storage_get_attribute()
@@ -929,59 +927,38 @@ mcp_account_storage_list (McpAccountStorage *storage,
 }
 
 /**
- * McpAccountStorageGetIdentifierFunc:
- * @storage: an #McpAccountStorage instance
- * @account: the unique name of the account
- * @identifier: (out caller-allocates): a zero-filled #GValue whose type
- *  can be sent over D-Bus by dbus-glib, to hold the identifier.
- *
- * An implementation of mcp_account_storage_get_identifier().
- */
-
-/**
- * mcp_account_storage_get_identifier:
+ * mcp_account_storage_dup_identifier:
  * @storage: an #McpAccountStorage instance
  * @account: the unique name of the account
- * @identifier: (out caller-allocates): a zero-filled #GValue whose type
- *  can be sent over D-Bus by dbus-glib, to hold the identifier.
  *
- * Get the storage-specific identifier for this account. The type is variant,
- * hence the GValue.
+ * Get the storage-specific identifier for this account.
  *
- * The default implementation returns @account as a %G_TYPE_STRING.
+ * The default implementation returns @account as a string.
  *
  * This method will only be called for the storage plugin that "owns"
  * the account.
+ *
+ * If the implementation returns a floating reference, ownership will
+ * be taken by mcp_account_storage_dup_identifer(), so that it always
+ * returns a "full" reference.
+ *
+ * Returns: (transfer full): the identifier
  */
-void
-mcp_account_storage_get_identifier (McpAccountStorage *storage,
-    const gchar *account,
-    GValue *identifier)
+GVariant *
+mcp_account_storage_dup_identifier (McpAccountStorage *storage,
+    const gchar *account)
 {
   McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
 
   SDEBUG (storage, "%s", account);
-  g_return_if_fail (iface != NULL);
-  g_return_if_fail (iface->get_identifier != NULL);
-  g_return_if_fail (identifier != NULL);
-  g_return_if_fail (!G_IS_VALUE (identifier));
+  g_return_val_if_fail (iface != NULL, NULL);
+  g_return_val_if_fail (iface->dup_identifier != NULL, NULL);
 
-  iface->get_identifier (storage, account, identifier);
+  return g_variant_take_ref (iface->dup_identifier (storage, account));
 }
 
 /**
- * McpAccountStorageGetAdditionalInfoFunc
- * @storage: an #McpAccountStorage instance
- * @account: the unique name of the account
- *
- * An implementation of mcp_account_storage_get_identifier().
- *
- * Returns: (transfer container) (element-type utf8 GObject.Value): additional
- *  storage-specific information
- */
-
-/**
- * mcp_account_storage_get_additional_info:
+ * mcp_account_storage_dup_additional_info:
  * @storage: an #McpAccountStorage instance
  * @account: the unique name of the account
  *
@@ -993,20 +970,24 @@ mcp_account_storage_get_identifier (McpAccountStorage *storage,
  *
  * The default implementation returns an empty map.
  *
- * Returns: (transfer container) (element-type utf8 GObject.Value): additional
- *  storage-specific information, which must not be %NULL
+ * If the implementation returns a floating reference, ownership will
+ * be taken by mcp_account_storage_dup_additional_info(), so that it
+ * always returns a "full" reference.
+ *
+ * Returns: a non-%NULL %G_VARIANT_TYPE_VARDICT of storage-specific
+ *  information
  */
-GHashTable *
-mcp_account_storage_get_additional_info (McpAccountStorage *storage,
+GVariant *
+mcp_account_storage_dup_additional_info (McpAccountStorage *storage,
     const gchar *account)
 {
   McpAccountStorageIface *iface = MCP_ACCOUNT_STORAGE_GET_IFACE (storage);
 
   SDEBUG (storage, "%s", account);
-  g_return_val_if_fail (iface != NULL, FALSE);
-  g_return_val_if_fail (iface->get_additional_info != NULL, FALSE);
+  g_return_val_if_fail (iface != NULL, NULL);
+  g_return_val_if_fail (iface->dup_additional_info != NULL, NULL);
 
-  return iface->get_additional_info (storage, account);
+  return g_variant_take_ref (iface->dup_additional_info (storage, account));
 }
 
 /**
diff --git a/mission-control-plugins/account-storage.h b/mission-control-plugins/account-storage.h
index b801521..e24ecae 100644
--- a/mission-control-plugins/account-storage.h
+++ b/mission-control-plugins/account-storage.h
@@ -116,11 +116,10 @@ struct _McpAccountStorageIface
   GList * (*list) (McpAccountStorage *storage,
     McpAccountManager *am);
 
-  void (*get_identifier) (McpAccountStorage *storage,
-    const gchar *account,
-    GValue *identifier);
+  GVariant *(*dup_identifier) (McpAccountStorage *storage,
+    const gchar *account);
 
-  GHashTable * (*get_additional_info) (McpAccountStorage *storage,
+  GVariant *(*dup_additional_info) (McpAccountStorage *storage,
     const gchar *account);
 
   TpStorageRestrictionFlags (*get_restrictions) (McpAccountStorage *storage,
@@ -198,12 +197,10 @@ mcp_account_storage_commit (McpAccountStorage *storage,
 GList *mcp_account_storage_list (McpAccountStorage *storage,
     McpAccountManager *am);
 
-void mcp_account_storage_get_identifier (McpAccountStorage *storage,
-    const gchar *account,
-    GValue *identifier);
+GVariant *mcp_account_storage_dup_identifier (McpAccountStorage *storage,
+    const gchar *account);
 
-GHashTable *mcp_account_storage_get_additional_info (
-    McpAccountStorage *storage,
+GVariant *mcp_account_storage_dup_additional_info (McpAccountStorage *storage,
     const gchar *account);
 
 TpStorageRestrictionFlags mcp_account_storage_get_restrictions (
diff --git a/src/mcd-account.c b/src/mcd-account.c
index f4c51b4..8652412 100644
--- a/src/mcd-account.c
+++ b/src/mcd-account.c
@@ -1963,16 +1963,15 @@ get_storage_identifier (TpSvcDBusProperties *self,
 {
 
   McdAccount *account = MCD_ACCOUNT (self);
+  GVariant *variant;
   GValue identifier = G_VALUE_INIT;
 
   g_value_init (value, G_TYPE_VALUE);
-
-  mcp_account_storage_get_identifier (
-      account->priv->storage_plugin, account->priv->unique_name,
-      &identifier);
-
+  variant = mcp_account_storage_dup_identifier (
+      account->priv->storage_plugin, account->priv->unique_name);
+  dbus_g_value_parse_g_variant (variant, &identifier);
+  g_variant_unref (variant);
   g_value_set_boxed (value, &identifier);
-
   g_value_unset (&identifier);
 }
 
@@ -1980,15 +1979,14 @@ static void
 get_storage_specific_info (TpSvcDBusProperties *self,
     const gchar *name, GValue *value)
 {
-  GHashTable *storage_specific_info;
+  GVariant *storage_specific_info;
   McdAccount *account = MCD_ACCOUNT (self);
 
   g_value_init (value, TP_HASH_TYPE_STRING_VARIANT_MAP);
-
-  storage_specific_info = mcp_account_storage_get_additional_info (
+  storage_specific_info = mcp_account_storage_dup_additional_info (
       account->priv->storage_plugin, account->priv->unique_name);
-
-  g_value_take_boxed (value, storage_specific_info);
+  g_value_take_boxed (value, tp_asv_from_vardict (storage_specific_info));
+  g_variant_unref (storage_specific_info);
 }
 
 static TpStorageRestrictionFlags
diff --git a/tests/twisted/dbus-account-plugin.c b/tests/twisted/dbus-account-plugin.c
index 0434191..3fb9a52 100644
--- a/tests/twisted/dbus-account-plugin.c
+++ b/tests/twisted/dbus-account-plugin.c
@@ -1357,44 +1357,37 @@ test_dbus_account_plugin_commit (McpAccountStorage *storage,
   return TRUE;
 }
 
-static void
-test_dbus_account_plugin_get_identifier (McpAccountStorage *storage,
-    const gchar *account_name,
-    GValue *identifier)
+static GVariant *
+test_dbus_account_plugin_dup_identifier (McpAccountStorage *storage,
+    const gchar *account_name)
 {
   TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (storage);
   Account *account = lookup_account (self, account_name);
 
   DEBUG ("%s", account_name);
 
-  g_return_if_fail (self->active);
-  g_return_if_fail (account != NULL);
+  g_return_val_if_fail (self->active, NULL);
+  g_return_val_if_fail (account != NULL, NULL);
 
   /* Our "library-specific unique identifier" is just the object-path
    * as a string. */
-  g_value_init (identifier, G_TYPE_STRING);
-  g_value_set_string (identifier, account->path);
+  return g_variant_ref_sink (g_variant_new_object_path (account->path));
 }
 
-static GHashTable *
-test_dbus_account_plugin_get_additional_info (McpAccountStorage *storage,
+static GVariant *
+test_dbus_account_plugin_dup_additional_info (McpAccountStorage *storage,
     const gchar *account_name)
 {
   TestDBusAccountPlugin *self = TEST_DBUS_ACCOUNT_PLUGIN (storage);
   Account *account = lookup_account (self, account_name);
-  GHashTable *ret;
 
   DEBUG ("%s", account_name);
 
   g_return_val_if_fail (self->active, NULL);
   g_return_val_if_fail (account != NULL, NULL);
 
-  ret = g_hash_table_new_full (g_str_hash, g_str_equal,
-      g_free, (GDestroyNotify) tp_g_value_slice_free);
-  g_hash_table_insert (ret, g_strdup ("hello"),
-      tp_g_value_slice_new_static_string ("world"));
-
-  return ret;
+  return g_variant_ref_sink (g_variant_new_parsed (
+        "{ 'hello': <'world'> }"));
 }
 
 static guint
@@ -1440,8 +1433,8 @@ account_storage_iface_init (McpAccountStorageIface *iface)
   iface->delete_async = test_dbus_account_plugin_delete_async;
   iface->delete_finish = test_dbus_account_plugin_delete_finish;
   iface->commit = test_dbus_account_plugin_commit;
-  iface->get_identifier = test_dbus_account_plugin_get_identifier;
-  iface->get_additional_info = test_dbus_account_plugin_get_additional_info;
+  iface->dup_identifier = test_dbus_account_plugin_dup_identifier;
+  iface->dup_additional_info = test_dbus_account_plugin_dup_additional_info;
   iface->get_restrictions = test_dbus_account_plugin_get_restrictions;
   iface->create = test_dbus_account_plugin_create;
 }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-telepathy/telepathy-mission-control-6.git



More information about the Pkg-telepathy-commits mailing list