[rhythmbox] ext-db: helper for printing keys in debug output



commit edd9570aaea41f683e7335f0ae1138bf394c6a93
Author: Jonathan Matthew <jonathan d14n org>
Date:   Mon Jan 5 09:06:30 2015 +1000

    ext-db: helper for printing keys in debug output

 metadata/rb-ext-db-key.c |   49 ++++++++++++++++++++++++++++++++++++++++++++++
 metadata/rb-ext-db-key.h |    2 +
 2 files changed, 51 insertions(+), 0 deletions(-)
---
diff --git a/metadata/rb-ext-db-key.c b/metadata/rb-ext-db-key.c
index 6b0c7cb..09b35b5 100644
--- a/metadata/rb-ext-db-key.c
+++ b/metadata/rb-ext-db-key.c
@@ -599,3 +599,52 @@ rb_ext_db_key_to_store_key (RBExtDBKey *key)
        create_store_key (key, 0, &k);
        return k;
 }
+
+static void
+append_field (GString *s, RBExtDBField *f)
+{
+       int i;
+
+       g_string_append_printf (s, " %s%s{", f->name, f->match_null ? "~" : "=");
+       for (i = 0; i < f->values->len; i++) {
+               if (i != 0)
+                       g_string_append (s, "\",\"");
+               else
+                       g_string_append (s, "\"");
+               g_string_append (s, g_ptr_array_index (f->values, i));
+       }
+       if (i != 0)
+               g_string_append (s, "\"}");
+       else
+               g_string_append (s, "}");
+}
+
+/**
+ * rb_ext_db_key_to_string:
+ * @key: a @RBExtDBKey
+ *
+ * Generates a readable string format from the key.
+ *
+ * Return value: (transfer full): string form of the key
+ */
+char *
+rb_ext_db_key_to_string (RBExtDBKey *key)
+{
+       GString *s;
+       GList *l;
+
+       s = g_string_sized_new (100);
+       g_string_append (s, key->lookup ? "[lookup]" : "[storage]");
+       for (l = key->fields; l != NULL; l = l->next) {
+               append_field (s, l->data);
+       }
+
+       if (key->lookup && key->info != NULL) {
+               g_string_append (s, " info: ");
+               for (l = key->info; l != NULL; l = l->next) {
+                       append_field (s, l->data);
+               }
+       }
+
+       return g_string_free (s, FALSE);
+}
diff --git a/metadata/rb-ext-db-key.h b/metadata/rb-ext-db-key.h
index 318af55..4c1d206 100644
--- a/metadata/rb-ext-db-key.h
+++ b/metadata/rb-ext-db-key.h
@@ -85,6 +85,8 @@ void                  rb_ext_db_key_lookups           (RBExtDBKey *key,
 
 TDB_DATA               rb_ext_db_key_to_store_key      (RBExtDBKey *key);
 
+char *                 rb_ext_db_key_to_string         (RBExtDBKey *key);
+
 G_END_DECLS
 
 #endif /* RB_EXT_DB_KEY_H */


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