[gvfs/tracker-metadata] metadata: Try reconnecting to tracker-store periodically
- From: Tomas Bzatek <tbzatek src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gvfs/tracker-metadata] metadata: Try reconnecting to tracker-store periodically
- Date: Thu, 16 Dec 2010 15:19:18 +0000 (UTC)
commit f1700e070e9aa902c7f346bf884802cdd2b81d45
Author: Tomas Bzatek <tbzatek redhat com>
Date: Thu Dec 16 16:17:18 2010 +0100
metadata: Try reconnecting to tracker-store periodically
Timeout is set to five seconds, could be tweaked.
metadata/metadata-tracker-miner.c | 90 ++++++++++++++++++++++++------------
1 files changed, 60 insertions(+), 30 deletions(-)
---
diff --git a/metadata/metadata-tracker-miner.c b/metadata/metadata-tracker-miner.c
index 69e4846..f539b09 100644
--- a/metadata/metadata-tracker-miner.c
+++ b/metadata/metadata-tracker-miner.c
@@ -44,6 +44,7 @@
struct MetadataTrackerMinerPrivate
{
TrackerSparqlConnection *connection;
+ guint running_connection_attempt;
GQueue *queue;
guint running_queue_id;
@@ -269,6 +270,8 @@ typedef struct {
} MetadataTrackerMinerEntry;
static gboolean process_queue (MetadataTrackerMiner *miner);
+static void schedule_queue_pickup (MetadataTrackerMiner *miner);
+
static void
push_to_tracker_cb (GObject *source,
@@ -298,6 +301,8 @@ process_queue (MetadataTrackerMiner *miner)
GFile *file;
char *data;
+ g_return_val_if_fail (miner->priv->connection != NULL, FALSE);
+
g_print ("process_queue: Picking up queue\n");
entry = g_queue_pop_head (miner->priv->queue);
@@ -429,16 +434,65 @@ queue_push_data_to_tracker (MetadataTrackerMiner *miner,
/* FIXME: mutex? */
g_queue_push_head (miner->priv->queue, entry);
+ schedule_queue_pickup (miner);
+}
+
+static void
+create_connection_cb (GObject *source_object,
+ GAsyncResult *res,
+ gpointer user_data)
+{
+ TrackerSparqlConnection *connection;
+ MetadataTrackerMiner *miner;
+ GError *error;
+
+ miner = user_data;
+ error = NULL;
- /* FIXME: mutex? */
- if (miner->priv->connection != NULL && miner->priv->running_queue_id == 0)
- miner->priv->running_queue_id = g_idle_add ((GSourceFunc) process_queue, miner);
+ connection = tracker_sparql_connection_get_finish (res, &error);
+ if (error != NULL)
+ {
+ g_critical ("Could not initialize Tracker: %s", error->message);
+ g_error_free (error);
+ }
+ miner->priv->connection = connection;
+ miner->priv->running_connection_attempt = 0;
+ g_print ("create_connection_cb: Initialized.\n");
+
+ schedule_queue_pickup (miner);
+}
+
+static gboolean
+create_connection_timeout (MetadataTrackerMiner *miner)
+{
+ tracker_sparql_connection_get_async (NULL, create_connection_cb, miner);
+
+ return FALSE;
+}
+
+static void
+schedule_queue_pickup (MetadataTrackerMiner *miner)
+{
+ if (miner->priv->connection != NULL)
+ {
+ /* FIXME: mutex? */
+ if (miner->priv->running_queue_id == 0)
+ miner->priv->running_queue_id = g_idle_add ((GSourceFunc) process_queue, miner);
+ }
+ else
+ {
+ if (miner->priv->running_connection_attempt == 0)
+ miner->priv->running_connection_attempt = g_timeout_add_seconds (5, (GSourceFunc) create_connection_timeout, miner);
+ }
}
+
+
+
G_DEFINE_TYPE (MetadataTrackerMiner, metadata_tracker_miner, G_TYPE_OBJECT)
static void
@@ -466,42 +520,18 @@ metadata_tracker_miner_class_init (MetadataTrackerMinerClass *klass)
g_type_class_add_private (object_class, sizeof (MetadataTrackerMinerPrivate));
}
-static void
-create_connection_cb (GObject *source_object,
- GAsyncResult *res,
- gpointer user_data)
-{
- TrackerSparqlConnection *connection;
- MetadataTrackerMiner *miner;
- GError *error;
-
- miner = user_data;
- error = NULL;
-
- connection = tracker_sparql_connection_get_finish (res, &error);
- if (error != NULL)
- {
- g_critical ("Could not initialize Tracker: %s", error->message);
- g_error_free (error);
- }
- miner->priv->connection = connection;
- g_print ("create_connection_cb: Initialized.\n");
-
- /* Process queue */
- if (connection != NULL && miner->priv->running_queue_id == 0)
- miner->priv->running_queue_id = g_idle_add ((GSourceFunc) process_queue, miner);
-}
-
static void
metadata_tracker_miner_init (MetadataTrackerMiner *object)
{
object->priv = METADATA_TRACKER_MINER_GET_PRIVATE (object);
object->priv->running_queue_id = 0;
+
+ object->priv->queue = g_queue_new ();
+ object->priv->running_connection_attempt = 1; /* spawn manually now */
/* FIXME: do we need cancellable? */
tracker_sparql_connection_get_async (NULL, create_connection_cb, object);
- object->priv->queue = g_queue_new ();
}
MetadataTrackerMiner *
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]