[gnome-online-miners/wip/rishi/insert-share: 18/19] miner: insert shared



commit b3fa3c8fc55a3720a067250083edc2a9ce2d114e
Author: Debarshi Ray <debarshir gnome org>
Date:   Sat Sep 3 19:07:03 2016 +0200

    miner: insert shared

 src/gom-miner.c |  154 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gom-miner.h |   15 +++++
 2 files changed, 169 insertions(+), 0 deletions(-)
---
diff --git a/src/gom-miner.c b/src/gom-miner.c
index 7947f37..ad6a989 100644
--- a/src/gom-miner.c
+++ b/src/gom-miner.c
@@ -49,6 +49,15 @@ typedef struct {
   GList *pending_jobs;
 } CleanupJob;
 
+typedef struct {
+  GomMiner *self;
+  gchar *datasource_urn;
+  gchar *shared_id;
+  gchar *shared_type;
+  gchar *source_urn;
+  gpointer service;
+} InsertSharedContentData;
+
 static GThreadPool *cleanup_pool;
 
 static void cleanup_job (gpointer data, gpointer user_data);
@@ -72,6 +81,41 @@ gom_account_miner_job_free (GomAccountMinerJob *job)
 }
 
 static void
+gom_insert_shared_content_data_free (InsertSharedContentData *data)
+{
+  GOM_MINER_GET_CLASS (data->self)->destroy_service (self, data->service);
+
+  g_object_unref (data->self);
+  g_free (data->datasource_urn);
+  g_free (data->shared_id);
+  g_free (data->shared_type);
+  g_free (data->source_urn);
+
+  g_slice_free (InsertSharedContentData, data);
+}
+
+static InsertSharedContentData *
+gom_insert_shared_content_data_new (GomMiner *self,
+                                    const gchar *datasource_urn,
+                                    const gchar *shared_id,
+                                    const gchar *shared_type,
+                                    const gchar *shared_urn,
+                                    gpointer service)
+{
+  InsertSharedContentData *retval;
+
+  retval = g_slice_new0 (InsertSharedContentData);
+  retval->self = g_object_ref (self);
+  retval->datasource_urn = g_strdup (datasource_urn);
+  retval->shared_id = g_strdup (shared_id);
+  retval->shared_type = g_strdup (shared_type);
+  retval->shared_urn = g_strdup (shared_urn);
+  retval->service = service;
+
+  return retval;
+}
+
+static void
 gom_miner_dispose (GObject *object)
 {
   GomMiner *self = GOM_MINER (object);
@@ -711,6 +755,116 @@ gom_miner_get_display_name (GomMiner *self)
   return self->priv->display_name;
 }
 
+static void
+gom_miner_insert_shared_content_in_thread_func (GTask *task,
+                                                gpointer source_object,
+                                                gpointer task_data,
+                                                GCancellable *cancellable)
+{
+  GomMiner *self = GOM_MINER (source_object);
+  GError *error;
+  InsertSharedContentData *data = (InsertSharedContentData *) task_data;
+
+  error = NULL;
+  GOM_MINER_GET_CLASS (self)->insert_shared_content (self,
+                                                     self->priv->connection,
+                                                     service,
+                                                     datasource_urn,
+                                                     shared_id,
+                                                     shared_type,
+                                                     source_urn,
+                                                     cancellable,
+                                                     &error);
+  if (error != NULL)
+    {
+      g_task_return_error (task, error);
+    }
+}
+
+void
+gom_miner_insert_shared_content_async (GomMiner *self,
+                                       const gchar *account_id,
+                                       const gchar *shared_id,
+                                       const gchar *shared_type,
+                                       const gchar *source_urn,
+                                       GCancellable *cancellable,
+                                       GAsyncReadyCallback callback,
+                                       gpointer user_data)
+{
+  GTask *task = NULL;
+  GoaDocuments *documents;
+  GoaObject *object = NULL;
+  GoaPhotos *photos;
+  InsertSharedContentData *data;
+  gpointer service;
+
+  task = g_task_new (self, cancellable, callback, user_data);
+  g_task_set_source_tag (task, gom_miner_insert_shared_content_async);
+
+  if (self->priv->client_error != NULL)
+    {
+      g_task_return_error (task, g_error_copy (self->priv->client_error));
+      goto out;
+    }
+
+  if (self->priv->connection_error != NULL)
+    {
+      g_task_return_error (task, g_error_copy (self->priv->connection_error));
+      goto out;
+    }
+
+  object = goa_client_lookup_by_id (self->priv->client, account_id);
+  if (object == NULL)
+    {
+      /* throw error */
+      goto out;
+    }
+
+  documents = goa_object_peek_documents (object);
+  photos = goa_object_peek_photos (object);
+
+  if (g_strcmp (shared_type, "documents") == 0 && documents == NULL)
+    {
+      /* throw error */
+      goto out;
+    }
+
+  if (g_strcmp (shared_type, "photos") == 0 && photos == NULL)
+    {
+      /* throw error */
+      goto out;
+    }
+
+  service = GOM_MINER_GET_CLASS (self)->create_service (self, object, shared_type);
+  if (service == NULL)
+    {
+      /* throw error */
+      goto out;
+    }
+
+  data = gom_insert_shared_content_data_new (self, datasource_urn, shared_id, shared_type, source_urn, 
service);
+  g_task_set_task_data (task, data, (GDestroyNotify) gom_insert_shared_content_data_free);
+
+  g_task_run_in_thread (task, gom_miner_insert_shared_content_in_thread_func);
+
+ out:
+  g_clear_object (&object);
+  g_clear_object (&task);
+}
+
+gboolean
+gom_miner_insert_shared_content_finish (GomMiner *self, GAsyncResult *res, GError **error)
+{
+  GTask *task;
+
+  g_assert (g_task_is_valid (res, self));
+  task = G_TASK (res);
+
+  g_assert (g_task_get_source_tag (task) == gom_miner_insert_shared_content_async);
+
+  return g_task_propagate_boolean (task, error);
+}
+
 void
 gom_miner_refresh_db_async (GomMiner *self,
                             GCancellable *cancellable,
diff --git a/src/gom-miner.h b/src/gom-miner.h
index a1b9349..f12bd0b 100644
--- a/src/gom-miner.h
+++ b/src/gom-miner.h
@@ -87,9 +87,13 @@ struct _GomMinerClass
   char *miner_identifier;
   gint  version;
 
+  gpointer (*create_service) (GomMiner *self, GoaObject *object, const gchar *type);
+
   GHashTable * (*create_services) (GomMiner *self,
                                    GoaObject *object);
 
+  void (*destroy_service) (GomMiner *self, gpointer service);
+
   void (*query) (GomAccountMinerJob *job,
                  TrackerSparqlConnection *connection,
                  GHashTable *previous_resources,
@@ -102,6 +106,17 @@ GType gom_miner_get_type (void);
 
 const gchar * gom_miner_get_display_name (GomMiner *self);
 
+void gom_miner_insert_shared_content_async (GomMiner *self,
+                                            const gchar *account_id,
+                                            const gchar *shared_id,
+                                            const gchar *shared_type,
+                                            const gchar *source_urn,
+                                            GCancellable *cancellable,
+                                            GAsyncReadyCallback callback,
+                                            gpointer user_data);
+
+gboolean gom_miner_insert_shared_content_finish (GomMiner *self, GAsyncResult *res, GError **error);
+
 void gom_miner_refresh_db_async (GomMiner *self,
                                  GCancellable *cancellable,
                                  GAsyncReadyCallback callback,


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