Commit cbc86dcf authored by Christian Hergert's avatar Christian Hergert

xml-tree-builder: port to IdeTask

parent bee4fac2
......@@ -51,7 +51,7 @@ typedef struct
typedef struct
{
IdeXmlTreeBuilder *self;
GTask *task;
IdeTask *task;
GPtrArray *schemas;
guint index;
} FetchSchemasState;
......@@ -154,7 +154,7 @@ fetch_schemas_cb (GObject *object,
g_assert (DZL_IS_TASK_CACHE (schemas_cache));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (state != NULL);
g_assert (G_IS_TASK (state->task));
g_assert (IDE_IS_TASK (state->task));
g_assert (IDE_IS_XML_TREE_BUILDER (state->self));
g_assert (state->schemas != NULL);
g_assert (state->index < state->schemas->len);
......@@ -189,13 +189,13 @@ fetch_schemas_cb (GObject *object,
entry->mtime = cache_entry->mtime;
}
count = g_task_get_task_data (state->task);
count = ide_task_get_task_data (state->task);
g_assert (count != NULL);
(*count)--;
if (*count == 0)
g_task_return_boolean (state->task, TRUE);
ide_task_return_boolean (state->task, TRUE);
}
static void
......@@ -205,7 +205,7 @@ fetch_schemas_async (IdeXmlTreeBuilder *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_autoptr(GPtrArray) schemas_copy = NULL;
IdeXmlService *service;
DzlTaskCache *schemas_cache;
......@@ -217,12 +217,12 @@ fetch_schemas_async (IdeXmlTreeBuilder *self,
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
/* TODO: use a worker thread */
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, fetch_schemas_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, fetch_schemas_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
count = g_new0 (guint, 1);
g_task_set_task_data (task, count, g_free);
ide_task_set_task_data (task, count, g_free);
/* Make a copy of schemas to ensure they cannot be changed
* during the lifetime of the operation, as the index within
......@@ -263,7 +263,7 @@ fetch_schemas_async (IdeXmlTreeBuilder *self,
}
if (*count == 0)
g_task_return_boolean (task, TRUE);
ide_task_return_boolean (task, TRUE);
}
static gboolean
......@@ -271,17 +271,17 @@ fetch_schemas_finish (IdeXmlTreeBuilder *self,
GAsyncResult *result,
GError **error)
{
GTask *task = (GTask *)result;
IdeTask *task = (IdeTask *)result;
g_return_val_if_fail (IDE_IS_XML_TREE_BUILDER (self), FALSE);
g_return_val_if_fail (G_IS_TASK (result), FALSE);
g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
g_return_val_if_fail (error != NULL, FALSE);
return g_task_propagate_boolean (task, error);
return ide_task_propagate_boolean (task, error);
}
static void
ide_xml_tree_builder_parse_worker (GTask *task,
ide_xml_tree_builder_parse_worker (IdeTask *task,
gpointer source_object,
gpointer task_data,
GCancellable *cancellable)
......@@ -296,14 +296,14 @@ ide_xml_tree_builder_parse_worker (GTask *task,
gint parser_flags;
g_assert (IDE_IS_XML_TREE_BUILDER (self));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
g_assert (state != NULL);
g_assert (cancellable == NULL || G_IS_CANCELLABLE (cancellable));
if (g_task_return_error_if_cancelled (task))
if (ide_task_return_error_if_cancelled (task))
return;
state = g_task_get_task_data (task);
state = ide_task_get_task_data (task);
g_assert (state != NULL);
g_assert (state->analysis != NULL);
......@@ -418,9 +418,9 @@ ide_xml_tree_builder_parse_worker (GTask *task,
g_debug ("can't create xmlDoc\n");
}
g_task_return_pointer (task,
g_steal_pointer (&state->analysis),
(GDestroyNotify)ide_xml_analysis_unref);
ide_task_return_pointer (task,
g_steal_pointer (&state->analysis),
(GDestroyNotify)ide_xml_analysis_unref);
}
static void
......@@ -430,16 +430,16 @@ ide_xml_tree_builder_build_tree_cb2 (GObject *object,
{
IdeXmlTreeBuilder *self = (IdeXmlTreeBuilder *)object;
g_autoptr(GError) error = NULL;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_assert (IDE_IS_XML_TREE_BUILDER (self));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
if (!fetch_schemas_finish (self, result, &error))
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
else
g_task_run_in_thread (task, ide_xml_tree_builder_parse_worker);
ide_task_run_in_thread (task, ide_xml_tree_builder_parse_worker);
}
static void
......@@ -448,7 +448,7 @@ ide_xml_tree_builder_build_tree_cb (GObject *object,
gpointer user_data)
{
g_autoptr(IdeXmlAnalysis) analysis = NULL;
g_autoptr(GTask) task = user_data;
g_autoptr(IdeTask) task = user_data;
g_autoptr(GError) error = NULL;
IdeXmlTreeBuilder *self;
TreeBuilderState *state;
......@@ -456,22 +456,22 @@ ide_xml_tree_builder_build_tree_cb (GObject *object,
g_assert (IDE_IS_XML_PARSER (object));
g_assert (G_IS_ASYNC_RESULT (result));
g_assert (G_IS_TASK (task));
g_assert (IDE_IS_TASK (task));
self = g_task_get_source_object (task);
self = ide_task_get_source_object (task);
g_assert (IDE_IS_XML_TREE_BUILDER (self));
state = g_task_get_task_data (task);
state = ide_task_get_task_data (task);
g_assert (state != NULL);
cancellable = g_task_get_cancellable (task);
cancellable = ide_task_get_cancellable (task);
g_assert (!cancellable || G_IS_CANCELLABLE (cancellable));
analysis = ide_xml_parser_get_analysis_finish (self->parser, result, &error);
if (analysis == NULL)
{
g_task_return_error (task, g_steal_pointer (&error));
ide_task_return_error (task, g_steal_pointer (&error));
return;
}
......@@ -480,9 +480,9 @@ ide_xml_tree_builder_build_tree_cb (GObject *object,
if (analysis->schemas == NULL)
{
g_task_return_pointer (task,
g_steal_pointer (&analysis),
(GDestroyNotify)ide_xml_analysis_unref);
ide_task_return_pointer (task,
g_steal_pointer (&analysis),
(GDestroyNotify)ide_xml_analysis_unref);
return;
}
......@@ -500,7 +500,7 @@ ide_xml_tree_builder_build_tree_async (IdeXmlTreeBuilder *self,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_autoptr(GTask) task = NULL;
g_autoptr(IdeTask) task = NULL;
g_autoptr(TreeBuilderState) state = NULL;
g_autoptr(GBytes) content = NULL;
gint64 sequence = 0;
......@@ -509,18 +509,18 @@ ide_xml_tree_builder_build_tree_async (IdeXmlTreeBuilder *self,
g_return_if_fail (G_IS_FILE (file));
g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
task = g_task_new (self, cancellable, callback, user_data);
g_task_set_source_tag (task, ide_xml_tree_builder_build_tree_async);
g_task_set_priority (task, G_PRIORITY_LOW);
task = ide_task_new (self, cancellable, callback, user_data);
ide_task_set_source_tag (task, ide_xml_tree_builder_build_tree_async);
ide_task_set_priority (task, G_PRIORITY_LOW);
content = ide_xml_tree_builder_get_file_content (self, file, &sequence);
if (content == NULL || g_bytes_get_size (content) == 0)
{
g_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
_("Failed to create the XML tree."));
ide_task_return_new_error (task,
G_IO_ERROR,
G_IO_ERROR_FAILED,
_("Failed to create the XML tree."));
return;
}
......@@ -529,9 +529,9 @@ ide_xml_tree_builder_build_tree_async (IdeXmlTreeBuilder *self,
state->content = g_bytes_ref (content);
state->sequence = sequence;
g_task_set_task_data (task,
g_steal_pointer (&state),
(GDestroyNotify)tree_builder_state_free);
ide_task_set_task_data (task,
g_steal_pointer (&state),
(GDestroyNotify)tree_builder_state_free);
ide_xml_parser_get_analysis_async (self->parser,
file,
......@@ -550,7 +550,7 @@ ide_xml_tree_builder_build_tree_finish (IdeXmlTreeBuilder *self,
g_return_val_if_fail (IDE_IS_XML_TREE_BUILDER (self), NULL);
g_return_val_if_fail (G_IS_ASYNC_RESULT (result), NULL);
return g_task_propagate_pointer (G_TASK (result), error);
return ide_task_propagate_pointer (IDE_TASK (result), error);
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment