[gnumeric] solver: rearrange timeout reason handling.
- From: Morten Welinder <mortenw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] solver: rearrange timeout reason handling.
- Date: Wed, 28 Dec 2011 22:05:13 +0000 (UTC)
commit 111a16b5d41e5cdd524d28d58ce26240c63907d3
Author: Morten Welinder <terra gnome org>
Date: Wed Dec 28 17:04:46 2011 -0500
solver: rearrange timeout reason handling.
NEWS | 1 +
src/dialogs/ChangeLog | 2 ++
src/dialogs/dialog-solver.c | 27 +++++++++++++++------------
src/tools/ChangeLog | 3 +++
src/tools/gnm-solver.c | 41 +++++++++++++++++++++++++++++++++++++----
src/tools/gnm-solver.h | 6 +++++-
6 files changed, 63 insertions(+), 17 deletions(-)
---
diff --git a/NEWS b/NEWS
index b90eb87..bd68cf8 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,7 @@ Andreas:
Morten:
* Improve parsing on numbers with non-ascii digits.
* Make solver check for exceeding the time limit.
+ * Fix object life-cycle problems in solver.
--------------------------------------------------------------------------
Gnumeric 1.11.1
diff --git a/src/dialogs/ChangeLog b/src/dialogs/ChangeLog
index fbb4afb..a161588 100644
--- a/src/dialogs/ChangeLog
+++ b/src/dialogs/ChangeLog
@@ -1,6 +1,8 @@
2011-12-28 Morten Welinder <terra gnome org>
* dialog-solver.c (cb_timer_tick): Check for timeout.
+ (run_solver): Store the right signal ids in the right variables.
+ Just because we can. Hook up a reason notifier too.
2011-12-27 Jean Brefort <jean brefort normalesup org>
diff --git a/src/dialogs/dialog-solver.c b/src/dialogs/dialog-solver.c
index 33f0100..090d8e6 100644
--- a/src/dialogs/dialog-solver.c
+++ b/src/dialogs/dialog-solver.c
@@ -87,8 +87,9 @@ typedef struct {
GtkWidget *objective_value_widget;
GtkWidget *stop_button;
GtkWidget *ok_button;
- char *reason; /* for cancel or error */
- gulong sig_notify_result, sig_notify_status;
+ gulong sig_notify_result;
+ gulong sig_notify_status;
+ gulong sig_notify_reason;
} run;
Sheet *sheet;
@@ -361,7 +362,6 @@ free_state (SolverState *state)
{
if (state->orig_params)
g_object_unref (state->orig_params);
- g_free (state->run.reason);
g_free (state);
}
@@ -541,9 +541,9 @@ cb_notify_status (SolverState *state)
break;
}
- if (state->run.reason) {
+ if (sol->reason) {
char *text2 = g_strconcat (text,
- " (", state->run.reason, ")",
+ " (", sol->reason, ")",
NULL);
gtk_label_set_text (GTK_LABEL (state->run.status_widget),
text2);
@@ -623,9 +623,7 @@ cb_timer_tick (SolverState *state)
gtk_label_set_text (GTK_LABEL (state->run.timer_widget), txt);
g_free (txt);
- if (gnm_solver_check_timeout (sol, TRUE)) {
- g_free (state->run.reason);
- state->run.reason = g_strdup (_("Timeout"));
+ if (gnm_solver_check_timeout (sol)) {
cb_notify_status (state);
}
@@ -660,8 +658,6 @@ run_solver (SolverState *state, GnmSolverParameters *param)
}
state->run.solver = sol;
- g_free (state->run.reason);
- state->run.reason = NULL;
vinput = gnm_solver_param_get_input (param);
gnm_sheet_range_from_value (&sr, vinput);
@@ -731,14 +727,19 @@ run_solver (SolverState *state, GnmSolverParameters *param)
table, TRUE, TRUE, 0);
gtk_widget_show_all (GTK_WIDGET (dialog));
- state->run.sig_notify_result =
+ state->run.sig_notify_status =
g_signal_connect_swapped (G_OBJECT (sol),
"notify::status",
G_CALLBACK (cb_notify_status),
state);
+ state->run.sig_notify_reason =
+ g_signal_connect_swapped (G_OBJECT (sol),
+ "notify::reason",
+ G_CALLBACK (cb_notify_status),
+ state);
cb_notify_status (state);
- state->run.sig_notify_status =
+ state->run.sig_notify_result =
g_signal_connect_swapped (G_OBJECT (sol),
"notify::result",
G_CALLBACK (cb_notify_result),
@@ -772,6 +773,8 @@ run_solver (SolverState *state, GnmSolverParameters *param)
state->run.sig_notify_result);
g_signal_handler_disconnect (G_OBJECT (sol),
state->run.sig_notify_status);
+ g_signal_handler_disconnect (G_OBJECT (sol),
+ state->run.sig_notify_reason);
if (sol->status == GNM_SOLVER_STATUS_RUNNING)
gnm_solver_stop (sol, NULL);
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index fb4aedd..c299cba 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,6 +1,9 @@
2011-12-28 Morten Welinder <terra gnome org>
* gnm-solver.c (gnm_solver_check_timeout): New function.
+ (gnm_solver_param_class_init): Hook gnm_solver_param_finalize up
+ as a finalizer, not a dispose handler!
+ (gnm_solver_set_reason): New function, backed by a property.
2011-11-27 Morten Welinder <terra gnome org>
diff --git a/src/tools/gnm-solver.c b/src/tools/gnm-solver.c
index 50db8c9..ef6f737 100644
--- a/src/tools/gnm-solver.c
+++ b/src/tools/gnm-solver.c
@@ -705,7 +705,7 @@ gnm_solver_param_class_init (GObjectClass *object_class)
gnm_solver_param_parent_class = g_type_class_peek_parent (object_class);
object_class->constructor = gnm_solver_param_constructor;
- object_class->dispose = gnm_solver_param_finalize;
+ object_class->finalize = gnm_solver_param_finalize;
object_class->set_property = gnm_solver_param_set_property;
object_class->get_property = gnm_solver_param_get_property;
@@ -744,6 +744,7 @@ static guint solver_signals[SOL_SIG_LAST] = { 0 };
enum {
SOL_PROP_0,
SOL_PROP_STATUS,
+ SOL_PROP_REASON,
SOL_PROP_PARAMS,
SOL_PROP_RESULT,
SOL_PROP_STARTTIME,
@@ -764,6 +765,8 @@ gnm_solver_dispose (GObject *obj)
}
}
+ gnm_solver_set_reason (sol, NULL);
+
if (sol->result) {
g_object_unref (sol->result);
sol->result = NULL;
@@ -788,6 +791,10 @@ gnm_solver_get_property (GObject *object, guint property_id,
g_value_set_enum (value, sol->status);
break;
+ case SOL_PROP_REASON:
+ g_value_set_string (value, sol->reason);
+ break;
+
case SOL_PROP_PARAMS:
g_value_set_object (value, sol->params);
break;
@@ -821,6 +828,10 @@ gnm_solver_set_property (GObject *object, guint property_id,
gnm_solver_set_status (sol, g_value_get_enum (value));
break;
+ case SOL_PROP_REASON:
+ gnm_solver_set_reason (sol, g_value_get_string (value));
+ break;
+
case SOL_PROP_PARAMS:
if (sol->params) g_object_unref (sol->params);
sol->params = g_value_dup_object (value);
@@ -916,7 +927,7 @@ gnm_solver_elapsed (GnmSolver *solver)
}
gboolean
-gnm_solver_check_timeout (GnmSolver *solver, gboolean act)
+gnm_solver_check_timeout (GnmSolver *solver)
{
GnmSolverParameters *sp;
@@ -930,8 +941,8 @@ gnm_solver_check_timeout (GnmSolver *solver, gboolean act)
if (gnm_solver_elapsed (solver) <= sp->options.max_time_sec)
return FALSE;
- if (act)
- gnm_solver_stop (solver, NULL);
+ gnm_solver_stop (solver, NULL);
+ gnm_solver_set_reason (solver, _("Timeout"));
return TRUE;
}
@@ -1003,6 +1014,8 @@ gnm_solver_set_status (GnmSolver *solver, GnmSolverStatus status)
if (status == solver->status)
return;
+ gnm_solver_set_reason (solver, NULL);
+
old_status = solver->status;
solver->status = status;
g_object_notify (G_OBJECT (solver), "status");
@@ -1018,6 +1031,19 @@ gnm_solver_set_status (GnmSolver *solver, GnmSolverStatus status)
NULL);
}
+void
+gnm_solver_set_reason (GnmSolver *solver, const char *reason)
+{
+ g_return_if_fail (GNM_IS_SOLVER (solver));
+
+ if (g_strcmp0 (reason, solver->reason) == 0)
+ return;
+
+ g_free (solver->reason);
+ solver->reason = g_strdup (reason);
+}
+
+
gboolean
gnm_solver_has_solution (GnmSolver *solver)
{
@@ -1217,6 +1243,13 @@ gnm_solver_class_init (GObjectClass *object_class)
GSF_PARAM_STATIC |
G_PARAM_READWRITE));
+ g_object_class_install_property (object_class, SOL_PROP_REASON,
+ g_param_spec_string ("reason", _("reason"),
+ _("The reason behind the solver's status"),
+ NULL,
+ GSF_PARAM_STATIC |
+ G_PARAM_READWRITE));
+
g_object_class_install_property (object_class, SOL_PROP_PARAMS,
g_param_spec_object ("params", _("Parameters"),
_("Solver parameters"),
diff --git a/src/tools/gnm-solver.h b/src/tools/gnm-solver.h
index 7cbd752..162ec16 100644
--- a/src/tools/gnm-solver.h
+++ b/src/tools/gnm-solver.h
@@ -196,6 +196,8 @@ typedef struct {
GObject parent;
GnmSolverStatus status;
+ char *reason;
+
GnmSolverParameters *params;
GnmSolverResult *result;
double starttime, endtime;
@@ -222,11 +224,13 @@ gboolean gnm_solver_stop (GnmSolver *solver, GError **err);
void gnm_solver_set_status (GnmSolver *solver, GnmSolverStatus status);
+void gnm_solver_set_reason (GnmSolver *solver, const char *reason);
+
void gnm_solver_store_result (GnmSolver *solver);
double gnm_solver_elapsed (GnmSolver *solver);
-gboolean gnm_solver_check_timeout (GnmSolver *solver, gboolean act);
+gboolean gnm_solver_check_timeout (GnmSolver *solver);
gboolean gnm_solver_finished (GnmSolver *solver);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]