diff options
author | Cyrille Bagard <nocbos@gmail.com> | 2018-06-06 16:59:19 (GMT) |
---|---|---|
committer | Cyrille Bagard <nocbos@gmail.com> | 2018-06-06 16:59:19 (GMT) |
commit | 74063a8f0e00e1b53b45ddcbd47348d9acce3f67 (patch) | |
tree | 3a576ad4f3a82d795ebc84562df522407bc135ef | |
parent | 3b2c60d63cf14ab1350125a4cba9dce1cefeb58e (diff) |
Simplified the whole loading process.
-rw-r--r-- | src/analysis/loading.c | 71 | ||||
-rw-r--r-- | src/analysis/loading.h | 4 | ||||
-rw-r--r-- | src/analysis/project.c | 38 |
3 files changed, 56 insertions, 57 deletions
diff --git a/src/analysis/loading.c b/src/analysis/loading.c index 5e0f651..fa2118f 100644 --- a/src/analysis/loading.c +++ b/src/analysis/loading.c @@ -52,7 +52,10 @@ typedef struct _GExploringWork { GDelayedWork parent; /* A laisser en premier */ - const wgroup_id_t *wid; /* Groupe d'appartenance */ + wgroup_id_t wid; /* Groupe d'appartenance */ +#ifndef NDEBUG + bool wid_defined; /* Validation de l'identifiant */ +#endif GBinContent *content; /* Contenu brut à disposition */ @@ -88,7 +91,7 @@ static GExploringWork *g_exploring_work_new(GBinContent *); static wgroup_id_t g_exploring_work_get_group_id(const GExploringWork *); /* Définit l'identifiant du groupe de rattachement de la tâche. */ -static void g_exploring_work_set_group_id(GExploringWork *, const wgroup_id_t *); +static void g_exploring_work_set_group_id(GExploringWork *, wgroup_id_t); /* Réalise l'exploration effective de formes de contenus. */ static void g_exploring_work_process(GExploringWork *, GtkStatusStack *); @@ -169,7 +172,10 @@ typedef struct _GResolvingWork { GDelayedWork parent; /* A laisser en premier */ - const wgroup_id_t *wid; /* Groupe d'appartenance */ + wgroup_id_t wid; /* Groupe d'appartenance */ +#ifndef NDEBUG + bool wid_defined; /* Validation de l'identifiant */ +#endif GBinContent *content; /* Contenu brut à disposition */ @@ -205,7 +211,7 @@ static GResolvingWork *g_resolving_work_new(GBinContent *); static wgroup_id_t g_resolving_work_get_group_id(const GResolvingWork *); /* Définit l'identifiant du groupe de rattachement de la tâche. */ -static void g_resolving_work_set_group_id(GResolvingWork *, const wgroup_id_t *); +static void g_resolving_work_set_group_id(GResolvingWork *, wgroup_id_t); /* Réalise la conversion effective de formes de contenus. */ static void g_resolving_work_process(GResolvingWork *, GtkStatusStack *); @@ -220,7 +226,7 @@ typedef struct _resolving_group { size_t remaining; /* Nombre de tâches restantes */ - const wgroup_id_t *wid; /* Groupe d'appartenance */ + wgroup_id_t wid; /* Groupe d'appartenance */ GLoadedContent **loaded; /* Contenus reconnus à intégrer*/ size_t count; /* Taille de cette liste */ @@ -322,7 +328,9 @@ static void g_exploring_work_class_init(GExploringWorkClass *klass) static void g_exploring_work_init(GExploringWork *work) { - work->wid = NULL; +#ifndef NDEBUG + work->wid_defined = false; +#endif work->content = NULL; @@ -411,9 +419,9 @@ static wgroup_id_t g_exploring_work_get_group_id(const GExploringWork *work) { wgroup_id_t result; /* Identifiant à retourner */ - assert(work->wid != NULL); + assert(work->wid_defined); - result = *work->wid; + result = work->wid; return result; @@ -433,8 +441,12 @@ static wgroup_id_t g_exploring_work_get_group_id(const GExploringWork *work) * * ******************************************************************************/ -static void g_exploring_work_set_group_id(GExploringWork *work, const wgroup_id_t *wid) +static void g_exploring_work_set_group_id(GExploringWork *work, wgroup_id_t wid) { +#ifndef NDEBUG + work->wid_defined = true; +#endif + work->wid = wid; } @@ -680,11 +692,10 @@ static void g_content_explorer_ack(GContentExplorer *explorer, GExploringWork *w * * ******************************************************************************/ -const wgroup_id_t *g_content_explorer_create_group(GContentExplorer *explorer, GBinContent *content) +wgroup_id_t g_content_explorer_create_group(GContentExplorer *explorer, GBinContent *content) { - const wgroup_id_t *result; /* Identifiant à retourner */ + wgroup_id_t result; /* Identifiant à retourner */ GWorkQueue *queue; /* Gestionnaire de différés */ - wgroup_id_t new; /* Nouvel identifiant */ exploring_group *group; /* Groupe ciblé par l'opération*/ GExploringWork *work; /* Nouvelle vague d'exploration*/ @@ -694,10 +705,10 @@ const wgroup_id_t *g_content_explorer_create_group(GContentExplorer *explorer, G queue = get_work_queue(); - new = g_work_queue_define_work_group(queue); + result = g_work_queue_define_work_group(queue); #ifndef NDEBUG - group = g_content_explorer_find_group(explorer, new); + group = g_content_explorer_find_group(explorer, result); assert(group == NULL); #endif @@ -710,9 +721,7 @@ const wgroup_id_t *g_content_explorer_create_group(GContentExplorer *explorer, G group->original = content; g_object_ref(G_OBJECT(content)); - group->wid = new; - - result = &group->wid; + group->wid = result; group->contents = NULL; group->count = 0; @@ -720,11 +729,11 @@ const wgroup_id_t *g_content_explorer_create_group(GContentExplorer *explorer, G /* Alimentation du contenu initial */ work = g_exploring_work_new(content); - g_exploring_work_set_group_id(work, &group->wid); + g_exploring_work_set_group_id(work, result); g_signal_connect_swapped(work, "work-completed", G_CALLBACK(g_content_explorer_ack), explorer); - g_work_queue_schedule_work(queue, G_DELAYED_WORK(work), group->wid); + g_work_queue_schedule_work(queue, G_DELAYED_WORK(work), result); g_mutex_unlock(&explorer->mutex); @@ -818,7 +827,7 @@ void g_content_explorer_populate_group(GContentExplorer *explorer, wgroup_id_t w /* Relancement des explorations */ work = g_exploring_work_new(content); - g_exploring_work_set_group_id(work, &group->wid); + g_exploring_work_set_group_id(work, group->wid); g_signal_connect_swapped(work, "work-completed", G_CALLBACK(g_content_explorer_ack), explorer); @@ -937,7 +946,9 @@ static void g_resolving_work_class_init(GResolvingWorkClass *klass) static void g_resolving_work_init(GResolvingWork *work) { - work->wid = NULL; +#ifndef NDEBUG + work->wid_defined = false; +#endif work->content = NULL; @@ -1026,9 +1037,9 @@ static wgroup_id_t g_resolving_work_get_group_id(const GResolvingWork *work) { wgroup_id_t result; /* Identifiant à retourner */ - assert(work->wid != NULL); + assert(work->wid_defined); - result = *work->wid; + result = work->wid; return result; @@ -1048,8 +1059,12 @@ static wgroup_id_t g_resolving_work_get_group_id(const GResolvingWork *work) * * ******************************************************************************/ -static void g_resolving_work_set_group_id(GResolvingWork *work, const wgroup_id_t *wid) +static void g_resolving_work_set_group_id(GResolvingWork *work, wgroup_id_t wid) { +#ifndef NDEBUG + work->wid_defined = true; +#endif + work->wid = wid; } @@ -1154,7 +1169,7 @@ static void g_content_resolver_init(GContentResolver *resolver) static void g_content_resolver_dispose(GContentResolver *resolver) { while (resolver->count > 0) - g_content_resolver_delete_group(resolver, *resolver->groups[0].wid); + g_content_resolver_delete_group(resolver, resolver->groups[0].wid); if (resolver->groups != NULL) free(resolver->groups); @@ -1231,7 +1246,7 @@ static resolving_group *g_content_resolver_find_group(GContentResolver *resolver result = NULL; for (i = 0; i < resolver->count && result == NULL; i++) - if (*resolver->groups[i].wid == wid) + if (resolver->groups[i].wid == wid) result = &resolver->groups[i]; return result; @@ -1292,7 +1307,7 @@ static void g_content_resolver_ack(GContentResolver *resolver, GResolvingWork *w * * ******************************************************************************/ -void g_content_resolver_create_group(GContentResolver *resolver, const wgroup_id_t *wid, GBinContent **contents, size_t count) +void g_content_resolver_create_group(GContentResolver *resolver, wgroup_id_t wid, GBinContent **contents, size_t count) { resolving_group *group; /* Groupe ciblé par l'opération*/ GWorkQueue *queue; /* Gestionnaire de différés */ @@ -1325,7 +1340,7 @@ void g_content_resolver_create_group(GContentResolver *resolver, const wgroup_id g_signal_connect_swapped(work, "work-completed", G_CALLBACK(g_content_resolver_ack), resolver); - g_work_queue_schedule_work(queue, G_DELAYED_WORK(work), *wid); + g_work_queue_schedule_work(queue, G_DELAYED_WORK(work), wid); } diff --git a/src/analysis/loading.h b/src/analysis/loading.h index 19cd12d..c7ede58 100644 --- a/src/analysis/loading.h +++ b/src/analysis/loading.h @@ -59,7 +59,7 @@ GType g_content_explorer_get_type(void); GContentExplorer *g_content_explorer_new(void); /* Initie une nouvelle vague d'exploration de contenu. */ -const wgroup_id_t *g_content_explorer_create_group(GContentExplorer *, GBinContent *); +wgroup_id_t g_content_explorer_create_group(GContentExplorer *, GBinContent *); /* Termine une vague d'exploration de contenu. */ void g_content_explorer_delete_group(GContentExplorer *, wgroup_id_t); @@ -97,7 +97,7 @@ GType g_content_resolver_get_type(void); GContentResolver *g_content_resolver_new(void); /* Initie une nouvelle vague de résolution de contenus. */ -void g_content_resolver_create_group(GContentResolver *, const wgroup_id_t *, GBinContent **, size_t); +void g_content_resolver_create_group(GContentResolver *, wgroup_id_t, GBinContent **, size_t); /* Termine une vague de résolution de contenu. */ void g_content_resolver_delete_group(GContentResolver *, wgroup_id_t); diff --git a/src/analysis/project.c b/src/analysis/project.c index 13887ee..83b41c4 100644 --- a/src/analysis/project.c +++ b/src/analysis/project.c @@ -118,7 +118,7 @@ typedef struct _GLoadingHandler xmlDoc *xdoc; /* Structure XML chargée ? */ xmlXPathContext *context; /* Eventuel contexte XML */ - const wgroup_id_t **exp_wids; /* Identifiants d'exploration */ + wgroup_id_t *exp_wids; /* Identifiants d'exploration */ size_t exp_count; /* Quantitié d'identifiants */ size_t resolved; /* Compteur de résolutions */ GCond wait_cond; /* Réveil d'attente de fin */ @@ -159,7 +159,7 @@ static GLoadingHandler *g_loading_handler_new_recovering(GStudyProject *, xmlDoc static void g_loading_handler_process(GLoadingHandler *, GtkStatusStack *); /* Détermine si un encadrement est adapté pour un identifiant. */ -static bool g_loading_handler_check(GLoadingHandler *, wgroup_id_t, const wgroup_id_t **); +static bool g_loading_handler_check(GLoadingHandler *, wgroup_id_t); /* Note la fin d'une phase d'exploration de contenu. */ static void on_new_content_explored(GContentExplorer *, wgroup_id_t, GLoadingHandler *); @@ -865,8 +865,8 @@ static void g_loading_handler_dispose(GLoadingHandler *handler) for (i = 0; i < handler->exp_count; i++) { - g_content_resolver_delete_group(resolver, *handler->exp_wids[i]); - g_content_explorer_delete_group(explorer, *handler->exp_wids[i]); + g_content_resolver_delete_group(resolver, handler->exp_wids[i]); + g_content_explorer_delete_group(explorer, handler->exp_wids[i]); } g_mutex_unlock(&handler->mutex); @@ -938,7 +938,7 @@ static GLoadingHandler *g_loading_handler_new_discovering(GStudyProject *project result->xdoc = NULL; result->context = NULL; - result->exp_wids = (const wgroup_id_t **)malloc(sizeof(wgroup_id_t *)); + result->exp_wids = (wgroup_id_t *)malloc(sizeof(wgroup_id_t)); result->exp_count = 1; result->resolved = 0; @@ -997,7 +997,7 @@ static GLoadingHandler *g_loading_handler_new_recovering(GStudyProject *project, result->xdoc = xdoc; result->context = context; - result->exp_wids = (const wgroup_id_t **)malloc(count * sizeof(wgroup_id_t *)); + result->exp_wids = (wgroup_id_t *)malloc(count * sizeof(wgroup_id_t)); result->resolved = 0; @@ -1075,7 +1075,6 @@ static void g_loading_handler_process(GLoadingHandler *handler, GtkStatusStack * * * * Paramètres : handler = gestionnaire dont contenu est à consulter. * * wid = identifiant du groupe d'exploration recherché. * -* ptr = pointeur vers la valeur d'origine externe. * * * * Description : Détermine si un encadrement est adapté pour un identifiant. * * * @@ -1085,31 +1084,17 @@ static void g_loading_handler_process(GLoadingHandler *handler, GtkStatusStack * * * ******************************************************************************/ -static bool g_loading_handler_check(GLoadingHandler *handler, wgroup_id_t wid, const wgroup_id_t **ptr) +static bool g_loading_handler_check(GLoadingHandler *handler, wgroup_id_t wid) { bool result; /* Bilan à retourner */ - const wgroup_id_t *value; /* Raccourci de confort */ size_t i; /* Boucle de parcours */ assert(!g_mutex_trylock(&handler->mutex)); result = false; - value = NULL; - for (i = 0; i < handler->exp_count && !result; i++) - { - value = handler->exp_wids[i]; - - result = (*value == wid); - - } - - if (ptr != NULL) - { - assert(!result || value != NULL); - *ptr = (result ? value : NULL); - } + result = (handler->exp_wids[i] == wid); return result; @@ -1132,7 +1117,6 @@ static bool g_loading_handler_check(GLoadingHandler *handler, wgroup_id_t wid, c static void on_new_content_explored(GContentExplorer *explorer, wgroup_id_t wid, GLoadingHandler *handler) { - const wgroup_id_t *wid_ptr; /* Référence vers l'origine */ GBinContent **available; /* Contenus binaires présents */ size_t count; /* Quantité de ces contenus */ GContentResolver *resolver; /* Resolveur de contenus */ @@ -1140,14 +1124,14 @@ static void on_new_content_explored(GContentExplorer *explorer, wgroup_id_t wid, g_mutex_lock(&handler->mutex); - if (g_loading_handler_check(handler, wid, &wid_ptr)) + if (g_loading_handler_check(handler, wid)) { available = g_content_explorer_get_all(explorer, wid, &count); assert(count > 0); resolver = get_current_content_resolver(); - g_content_resolver_create_group(resolver, wid_ptr, available, count); + g_content_resolver_create_group(resolver, wid, available, count); g_object_unref(G_OBJECT(resolver)); @@ -1191,7 +1175,7 @@ static void on_new_content_resolved(GContentResolver *resolver, wgroup_id_t wid, g_mutex_lock(&handler->mutex); - if (g_loading_handler_check(handler, wid, NULL)) + if (g_loading_handler_check(handler, wid)) { available = g_content_resolver_get_all(resolver, wid, &count); |