[PATCH 5/5] tracker: fix notifications bugs
- From: lionel g landwerlin linux intel com
- To: grilo-list gnome org
- Subject: [PATCH 5/5] tracker: fix notifications bugs
- Date: Tue, 8 Feb 2011 19:49:33 +0000
From: Lionel Landwerlin <lionel g landwerlin linux intel com>
This patch fix several notification related bugs :
* When a file is removed, we don't need to make a request on the
database to find its data source, since the file has been
removed from the DB, this is useless. Instead we just notify
all the sources that a file has been removed.
* When removing a volume, no need to notify that all its files
have been removed, one by one. Instead we deactivate the
source's notification and wait to have processed all items
before removing the source from the registry.
* Add mising g_object_unref on notified media
Signed-off-by: Lionel Landwerlin <lionel g landwerlin linux intel com>
---
src/tracker/grl-tracker.c | 121 ++++++++++++++++++++++++++++++++++++---------
1 files changed, 97 insertions(+), 24 deletions(-)
diff --git a/src/tracker/grl-tracker.c b/src/tracker/grl-tracker.c
index b631a81..998de9a 100644
--- a/src/tracker/grl-tracker.c
+++ b/src/tracker/grl-tracker.c
@@ -161,8 +161,9 @@ typedef struct {
GList *altered_items_list;
GList *altered_items_iter;
- /* List of new sources */
+ /* List of new/old sources */
GList *new_sources;
+ GList *old_sources;
/* Convenient stuff (for tracker/own callbacks...) */
TrackerSparqlCursor *cursor;
@@ -348,6 +349,7 @@ tracker_evt_update_free (tracker_evt_update_t *evt)
g_hash_table_destroy (evt->orphan_items);
g_list_free (evt->new_sources);
+ g_list_free (evt->old_sources);
if (evt->cursor != NULL)
g_object_unref (evt->cursor);
@@ -358,11 +360,18 @@ tracker_evt_update_free (tracker_evt_update_t *evt)
static void
tracker_evt_postupdate_sources (tracker_evt_update_t *evt)
{
- GList *new_source = evt->new_sources;
+ GList *source;
- while (new_source != NULL) {
- grl_tracker_add_source (GRL_TRACKER_SOURCE (new_source->data));
- new_source = new_source->next;
+ source = evt->old_sources;
+ while (source != NULL) {
+ grl_tracker_del_source (GRL_TRACKER_SOURCE (source->data));
+ source = source->next;
+ }
+
+ source = evt->new_sources;
+ while (source != NULL) {
+ grl_tracker_add_source (GRL_TRACKER_SOURCE (source->data));
+ source = source->next;
}
tracker_evt_update_free (evt);
@@ -413,14 +422,16 @@ tracker_evt_update_orphan_item_cb (GObject *object,
GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items,
GSIZE_TO_POINTER (id)));
- grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ID, str_id);
+ grl_media_set_id (media, str_id);
+ g_free (str_id);
GRL_DEBUG ("Update op=%i item=%i", change_type, id);
+ GRL_DEBUG ("Notify !");
grl_media_source_notify_change (GRL_MEDIA_SOURCE (plugin), media,
change_type, FALSE);
- g_free (str_id);
+ g_object_unref (media);
}
}
@@ -455,35 +466,91 @@ tracker_evt_update_orphans_cb (GObject *object,
static void
tracker_evt_update_orphans (tracker_evt_update_t *evt)
{
+ guint id;
+ gchar *str_id;
GString *request_str;
GList *subject, *subjects;
+ GrlMedia *media;
+ GList *source, *sources;
GRL_DEBUG ("%s", __FUNCTION__);
if (g_hash_table_size (evt->orphan_items) < 1)
return;
+ sources = grl_plugin_registry_get_sources (grl_plugin_registry_get_default (),
+ FALSE);
+
request_str = g_string_new (TRACKER_SOURCE_ITEM_START);
subjects = g_hash_table_get_keys (evt->orphan_items);
- subject = subjects;
-
- g_string_append_printf (request_str, "%i", GPOINTER_TO_INT (subject->data));
- subject = subject->next;
+ subject = subjects;
while (subject != NULL) {
- g_string_append_printf (request_str, ", %i",
- GPOINTER_TO_INT (subject->data));
+ id = GPOINTER_TO_INT (subject->data);
+ if (GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items,
+ subject->data)) != GRL_CONTENT_REMOVED) {
+ g_string_append_printf (request_str, "%u", id);
+ break;
+ } else {
+ /* Notify all sources that a been removed */
+ str_id = g_strdup_printf ("%u", id);
+ media = grl_media_new ();
+ grl_media_set_id (media, str_id);
+ g_free (str_id);
+
+ source = sources;
+ while (source != NULL) {
+ if (GRL_IS_TRACKER_SOURCE (source->data)) {
+ GRL_DEBUG ("Notify !");
+ grl_media_source_notify_change (GRL_MEDIA_SOURCE (source->data),
+ media, GRL_CONTENT_REMOVED, FALSE);
+ }
+ source = source->next;
+ }
+
+ g_object_unref (media);
+ }
subject = subject->next;
}
- g_list_free (subjects);
- g_string_append (request_str, TRACKER_SOURCE_ITEM_END);
+ if (subject != NULL) {
+ subject = subject->next;
+ while (subject != NULL) {
+ id = GPOINTER_TO_INT (subject->data);
+ if (GPOINTER_TO_INT (g_hash_table_lookup (evt->orphan_items,
+ subject->data)) != GRL_CONTENT_REMOVED) {
+ g_string_append_printf (request_str, ", %u", id);
+ } else {
+ /* Notify all sources that a been removed */
+ str_id = g_strdup_printf ("%u", id);
+ media = grl_media_new ();
+ grl_media_set_id (media, str_id);
+ g_free (str_id);
+
+ source = sources;
+ while (source != NULL) {
+ if (GRL_IS_TRACKER_SOURCE (source->data)) {
+ GRL_DEBUG ("Notify !");
+ grl_media_source_notify_change (GRL_MEDIA_SOURCE (source->data),
+ media, GRL_CONTENT_REMOVED, FALSE);
+ }
+ source = source->next;
+ }
+
+ g_object_unref (media);
+ }
+ subject = subject->next;
+ }
+ g_list_free (subjects);
- GRL_DEBUG ("\trequest : '%s'", request_str->str);
+ g_string_append (request_str, TRACKER_SOURCE_ITEM_END);
- tracker_sparql_connection_query_async (tracker_connection, request_str->str,
- NULL, (GAsyncReadyCallback) tracker_evt_update_orphans_cb,
- evt);
+ GRL_DEBUG ("\trequest : '%s'", request_str->str);
+
+ tracker_sparql_connection_query_async (tracker_connection, request_str->str,
+ NULL, (GAsyncReadyCallback) tracker_evt_update_orphans_cb,
+ evt);
+ }
g_string_free (request_str, TRUE);
}
@@ -516,15 +583,17 @@ tracker_evt_update_items_cb (gpointer key,
media = grl_media_new ();
str_id = g_strdup_printf ("%i", id);
- grl_data_set_string (GRL_DATA (media), GRL_METADATA_KEY_ID, str_id);
+ grl_media_set_id (media, str_id);
+ g_free (str_id);
GRL_DEBUG ("Update op=%i item=%i on source %s", evt->change_type, id,
grl_metadata_source_get_name (GRL_METADATA_SOURCE (source)));
+ GRL_DEBUG ("Notify !");
grl_media_source_notify_change (GRL_MEDIA_SOURCE (source), media,
evt->change_type, FALSE);
- g_free (str_id);
+ g_object_unref (media);
}
static void
@@ -599,7 +668,10 @@ tracker_evt_preupdate_sources_item_cb (GObject *object,
GRL_DEBUG ("\tChanges on source %p / %s", plugin, datasource);
}
} else if (!source_mounted && plugin != NULL) {
- grl_tracker_del_source (GRL_TRACKER_SOURCE (plugin));
+ GrlTrackerSourcePriv *priv = GRL_TRACKER_SOURCE (plugin)->priv;
+
+ priv->notify_changes = FALSE;
+ evt->old_sources = g_list_append (evt->old_sources, plugin);
}
tracker_sparql_cursor_next_async (evt->cursor, NULL,
@@ -684,10 +756,11 @@ tracker_dbus_signal_cb (GDBusConnection *connection,
g_variant_get (parameters, "(&sa(iiii)a(iiii))", &class_name, &iter1, &iter2);
- GRL_DEBUG ("\tTracker update event for class=%s ins=%lu del=%lu",
+ GRL_DEBUG ("\tTracker update event for class=%s ins=%lu del=%lu evt=%p",
class_name,
(unsigned long) g_variant_iter_n_children (iter1),
- (unsigned long) g_variant_iter_n_children (iter2));
+ (unsigned long) g_variant_iter_n_children (iter2),
+ evt);
/* Process deleted items */
while (g_variant_iter_loop (iter1, "(iiii)", &graph,
--
1.7.2.3
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]