[grilo] core: Move cancel() to GrlMetadataSource



commit c64f733b2ce14d237bddc40180f7abed60a4d04c
Author: Juan A. Suarez Romero <jasuarez igalia com>
Date:   Tue Apr 5 09:42:09 2011 +0000

    core: Move cancel() to GrlMetadataSource
    
    So GrlMetadataSource's methods can be cancelled too.
    
    Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>

 src/grl-media-source.c     |   23 ++-------------------
 src/grl-media-source.h     |    2 +-
 src/grl-metadata-source.c  |   46 ++++++++++++++++++++++++++++++++++++++++++++
 src/grl-metadata-source.h  |    7 +++++-
 src/grl-multiple.c         |    4 +-
 tools/grilo-test-ui/main.c |    3 +-
 6 files changed, 60 insertions(+), 25 deletions(-)
---
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index 280ee7b..3203a18 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -2054,27 +2054,10 @@ grl_media_source_cancel (GrlMediaSource *source, guint operation_id)
 
   g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
 
-  if (!grl_metadata_source_operation_is_ongoing (GRL_METADATA_SOURCE (source),
-                                                 operation_id)) {
-    GRL_DEBUG ("Tried to cancel invalid or already cancelled operation. "
-               "Skipping...");
-    return;
-  }
+  GRL_WARNING ("grl_media_source_cancel() is deprecated. "
+               "Use grl_metadata_source_cancel() instead");
 
-  /* Mark the operation as finished, if the source does
-     not implement cancellation or it did not make it in time, we will
-     not emit the results for this operation in any case.
-     At any rate, we will not free the operation data until we are sure
-     the plugin won't need it any more, which it will tell when it emits
-     remaining = 0 (which can happen because it did not cancel the op
-     or because it managed to cancel it and is signaling so) */
-  grl_metadata_source_set_operation_cancelled (GRL_METADATA_SOURCE (source), operation_id);
-
-  /* If the source provides an implementation for operation cancellation,
-     let's use that to avoid further unnecessary processing in the plugin */
-  if (GRL_MEDIA_SOURCE_GET_CLASS (source)->cancel) {
-    GRL_MEDIA_SOURCE_GET_CLASS (source)->cancel (source, operation_id);
-  }
+  grl_metadata_source_cancel (GRL_METADATA_SOURCE (source), operation_id);
 }
 
 /**
diff --git a/src/grl-media-source.h b/src/grl-media-source.h
index a0b110b..05453ca 100644
--- a/src/grl-media-source.h
+++ b/src/grl-media-source.h
@@ -493,7 +493,7 @@ void grl_media_source_remove_sync (GrlMediaSource *source,
                                    GError **error);
 
 
-void grl_media_source_cancel (GrlMediaSource *source, guint operation_id);
+G_GNUC_DEPRECATED void grl_media_source_cancel (GrlMediaSource *source, guint operation_id);
 
 G_GNUC_DEPRECATED void grl_media_source_set_operation_data (GrlMediaSource *source,
                                                             guint operation_id,
diff --git a/src/grl-metadata-source.c b/src/grl-metadata-source.c
index 1193baa..ebac1a4 100644
--- a/src/grl-metadata-source.c
+++ b/src/grl-metadata-source.c
@@ -1398,6 +1398,52 @@ grl_metadata_source_set_metadata_sync (GrlMetadataSource *source,
 }
 
 /**
+ * grl_metadata_source_cancel:
+ * @source: a metadata source
+ * @operation_id: the identifier of the running operation, as returned by the
+ * function that started it
+ *
+ * Cancel a running method.
+ *
+ * The derived class must implement the cancel vmethod in order to honour the
+ * request correctly. Otherwise, the operation will not be interrupted.
+ *
+ * In all cases, if this function is called on an ongoing operation, the
+ * corresponding callback will be called with the
+ * @GRL_CORE_ERROR_OPERATION_CANCELLED error set, and no more action will be
+ * taken for that operation after the said callback with error has been called.
+ */
+void
+grl_metadata_source_cancel (GrlMetadataSource *source, guint operation_id)
+{
+  GRL_DEBUG ("grl_metadata_source_cancel");
+
+  g_return_if_fail (GRL_IS_METADATA_SOURCE (source));
+
+  if (!grl_metadata_source_operation_is_ongoing (source, operation_id)) {
+    GRL_DEBUG ("Tried to cancel invalid or already cancelled operation. "
+               "Skipping...");
+    return;
+  }
+
+  /* Mark the operation as finished, if the source does not implement
+     cancellation or it did not make it in time, we will not emit the results
+     for this operation in any case.  At any rate, we will not free the
+     operation data until we are sure the plugin won't need it any more. In the
+     case of operations dealing with multiple results, like browse() or
+     search(), this will happen when it emits remaining = 0 (which can be
+     because it did not cancel the op or because it managed to cancel it and is
+     signaling so) */
+  grl_metadata_source_set_operation_cancelled (source, operation_id);
+
+  /* If the source provides an implementation for operation cancellation,
+     let's use that to avoid further unnecessary processing in the plugin */
+  if (GRL_METADATA_SOURCE_GET_CLASS (source)->cancel) {
+    GRL_METADATA_SOURCE_GET_CLASS (source)->cancel (source, operation_id);
+  }
+}
+
+/**
  * grl_metadata_source_supported_operations:
  * @source: a metadata source
  *
diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h
index 2f3dcae..d20b4d9 100644
--- a/src/grl-metadata-source.h
+++ b/src/grl-metadata-source.h
@@ -245,6 +245,7 @@ typedef struct _GrlMetadataSourceClass GrlMetadataSourceClass;
  * cannot be resolved for @media, TRUE otherwise. Optionally fill @missing_keys
  * with a list of keys that would be needed to resolve. See
  * grl_metadata_source_may_resolve().
+ * @cancel: cancel the current operation
  *
  * Grilo MetadataSource class. Override the vmethods to implement the
  * element functionality.
@@ -274,8 +275,10 @@ struct _GrlMetadataSourceClass {
   gboolean (*may_resolve) (GrlMetadataSource *source, GrlMedia *media,
                            GrlKeyID key_id, GList **missing_keys);
 
+  void (*cancel) (GrlMetadataSource *source, guint operation_id);
+
   /*< private >*/
