[grilo] core: Add synchronous version of grl_metadata_source_resolve_sync() function



commit bf6f126770d9b15d721d1dbe9e98769df59634c2
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Thu Jul 15 14:39:56 2010 +0200

    core: Add synchronous version of grl_metadata_source_resolve_sync() function

 src/grl-metadata-source.c |   68 +++++++++++++++++++++++++++++++++++++++++++++
 src/grl-metadata-source.h |    6 ++++
 2 files changed, 74 insertions(+), 0 deletions(-)
---
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index f3bdf6c..519c5fa 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -45,6 +45,7 @@
 
 #include "grl-metadata-source.h"
 #include "grl-metadata-source-priv.h"
+#include "grl-sync-priv.h"
 #include "grl-plugin-registry.h"
 #include "grl-error.h"
 #include "data/grl-media.h"
@@ -362,6 +363,24 @@ resolve_idle (gpointer user_data)
   return FALSE;
 }
 
+static void
+resolve_result_async_cb (GrlMetadataSource *source,
+                         GrlMedia *media,
+                         gpointer user_data,
+                         const GError *error)
+{
+  GrlDataSync *ds = (GrlDataSync *) user_data;
+
+  g_debug ("resolve_result_async_cb");
+
+  if (error) {
+    ds->error = g_error_copy (error);
+  }
+
+  ds->data = media;
+  ds->complete = TRUE;
+}
+
 static gboolean
 set_metadata_idle (gpointer user_data)
 {
@@ -597,6 +616,55 @@ grl_metadata_source_resolve (GrlMetadataSource *source,
 }
 
 /**
+ * grl_metadata_source_resolve_sync:
+ * @source: a metadata source
+ * @keys: the #GList of #GrlKeyID to retrieve
+ * @media: Transfer object where all the metadata is stored
+ * @flags: bitwise mask of #GrlMetadataResolutionFlags with the resolution
+ * strategy
+ * @error: a #GError, or @NULL
+ *
+ * This is the main method of the #GrlMetadataSource class. It will fetch the
+ * metadata of the requested keys.
+ *
+ * This function is synchronous.
+ *
+ * Returns: the updated #GrlMedia
+ */
+GrlMedia *
+grl_metadata_source_resolve_sync (GrlMetadataSource *source,
+                                  const GList *keys,
+                                  GrlMedia *media,
+                                  GrlMetadataResolutionFlags flags,
+                                  GError **error)
+{
+  GrlDataSync *ds;
+
+  ds = g_slice_new0 (GrlDataSync);
+
+  grl_metadata_source_resolve (source,
+                               keys,
+                               media,
+                               flags,
+                               resolve_result_async_cb,
+                               ds);
+
+  grl_wait_for_async_operation_complete (ds);
+
+  if (ds->error) {
+    if (error) {
+      *error = ds->error;
+    } else {
+      g_error_free (ds->error);
+    }
+  }
+
+  g_slice_free (GrlDataSync, ds);
+
+  return media;
+}
+
+/**
  * grl_metadata_source_filter_supported:
  * @source: a metadata source
  * @keys: the list of keys to filter out
diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h
index 54ba5c3..150f63f 100644
--- a/src/grl-metadata-source.h
+++ b/src/grl-metadata-source.h
@@ -283,6 +283,12 @@ void grl_metadata_source_resolve (GrlMetadataSource *source,
                                   GrlMetadataSourceResolveCb callback,
                                   gpointer user_data);
 
+GrlMedia *grl_metadata_source_resolve_sync (GrlMetadataSource *source,
+                                            const GList *keys,
+                                            GrlMedia *media,
+                                            GrlMetadataResolutionFlags flags,
+                                            GError **error);
+
 void grl_metadata_source_set_metadata (GrlMetadataSource *source,
 				       GrlMedia *media,
 				       GList *keys,



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