X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=goptions.c;h=08b17ac931ae2395ecc38c00a070fd9701505cdd;hp=b7239a5a36a27d69310d131317ac4e77d720a68e;hb=cf7cadec891c9e4226f2d93c2014c87a94ebd730;hpb=456fed9b8af36c537632c3351802e6b3aa415962 diff --git a/goptions.c b/goptions.c index b7239a5a..08b17ac9 100644 --- a/goptions.c +++ b/goptions.c @@ -9,6 +9,7 @@ #include "fio.h" #include "gfio.h" #include "ghelpers.h" +#include "gerror.h" #include "parse.h" struct gopt { @@ -27,7 +28,7 @@ struct gopt_combo { struct gopt_int { struct gopt gopt; - unsigned int lastval; + unsigned long long lastval; GtkWidget *spin; }; @@ -77,12 +78,15 @@ struct gopt_frame_widget { }; struct gopt_job_view { - struct flist_head list; struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR]; - GtkWidget *widgets[FIO_MAX_OPTS]; GtkWidget *vboxes[__FIO_OPT_C_NR]; + struct gopt *gopts[FIO_MAX_OPTS]; + GtkWidget *dialog; + GtkWidget *job_combo; + struct gfio_client *client; struct flist_head changed_list; struct thread_options *o; + int in_job_switch; }; static GNode *gopt_dep_tree; @@ -138,6 +142,7 @@ static void gopt_set_children_visible(struct gopt_job_view *gjv, while (child) { struct fio_option *o = child->data; struct gopt *g = o->gui_data; + GtkWidget *widget = g->box; /* * Recurse into child, if it also has children @@ -145,9 +150,7 @@ static void gopt_set_children_visible(struct gopt_job_view *gjv, if (g_node_n_children(child)) gopt_set_children_visible(gjv, o, visible); - if (gjv->widgets[g->opt_index]) - gtk_widget_set_sensitive(gjv->widgets[g->opt_index], visible); - + gtk_widget_set_sensitive(widget, visible); child = g_node_next_sibling(child); } } @@ -156,25 +159,46 @@ static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt, unsigned int idx, int type) { INIT_FLIST_HEAD(&gopt->changed_list); - g_object_ref(G_OBJECT(gopt->box)); - assert(!gjv->widgets[idx]); + assert(!gjv->gopts[idx]); gopt->opt_index = idx; gopt->opt_type = type; gopt->gjv = gjv; - gjv->widgets[idx] = gopt->box; + gjv->gopts[idx] = gopt; +} + +static void gopt_dialog_update_apply_button(struct gopt_job_view *gjv) +{ + GtkDialog *dialog = GTK_DIALOG(gjv->dialog); + gboolean set; + + set = !flist_empty(&gjv->changed_list); + gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_APPLY, set); + + if (set) { + gtk_widget_set_sensitive(gjv->job_combo, 0); + gtk_widget_set_tooltip_text(gjv->job_combo, "Apply option changes before switching to a new job"); + } else { + gtk_widget_set_sensitive(gjv->job_combo, 1); + gtk_widget_set_tooltip_text(gjv->job_combo, "Change current job"); + } } static void gopt_changed(struct gopt *gopt) { struct gopt_job_view *gjv = gopt->gjv; + if (gjv->in_job_switch) + return; + /* * Add to changed list. This also prevents the option from being * freed when the widget is destroyed. */ - if (flist_empty(&gopt->changed_list)) + if (flist_empty(&gopt->changed_list)) { flist_add_tail(&gopt->changed_list, &gjv->changed_list); + gopt_dialog_update_apply_button(gjv); + } } static void gopt_str_changed(GtkEntry *entry, gpointer data) @@ -196,12 +220,16 @@ static void gopt_str_destroy(GtkWidget *w, gpointer data) { struct gopt_str *s = (struct gopt_str *) data; - if (flist_empty(&s->gopt.changed_list)) - free(s); - + free(s); gtk_widget_destroy(w); } +static void gopt_str_store_set_val(struct gopt_str *s, const char *text) +{ + if (text) + gtk_entry_set_text(GTK_ENTRY(s->entry), text); +} + static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv, struct fio_option *o, const char *text, unsigned int idx) @@ -219,12 +247,12 @@ static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv, s->entry = gtk_entry_new(); gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR); - if (text) - gtk_entry_set_text(GTK_ENTRY(s->entry), text); - gtk_entry_set_editable(GTK_ENTRY(s->entry), 1); + gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1); - if (o->def) - gtk_entry_set_text(GTK_ENTRY(s->entry), o->def); + if (text) + gopt_str_store_set_val(s, text); + else if (o->def) + gopt_str_store_set_val(s, o->def); s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s); g_signal_connect(G_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s); @@ -251,9 +279,7 @@ static void gopt_combo_destroy(GtkWidget *w, gpointer data) { struct gopt_combo *c = (struct gopt_combo *) data; - if (flist_empty(&c->gopt.changed_list)) - free(c); - + free(c); gtk_widget_destroy(w); } @@ -272,7 +298,7 @@ static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv, else label = gtk_label_new(o->lname); - c->combo = gtk_combo_box_new_text(); + c->combo = gtk_combo_box_text_new(); gopt_mark_index(gjv, &c->gopt, idx, type); g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c); @@ -282,6 +308,24 @@ static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv, return c; } +static void gopt_combo_str_set_val(struct gopt_combo *c, const char *text) +{ + struct fio_option *o = &fio_options[c->gopt.opt_index]; + struct value_pair *vp; + int i; + + i = 0; + vp = &o->posval[0]; + while (vp->ival) { + if (!strcmp(vp->ival, text)) { + gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i); + break; + } + vp++; + i++; + } +} + static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv, struct fio_option *o, const char *text, unsigned int idx) @@ -295,20 +339,38 @@ static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv, i = 0; vp = &o->posval[0]; while (vp->ival) { - gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); if (o->def && !strcmp(vp->ival, o->def)) active = i; - if (text && !strcmp(vp->ival, text)) - active = i; vp++; i++; } gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); + if (text) + gopt_combo_str_set_val(c, text); c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); return &c->gopt; } +static void gopt_combo_int_set_val(struct gopt_combo *c, unsigned int ip) +{ + struct fio_option *o = &fio_options[c->gopt.opt_index]; + struct value_pair *vp; + int i; + + i = 0; + vp = &o->posval[0]; + while (vp->ival) { + if (vp->oval == ip) { + gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i); + break; + } + vp++; + i++; + } +} + static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv, struct fio_option *o, unsigned int *ip, unsigned int idx) @@ -322,7 +384,7 @@ static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv, i = 0; vp = &o->posval[0]; while (vp->ival) { - gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); if (ip && vp->oval == *ip) active = i; vp++; @@ -330,6 +392,8 @@ static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv, } gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); + if (ip) + gopt_combo_int_set_val(c, *ip); c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); return &c->gopt; } @@ -341,6 +405,18 @@ static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data) gopt_changed(&m->gopt); } +static void gopt_str_multi_destroy(GtkWidget *w, gpointer data) +{ + struct gopt_str_multi *m = (struct gopt_str_multi *) data; + + free(m); + gtk_widget_destroy(w); +} + +static void gopt_str_multi_set_val(struct gopt_str_multi *m, int val) +{ +} + static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv, struct fio_option *o, unsigned int idx) { @@ -373,6 +449,8 @@ static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv, i++; } + gopt_str_multi_set_val(m, 0); + g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m); return &m->gopt; } @@ -409,12 +487,16 @@ static void gopt_int_destroy(GtkWidget *w, gpointer data) { struct gopt_int *i = (struct gopt_int *) data; - if (flist_empty(&i->gopt.changed_list)) - free(i); - + free(i); gtk_widget_destroy(w); } +static void gopt_int_set_val(struct gopt_int *i, unsigned long long p) +{ + gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), p); + i->lastval = p; +} + static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, struct fio_option *o, unsigned long long *p, unsigned int idx) @@ -441,7 +523,7 @@ static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, else if (o->def) { long long val; - check_str_bytes(o->def, &val, NULL); + check_str_bytes(o->def, &val, o); defval = val; } @@ -452,8 +534,10 @@ static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval); gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT); gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval); - i->lastval = defval; + if (p) + gopt_int_set_val(i, *p); + else + gopt_int_set_val(i, defval); i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i); g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i); @@ -517,12 +601,15 @@ static void gopt_bool_destroy(GtkWidget *w, gpointer data) { struct gopt_bool *b = (struct gopt_bool *) data; - if (flist_empty(&b->gopt.changed_list)) - free(b); - + free(b); gtk_widget_destroy(w); } +static void gopt_bool_set_val(struct gopt_bool *b, unsigned int val) +{ + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), val); +} + static struct gopt *gopt_new_bool(struct gopt_job_view *gjv, struct fio_option *o, unsigned int *val, unsigned int idx) @@ -540,15 +627,16 @@ static struct gopt *gopt_new_bool(struct gopt_job_view *gjv, b->check = gtk_check_button_new(); gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL); - if (val) - defstate = *val; - else if (o->def && !strcmp(o->def, "1")) + if (o->def && !strcmp(o->def, "1")) defstate = 1; if (o->neg) defstate = !defstate; - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate); + if (val) + gopt_bool_set_val(b, *val); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate); b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b); g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b); @@ -603,20 +691,27 @@ static void gopt_range_destroy(GtkWidget *w, gpointer data) { struct gopt_range *r = (struct gopt_range *) data; - if (flist_empty(&r->gopt.changed_list)) - free(r); - + free(r); gtk_widget_destroy(w); } +static void gopt_int_range_set_val(struct gopt_range *r, unsigned int *vals) +{ + int i; + + for (i = 0; i < GOPT_RANGE_SPIN; i++) + gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), vals[i]); +} + static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, struct fio_option *o, unsigned int **ip, unsigned int idx) { struct gopt_range *r; - gint maxval, defval; GtkWidget *label; guint interval; + unsigned int defvals[GOPT_RANGE_SPIN]; + gint maxval; int i; r = calloc(1, sizeof(*r)); @@ -631,12 +726,13 @@ static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, if (!maxval) maxval = INT_MAX; - defval = 0; + memset(defvals, 0, sizeof(defvals)); if (o->def) { long long val; - check_str_bytes(o->def, &val, NULL); - defval = val; + check_str_bytes(o->def, &val, o); + for (i = 0; i < GOPT_RANGE_SPIN; i++) + defvals[i] = val; } interval = 1.0; @@ -646,15 +742,17 @@ static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, for (i = 0; i < GOPT_RANGE_SPIN; i++) { r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval); gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID); - if (ip) - gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), *ip[i]); - else - gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), defval); - gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0); - g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r); } + if (ip) + gopt_int_range_set_val(r, *ip); + else + gopt_int_range_set_val(r, defvals); + + for (i = 0; i < GOPT_RANGE_SPIN; i++) + g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r); + gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0); g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r); return &r->gopt; @@ -664,9 +762,7 @@ static void gopt_str_val_destroy(GtkWidget *w, gpointer data) { struct gopt_str_val *g = (struct gopt_str_val *) data; - if (flist_empty(&g->gopt.changed_list)) - free(g); - + free(g); gtk_widget_destroy(w); } @@ -708,13 +804,28 @@ static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data) gopt_changed(&g->gopt); } +static void gopt_str_val_set_val(struct gopt_str_val *g, unsigned long long val) +{ + int i = 0; + + do { + if (!val || (val % 1024)) + break; + + i++; + val /= 1024; + } while (1); + + gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val); + gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i); +} + static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, struct fio_option *o, unsigned long long *p, unsigned int idx) { struct gopt_str_val *g; const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" }; - unsigned long long val; GtkWidget *label; int i; @@ -734,10 +845,10 @@ static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g); g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g); - g->combo = gtk_combo_box_new_text(); + g->combo = gtk_combo_box_text_new(); i = 0; while (strlen(postfix[i])) { - gtk_combo_box_append_text(GTK_COMBO_BOX(g->combo), postfix[i]); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]); i++; } g->maxindex = i - 1; @@ -745,23 +856,8 @@ static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3); - /* - * Set the value - */ - if (p) { - val = *p; - i = 0; - do { - if (!val || (val % 1024)) - break; - - i++; - val /= 1024; - } while (1); - - gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val); - gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i); - } + if (p) + gopt_str_val_set_val(g, *p); g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g); @@ -769,6 +865,144 @@ static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, return &g->gopt; } +static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o, + struct gopt *gopt, struct thread_options *to) +{ + switch (o->type) { + case FIO_OPT_STR_VAL: { + unsigned long long *ullp = NULL; + struct gopt_str_val *g; + + if (o->off1) + ullp = td_var(to, o->off1); + + g = container_of(gopt, struct gopt_str_val, gopt); + if (ullp) + gopt_str_val_set_val(g, *ullp); + break; + } + case FIO_OPT_STR_VAL_TIME: { + unsigned long long *ullp = NULL; + struct gopt_int *i; + + if (o->off1) + ullp = td_var(to, o->off1); + + i = container_of(gopt, struct gopt_int, gopt); + if (ullp) + gopt_int_set_val(i, *ullp); + break; + } + case FIO_OPT_INT: + if (o->posval[0].ival) { + unsigned int *ip = NULL; + struct gopt_combo *c; + + if (o->off1) + ip = td_var(to, o->off1); + + c = container_of(gopt, struct gopt_combo, gopt); + if (ip) + gopt_combo_int_set_val(c, *ip); + } else { + unsigned int *ip = NULL; + struct gopt_int *i; + + if (o->off1) + ip = td_var(to, o->off1); + + i = container_of(gopt, struct gopt_int, gopt); + if (ip) + gopt_int_set_val(i, *ip); + } + break; + case FIO_OPT_STR_SET: + case FIO_OPT_BOOL: { + unsigned int *ip = NULL; + struct gopt_bool *b; + + if (o->off1) + ip = td_var(to, o->off1); + + b = container_of(gopt, struct gopt_bool, gopt); + if (ip) + gopt_bool_set_val(b, *ip); + break; + } + case FIO_OPT_STR: { + if (o->posval[0].ival) { + unsigned int *ip = NULL; + struct gopt_combo *c; + + if (o->off1) + ip = td_var(to, o->off1); + + c = container_of(gopt, struct gopt_combo, gopt); + if (ip) + gopt_combo_int_set_val(c, *ip); + } else { + struct gopt_str *s; + char *text = NULL; + + if (o->off1) { + char **p = td_var(to, o->off1); + + text = *p; + } + + s = container_of(gopt, struct gopt_str, gopt); + gopt_str_store_set_val(s, text); + } + + break; + } + case FIO_OPT_STR_STORE: { + struct gopt_combo *c; + char *text = NULL; + + if (o->off1) { + char **p = td_var(to, o->off1); + text = *p; + } + + if (!o->posval[0].ival) { + struct gopt_str *s; + + s = container_of(gopt, struct gopt_str, gopt); + gopt_str_store_set_val(s, text); + break; + } + + c = container_of(gopt, struct gopt_combo, gopt); + if (text) + gopt_combo_str_set_val(c, text); + break; + } + case FIO_OPT_STR_MULTI: + /* HANDLE ME */ + break; + case FIO_OPT_RANGE: { + struct gopt_range *r; + unsigned int *ip[4] = { td_var(to, o->off1), + td_var(to, o->off2), + td_var(to, o->off3), + td_var(to, o->off4) }; + + r = container_of(gopt, struct gopt_range, gopt); + gopt_int_range_set_val(r, *ip); + break; + } + /* still need to handle this one */ + case FIO_OPT_FLOAT_LIST: + break; + case FIO_OPT_DEPRECATED: + break; + default: + printf("ignore type %u\n", o->type); + break; + } +} + static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, struct fio_option *o, unsigned int opt_index, struct thread_options *to) @@ -794,15 +1028,23 @@ static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, go = gopt_new_ullong(gjv, o, ullp, opt_index); break; } - case FIO_OPT_INT: { - unsigned int *ip = NULL; + case FIO_OPT_INT: + if (o->posval[0].ival) { + unsigned int *ip = NULL; - if (o->off1) - ip = td_var(to, o->off1); + if (o->off1) + ip = td_var(to, o->off1); - go = gopt_new_int(gjv, o, ip, opt_index); - break; + go = gopt_new_combo_int(gjv, o, ip, opt_index); + } else { + unsigned int *ip = NULL; + + if (o->off1) + ip = td_var(to, o->off1); + + go = gopt_new_int(gjv, o, ip, opt_index); } + break; case FIO_OPT_STR_SET: case FIO_OPT_BOOL: { unsigned int *ip = NULL; @@ -906,6 +1148,19 @@ static void gopt_add_options(struct gopt_job_view *gjv, } } +static void gopt_set_options(struct gopt_job_view *gjv, + struct thread_options *to) +{ + int i; + + for (i = 0; fio_options[i].name; i++) { + struct fio_option *o = &fio_options[i]; + struct gopt *gopt = gjv->gopts[i]; + + gopt_set_option(gjv, o, gopt, to); + } +} + static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name) { GtkWidget *box, *vbox, *scroll; @@ -1058,7 +1313,7 @@ static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv, if (*p) free(*p); - *p = strdup(gtk_combo_box_get_active_text(GTK_COMBO_BOX(c->combo))); + *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo))); } static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv, @@ -1076,7 +1331,6 @@ static void gopt_handle_changed(struct gopt *gopt) { struct fio_option *o = &fio_options[gopt->opt_index]; struct gopt_job_view *gjv = gopt->gjv; - void *to_free = NULL; switch (gopt->opt_type) { case GOPT_COMBO_INT: { @@ -1084,7 +1338,6 @@ static void gopt_handle_changed(struct gopt *gopt) c = container_of(gopt, struct gopt_combo, gopt); gopt_handle_combo_int_changed(gjv, c, o); - to_free = c; break; } case GOPT_COMBO_STR: { @@ -1092,7 +1345,6 @@ static void gopt_handle_changed(struct gopt *gopt) c = container_of(gopt, struct gopt_combo, gopt); gopt_handle_combo_str_changed(gjv, c, o); - to_free = c; break; } case GOPT_INT: { @@ -1100,7 +1352,6 @@ static void gopt_handle_changed(struct gopt *gopt) i = container_of(gopt, struct gopt_int, gopt); gopt_handle_int_changed(gjv, i, o); - to_free = i; break; } case GOPT_BOOL: { @@ -1108,7 +1359,6 @@ static void gopt_handle_changed(struct gopt *gopt) b = container_of(gopt, struct gopt_bool, gopt); gopt_handle_bool_changed(gjv, b, o); - to_free = b; break; } case GOPT_STR: { @@ -1116,7 +1366,6 @@ static void gopt_handle_changed(struct gopt *gopt) s = container_of(gopt, struct gopt_str, gopt); gopt_handle_str_changed(gjv, s, o); - to_free = s; break; } case GOPT_STR_VAL: { @@ -1124,7 +1373,6 @@ static void gopt_handle_changed(struct gopt *gopt) s = container_of(gopt, struct gopt_str_val, gopt); gopt_handle_str_val_changed(gjv, s, o); - to_free = s; break; } case GOPT_RANGE: { @@ -1132,7 +1380,6 @@ static void gopt_handle_changed(struct gopt *gopt) r = container_of(gopt, struct gopt_range, gopt); gopt_handle_range_changed(gjv, r, o); - to_free = r; break; } case GOPT_STR_MULTI: { @@ -1140,58 +1387,169 @@ static void gopt_handle_changed(struct gopt *gopt) m = container_of(gopt, struct gopt_str_multi, gopt); gopt_handle_str_multi_changed(gjv, m, o); - to_free = m; break; } default: - log_err("gfio: bad option type %s/%d\n", gopt->opt_type); - return; + log_err("gfio: bad option type: %d\n", gopt->opt_type); + break; } +} + +static void gopt_report_update_status(struct gopt_job_view *gjv) +{ + struct gfio_client *gc = gjv->client; + char tmp[80]; - g_object_unref(G_OBJECT(gopt->box)); - free(to_free); + sprintf(tmp, "\nCompleted with error: %d\n", gc->update_job_status); + gfio_report_info(gc->ge->ui, "Update job", tmp); } -static void gopt_handle_changed_options(struct gopt_job_view *gjv) +static int gopt_handle_changed_options(struct gopt_job_view *gjv) { + struct gfio_client *gc = gjv->client; + struct flist_head *entry; + uint64_t waitid = 0; struct gopt *gopt; + int ret; + + flist_for_each(entry, &gjv->changed_list) { + gopt = flist_entry(entry, struct gopt, changed_list); + gopt_handle_changed(gopt); + } + + gc->update_job_status = 0; + gc->update_job_done = 0; + + ret = fio_client_update_options(gc->client, gjv->o, &waitid); + if (ret) + goto done; + + ret = fio_client_wait_for_reply(gc->client, waitid); + if (ret) + goto done; + + assert(gc->update_job_done); + if (gc->update_job_status) + goto done; while (!flist_empty(&gjv->changed_list)) { gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list); - flist_del(&gopt->changed_list); - gopt_handle_changed(gopt); + flist_del_init(&gopt->changed_list); } + +done: + gopt_dialog_update_apply_button(gjv); + return ret; } -void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) +static gint gopt_dialog_cancel(gint response) { - GtkWidget *dialog, *notebook, *topnotebook, *vbox; - struct gfio_client_options *gco; - struct thread_options *o; + switch (response) { + case GTK_RESPONSE_NONE: + case GTK_RESPONSE_REJECT: + case GTK_RESPONSE_DELETE_EVENT: + case GTK_RESPONSE_CANCEL: + case GTK_RESPONSE_NO: + return 1; + default: + return 0; + } +} + +static gint gopt_dialog_done(gint response) +{ + switch (response) { + case GTK_RESPONSE_ACCEPT: + case GTK_RESPONSE_OK: + case GTK_RESPONSE_YES: + return 1; + default: + return 0; + } +} + +static void gopt_handle_option_dialog(struct gopt_job_view *gjv) +{ + gint response; + + do { + response = gtk_dialog_run(GTK_DIALOG(gjv->dialog)); + + if (gopt_dialog_cancel(response) || + gopt_dialog_done(response)) + break; + + /* + * Apply + */ + gopt_handle_changed_options(gjv); + gopt_report_update_status(gjv); + } while (1); + + if (gopt_dialog_cancel(response)) + return; + + gopt_handle_changed_options(gjv); +} + +static void gopt_job_changed(GtkComboBox *box, gpointer data) +{ + struct gopt_job_view *gjv = (struct gopt_job_view *) data; + struct gfio_client_options *gco = NULL; + struct gfio_client *gc = gjv->client; struct flist_head *entry; - struct gopt_job_view *gjv; - FLIST_HEAD(gjv_list); + gchar *job; /* - * Just choose the first item, we need to make each options - * entry the main notebook, with the below options view as - * a sub-notebook + * The switch act should be sensitized appropriately, so that we + * never get here with modified options. */ - assert(!flist_empty(&gc->o_list)); + if (!flist_empty(&gjv->changed_list)) { + gfio_report_info(gc->ge->ui, "Internal Error", "Modified options on job switch.\nThat should not be possible!\n"); + return; + } + + job = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(gjv->job_combo)); + flist_for_each(entry, &gc->o_list) { + const char *name; + + gco = flist_entry(entry, struct gfio_client_options, list); + name = gco->o.name; + if (!name || !strlen(name)) + name = "Default job"; + + if (!strcmp(name, job)) + break; + + gco = NULL; + } + + if (!gco) { + gfio_report_info(gc->ge->ui, "Internal Error", "Could not find job description.\nThat should not be possible!\n"); + return; + } + + gjv->in_job_switch = 1; + gopt_set_options(gjv, &gco->o); + gjv->in_job_switch = 0; +} + +void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) +{ + GtkWidget *dialog, *notebook, *vbox, *topvbox, *combo; + struct gfio_client_options *gco; + struct flist_head *entry; + struct gopt_job_view *gjv; dialog = gtk_dialog_new_with_buttons("Fio options", GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, + GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); - gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768); - - topnotebook = gtk_notebook_new(); - gtk_notebook_set_scrollable(GTK_NOTEBOOK(topnotebook), 1); - gtk_notebook_popup_enable(GTK_NOTEBOOK(topnotebook)); - gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), topnotebook, TRUE, TRUE, 5); - + combo = gtk_combo_box_text_new(); flist_for_each(entry, &gc->o_list) { + struct thread_options *o; const char *name; gco = flist_entry(entry, struct gfio_client_options, list); @@ -1200,36 +1558,42 @@ void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) if (!name || !strlen(name)) name = "Default job"; - vbox = gopt_add_tab(topnotebook, name); + gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), name); + } + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); - notebook = gtk_notebook_new(); - gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1); - gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook)); - gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5); + gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768); - gjv = calloc(1, sizeof(*gjv)); - INIT_FLIST_HEAD(&gjv->list); - INIT_FLIST_HEAD(&gjv->changed_list); - gjv->o = o; - flist_add_tail(&gjv->list, &gjv_list); - gopt_add_group_tabs(notebook, gjv); - gopt_add_options(gjv, o); - } + topvbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + gtk_box_pack_start(GTK_BOX(topvbox), combo, FALSE, FALSE, 5); - gtk_widget_show_all(dialog); + vbox = gtk_vbox_new(TRUE, 5); + gtk_box_pack_start(GTK_BOX(topvbox), vbox, TRUE, TRUE, 5); - gtk_dialog_run(GTK_DIALOG(dialog)); + notebook = gtk_notebook_new(); + gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1); + gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook)); + gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5); - while (!flist_empty(&gjv_list)) { - gjv = flist_entry(gjv_list.next, struct gopt_job_view, list); + gjv = calloc(1, sizeof(*gjv)); + INIT_FLIST_HEAD(&gjv->changed_list); + gco = flist_entry(gc->o_list.next, struct gfio_client_options, list); + gjv->o = &gco->o; + gjv->dialog = dialog; + gjv->client = gc; + gjv->job_combo = combo; + gopt_add_group_tabs(notebook, gjv); + gopt_add_options(gjv, &gco->o); + gopt_dialog_update_apply_button(gjv); - gopt_handle_changed_options(gjv); + g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(gopt_job_changed), gjv); - flist_del(&gjv->list); - free(gjv); - } + gtk_widget_show_all(dialog); + + gopt_handle_option_dialog(gjv); gtk_widget_destroy(dialog); + free(gjv); } /*