gfio: start of per-job option edit
[fio.git] / goptions.c
index 30edd5cdac6e3fd8545063b7682f21afb9576aaa..202b0d2fddbfa61c5f9a8e71c412b763ff30914c 100644 (file)
@@ -43,6 +43,7 @@ struct gopt_str_val {
        struct gopt gopt;
        GtkWidget *spin;
        GtkWidget *combo;
+       unsigned int maxindex;
 };
 
 #define GOPT_RANGE_SPIN        4
@@ -65,6 +66,8 @@ struct gopt_frame_widget {
 };
 static struct gopt_frame_widget gopt_g_widgets[__FIO_OPT_G_NR];
 
+static GNode *gopt_dep_tree;
+
 static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
 {
        unsigned int mask, group;
@@ -104,24 +107,27 @@ static GtkWidget *gopt_get_group_frame(GtkWidget *box, unsigned int groupmask)
 static void gopt_set_children_visible(struct fio_option *parent,
                                      gboolean visible)
 {
-       struct fio_option *o;
-       int i;
+       GNode *child, *node;
 
-       /*
-        * This isn't super fast, but it should not be an issue. If it is, we
-        * can speed it up by caching the lookup at least. Or we can do it
-        * once, at init time.
-        */
-       for (i = 0; fio_options[i].name; i++) {
-               o = &fio_options[i];
-               if (!o->parent || !o->hide)
-                       continue;
+       if (parent->hide_on_set)
+               visible = !visible;
+
+       node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
+       child = g_node_first_child(node);
+       while (child) {
+               struct fio_option *o = child->data;
+               struct gopt *g = o->gui_data;
+
+               /*
+                * Recurse into child, if it also has children
+                */
+               if (g_node_n_children(child))
+                       gopt_set_children_visible(o, visible);
 
-               if (strcmp(parent->name, o->parent))
-                       continue;
+               if (gopt_widgets[g->opt_index])
+                       gtk_widget_set_sensitive(gopt_widgets[g->opt_index], visible);
 
-               if (gopt_widgets[i])
-                       gtk_widget_set_sensitive(gopt_widgets[i], visible);
+               child = g_node_next_sibling(child);
        }
 }
 
@@ -172,15 +178,15 @@ static struct gopt *gopt_new_str_store(struct fio_option *o, const char *text,
        if (text)
                gtk_entry_set_text(GTK_ENTRY(s->entry), text);
        gtk_entry_set_editable(GTK_ENTRY(s->entry), 1);
-       s->gopt.sig_handler = g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
-       g_signal_connect(GTK_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
 
        if (o->def)
                gtk_entry_set_text(GTK_ENTRY(s->entry), o->def);
 
+       s->gopt.sig_handler = g_signal_connect(GTK_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
+       g_signal_connect(GTK_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
+
        gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
-       o->gui_data = s;
        return &s->gopt;
 }
 
@@ -188,8 +194,10 @@ static void gopt_combo_changed(GtkComboBox *box, gpointer data)
 {
        struct gopt_combo *c = (struct gopt_combo *) data;
        struct fio_option *o = &fio_options[c->gopt.opt_index];
+       unsigned int index;
 
-       printf("combo %s changed\n", o->name);
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
+       gopt_set_children_visible(o, index);
 }
 
 static void gopt_combo_destroy(GtkWidget *w, gpointer data)
@@ -217,29 +225,27 @@ static struct gopt_combo *__gopt_new_combo(struct fio_option *o,
 
        c->combo = gtk_combo_box_new_text();
        gopt_mark_index(&c->gopt, idx);
-       c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
        g_signal_connect(GTK_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
 
        gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
 
-       o->gui_data = c;
        return c;
 }
 
 static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text,
                                       unsigned int idx)
 {
-       struct gopt_combo *combo;
+       struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       combo = __gopt_new_combo(o, idx);
+       c = __gopt_new_combo(o, idx);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
+               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
                if (o->def && !strcmp(vp->ival, o->def))
                        active = i;
                if (text && !strcmp(vp->ival, text))
@@ -248,31 +254,33 @@ static struct gopt *gopt_new_combo_str(struct fio_option *o, const char *text,
                i++;
        }
 
-       gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
-       return &combo->gopt;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
 }
 
 static struct gopt *gopt_new_combo_int(struct fio_option *o, unsigned int *ip,
                                       unsigned int idx)
 {
-       struct gopt_combo *combo;
+       struct gopt_combo *c;
        struct value_pair *vp;
        int i, active = 0;
 
-       combo = __gopt_new_combo(o, idx);
+       c = __gopt_new_combo(o, idx);
 
        i = 0;
        vp = &o->posval[0];
        while (vp->ival) {
-               gtk_combo_box_append_text(GTK_COMBO_BOX(combo->combo), vp->ival);
+               gtk_combo_box_append_text(GTK_COMBO_BOX(c->combo), vp->ival);
                if (ip && vp->oval == *ip)
                        active = i;
                vp++;
                i++;
        }
 
-       gtk_combo_box_set_active(GTK_COMBO_BOX(combo->combo), active);
-       return &combo->gopt;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       c->gopt.sig_handler = g_signal_connect(GTK_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
 }
 
 static struct gopt *gopt_new_str_multi(struct fio_option *o, unsigned int idx)
@@ -321,7 +329,8 @@ static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
        i->lastval = value;
 
        if (o->inv_opt) {
-               struct gopt_int *i_inv = o->inv_opt->gui_data;
+               struct gopt *b_inv = o->inv_opt->gui_data;
+               struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt);
                int cur_val;
 
                assert(o->type == o->inv_opt->type);
@@ -387,7 +396,6 @@ static struct gopt_int *__gopt_new_int(struct fio_option *o,
        gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
 
-       o->gui_data = i;
        return i;
 }
 
@@ -424,7 +432,8 @@ static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
        set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
 
        if (o->inv_opt) {
-               struct gopt_bool *b_inv = o->inv_opt->gui_data;
+               struct gopt *g_inv = o->inv_opt->gui_data;
+               struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt);
 
                assert(o->type == o->inv_opt->type);
 
@@ -475,7 +484,6 @@ static struct gopt *gopt_new_bool(struct fio_option *o, unsigned int *val,
 
        gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
        gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
-       o->gui_data = b;
        return &b->gopt;
 }
 
@@ -575,7 +583,6 @@ static struct gopt *gopt_new_int_range(struct fio_option *o, unsigned int **ip,
 
        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);
-       o->gui_data = r;
        return &r->gopt;
 }
 
@@ -601,9 +608,12 @@ static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
         * Can't rely on exact value, as fast changes increment >= 1
         */
        if (!val) {
-               val = 1;
                index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
-               gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               if (index + 1 <= g->maxindex) {
+                       val = 1;
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               } else
+                       val = 1023;
                gtk_spin_button_set_value(spin, val);
        } else {
                index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
@@ -630,6 +640,7 @@ static struct gopt *gopt_new_str_val(struct fio_option *o,
                label = gtk_label_new(o->name);
        else
                label = gtk_label_new(o->lname);
+       gopt_mark_index(&g->gopt, idx);
 
        g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0);
        gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID);
@@ -644,12 +655,12 @@ static struct gopt *gopt_new_str_val(struct fio_option *o,
                gtk_combo_box_append_text(GTK_COMBO_BOX(g->combo), postfix[i]);
                i++;
        }
+       g->maxindex = i - 1;
        gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
        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);
 
        g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
-       o->gui_data = g;
        return &g->gopt;
 }
 
@@ -756,6 +767,7 @@ static void gopt_add_option(GtkWidget *hbox, struct fio_option *o,
                        gtk_widget_set_tooltip_text(go->box, o->help);
 
                go->opt_type = o->type;
+               o->gui_data = go;
 
                dest = gopt_get_group_frame(hbox, o->group);
                if (!dest)
@@ -770,6 +782,8 @@ static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
        GtkWidget *hbox = NULL;
        int i;
 
+       gopt_dep_tree = g_node_new(NULL);
+
        /*
         * First add all options
         */
@@ -777,6 +791,26 @@ static void gopt_add_options(GtkWidget **vboxes, struct thread_options *to)
                struct fio_option *o = &fio_options[i];
                unsigned int mask = o->category;
                struct opt_group *og;
+               GNode *node, *nparent;
+
+               /*
+                * Insert node with either the root parent, or an
+                * option parent.
+                */
+               node = g_node_new(o);
+               nparent = gopt_dep_tree;
+               if (o->parent) {
+                       struct fio_option *parent;
+
+                       parent = fio_option_find(o->parent);
+                       nparent = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
+                       if (!nparent) {
+                               log_err("fio: did not find parent %s for opt %s\n", o->name, o->parent);
+                               nparent = gopt_dep_tree;
+                       }
+               }
+
+               g_node_insert(nparent, -1, node);
 
                while ((og = opt_group_from_mask(&mask)) != NULL) {
                        GtkWidget *vbox = vboxes[ffz(~og->mask)];
@@ -822,10 +856,21 @@ static void gopt_add_group_tabs(GtkWidget *notebook, GtkWidget **vbox)
        } while (1);
 }
 
-void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
+void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc)
 {
        GtkWidget *dialog, *notebook;
        GtkWidget *vboxes[__FIO_OPT_C_NR];
+       struct gfio_client_options *gco;
+       struct thread_options *o;
+
+       /*
+        * Just choose the first item, we need to make each options
+        * entry the main notebook, with the below options view as
+        * a sub-notebook
+        */
+       assert(!flist_empty(&gc->o_list));
+       gco = flist_entry(gc->o_list.next, struct gfio_client_options, list);
+       o = &gco->o;
 
        dialog = gtk_dialog_new_with_buttons("Fio options",
                        GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
@@ -848,6 +893,9 @@ void gopt_get_options_window(GtkWidget *window, struct thread_options *o)
        gtk_dialog_run(GTK_DIALOG(dialog));
 
        gtk_widget_destroy(dialog);
+
+       g_node_destroy(gopt_dep_tree);
+       gopt_dep_tree = NULL;
        memset(gopt_widgets, 0, sizeof(gopt_widgets));
        memset(gopt_g_widgets, 0, sizeof(gopt_g_widgets));
 }