-  gpointer _grl_reserved[GRL_PADDING - 2];
+  gpointer _grl_reserved[GRL_PADDING - 3];
 };
 
 G_BEGIN_DECLS
@@ -343,6 +346,8 @@ GList *grl_metadata_source_set_metadata_sync (GrlMetadataSource *source,
                                               GrlMetadataWritingFlags flags,
                                               GError **error);
 
+void grl_metadata_source_cancel (GrlMetadataSource *source, guint operation_id);
+
 const gchar *grl_metadata_source_get_id (GrlMetadataSource *source);
 
 const gchar *grl_metadata_source_get_name (GrlMetadataSource *source);
diff --git a/src/grl-multiple.c b/src/grl-multiple.c
index 1c423ad..a49fce6 100644
--- a/src/grl-multiple.c
+++ b/src/grl-multiple.c
@@ -598,8 +598,8 @@ grl_multiple_cancel (guint search_id)
     GRL_DEBUG ("cancelling operation %s:%u",
                grl_metadata_source_get_name (GRL_METADATA_SOURCE (sources->data)),
                GPOINTER_TO_UINT (ids->data));
-    grl_media_source_cancel (GRL_MEDIA_SOURCE (sources->data),
-                             GPOINTER_TO_INT (ids->data));
+    grl_metadata_source_cancel (GRL_METADATA_SOURCE (sources->data),
+                                GPOINTER_TO_INT (ids->data));
     sources = g_list_next (sources);
     ids = g_list_next (ids);
   }
diff --git a/tools/grilo-test-ui/main.c b/tools/grilo-test-ui/main.c
index 7abebe2..9983c6b 100644
--- a/tools/grilo-test-ui/main.c
+++ b/tools/grilo-test-ui/main.c
@@ -505,7 +505,8 @@ cancel_current_operation (void)
 {
   if (ui_state->op_ongoing) {
     if (!ui_state->multiple) {
-      grl_media_source_cancel (ui_state->cur_op_source, ui_state->cur_op_id);
+      grl_metadata_source_cancel (GRL_METADATA_SOURCE (ui_state->cur_op_source),
+                                  ui_state->cur_op_id);
     } else {
       grl_multiple_cancel (ui_state->cur_op_id);
     }



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