[gnome-documents/wip/skydrive] miner: Introduce libgdminer-1.0.la



commit d9ae9c331093835b8f238e1a4d3c2d4d19734e31
Author: Debarshi Ray <debarshir gnome org>
Date:   Wed May 23 19:56:36 2012 +0200

    miner: Introduce libgdminer-1.0.la
    
    Lots of code can be shared between the different miners. This is a
    step in that direction.
    
    To start with _tracker_sparql_connection_ensure_resource has been
    factored out.
    
    Fixes: https://bugzilla.gnome.org/666535

 src/Makefile-miner.am        |   32 ++++++++++
 src/miner/gd-gdata-miner.c   |  106 +--------------------------------
 src/miner/gd-miner-tracker.c |  132 ++++++++++++++++++++++++++++++++++++++++++
 src/miner/gd-miner-tracker.h |   40 +++++++++++++
 4 files changed, 207 insertions(+), 103 deletions(-)
---
diff --git a/src/Makefile-miner.am b/src/Makefile-miner.am
index d880443..6c10eb9 100644
--- a/src/Makefile-miner.am
+++ b/src/Makefile-miner.am
@@ -1,3 +1,33 @@
+pkglib_LTLIBRARIES += libgdminer-1.0.la
+
+gdminer_source_h = \
+    miner/gd-miner-tracker.h \
+    $(NULL)
+
+gdminer_source_c = \
+    miner/gd-miner-tracker.c \
+    $(NULL)
+
+libgdminer_1_0_la_CPPFLAGS = \
+    -DG_LOG_DOMAIN=\"Gdminer\" \
+    -DG_DISABLE_DEPRECATED \
+    -DGOA_API_IS_SUBJECT_TO_CHANGE \
+    $(DOCUMENTS_CFLAGS) \
+    $(NULL)
+
+libgdminer_1_0_la_LIBADD = \
+    $(DOCUMENTS_LIBS) \
+    $(NULL)
+
+libgdminer_1_0_la_LDFLAGS = \
+    -avoid-version \
+    $(NULL)
+
+libgdminer_1_0_la_SOURCES = \
+    $(gdminer_source_h) \
+    $(gdminer_source_c) \
+    $(NULL)
+
 libexec_PROGRAMS += gd-tracker-gdata-miner
 
 gd_tracker_gdata_miner_SOURCES = \
@@ -15,6 +45,7 @@ gd_tracker_gdata_miner_CFLAGS = \
     $(NULL)
 
 gd_tracker_gdata_miner_LDADD = \
+    libgdminer-1.0.la  \
     libgdprivate-1.0.la  \
     $(MINER_LIBS) \
     $(DOCUMENTS_LIBS) \
@@ -37,6 +68,7 @@ gd_tracker_zpj_miner_CFLAGS = \
     $(NULL)
 
 gd_tracker_zpj_miner_LDADD = \
+    libgdminer-1.0.la  \
     libgdprivate-1.0.la  \
     $(MINER_LIBS) \
     $(DOCUMENTS_LIBS) \
diff --git a/src/miner/gd-gdata-miner.c b/src/miner/gd-gdata-miner.c
index b60e3d9..bba7442 100644
--- a/src/miner/gd-gdata-miner.c
+++ b/src/miner/gd-gdata-miner.c
@@ -25,6 +25,7 @@
 
 #include "gd-gdata-goa-authorizer.h"
 #include "gd-gdata-miner.h"
+#include "gd-miner-tracker.h"
 #include "gd-utils.h"
 
 #define MINER_IDENTIFIER "gd:gdata:miner:86ec9bc9-c242-427f-aa19-77b5a2c9b6f0"
@@ -251,107 +252,6 @@ _tracker_utils_ensure_contact_resource (TrackerSparqlConnection *connection,
   return retval;
 }
 
