[PATCH 2/5] core: Add API to handle "content-changed" signal



Add notify_changed_start() and notify_changed_stop() functions so sources know
when they can emit the signal and when not.

Sources that are able to emit "content-changed" signal must re-implement
notify_changed_start() function.

Added a notify_changed() function too that sources can use to send the signal.

Signed-off-by: Juan A. Suarez Romero <jasuarez igalia com>
---
 src/grl-error.h           |    4 ++-
 src/grl-media-source.c    |   67 +++++++++++++++++++++++++++++++++++++++++++++
 src/grl-media-source.h    |   17 +++++++++++
 src/grl-metadata-source.h |    2 +
 4 files changed, 89 insertions(+), 1 deletions(-)

diff --git a/src/grl-error.h b/src/grl-error.h
index 4f654ab..d76a5fb 100644
--- a/src/grl-error.h
+++ b/src/grl-error.h
@@ -54,6 +54,7 @@
  * @GRL_CORE_ERROR_LOAD_PLUGIN_FAILED: Failed to load plugin
  * @GRL_CORE_ERROR_UNLOAD_PLUGIN_FAILED: Failed to unload plugin
  * @GRL_CORE_ERROR_REGISTER_METADATA_KEY_FAILED: Failed to register metadata key
+ * @GRL_CORE_ERROR_NOTIFY_CHANGED_FAILED: Failed to start changed notifications
  *
  * These constants identify all the available core errors
  */
@@ -73,7 +74,8 @@ typedef enum {
   GRL_CORE_ERROR_UNREGISTER_SOURCE_FAILED,
   GRL_CORE_ERROR_LOAD_PLUGIN_FAILED,
   GRL_CORE_ERROR_UNLOAD_PLUGIN_FAILED,
-  GRL_CORE_ERROR_REGISTER_METADATA_KEY_FAILED
+  GRL_CORE_ERROR_REGISTER_METADATA_KEY_FAILED,
+  GRL_CORE_ERROR_NOTIFY_CHANGED_FAILED
 } GrlCoreError;
 
 #endif /* _GRL_ERROR_H_ */
diff --git a/src/grl-media-source.c b/src/grl-media-source.c
index fd2e804..215b282 100644
--- a/src/grl-media-source.c
+++ b/src/grl-media-source.c
@@ -2045,6 +2045,8 @@ grl_media_source_supported_operations (GrlMetadataSource *metadata_source)
   if (media_source_class->test_media_from_uri &&
       media_source_class->media_from_uri)
     caps |= GRL_OP_MEDIA_FROM_URI;
+  if (media_source_class->notify_changed_start)
+    caps |= GRL_OP_NOTIFY_CHANGED;
 
   return caps;
 }
@@ -2534,3 +2536,68 @@ grl_media_source_get_media_from_uri_sync (GrlMediaSource *source,
 
   return result;
 }
