[tracker/class-signal: 33/61] tracker-store, tracker-writeback: Changed the Writeback signal to use IDs
- From: Philip Van Hoof <pvanhoof src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tracker/class-signal: 33/61] tracker-store, tracker-writeback: Changed the Writeback signal to use IDs
- Date: Wed, 1 Sep 2010 12:41:15 +0000 (UTC)
commit 0b5f25a3619ab397607354108584700e34362717
Author: Philip Van Hoof <philip codeminded be>
Date: Tue Aug 24 12:52:26 2010 +0200
tracker-store, tracker-writeback: Changed the Writeback signal to use IDs
The rdf_types array used to be an array of class URI strings. With the
support for tracker:id() can tracker-writeback (over libtracker-sparql)
also receive the IDs of the classes, and then query for it.
data/dbus/tracker-resources.xml | 2 +-
src/libtracker-client/tracker.c | 2 +-
src/libtracker-common/tracker-dbus.h | 4 +-
src/miners/flickr/tracker-miner-flickr.vala | 17 ++--
src/miners/flickr/tracker-writeback.c | 4 +-
src/miners/flickr/tracker-writeback.h | 2 +-
src/tracker-store/tracker-events.c | 4 +-
src/tracker-store/tracker-resources.c | 2 +-
src/tracker-store/tracker-writeback.c | 21 +++--
src/tracker-writeback/tracker-main.c | 21 +++--
src/tracker-writeback/tracker-writeback-consumer.c | 114 +++++++++++++++++---
src/tracker-writeback/tracker-writeback-consumer.h | 2 +-
.../tracker-writeback-dispatcher.c | 10 +-
.../tracker-writeback-dispatcher.h | 2 +-
14 files changed, 153 insertions(+), 54 deletions(-)
---
diff --git a/data/dbus/tracker-resources.xml b/data/dbus/tracker-resources.xml
index 1403a26..8e15123 100644
--- a/data/dbus/tracker-resources.xml
+++ b/data/dbus/tracker-resources.xml
@@ -51,7 +51,7 @@
</method>
<signal name="Writeback">
- <arg type="a{sas}" name="subjects" />
+ <arg type="a{sai}" name="subjects" />
</signal>
<signal name="ClassSignal">
diff --git a/src/libtracker-client/tracker.c b/src/libtracker-client/tracker.c
index 2196593..b70c52a 100644
--- a/src/libtracker-client/tracker.c
+++ b/src/libtracker-client/tracker.c
@@ -576,7 +576,7 @@ client_constructed (GObject *object)
dbus_g_proxy_add_signal (private->proxy_resources,
"Writeback",
- TRACKER_TYPE_STR_STRV_MAP,
+ TRACKER_TYPE_STR_ARRAY_MAP,
G_TYPE_INVALID);
private->is_constructed = TRUE;
diff --git a/src/libtracker-common/tracker-dbus.h b/src/libtracker-common/tracker-dbus.h
index af56129..15c88f0 100644
--- a/src/libtracker-common/tracker-dbus.h
+++ b/src/libtracker-common/tracker-dbus.h
@@ -38,8 +38,8 @@ G_BEGIN_DECLS
#define TRACKER_DBUS_ERROR tracker_dbus_error_quark()
-#define TRACKER_TYPE_STR_STRV_MAP \
- dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_STRV)
+#define TRACKER_TYPE_STR_ARRAY_MAP \
+ dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, DBUS_TYPE_G_INT_ARRAY)
#define TRACKER_TYPE_THREE_INT_ARRAY \
dbus_g_type_get_collection ("GPtrArray", \
diff --git a/src/miners/flickr/tracker-miner-flickr.vala b/src/miners/flickr/tracker-miner-flickr.vala
index 4a470f7..83cde58 100644
--- a/src/miners/flickr/tracker-miner-flickr.vala
+++ b/src/miners/flickr/tracker-miner-flickr.vala
@@ -731,14 +731,17 @@ public class MinerFlickr : Tracker.MinerWeb {
weak string[] rdf_classes;
foreach (string uri in uris) {
- rdf_classes = (string[])properties.lookup (uri);
+ // This part is not correct anylonger, the hashtable contains IDs
+ // instead of string uris
- for (uint i = 0; rdf_classes[i] != null; i++) {
- if (rdf_classes[i] == NMM_PHOTO) {
- writeback_photo (uri);
- return;
- }
- }
+ //rdf_classes = (string[])properties.lookup (uri);
+
+ //for (uint i = 0; rdf_classes[i] != null; i++) {
+ //if (rdf_classes[i] == NMM_PHOTO) {
+ //writeback_photo (uri);
+ //return;
+ //}
+ //}
}
}
diff --git a/src/miners/flickr/tracker-writeback.c b/src/miners/flickr/tracker-writeback.c
index befffe0..c4943b0 100644
--- a/src/miners/flickr/tracker-writeback.c
+++ b/src/miners/flickr/tracker-writeback.c
@@ -74,7 +74,7 @@ tracker_writeback_init (void)
dbus_g_proxy_add_signal (proxy_resources,
"Writeback",
- TRACKER_TYPE_STR_STRV_MAP,
+ TRACKER_TYPE_STR_ARRAY_MAP,
G_TYPE_INVALID);
}
@@ -114,7 +114,7 @@ tracker_writeback_connect (TrackerWritebackCallback callback,
dbus_g_proxy_connect_signal (proxy_resources,
"Writeback",
G_CALLBACK (writeback_cb),
- NULL,
+ NULL,
NULL);
}
diff --git a/src/miners/flickr/tracker-writeback.h b/src/miners/flickr/tracker-writeback.h
index c6c38aa..33d1531 100644
--- a/src/miners/flickr/tracker-writeback.h
+++ b/src/miners/flickr/tracker-writeback.h
@@ -40,7 +40,7 @@ typedef void (*TrackerWritebackCallback) (const GHashTable *resources,
void tracker_writeback_init (void);
void tracker_writeback_shutdown (void);
guint tracker_writeback_connect (TrackerWritebackCallback callback,
- gpointer user_data);
+ gpointer user_data);
void tracker_writeback_disconnect (guint handle);
G_END_DECLS
diff --git a/src/tracker-store/tracker-events.c b/src/tracker-store/tracker-events.c
index 1082668..2ce7bf8 100644
--- a/src/tracker-store/tracker-events.c
+++ b/src/tracker-store/tracker-events.c
@@ -190,8 +190,8 @@ tracker_events_add_delete (gint graph_id,
void
tracker_events_reset (void)
{
- GHashTableIter iter;
- gpointer key, value;
+/* GHashTableIter iter;
+ gpointer key, value; */
g_return_if_fail (private != NULL);
/*
diff --git a/src/tracker-store/tracker-resources.c b/src/tracker-store/tracker-resources.c
index 047efb0..a7ac25c 100644
--- a/src/tracker-store/tracker-resources.c
+++ b/src/tracker-store/tracker-resources.c
@@ -119,7 +119,7 @@ tracker_resources_class_init (TrackerResourcesClass *klass)
NULL, NULL,
g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
- TRACKER_TYPE_STR_STRV_MAP);
+ TRACKER_TYPE_STR_ARRAY_MAP);
/* This is just for introspection to work */
signals[CLASSSIGNAL] =
diff --git a/src/tracker-store/tracker-writeback.c b/src/tracker-store/tracker-writeback.c
index 16a3c0b..b519947 100644
--- a/src/tracker-store/tracker-writeback.c
+++ b/src/tracker-store/tracker-writeback.c
@@ -33,21 +33,28 @@ typedef struct {
static WritebackPrivate *private;
-static GStrv
-copy_rdf_types (GPtrArray *rdf_types)
+static GArray*
+rdf_types_to_array (GPtrArray *rdf_types)
{
- GStrv new_types;
+ GArray *new_types;
guint n;
- new_types = g_new0 (gchar *, rdf_types->len + 1);
+ new_types = g_array_sized_new (FALSE, FALSE, sizeof (gint), rdf_types->len);
for (n = 0; n < rdf_types->len; n++) {
- new_types[n] = g_strdup (tracker_class_get_uri (rdf_types->pdata[n]));
+ gint id = tracker_class_get_id (rdf_types->pdata[n]);
+ g_array_append_val (new_types, id);
}
return new_types;
}
+static void
+array_free (GArray *array)
+{
+ g_array_free (array, TRUE);
+}
+
void
tracker_writeback_check (gint graph_id,
gint subject_id,
@@ -73,12 +80,12 @@ tracker_writeback_check (gint graph_id,
if (!private->events) {
private->events = g_hash_table_new_full (g_str_hash, g_str_equal,
(GDestroyNotify) g_free,
- (GDestroyNotify) g_strfreev);
+ (GDestroyNotify) array_free);
}
g_hash_table_insert (private->events,
g_strdup (subject),
- copy_rdf_types (rdf_types));
+ rdf_types_to_array (rdf_types));
}
}
diff --git a/src/tracker-writeback/tracker-main.c b/src/tracker-writeback/tracker-main.c
index 76e1763..ec64570 100644
--- a/src/tracker-writeback/tracker-main.c
+++ b/src/tracker-writeback/tracker-main.c
@@ -59,8 +59,8 @@ static GOptionEntry entries[] = {
};
typedef struct {
- gchar *subject;
- GStrv rdf_types;
+ gchar *subject;
+ GArray *rdf_types;
} WritebackData;
static TrackerWritebackConsumer *consumer = NULL;
@@ -68,14 +68,21 @@ static TrackerWritebackDispatcher *dispatcher = NULL;
static GMainContext *dispatcher_context = NULL;
static WritebackData *
-writeback_data_new (const gchar *subject,
- const GStrv rdf_types)
+writeback_data_new (const gchar *subject,
+ GArray *rdf_types)
{
WritebackData *data;
+ guint i;
data = g_slice_new (WritebackData);
data->subject = g_strdup (subject);
- data->rdf_types = g_strdupv (rdf_types);
+
+ data->rdf_types = g_array_sized_new (FALSE, FALSE, sizeof (gint), rdf_types->len);
+
+ for (i = 0; i < rdf_types->len; i++) {
+ gint id = g_array_index (rdf_types, gint, i);
+ g_array_append_val (data->rdf_types, id);
+ }
return data;
}
@@ -84,7 +91,7 @@ static void
writeback_data_free (WritebackData *data)
{
g_free (data->subject);
- g_strfreev (data->rdf_types);
+ g_array_free (data->rdf_types, TRUE);
g_slice_free (WritebackData, data);
}
@@ -107,7 +114,7 @@ on_writeback_idle_cb (gpointer user_data)
static void
on_writeback_cb (TrackerWritebackDispatcher *dispatcher,
const gchar *subject,
- const GStrv rdf_types)
+ GArray *rdf_types)
{
WritebackData *data;
diff --git a/src/tracker-writeback/tracker-writeback-consumer.c b/src/tracker-writeback/tracker-writeback-consumer.c
index 7dfde54..968361f 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.c
+++ b/src/tracker-writeback/tracker-writeback-consumer.c
@@ -37,8 +37,9 @@
#define TRACKER_INTERFACE_RESOURCES "org.freedesktop.Tracker1.Resources"
typedef struct {
- gchar *subject;
- GStrv rdf_types;
+ gchar *subject;
+ GStrv rdf_types;
+ GArray *rdf_types_int;
} QueryData;
typedef struct {
@@ -227,13 +228,12 @@ sparql_query_cb (GObject *object,
g_message (" No files qualify for updates");
}
g_ptr_array_free (results, TRUE);
+ g_object_unref (cursor);
} else {
g_message (" No files qualify for updates (%s)", error->message);
g_error_free (error);
}
- g_object_unref (cursor);
-
g_free (data->subject);
g_strfreev (data->rdf_types);
g_slice_free (QueryData, data);
@@ -241,13 +241,81 @@ sparql_query_cb (GObject *object,
priv->idle_id = g_idle_add (process_queue_cb, consumer);
}
+static void
+rdf_types_to_uris_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TrackerWritebackConsumerPrivate *priv;
+ TrackerWritebackConsumer *consumer;
+ QueryData *data;
+ GError *error = NULL;
+ TrackerSparqlCursor *cursor;
+
+ consumer = TRACKER_WRITEBACK_CONSUMER (user_data);
+ priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
+
+ data = g_queue_peek_head (priv->process_queue);
+
+ cursor = tracker_sparql_connection_query_finish (TRACKER_SPARQL_CONNECTION (object), result, &error);
+
+ if (!error) {
+ gchar *query;
+ GArray *rdf_types;
+ guint i;
+
+ rdf_types = g_array_new (TRUE, TRUE, sizeof (gchar *));
+
+ while (tracker_sparql_cursor_next (cursor, NULL, NULL)) {
+ gchar *uri = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+ g_array_append_val (rdf_types, uri);
+ }
+
+ data->rdf_types = g_strdupv ((gchar **) rdf_types->data);
+
+ for (i = 0; i < rdf_types->len; i++)
+ g_free (g_array_index (rdf_types, gchar*, i));
+ g_array_free (rdf_types, TRUE);
+
+ g_object_unref (cursor);
+
+ query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
+ " <%s> ?predicate ?object ; "
+ " nie:url ?url ."
+ " ?predicate tracker:writeback true "
+ "}",
+ data->subject, data->subject);
+
+ tracker_sparql_connection_query_async (priv->connection,
+ query,
+ NULL,
+ sparql_query_cb,
+ consumer);
+
+ g_free (query);
+
+ } else {
+ g_message (" No files qualify for updates (%s)", error->message);
+ g_error_free (error);
+ data = g_queue_pop_head (priv->process_queue);
+ g_free (data->subject);
+ g_strfreev (data->rdf_types);
+ g_slice_free (QueryData, data);
+
+ priv->idle_id = g_idle_add (process_queue_cb, consumer);
+ }
+
+ g_array_free (data->rdf_types_int, TRUE);
+}
+
static gboolean
process_queue_cb (gpointer user_data)
{
TrackerWritebackConsumerPrivate *priv;
TrackerWritebackConsumer *consumer;
QueryData *data;
- gchar *query;
+ GString *query;
+ guint i;
consumer = TRACKER_WRITEBACK_CONSUMER (user_data);
priv = TRACKER_WRITEBACK_CONSUMER_GET_PRIVATE (consumer);
@@ -260,20 +328,27 @@ process_queue_cb (gpointer user_data)
return FALSE;
}
- query = g_strdup_printf ("SELECT ?url '%s' ?predicate ?object {"
- " <%s> ?predicate ?object ; "
- " nie:url ?url ."
- " ?predicate tracker:writeback true "
- "}",
- data->subject, data->subject);
+ query = g_string_new ("SELECT ?resource { ?resource a rdfs:Class . "
+ "FILTER (tracker:id (?resource) IN (");
+
+ for (i = 0; i < data->rdf_types_int->len; i++) {
+ gint id = g_array_index (data->rdf_types_int, gint, i);
+ if (i != 0) {
+ g_string_append_printf (query, ", %d", id);
+ } else {
+ g_string_append_printf (query, "%d", id);
+ }
+ }
+
+ g_string_append (query, ")) }");
tracker_sparql_connection_query_async (priv->connection,
- query,
+ query->str,
NULL,
- sparql_query_cb,
+ rdf_types_to_uris_cb,
consumer);
- g_free (query);
+ g_string_free (query, TRUE);
/* Keep "processing" state */
priv->idle_id = 0;
@@ -283,10 +358,11 @@ process_queue_cb (gpointer user_data)
void
tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
const gchar *subject,
- const GStrv rdf_types)
+ GArray *rdf_types)
{
TrackerWritebackConsumerPrivate *priv;
QueryData *data;
+ guint i;
g_return_if_fail (TRACKER_IS_WRITEBACK_CONSUMER (consumer));
g_return_if_fail (subject != NULL);
@@ -296,7 +372,13 @@ tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
data = g_slice_new (QueryData);
data->subject = g_strdup (subject);
- data->rdf_types = g_strdupv (rdf_types);
+
+ data->rdf_types_int = g_array_sized_new (FALSE, FALSE, sizeof (gint), rdf_types->len);
+
+ for (i = 0; i < rdf_types->len; i++) {
+ gint id = g_array_index (rdf_types, gint, i);
+ g_array_append_val (data->rdf_types_int, id);
+ }
g_queue_push_tail (priv->process_queue, data);
diff --git a/src/tracker-writeback/tracker-writeback-consumer.h b/src/tracker-writeback/tracker-writeback-consumer.h
index d36c48b..6e20054 100644
--- a/src/tracker-writeback/tracker-writeback-consumer.h
+++ b/src/tracker-writeback/tracker-writeback-consumer.h
@@ -50,7 +50,7 @@ TrackerWritebackConsumer * tracker_writeback_consumer_new (void);
void tracker_writeback_consumer_add_subject (TrackerWritebackConsumer *consumer,
const gchar *subject,
- const GStrv rdf_types);
+ GArray *rdf_types);
G_END_DECLS
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.c b/src/tracker-writeback/tracker-writeback-dispatcher.c
index 2691d8c..0cb816c 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.c
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.c
@@ -92,7 +92,7 @@ tracker_writeback_dispatcher_class_init (TrackerWritebackDispatcherClass *klass)
G_STRUCT_OFFSET (TrackerWritebackDispatcherClass, writeback),
NULL, NULL,
tracker_marshal_VOID__STRING_BOXED,
- G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_STRV);
+ G_TYPE_NONE, 2, G_TYPE_STRING, G_TYPE_ARRAY);
g_type_class_add_private (object_class, sizeof (TrackerWritebackDispatcherPrivate));
}
@@ -114,7 +114,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
signature = dbus_message_iter_get_signature (&iter);
- if (g_strcmp0 (signature, "a{sas}") != 0) {
+ if (g_strcmp0 (signature, "a{sai}") != 0) {
g_critical (" Unexpected message signature '%s'", signature);
g_free (signature);
return;
@@ -132,7 +132,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
const gchar *subject;
GArray *rdf_types;
- rdf_types = g_array_new (TRUE, TRUE, sizeof (gchar *));
+ rdf_types = g_array_new (FALSE, FALSE, sizeof (gint));
dbus_message_iter_recurse (&arr, &dict);
@@ -142,7 +142,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
dbus_message_iter_recurse (&dict, &types_arr);
while ((arg_type = dbus_message_iter_get_arg_type (&types_arr)) != DBUS_TYPE_INVALID) {
- const gchar *type;
+ gint type;
dbus_message_iter_get_basic (&types_arr, &type);
@@ -151,7 +151,7 @@ handle_writeback_signal (TrackerWritebackDispatcher *dispatcher,
dbus_message_iter_next (&types_arr);
}
- g_signal_emit (dispatcher, signals[WRITEBACK], 0, subject, rdf_types->data);
+ g_signal_emit (dispatcher, signals[WRITEBACK], 0, subject, rdf_types);
g_array_free (rdf_types, TRUE);
dbus_message_iter_next (&arr);
diff --git a/src/tracker-writeback/tracker-writeback-dispatcher.h b/src/tracker-writeback/tracker-writeback-dispatcher.h
index ec600ac..03e3684 100644
--- a/src/tracker-writeback/tracker-writeback-dispatcher.h
+++ b/src/tracker-writeback/tracker-writeback-dispatcher.h
@@ -45,7 +45,7 @@ struct TrackerWritebackDispatcherClass {
void (* writeback) (TrackerWritebackDispatcher *dispatcher,
const gchar *subject,
- const GStrv rdf_types);
+ GArray *rdf_types);
};
GType tracker_writeback_dispatcher_get_type (void) G_GNUC_CONST;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]