[gnome-online-miners/wip/rishi/insert-share: 18/20] miner: Add gom_miner_insert_shared_content_async
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-online-miners/wip/rishi/insert-share: 18/20] miner: Add gom_miner_insert_shared_content_async
- Date: Mon, 5 Sep 2016 13:13:18 +0000 (UTC)
commit 441b1d681cc541ee339deee7a1f4cedd32d98c4b
Author: Debarshi Ray <debarshir gnome org>
Date: Sat Sep 3 19:07:03 2016 +0200
miner: Add gom_miner_insert_shared_content_async
src/gom-miner.c | 172 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gom-miner.h | 15 +++++
2 files changed, 187 insertions(+), 0 deletions(-)
---
diff --git a/src/gom-miner.c b/src/gom-miner.c
index 07ed6b0..52cdb3f 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 *account_id;
+ 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->account_id);
+ 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 *account_id,
+ 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->account_id = g_strdup (account_id);
+ 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,134 @@ 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;
+ gchar *datasource_urn = NULL;
+ gchar *root_element_urn = NULL;
+
+ datasource_urn = g_strdup_printf ("gd:goa-account:%s", data->account_id);
+ root_element_urn = g_strdup_printf ("gd:goa-account:%s:root-element", data->account_id);
+
+ error = NULL;
+ gom_miner_ensure_datasource (self, datasource_urn, root_element_urn, cancellable, &error);
+ if (error != NULL)
+ {
+ g_task_return_error (task, error);
+ goto out;
+ }
+
+ 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);
+ goto out;
+ }
+
+ out:
+ g_free (datasource_urn);
+ g_free (root_element_urn);
+}
+
+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, account_id, 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]