-static gchar*
-_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
-                                            GCancellable *cancellable,
-                                            GError **error,
-                                            const gchar *graph,
-                                            const gchar *identifier,
-                                            const gchar *class,
-                                            ...)
-{
-  GString *select, *insert, *inner;
-  va_list args;
-  const gchar *arg;
-  TrackerSparqlCursor *cursor;
-  gboolean res;
-  gchar *retval = NULL;
-  gchar *graph_str;
-  GVariant *insert_res;
-  GVariantIter *iter;
-  gchar *key = NULL, *val = NULL;
-
-  /* build the inner query with all the classes */
-  va_start (args, class);
-  inner = g_string_new (NULL);
-
-  for (arg = class; arg != NULL; arg = va_arg (args, const gchar *))
-    g_string_append_printf (inner, " a %s; ", arg);
-
-  g_string_append_printf (inner, "nao:identifier \"%s\"", identifier);
-
-  va_end (args);
-
-  /* query if such a resource is already in the DB */
-  select = g_string_new (NULL);
-  g_string_append_printf (select, 
-                          "SELECT ?urn WHERE { ?urn %s }", inner->str);
-
-  cursor = tracker_sparql_connection_query (connection,
-                                            select->str,
-                                            cancellable, error);
-
-  g_string_free (select, TRUE);
-
-  if (*error != NULL)
-    goto out;
-
-  res = tracker_sparql_cursor_next (cursor, cancellable, error);
-
-  if (*error != NULL)
-    goto out;
-
-  if (res)
-    {
-      /* return the found resource */
-      retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
-      g_debug ("Found resource in the store: %s", retval);
-      goto out;
-    }
-
-  /* not found, create the resource */
-  insert = g_string_new (NULL);
-  graph_str = _tracker_utils_format_into_graph (graph);
-
-  g_string_append_printf (insert, "INSERT %s { _:res %s }", 
-                          graph_str, inner->str);
-  g_free (graph_str);
-  g_string_free (inner, TRUE);
-
-  insert_res = 
-    tracker_sparql_connection_update_blank (connection, insert->str,
-                                            G_PRIORITY_DEFAULT, NULL, error);
-
-  g_string_free (insert, TRUE);
-
-  if (*error != NULL)
-    goto out;
-
-  /* the result is an "aaa{ss}" variant */
-  g_variant_get (insert_res, "aaa{ss}", &iter);
-  g_variant_iter_next (iter, "aa{ss}", &iter);
-  g_variant_iter_next (iter, "a{ss}", &iter);
-  g_variant_iter_next (iter, "{ss}", &key, &val);
-
-  g_variant_iter_free (iter);
-  g_variant_unref (insert_res);
-
-  if (g_strcmp0 (key, "res") == 0)
-    {
-      retval = val;
-    }
-  else
-    {
-      g_free (val);
-      goto out;
-    }
-
-  g_debug ("Created a new resource: %s", retval);
-
- out:
-  g_clear_object (&cursor);
-  return retval;
-}
 
 typedef struct {
   GdGDataMiner *self;
@@ -517,7 +417,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
   else if (GDATA_IS_DOCUMENTS_FOLDER (doc_entry))
     class = "nfo:DataContainer";
  
-  resource = _tracker_sparql_connection_ensure_resource
+  resource = gd_miner_tracker_sparql_connection_ensure_resource
     (job->connection, 
      job->cancellable, error,
      resource_url, identifier,
@@ -559,7 +459,7 @@ account_miner_job_process_entry (AccountMinerJob *job,
       parent_resource_id = 
         g_strdup_printf ("gd:collection:%s", gdata_link_get_uri (parent));
 
-      parent_resource_urn = _tracker_sparql_connection_ensure_resource
+      parent_resource_urn = gd_miner_tracker_sparql_connection_ensure_resource
         (job->connection, job->cancellable, error,
          NULL, parent_resource_id,
          "nfo:RemoteDataObject", "nfo:DataContainer", NULL);
diff --git a/src/miner/gd-miner-tracker.c b/src/miner/gd-miner-tracker.c
new file mode 100644
index 0000000..dffd942
--- /dev/null
+++ b/src/miner/gd-miner-tracker.c
@@ -0,0 +1,132 @@
+/*
+ * Copyright (c) 2011, 2012 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#include <glib.h>
+
+#include "gd-miner-tracker.h"
+
+static gchar *
+_tracker_utils_format_into_graph (const gchar *graph)
+{
+  return (graph != NULL) ? g_strdup_printf ("INTO <%s> ", graph) : g_strdup ("");
+}
+
+gchar *
+gd_miner_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
+                                                    GCancellable *cancellable,
+                                                    GError **error,
+                                                    const gchar *graph,
+                                                    const gchar *identifier,
+                                                    const gchar *class,
+                                                    ...)
+{
+  GString *select, *insert, *inner;
+  va_list args;
+  const gchar *arg;
+  TrackerSparqlCursor *cursor;
+  gboolean res;
+  gchar *retval = NULL;
+  gchar *graph_str;
+  GVariant *insert_res;
+  GVariantIter *iter;
+  gchar *key = NULL, *val = NULL;
+
+  /* build the inner query with all the classes */
+  va_start (args, class);
+  inner = g_string_new (NULL);
+
+  for (arg = class; arg != NULL; arg = va_arg (args, const gchar *))
+    g_string_append_printf (inner, " a %s; ", arg);
+
+  g_string_append_printf (inner, "nao:identifier \"%s\"", identifier);
+
+  va_end (args);
+
+  /* query if such a resource is already in the DB */
+  select = g_string_new (NULL);
+  g_string_append_printf (select,
+                          "SELECT ?urn WHERE { ?urn %s }", inner->str);
+
+  cursor = tracker_sparql_connection_query (connection,
+                                            select->str,
+                                            cancellable, error);
+
+  g_string_free (select, TRUE);
+
+  if (*error != NULL)
+    goto out;
+
+  res = tracker_sparql_cursor_next (cursor, cancellable, error);
+
+  if (*error != NULL)
+    goto out;
+
+  if (res)
+    {
+      /* return the found resource */
+      retval = g_strdup (tracker_sparql_cursor_get_string (cursor, 0, NULL));
+      g_debug ("Found resource in the store: %s", retval);
+      goto out;
+    }
+
+  /* not found, create the resource */
+  insert = g_string_new (NULL);
+  graph_str = _tracker_utils_format_into_graph (graph);
+
+  g_string_append_printf (insert, "INSERT %s { _:res %s }",
+                          graph_str, inner->str);
+  g_free (graph_str);
+  g_string_free (inner, TRUE);
+
+  insert_res =
+    tracker_sparql_connection_update_blank (connection, insert->str,
+                                            G_PRIORITY_DEFAULT, NULL, error);
+
+  g_string_free (insert, TRUE);
+
+  if (*error != NULL)
+    goto out;
+
+  /* the result is an "aaa{ss}" variant */
+  g_variant_get (insert_res, "aaa{ss}", &iter);
+  g_variant_iter_next (iter, "aa{ss}", &iter);
+  g_variant_iter_next (iter, "a{ss}", &iter);
+  g_variant_iter_next (iter, "{ss}", &key, &val);
+
+  g_variant_iter_free (iter);
+  g_variant_unref (insert_res);
+
+  if (g_strcmp0 (key, "res") == 0)
+    {
+      retval = val;
+    }
+  else
+    {
+      g_free (val);
+      goto out;
+    }
+
+  g_debug ("Created a new resource: %s", retval);
+
+ out:
+  g_clear_object (&cursor);
+  return retval;
+}
diff --git a/src/miner/gd-miner-tracker.h b/src/miner/gd-miner-tracker.h
new file mode 100644
index 0000000..85dcbfd
--- /dev/null
+++ b/src/miner/gd-miner-tracker.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2011, 2012 Red Hat, Inc.
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * Author: Cosimo Cecchi <cosimoc redhat com>
+ *
+ */
+
+#ifndef __GD_MINER_TRACKER_H__
+#define __GD_MINER_TRACKER_H__
+
+#include <gio/gio.h>
+#include <libtracker-sparql/tracker-sparql.h>
+
+G_BEGIN_DECLS
+
+gchar *gd_miner_tracker_sparql_connection_ensure_resource (TrackerSparqlConnection *connection,
+                                                           GCancellable *cancellable,
+                                                           GError **error,
+                                                           const gchar *graph,
+                                                           const gchar *identifier,
+                                                           const gchar *class,
+                                                           ...);
+
+G_END_DECLS
+
+#endif /* __GD_MINER_TRACKER_H__ */



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