summaryrefslogtreecommitdiff
path: root/src/glibext
diff options
context:
space:
mode:
Diffstat (limited to 'src/glibext')
-rw-r--r--src/glibext/delayed-int.h4
-rw-r--r--src/glibext/delayed.c96
-rw-r--r--src/glibext/delayed.h3
3 files changed, 103 insertions, 0 deletions
diff --git a/src/glibext/delayed-int.h b/src/glibext/delayed-int.h
index b2e2b23..2aabf0b 100644
--- a/src/glibext/delayed-int.h
+++ b/src/glibext/delayed-int.h
@@ -45,6 +45,10 @@ struct _GDelayedWork
run_task_fc run; /* Traitement externalisé */
+ bool completed; /* Fin de la tâche ? */
+ GMutex *mutex; /* Accès à la variable */
+ GCond *cond; /* Attente de changement */
+
};
/* Travail différé (classe) */
diff --git a/src/glibext/delayed.c b/src/glibext/delayed.c
index 8f23538..92e167a 100644
--- a/src/glibext/delayed.c
+++ b/src/glibext/delayed.c
@@ -40,6 +40,12 @@ static void g_delayed_work_class_init(GDelayedWorkClass *);
/* Initialise une instance de travail différé. */
static void g_delayed_work_init(GDelayedWork *);
+/* Supprime toutes les références externes. */
+static void g_delayed_work_dispose(GDelayedWork *);
+
+/* Procède à la libération totale de la mémoire. */
+static void g_delayed_work_finalize(GDelayedWork *);
+
/* Mène l'opération programmée. */
static void g_delayed_work_process(GDelayedWork *, GtkExtStatusBar *);
@@ -155,6 +161,13 @@ G_DEFINE_TYPE(GDelayedWork, g_delayed_work, G_TYPE_OBJECT);
static void g_delayed_work_class_init(GDelayedWorkClass *klass)
{
+ GObjectClass *object; /* Autre version de la classe */
+
+ object = G_OBJECT_CLASS(klass);
+
+ object->dispose = (GObjectFinalizeFunc/* ! */)g_delayed_work_dispose;
+ object->finalize = (GObjectFinalizeFunc)g_delayed_work_finalize;
+
g_signal_new("work-completed",
G_TYPE_DELAYED_WORK,
G_SIGNAL_RUN_LAST,
@@ -180,6 +193,58 @@ static void g_delayed_work_class_init(GDelayedWorkClass *klass)
static void g_delayed_work_init(GDelayedWork *work)
{
+ work->completed = false;
+ work->mutex = g_mutex_new();
+ work->cond = g_cond_new();
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : work = instance d'objet GLib à traiter. *
+* *
+* Description : Supprime toutes les références externes. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_delayed_work_dispose(GDelayedWork *work)
+{
+ gpointer obj_class; /* Classe parente */
+
+ g_mutex_free(work->mutex);
+ g_cond_free(work->cond);
+
+ obj_class = g_type_class_peek_parent(G_DELAYED_WORK_GET_CLASS(work));
+
+ //G_OBJECT_CLASS(obj_class)->dispose(G_OBJECT(work));
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : work = instance d'objet GLib à traiter. *
+* *
+* Description : Procède à la libération totale de la mémoire. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+static void g_delayed_work_finalize(GDelayedWork *work)
+{
+ gpointer obj_class; /* Classe parente */
+
+ obj_class = g_type_class_peek_parent(G_DELAYED_WORK_GET_CLASS(work));
+
+ //G_OBJECT_CLASS(obj_class)->finalize(G_OBJECT(work));
}
@@ -203,6 +268,37 @@ static void g_delayed_work_process(GDelayedWork *work, GtkExtStatusBar *statusba
g_signal_emit_by_name(work, "work-completed");
+ g_mutex_lock(work->mutex);
+
+ work->completed = true;
+
+ g_cond_signal(work->cond);
+ g_mutex_unlock(work->mutex);
+
+}
+
+
+/******************************************************************************
+* *
+* Paramètres : work = travail à surveiller. *
+* *
+* Description : Attend la fin de l'exécution d'une tâche donnée. *
+* *
+* Retour : - *
+* *
+* Remarques : - *
+* *
+******************************************************************************/
+
+void g_delayed_work_wait_for_completion(GDelayedWork *work)
+{
+ g_mutex_lock(work->mutex);
+
+ while (!work->completed)
+ g_cond_wait(work->cond, work->mutex);
+
+ g_mutex_unlock(work->mutex);
+
}
diff --git a/src/glibext/delayed.h b/src/glibext/delayed.h
index 501bb7f..d2649e1 100644
--- a/src/glibext/delayed.h
+++ b/src/glibext/delayed.h
@@ -51,6 +51,9 @@ typedef struct _GDelayedWorkClass GDelayedWorkClass;
/* Indique le type défini pour les travaux différés. */
GType g_delayed_work_get_type(void);
+/* Attend la fin de l'exécution d'une tâche donnée. */
+void g_delayed_work_wait_for_completion(GDelayedWork *);
+
/* ------------------------- TRAITEMENT DE TACHES DIFFEREES ------------------------- */