+
+/**
+ * grl_media_source_notify_changed_start:
+ * @source: a media source
+ * @error: a #GError, or @NULL
+ *
+ * Starts signal "content-changed" emission when source finds changes in the content.
+ *
+ * Returns: @TRUE if initialization has succeed.
+ */
+gboolean
+grl_media_source_notify_changed_start (GrlMediaSource *source,
+                                       GError **error)
+{
+  g_return_val_if_fail (GRL_IS_MEDIA_SOURCE (source), FALSE);
+  g_return_val_if_fail (grl_media_source_supported_operations (GRL_METADATA_SOURCE (source)) &
+                        GRL_OP_NOTIFY_CHANGED, FALSE);
+
+  return GRL_MEDIA_SOURCE_GET_CLASS (source)->notify_changed_start (source,
+                                                                    error);
+}
+
+/**
+ * grl_media_source_notify_changed_stop:
+ * @source: a media source
+ *
+ * Stops emitting "content-changed" signal.
+ */
+void grl_media_source_notify_changed_stop (GrlMediaSource *source)
+{
+  g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
+
+  GrlMediaSourceClass *source_class = GRL_MEDIA_SOURCE_GET_CLASS (source);
+
+  if (source_class->notify_changed_stop) {
+    source_class->notify_changed_stop (source);
+  }
+}
+
+/**
+ * grl_media_source_notify_changed:
+ * @source: a media source
+ * @media: (allow-none): the media which has changed
+ * @change_type: the type of change
+ * @location_unknown: if change has happpened in @media or any descendant
+ *
+ * Emits "content-changed" signal to notify a changed happend in @source.
+ *
+ * See GrlMediaSource::content-changed signal
+ */
+void grl_media_source_notify_changed (GrlMediaSource *source,
+                                      GrlMedia *media,
+                                      GrlMediaSourceChangeType change_type,
+                                      gboolean location_unknown)
+{
+  g_return_if_fail (GRL_IS_MEDIA_SOURCE (source));
+  g_return_if_fail (!media || GRL_IS_MEDIA (media));
+
+  g_signal_emit (source,
+                 registry_signals[SIG_CONTENT_CHANGED],
+                 0,
+                 media,
+                 change_type,
+                 location_unknown);
+}
diff --git a/src/grl-media-source.h b/src/grl-media-source.h
index 83a5360..4ccd95a 100644
--- a/src/grl-media-source.h
+++ b/src/grl-media-source.h
@@ -363,6 +363,8 @@ typedef struct _GrlMediaSourceClass GrlMediaSourceClass;
  * instances from a given URI.
  * @media_from_uri: Creates a #GrlMedia instance representing the media
  * exposed by a certain URI.
+ * @notify_changed_start: start to send events about changes in content
+ * @notify_changed_stop: stop sending events about changes in content
  *
  * Grilo MediaSource class. Override the vmethods to implement the
  * source functionality.
@@ -393,6 +395,11 @@ struct _GrlMediaSourceClass {
   void (*media_from_uri) (GrlMediaSource *source,
 			  GrlMediaSourceMediaFromUriSpec *mfss);
 
+  gboolean (*notify_changed_start) (GrlMediaSource *source,
+                                    GError **error);
+
+  void (*notify_changed_stop) (GrlMediaSource *source);
+
   /*< private >*/
   gpointer _grl_reserved[GRL_PADDING];
 
@@ -522,6 +529,16 @@ GrlMedia *grl_media_source_get_media_from_uri_sync (GrlMediaSource *source,
                                                     GrlMetadataResolutionFlags flags,
                                                     GError **error);
 
+gboolean grl_media_source_notify_changed_start (GrlMediaSource *source,
+                                                GError **error);
+
+void grl_media_source_notify_changed_stop (GrlMediaSource *source);
+
+void grl_media_source_notify_changed (GrlMediaSource *source,
+                                      GrlMedia *media,
+                                      GrlMediaSourceChangeType change_type,
+                                      gboolean location_unknown);
+
 G_END_DECLS
 
 #endif /* _GRL_MEDIA_SOURCE_H_ */
diff --git a/src/grl-metadata-source.h b/src/grl-metadata-source.h
index de80c8b..3da29e9 100644
--- a/src/grl-metadata-source.h
+++ b/src/grl-metadata-source.h
@@ -205,6 +205,7 @@ typedef struct {
  * @GRL_OP_SET_METADATA: Update metadata of a #GrlMedia in a service.
  * @GRL_OP_MEDIA_FROM_URI: Create a #GrlMedia instance from an URI
  * representing a media resource.
+ * @GRL_OP_NOTIFY_CHANGED: Notify about changes in the #GrlMediaSource.
  *
  * Bitwise flags which reflect the kind of operations that a
  * #GrlMediaPlugin supports.
@@ -221,6 +222,7 @@ typedef enum {
   GRL_OP_REMOVE          = 1 << 7,
   GRL_OP_SET_METADATA    = 1 << 8,
   GRL_OP_MEDIA_FROM_URI  = 1 << 9,
+  GRL_OP_NOTIFY_CHANGED  = 1 << 10,
 } GrlSupportedOps;
 
 /* GrlMetadataSource class */
-- 
1.7.3.5



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