blob: 08b17ac931ae2395ecc38c00a070fd9701505cdd [file] [log] [blame]
Jens Axboe9af4a242012-03-16 10:13:49 +01001#include <locale.h>
2#include <malloc.h>
3#include <string.h>
4
5#include <glib.h>
6#include <cairo.h>
7#include <gtk/gtk.h>
8
9#include "fio.h"
10#include "gfio.h"
11#include "ghelpers.h"
Jens Axboe28db2562012-03-28 10:27:42 +020012#include "gerror.h"
Jens Axboe9af4a242012-03-16 10:13:49 +010013#include "parse.h"
14
15struct gopt {
16 GtkWidget *box;
17 unsigned int opt_index;
18 unsigned int opt_type;
Jens Axboe8f9e46a2012-03-19 22:01:20 +010019 gulong sig_handler;
Jens Axboe753e9e62012-03-24 20:22:29 +010020 struct gopt_job_view *gjv;
Jens Axboea3fc0ff2012-03-26 12:18:23 +020021 struct flist_head changed_list;
Jens Axboe9af4a242012-03-16 10:13:49 +010022};
23
24struct gopt_combo {
25 struct gopt gopt;
26 GtkWidget *combo;
27};
28
29struct gopt_int {
30 struct gopt gopt;
Jens Axboe28db2562012-03-28 10:27:42 +020031 unsigned long long lastval;
Jens Axboe9af4a242012-03-16 10:13:49 +010032 GtkWidget *spin;
33};
34
35struct gopt_bool {
36 struct gopt gopt;
37 GtkWidget *check;
38};
39
40struct gopt_str {
41 struct gopt gopt;
42 GtkWidget *entry;
43};
44
Jens Axboe7fc35ff2012-03-20 09:32:35 +010045struct gopt_str_val {
46 struct gopt gopt;
47 GtkWidget *spin;
48 GtkWidget *combo;
Jens Axboe481c2422012-03-20 09:49:49 +010049 unsigned int maxindex;
Jens Axboe7fc35ff2012-03-20 09:32:35 +010050};
51
Jens Axboe1da10c12012-03-16 19:41:01 +010052#define GOPT_RANGE_SPIN 4
53
Jens Axboe9af4a242012-03-16 10:13:49 +010054struct gopt_range {
55 struct gopt gopt;
Jens Axboe1da10c12012-03-16 19:41:01 +010056 GtkWidget *spins[GOPT_RANGE_SPIN];
Jens Axboe9af4a242012-03-16 10:13:49 +010057};
58
Jens Axboe7386d4a2012-03-19 18:36:29 +010059struct gopt_str_multi {
60 struct gopt gopt;
61 GtkWidget *checks[PARSE_MAX_VP];
62};
63
Jens Axboea3fc0ff2012-03-26 12:18:23 +020064enum {
65 GOPT_COMBO_INT = 1,
66 GOPT_COMBO_STR,
67 GOPT_INT,
68 GOPT_BOOL,
69 GOPT_STR,
70 GOPT_STR_VAL,
71 GOPT_RANGE,
72 GOPT_STR_MULTI,
73};
74
Jens Axboee8b0e952012-03-19 14:37:08 +010075struct gopt_frame_widget {
76 GtkWidget *vbox[2];
77 unsigned int nr;
Jens Axboeec0218f2012-03-16 21:45:05 +010078};
Jens Axboe753e9e62012-03-24 20:22:29 +010079
80struct gopt_job_view {
Jens Axboe753e9e62012-03-24 20:22:29 +010081 struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR];
Jens Axboe753e9e62012-03-24 20:22:29 +010082 GtkWidget *vboxes[__FIO_OPT_C_NR];
Jens Axboe28db2562012-03-28 10:27:42 +020083 struct gopt *gopts[FIO_MAX_OPTS];
Jens Axboe40c60512012-03-27 16:03:04 +020084 GtkWidget *dialog;
Jens Axboe28db2562012-03-28 10:27:42 +020085 GtkWidget *job_combo;
Jens Axboe40c60512012-03-27 16:03:04 +020086 struct gfio_client *client;
Jens Axboea3fc0ff2012-03-26 12:18:23 +020087 struct flist_head changed_list;
88 struct thread_options *o;
Jens Axboe28db2562012-03-28 10:27:42 +020089 int in_job_switch;
Jens Axboe753e9e62012-03-24 20:22:29 +010090};
Jens Axboeec0218f2012-03-16 21:45:05 +010091
Jens Axboec504ee52012-03-20 11:29:09 +010092static GNode *gopt_dep_tree;
93
Jens Axboe753e9e62012-03-24 20:22:29 +010094static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
95 GtkWidget *box, unsigned int groupmask)
Jens Axboeec0218f2012-03-16 21:45:05 +010096{
Jens Axboee8b0e952012-03-19 14:37:08 +010097 unsigned int mask, group;
98 struct opt_group *og;
99 GtkWidget *frame, *hbox;
100 struct gopt_frame_widget *gfw;
Jens Axboeec0218f2012-03-16 21:45:05 +0100101
Jens Axboee8b0e952012-03-19 14:37:08 +0100102 if (!groupmask)
103 return 0;
104
105 mask = groupmask;
106 og = opt_group_cat_from_mask(&mask);
107 if (!og)
108 return NULL;
109
110 group = ffz(~groupmask);
Jens Axboe753e9e62012-03-24 20:22:29 +0100111 gfw = &gjv->g_widgets[group];
Jens Axboee8b0e952012-03-19 14:37:08 +0100112 if (!gfw->vbox[0]) {
113 frame = gtk_frame_new(og->name);
114 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
115 hbox = gtk_hbox_new(FALSE, 0);
116 gtk_container_add(GTK_CONTAINER(frame), hbox);
117 gfw->vbox[0] = gtk_vbox_new(TRUE, 5);
118 gfw->vbox[1] = gtk_vbox_new(TRUE, 5);
119 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5);
120 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5);
Jens Axboeec0218f2012-03-16 21:45:05 +0100121 }
Jens Axboee8b0e952012-03-19 14:37:08 +0100122
123 hbox = gtk_hbox_new(FALSE, 3);
124 gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5);
125 return hbox;
Jens Axboeec0218f2012-03-16 21:45:05 +0100126}
Jens Axboeb6caa832012-03-16 21:22:56 +0100127
128/*
129 * Mark children as invisible, if needed.
130 */
Jens Axboe19921182012-03-24 20:35:16 +0100131static void gopt_set_children_visible(struct gopt_job_view *gjv,
132 struct fio_option *parent,
Jens Axboe231edf62012-03-20 08:31:29 +0100133 gboolean visible)
Jens Axboeb6caa832012-03-16 21:22:56 +0100134{
Jens Axboec504ee52012-03-20 11:29:09 +0100135 GNode *child, *node;
Jens Axboeb6caa832012-03-16 21:22:56 +0100136
Jens Axboea4ed77f2012-03-20 10:19:44 +0100137 if (parent->hide_on_set)
138 visible = !visible;
139
Jens Axboec504ee52012-03-20 11:29:09 +0100140 node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
141 child = g_node_first_child(node);
142 while (child) {
143 struct fio_option *o = child->data;
144 struct gopt *g = o->gui_data;
Jens Axboe28db2562012-03-28 10:27:42 +0200145 GtkWidget *widget = g->box;
Jens Axboeb6caa832012-03-16 21:22:56 +0100146
Jens Axboec504ee52012-03-20 11:29:09 +0100147 /*
148 * Recurse into child, if it also has children
149 */
150 if (g_node_n_children(child))
Jens Axboe19921182012-03-24 20:35:16 +0100151 gopt_set_children_visible(gjv, o, visible);
Jens Axboeb6caa832012-03-16 21:22:56 +0100152
Jens Axboe28db2562012-03-28 10:27:42 +0200153 gtk_widget_set_sensitive(widget, visible);
Jens Axboec504ee52012-03-20 11:29:09 +0100154 child = g_node_next_sibling(child);
Jens Axboeb6caa832012-03-16 21:22:56 +0100155 }
156}
157
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200158static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt,
159 unsigned int idx, int type)
160{
161 INIT_FLIST_HEAD(&gopt->changed_list);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200162
Jens Axboe28db2562012-03-28 10:27:42 +0200163 assert(!gjv->gopts[idx]);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200164 gopt->opt_index = idx;
165 gopt->opt_type = type;
166 gopt->gjv = gjv;
Jens Axboe28db2562012-03-28 10:27:42 +0200167 gjv->gopts[idx] = gopt;
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200168}
169
Jens Axboe28db2562012-03-28 10:27:42 +0200170static void gopt_dialog_update_apply_button(struct gopt_job_view *gjv)
Jens Axboe40c60512012-03-27 16:03:04 +0200171{
172 GtkDialog *dialog = GTK_DIALOG(gjv->dialog);
173 gboolean set;
174
175 set = !flist_empty(&gjv->changed_list);
176 gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_APPLY, set);
Jens Axboe28db2562012-03-28 10:27:42 +0200177
178 if (set) {
179 gtk_widget_set_sensitive(gjv->job_combo, 0);
180 gtk_widget_set_tooltip_text(gjv->job_combo, "Apply option changes before switching to a new job");
181 } else {
182 gtk_widget_set_sensitive(gjv->job_combo, 1);
183 gtk_widget_set_tooltip_text(gjv->job_combo, "Change current job");
184 }
Jens Axboe40c60512012-03-27 16:03:04 +0200185}
186
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200187static void gopt_changed(struct gopt *gopt)
188{
189 struct gopt_job_view *gjv = gopt->gjv;
190
Jens Axboe28db2562012-03-28 10:27:42 +0200191 if (gjv->in_job_switch)
192 return;
193
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200194 /*
195 * Add to changed list. This also prevents the option from being
196 * freed when the widget is destroyed.
197 */
Jens Axboe40c60512012-03-27 16:03:04 +0200198 if (flist_empty(&gopt->changed_list)) {
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200199 flist_add_tail(&gopt->changed_list, &gjv->changed_list);
Jens Axboe28db2562012-03-28 10:27:42 +0200200 gopt_dialog_update_apply_button(gjv);
Jens Axboe40c60512012-03-27 16:03:04 +0200201 }
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200202}
203
Jens Axboeb6caa832012-03-16 21:22:56 +0100204static void gopt_str_changed(GtkEntry *entry, gpointer data)
205{
206 struct gopt_str *s = (struct gopt_str *) data;
207 struct fio_option *o = &fio_options[s->gopt.opt_index];
208 const gchar *text;
209 int set;
210
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200211 gopt_changed(&s->gopt);
212
Jens Axboeb6caa832012-03-16 21:22:56 +0100213 text = gtk_entry_get_text(GTK_ENTRY(s->entry));
214 set = strcmp(text, "") != 0;
Jens Axboe19921182012-03-24 20:35:16 +0100215
216 gopt_set_children_visible(s->gopt.gjv, o, set);
Jens Axboeb6caa832012-03-16 21:22:56 +0100217}
218
Jens Axboe231edf62012-03-20 08:31:29 +0100219static void gopt_str_destroy(GtkWidget *w, gpointer data)
220{
221 struct gopt_str *s = (struct gopt_str *) data;
222
Jens Axboec04942a2012-03-26 14:25:26 +0200223 free(s);
Jens Axboe231edf62012-03-20 08:31:29 +0100224 gtk_widget_destroy(w);
225}
226
Jens Axboe28db2562012-03-28 10:27:42 +0200227static void gopt_str_store_set_val(struct gopt_str *s, const char *text)
228{
229 if (text)
230 gtk_entry_set_text(GTK_ENTRY(s->entry), text);
231}
232
Jens Axboe753e9e62012-03-24 20:22:29 +0100233static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv,
234 struct fio_option *o, const char *text,
Jens Axboe231edf62012-03-20 08:31:29 +0100235 unsigned int idx)
Jens Axboe9af4a242012-03-16 10:13:49 +0100236{
237 struct gopt_str *s;
238 GtkWidget *label;
239
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200240 s = calloc(1, sizeof(*s));
Jens Axboe9af4a242012-03-16 10:13:49 +0100241
242 s->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboee8b0e952012-03-19 14:37:08 +0100243 if (!o->lname)
244 label = gtk_label_new(o->name);
245 else
246 label = gtk_label_new(o->lname);
Jens Axboe9af4a242012-03-16 10:13:49 +0100247
248 s->entry = gtk_entry_new();
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200249 gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR);
Jens Axboef762cef2012-03-26 13:51:11 +0200250 gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1);
Jens Axboe9af4a242012-03-16 10:13:49 +0100251
Jens Axboe28db2562012-03-28 10:27:42 +0200252 if (text)
253 gopt_str_store_set_val(s, text);
254 else if (o->def)
255 gopt_str_store_set_val(s, o->def);
Jens Axboe9af4a242012-03-16 10:13:49 +0100256
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200257 s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
258 g_signal_connect(G_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
Jens Axboe4fbcd652012-03-20 10:05:38 +0100259
Jens Axboe9af4a242012-03-16 10:13:49 +0100260 gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
Jens Axboee8b0e952012-03-19 14:37:08 +0100261 gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
Jens Axboe9af4a242012-03-16 10:13:49 +0100262 return &s->gopt;
263}
264
Jens Axboeb6caa832012-03-16 21:22:56 +0100265static void gopt_combo_changed(GtkComboBox *box, gpointer data)
Jens Axboe9af4a242012-03-16 10:13:49 +0100266{
Jens Axboeb6caa832012-03-16 21:22:56 +0100267 struct gopt_combo *c = (struct gopt_combo *) data;
268 struct fio_option *o = &fio_options[c->gopt.opt_index];
Jens Axboeb2452a42012-03-20 10:29:45 +0100269 unsigned int index;
Jens Axboe9af4a242012-03-16 10:13:49 +0100270
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200271 gopt_changed(&c->gopt);
272
Jens Axboeb2452a42012-03-20 10:29:45 +0100273 index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
Jens Axboe19921182012-03-24 20:35:16 +0100274
275 gopt_set_children_visible(c->gopt.gjv, o, index);
Jens Axboe39f04332012-03-16 16:34:06 +0100276}
277
Jens Axboe231edf62012-03-20 08:31:29 +0100278static void gopt_combo_destroy(GtkWidget *w, gpointer data)
279{
280 struct gopt_combo *c = (struct gopt_combo *) data;
281
Jens Axboec04942a2012-03-26 14:25:26 +0200282 free(c);
Jens Axboe231edf62012-03-20 08:31:29 +0100283 gtk_widget_destroy(w);
284}
285
Jens Axboe753e9e62012-03-24 20:22:29 +0100286static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv,
287 struct fio_option *o,
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200288 unsigned int idx, int type)
Jens Axboeb6caa832012-03-16 21:22:56 +0100289{
290 struct gopt_combo *c;
291 GtkWidget *label;
292
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200293 c = calloc(1, sizeof(*c));
Jens Axboeb6caa832012-03-16 21:22:56 +0100294
295 c->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboee8b0e952012-03-19 14:37:08 +0100296 if (!o->lname)
297 label = gtk_label_new(o->name);
298 else
299 label = gtk_label_new(o->lname);
Jens Axboeb6caa832012-03-16 21:22:56 +0100300
Jens Axboef762cef2012-03-26 13:51:11 +0200301 c->combo = gtk_combo_box_text_new();
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200302 gopt_mark_index(gjv, &c->gopt, idx, type);
303 g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
Jens Axboeb6caa832012-03-16 21:22:56 +0100304
Jens Axboee8b0e952012-03-19 14:37:08 +0100305 gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
306 gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
307
Jens Axboeb6caa832012-03-16 21:22:56 +0100308 return c;
309}
310
Jens Axboe28db2562012-03-28 10:27:42 +0200311static void gopt_combo_str_set_val(struct gopt_combo *c, const char *text)
312{
313 struct fio_option *o = &fio_options[c->gopt.opt_index];
314 struct value_pair *vp;
315 int i;
316
317 i = 0;
318 vp = &o->posval[0];
319 while (vp->ival) {
320 if (!strcmp(vp->ival, text)) {
321 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
322 break;
323 }
324 vp++;
325 i++;
326 }
327}
328
Jens Axboe753e9e62012-03-24 20:22:29 +0100329static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv,
330 struct fio_option *o, const char *text,
Jens Axboe231edf62012-03-20 08:31:29 +0100331 unsigned int idx)
Jens Axboe39f04332012-03-16 16:34:06 +0100332{
Jens Axboe4fbcd652012-03-20 10:05:38 +0100333 struct gopt_combo *c;
Jens Axboe39f04332012-03-16 16:34:06 +0100334 struct value_pair *vp;
335 int i, active = 0;
336
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200337 c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR);
Jens Axboe39f04332012-03-16 16:34:06 +0100338
Jens Axboe9af4a242012-03-16 10:13:49 +0100339 i = 0;
340 vp = &o->posval[0];
341 while (vp->ival) {
Jens Axboef762cef2012-03-26 13:51:11 +0200342 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
Jens Axboe9af4a242012-03-16 10:13:49 +0100343 if (o->def && !strcmp(vp->ival, o->def))
344 active = i;
345 vp++;
346 i++;
347 }
348
Jens Axboe4fbcd652012-03-20 10:05:38 +0100349 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
Jens Axboe28db2562012-03-28 10:27:42 +0200350 if (text)
351 gopt_combo_str_set_val(c, text);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200352 c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
Jens Axboe4fbcd652012-03-20 10:05:38 +0100353 return &c->gopt;
Jens Axboe9af4a242012-03-16 10:13:49 +0100354}
355
Jens Axboe28db2562012-03-28 10:27:42 +0200356static void gopt_combo_int_set_val(struct gopt_combo *c, unsigned int ip)
357{
358 struct fio_option *o = &fio_options[c->gopt.opt_index];
359 struct value_pair *vp;
360 int i;
361
362 i = 0;
363 vp = &o->posval[0];
364 while (vp->ival) {
365 if (vp->oval == ip) {
366 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
367 break;
368 }
369 vp++;
370 i++;
371 }
372}
373
Jens Axboe753e9e62012-03-24 20:22:29 +0100374static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv,
375 struct fio_option *o, unsigned int *ip,
Jens Axboe231edf62012-03-20 08:31:29 +0100376 unsigned int idx)
Jens Axboe9af4a242012-03-16 10:13:49 +0100377{
Jens Axboe4fbcd652012-03-20 10:05:38 +0100378 struct gopt_combo *c;
Jens Axboe39f04332012-03-16 16:34:06 +0100379 struct value_pair *vp;
380 int i, active = 0;
381
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200382 c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT);
Jens Axboe39f04332012-03-16 16:34:06 +0100383
384 i = 0;
385 vp = &o->posval[0];
386 while (vp->ival) {
Jens Axboef762cef2012-03-26 13:51:11 +0200387 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
Jens Axboe39f04332012-03-16 16:34:06 +0100388 if (ip && vp->oval == *ip)
389 active = i;
390 vp++;
391 i++;
392 }
393
Jens Axboe4fbcd652012-03-20 10:05:38 +0100394 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
Jens Axboe28db2562012-03-28 10:27:42 +0200395 if (ip)
396 gopt_combo_int_set_val(c, *ip);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200397 c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
Jens Axboe4fbcd652012-03-20 10:05:38 +0100398 return &c->gopt;
Jens Axboe39f04332012-03-16 16:34:06 +0100399}
400
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200401static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data)
402{
403 struct gopt_str_multi *m = (struct gopt_str_multi *) data;
404
405 gopt_changed(&m->gopt);
406}
407
Jens Axboebb3d3c42012-03-26 14:28:36 +0200408static void gopt_str_multi_destroy(GtkWidget *w, gpointer data)
409{
410 struct gopt_str_multi *m = (struct gopt_str_multi *) data;
411
412 free(m);
413 gtk_widget_destroy(w);
414}
415
Jens Axboe28db2562012-03-28 10:27:42 +0200416static void gopt_str_multi_set_val(struct gopt_str_multi *m, int val)
417{
418}
419
Jens Axboe753e9e62012-03-24 20:22:29 +0100420static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv,
421 struct fio_option *o, unsigned int idx)
Jens Axboe7386d4a2012-03-19 18:36:29 +0100422{
423 struct gopt_str_multi *m;
424 struct value_pair *vp;
425 GtkWidget *frame, *hbox;
426 int i;
427
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200428 m = calloc(1, sizeof(*m));
Jens Axboe7386d4a2012-03-19 18:36:29 +0100429 m->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200430 gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI);
Jens Axboe7386d4a2012-03-19 18:36:29 +0100431
432 if (!o->lname)
433 frame = gtk_frame_new(o->name);
434 else
435 frame = gtk_frame_new(o->lname);
436 gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3);
437
438 hbox = gtk_hbox_new(FALSE, 3);
439 gtk_container_add(GTK_CONTAINER(frame), hbox);
440
441 i = 0;
442 vp = &o->posval[0];
443 while (vp->ival) {
444 m->checks[i] = gtk_check_button_new_with_label(vp->ival);
445 gtk_widget_set_tooltip_text(m->checks[i], vp->help);
446 gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200447 g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m);
Jens Axboe456fed92012-03-26 12:38:33 +0200448 vp++;
449 i++;
Jens Axboe7386d4a2012-03-19 18:36:29 +0100450 }
451
Jens Axboe28db2562012-03-28 10:27:42 +0200452 gopt_str_multi_set_val(m, 0);
Jens Axboebb3d3c42012-03-26 14:28:36 +0200453 g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m);
Jens Axboe7386d4a2012-03-19 18:36:29 +0100454 return &m->gopt;
455}
456
Jens Axboeb6caa832012-03-16 21:22:56 +0100457static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
458{
459 struct gopt_int *i = (struct gopt_int *) data;
460 struct fio_option *o = &fio_options[i->gopt.opt_index];
Jens Axboe90265352012-03-19 20:29:44 +0100461 GtkAdjustment *adj;
462 int value, delta;
Jens Axboeb6caa832012-03-16 21:22:56 +0100463
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200464 gopt_changed(&i->gopt);
465
Jens Axboe90265352012-03-19 20:29:44 +0100466 adj = gtk_spin_button_get_adjustment(spin);
467 value = gtk_adjustment_get_value(adj);
468 delta = value - i->lastval;
469 i->lastval = value;
470
471 if (o->inv_opt) {
Jens Axboec504ee52012-03-20 11:29:09 +0100472 struct gopt *b_inv = o->inv_opt->gui_data;
473 struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt);
Jens Axboe90265352012-03-19 20:29:44 +0100474 int cur_val;
475
Jens Axboea01a1bc2012-03-19 21:13:01 +0100476 assert(o->type == o->inv_opt->type);
477
Jens Axboe90265352012-03-19 20:29:44 +0100478 cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
479 cur_val -= delta;
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100480 g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
Jens Axboe90265352012-03-19 20:29:44 +0100481 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100482 g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
Jens Axboe90265352012-03-19 20:29:44 +0100483 }
Jens Axboeb6caa832012-03-16 21:22:56 +0100484}
485
Jens Axboe231edf62012-03-20 08:31:29 +0100486static void gopt_int_destroy(GtkWidget *w, gpointer data)
487{
488 struct gopt_int *i = (struct gopt_int *) data;
489
Jens Axboec04942a2012-03-26 14:25:26 +0200490 free(i);
Jens Axboe231edf62012-03-20 08:31:29 +0100491 gtk_widget_destroy(w);
492}
493
Jens Axboe28db2562012-03-28 10:27:42 +0200494static void gopt_int_set_val(struct gopt_int *i, unsigned long long p)
495{
496 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), p);
497 i->lastval = p;
498}
499
Jens Axboe753e9e62012-03-24 20:22:29 +0100500static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv,
501 struct fio_option *o,
Jens Axboe231edf62012-03-20 08:31:29 +0100502 unsigned long long *p, unsigned int idx)
Jens Axboe39f04332012-03-16 16:34:06 +0100503{
504 unsigned long long defval;
Jens Axboe9af4a242012-03-16 10:13:49 +0100505 struct gopt_int *i;
Jens Axboe20eb06b2012-03-16 19:57:23 +0100506 guint maxval, interval;
Jens Axboe9af4a242012-03-16 10:13:49 +0100507 GtkWidget *label;
508
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200509 i = calloc(1, sizeof(*i));
Jens Axboe9af4a242012-03-16 10:13:49 +0100510 i->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboee8b0e952012-03-19 14:37:08 +0100511 if (!o->lname)
512 label = gtk_label_new(o->name);
513 else
514 label = gtk_label_new(o->lname);
Jens Axboe9af4a242012-03-16 10:13:49 +0100515
516 maxval = o->maxval;
517 if (!maxval)
Jens Axboe39f04332012-03-16 16:34:06 +0100518 maxval = UINT_MAX;
Jens Axboe9af4a242012-03-16 10:13:49 +0100519
520 defval = 0;
Jens Axboe39f04332012-03-16 16:34:06 +0100521 if (p)
522 defval = *p;
523 else if (o->def) {
Jens Axboe9af4a242012-03-16 10:13:49 +0100524 long long val;
525
Jens Axboe83ea4222012-03-28 14:01:46 +0200526 check_str_bytes(o->def, &val, o);
Jens Axboe9af4a242012-03-16 10:13:49 +0100527 defval = val;
528 }
529
Jens Axboe20eb06b2012-03-16 19:57:23 +0100530 interval = 1.0;
531 if (o->interval)
532 interval = o->interval;
533
534 i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200535 gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT);
Jens Axboe9af4a242012-03-16 10:13:49 +0100536 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
Jens Axboe28db2562012-03-28 10:27:42 +0200537 if (p)
538 gopt_int_set_val(i, *p);
539 else
540 gopt_int_set_val(i, defval);
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100541 i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
Jens Axboe231edf62012-03-20 08:31:29 +0100542 g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i);
Jens Axboe9af4a242012-03-16 10:13:49 +0100543
544 gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
Jens Axboee8b0e952012-03-19 14:37:08 +0100545 gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
Jens Axboeb6caa832012-03-16 21:22:56 +0100546
547 return i;
Jens Axboe9af4a242012-03-16 10:13:49 +0100548}
549
Jens Axboe753e9e62012-03-24 20:22:29 +0100550static struct gopt *gopt_new_int(struct gopt_job_view *gjv,
551 struct fio_option *o, unsigned int *ip,
Jens Axboe231edf62012-03-20 08:31:29 +0100552 unsigned int idx)
Jens Axboe39f04332012-03-16 16:34:06 +0100553{
554 unsigned long long ullp;
Jens Axboeb6caa832012-03-16 21:22:56 +0100555 struct gopt_int *i;
Jens Axboe39f04332012-03-16 16:34:06 +0100556
557 if (ip) {
558 ullp = *ip;
Jens Axboe753e9e62012-03-24 20:22:29 +0100559 i = __gopt_new_int(gjv, o, &ullp, idx);
Jens Axboeb6caa832012-03-16 21:22:56 +0100560 } else
Jens Axboe753e9e62012-03-24 20:22:29 +0100561 i = __gopt_new_int(gjv, o, NULL, idx);
Jens Axboe39f04332012-03-16 16:34:06 +0100562
Jens Axboeb6caa832012-03-16 21:22:56 +0100563 return &i->gopt;
Jens Axboe39f04332012-03-16 16:34:06 +0100564}
565
Jens Axboe753e9e62012-03-24 20:22:29 +0100566static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv,
567 struct fio_option *o, unsigned long long *p,
Jens Axboeb6caa832012-03-16 21:22:56 +0100568 unsigned int idx)
Jens Axboe39f04332012-03-16 16:34:06 +0100569{
Jens Axboeb6caa832012-03-16 21:22:56 +0100570 struct gopt_int *i;
571
Jens Axboe753e9e62012-03-24 20:22:29 +0100572 i = __gopt_new_int(gjv, o, p, idx);
Jens Axboeb6caa832012-03-16 21:22:56 +0100573 return &i->gopt;
Jens Axboe39f04332012-03-16 16:34:06 +0100574}
575
Jens Axboeb6caa832012-03-16 21:22:56 +0100576static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
577{
578 struct gopt_bool *b = (struct gopt_bool *) data;
579 struct fio_option *o = &fio_options[b->gopt.opt_index];
580 gboolean set;
581
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200582 gopt_changed(&b->gopt);
583
Jens Axboeb6caa832012-03-16 21:22:56 +0100584 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
Jens Axboea01a1bc2012-03-19 21:13:01 +0100585
586 if (o->inv_opt) {
Jens Axboec504ee52012-03-20 11:29:09 +0100587 struct gopt *g_inv = o->inv_opt->gui_data;
588 struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt);
Jens Axboea01a1bc2012-03-19 21:13:01 +0100589
590 assert(o->type == o->inv_opt->type);
591
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100592 g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
Jens Axboea01a1bc2012-03-19 21:13:01 +0100593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set);
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100594 g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
Jens Axboea01a1bc2012-03-19 21:13:01 +0100595 }
596
Jens Axboe19921182012-03-24 20:35:16 +0100597 gopt_set_children_visible(b->gopt.gjv, o, set);
Jens Axboeb6caa832012-03-16 21:22:56 +0100598}
599
Jens Axboe231edf62012-03-20 08:31:29 +0100600static void gopt_bool_destroy(GtkWidget *w, gpointer data)
601{
602 struct gopt_bool *b = (struct gopt_bool *) data;
603
Jens Axboec04942a2012-03-26 14:25:26 +0200604 free(b);
Jens Axboe231edf62012-03-20 08:31:29 +0100605 gtk_widget_destroy(w);
606}
607
Jens Axboe28db2562012-03-28 10:27:42 +0200608static void gopt_bool_set_val(struct gopt_bool *b, unsigned int val)
609{
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), val);
611}
612
Jens Axboe753e9e62012-03-24 20:22:29 +0100613static struct gopt *gopt_new_bool(struct gopt_job_view *gjv,
614 struct fio_option *o, unsigned int *val,
Jens Axboe231edf62012-03-20 08:31:29 +0100615 unsigned int idx)
Jens Axboe9af4a242012-03-16 10:13:49 +0100616{
617 struct gopt_bool *b;
618 GtkWidget *label;
619 int defstate = 0;
620
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200621 b = calloc(1, sizeof(*b));
Jens Axboe9af4a242012-03-16 10:13:49 +0100622 b->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboee8b0e952012-03-19 14:37:08 +0100623 if (!o->lname)
624 label = gtk_label_new(o->name);
625 else
626 label = gtk_label_new(o->lname);
Jens Axboe9af4a242012-03-16 10:13:49 +0100627
628 b->check = gtk_check_button_new();
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200629 gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL);
Jens Axboe28db2562012-03-28 10:27:42 +0200630 if (o->def && !strcmp(o->def, "1"))
Jens Axboe9af4a242012-03-16 10:13:49 +0100631 defstate = 1;
632
Jens Axboed872fb42012-03-19 19:17:49 +0100633 if (o->neg)
634 defstate = !defstate;
635
Jens Axboe28db2562012-03-28 10:27:42 +0200636 if (val)
637 gopt_bool_set_val(b, *val);
638 else
639 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
Jens Axboe8f9e46a2012-03-19 22:01:20 +0100640 b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
Jens Axboe231edf62012-03-20 08:31:29 +0100641 g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b);
Jens Axboe9af4a242012-03-16 10:13:49 +0100642
643 gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
Jens Axboee8b0e952012-03-19 14:37:08 +0100644 gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
Jens Axboe9af4a242012-03-16 10:13:49 +0100645 return &b->gopt;
646}
647
Jens Axboe1da10c12012-03-16 19:41:01 +0100648/*
649 * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
650 * If the max is made smaller than min, adjust min down.
651 * If the min is made larger than max, adjust the max.
652 */
653static void range_value_changed(GtkSpinButton *spin, gpointer data)
654{
655 struct gopt_range *r = (struct gopt_range *) data;
656 int changed = -1, i;
657 gint val, mval;
658
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200659 gopt_changed(&r->gopt);
660
Jens Axboe1da10c12012-03-16 19:41:01 +0100661 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
662 if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
663 changed = i;
664 break;
665 }
666 }
667
668 assert(changed != -1);
669
670 /*
671 * Min changed
672 */
673 if (changed == 0 || changed == 2) {
674 GtkWidget *mspin = r->spins[changed + 1];
675
676 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
677 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
678 if (val > mval)
679 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
680 } else {
681 GtkWidget *mspin = r->spins[changed - 1];
682
683 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
684 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
685 if (val < mval)
686 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
687 }
688}
689
Jens Axboe231edf62012-03-20 08:31:29 +0100690static void gopt_range_destroy(GtkWidget *w, gpointer data)
691{
692 struct gopt_range *r = (struct gopt_range *) data;
693
Jens Axboec04942a2012-03-26 14:25:26 +0200694 free(r);
Jens Axboe231edf62012-03-20 08:31:29 +0100695 gtk_widget_destroy(w);
696}
697
Jens Axboe28db2562012-03-28 10:27:42 +0200698static void gopt_int_range_set_val(struct gopt_range *r, unsigned int *vals)
699{
700 int i;
701
702 for (i = 0; i < GOPT_RANGE_SPIN; i++)
703 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), vals[i]);
704}
705
Jens Axboe753e9e62012-03-24 20:22:29 +0100706static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv,
707 struct fio_option *o, unsigned int **ip,
Jens Axboeb6caa832012-03-16 21:22:56 +0100708 unsigned int idx)
Jens Axboe9af4a242012-03-16 10:13:49 +0100709{
710 struct gopt_range *r;
Jens Axboe9af4a242012-03-16 10:13:49 +0100711 GtkWidget *label;
Jens Axboe20eb06b2012-03-16 19:57:23 +0100712 guint interval;
Jens Axboe28db2562012-03-28 10:27:42 +0200713 unsigned int defvals[GOPT_RANGE_SPIN];
714 gint maxval;
Jens Axboe9af4a242012-03-16 10:13:49 +0100715 int i;
716
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200717 r = calloc(1, sizeof(*r));
Jens Axboe9af4a242012-03-16 10:13:49 +0100718 r->gopt.box = gtk_hbox_new(FALSE, 3);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200719 gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE);
Jens Axboee8b0e952012-03-19 14:37:08 +0100720 if (!o->lname)
721 label = gtk_label_new(o->name);
722 else
723 label = gtk_label_new(o->lname);
Jens Axboe9af4a242012-03-16 10:13:49 +0100724
725 maxval = o->maxval;
726 if (!maxval)
727 maxval = INT_MAX;
728
Jens Axboe28db2562012-03-28 10:27:42 +0200729 memset(defvals, 0, sizeof(defvals));
Jens Axboe9af4a242012-03-16 10:13:49 +0100730 if (o->def) {
731 long long val;
732
Jens Axboe83ea4222012-03-28 14:01:46 +0200733 check_str_bytes(o->def, &val, o);
Jens Axboe28db2562012-03-28 10:27:42 +0200734 for (i = 0; i < GOPT_RANGE_SPIN; i++)
735 defvals[i] = val;
Jens Axboe9af4a242012-03-16 10:13:49 +0100736 }
737
Jens Axboe20eb06b2012-03-16 19:57:23 +0100738 interval = 1.0;
739 if (o->interval)
740 interval = o->interval;
741
Jens Axboe1da10c12012-03-16 19:41:01 +0100742 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
Jens Axboe20eb06b2012-03-16 19:57:23 +0100743 r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
Jens Axboe9af4a242012-03-16 10:13:49 +0100744 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
Jens Axboe9af4a242012-03-16 10:13:49 +0100745 gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
746 }
747
Jens Axboe28db2562012-03-28 10:27:42 +0200748 if (ip)
749 gopt_int_range_set_val(r, *ip);
750 else
751 gopt_int_range_set_val(r, defvals);
752
753 for (i = 0; i < GOPT_RANGE_SPIN; i++)
754 g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
755
Jens Axboee8b0e952012-03-19 14:37:08 +0100756 gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
Jens Axboe231edf62012-03-20 08:31:29 +0100757 g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r);
Jens Axboe9af4a242012-03-16 10:13:49 +0100758 return &r->gopt;
759}
760
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100761static void gopt_str_val_destroy(GtkWidget *w, gpointer data)
762{
763 struct gopt_str_val *g = (struct gopt_str_val *) data;
764
Jens Axboec04942a2012-03-26 14:25:26 +0200765 free(g);
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100766 gtk_widget_destroy(w);
767}
768
769static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
770{
771 struct gopt_str_val *g = (struct gopt_str_val *) data;
772 unsigned int val;
773 GtkAdjustment *adj;
774 gint index;
775
776 adj = gtk_spin_button_get_adjustment(spin);
777 val = gtk_adjustment_get_value(adj);
778
779 /*
780 * Can't rely on exact value, as fast changes increment >= 1
781 */
782 if (!val) {
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100783 index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
Jens Axboe481c2422012-03-20 09:49:49 +0100784 if (index + 1 <= g->maxindex) {
785 val = 1;
786 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
787 } else
788 val = 1023;
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100789 gtk_spin_button_set_value(spin, val);
790 } else {
791 index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
792 if (index) {
793 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), --index);
794 gtk_spin_button_set_value(spin, 1023);
795 } else
796 gtk_spin_button_set_value(spin, 0);
797 }
798}
799
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200800static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data)
801{
802 struct gopt_str_val *g = (struct gopt_str_val *) data;
803
804 gopt_changed(&g->gopt);
805}
806
Jens Axboe28db2562012-03-28 10:27:42 +0200807static void gopt_str_val_set_val(struct gopt_str_val *g, unsigned long long val)
808{
809 int i = 0;
810
811 do {
812 if (!val || (val % 1024))
813 break;
814
815 i++;
816 val /= 1024;
817 } while (1);
818
819 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val);
820 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i);
821}
822
Jens Axboe753e9e62012-03-24 20:22:29 +0100823static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv,
824 struct fio_option *o,
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100825 unsigned long long *p, unsigned int idx)
826{
827 struct gopt_str_val *g;
828 const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" };
829 GtkWidget *label;
830 int i;
831
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200832 g = calloc(1, sizeof(*g));
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100833 g->gopt.box = gtk_hbox_new(FALSE, 3);
834 if (!o->lname)
835 label = gtk_label_new(o->name);
836 else
837 label = gtk_label_new(o->lname);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200838 gopt_mark_index(gjv, &g->gopt, idx, GOPT_STR_VAL);
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100839
840 g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0);
841 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID);
842 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), 0);
843 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(g->spin), 1);
844 gtk_box_pack_start(GTK_BOX(g->gopt.box), g->spin, FALSE, FALSE, 0);
845 g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200846 g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g);
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100847
Jens Axboef762cef2012-03-26 13:51:11 +0200848 g->combo = gtk_combo_box_text_new();
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100849 i = 0;
850 while (strlen(postfix[i])) {
Jens Axboef762cef2012-03-26 13:51:11 +0200851 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]);
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100852 i++;
853 }
Jens Axboe481c2422012-03-20 09:49:49 +0100854 g->maxindex = i - 1;
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100855 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
856 gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0);
857 gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3);
858
Jens Axboe28db2562012-03-28 10:27:42 +0200859 if (p)
860 gopt_str_val_set_val(g, *p);
Jens Axboea3fc0ff2012-03-26 12:18:23 +0200861
862 g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g);
863
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100864 g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
Jens Axboe7fc35ff2012-03-20 09:32:35 +0100865 return &g->gopt;
866}
867
Jens Axboe28db2562012-03-28 10:27:42 +0200868static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
869 struct gopt *gopt, struct thread_options *to)
870{
871 switch (o->type) {
872 case FIO_OPT_STR_VAL: {
873 unsigned long long *ullp = NULL;
874 struct gopt_str_val *g;
875
876 if (o->off1)
877 ullp = td_var(to, o->off1);
878
879 g = container_of(gopt, struct gopt_str_val, gopt);
880 if (ullp)
881 gopt_str_val_set_val(g, *ullp);
882 break;
883 }
884 case FIO_OPT_STR_VAL_TIME: {
885 unsigned long long *ullp = NULL;
886 struct gopt_int *i;
887
888 if (o->off1)
889 ullp = td_var(to, o->off1);
890
891 i = container_of(gopt, struct gopt_int, gopt);
892 if (ullp)
893 gopt_int_set_val(i, *ullp);
894 break;
895 }
Jens Axboec27d66b2013-04-09 20:49:34 +0200896 case FIO_OPT_INT:
897 if (o->posval[0].ival) {
898 unsigned int *ip = NULL;
899 struct gopt_combo *c;
Jens Axboe28db2562012-03-28 10:27:42 +0200900
Jens Axboec27d66b2013-04-09 20:49:34 +0200901 if (o->off1)
902 ip = td_var(to, o->off1);
Jens Axboe28db2562012-03-28 10:27:42 +0200903
Jens Axboec27d66b2013-04-09 20:49:34 +0200904 c = container_of(gopt, struct gopt_combo, gopt);
905 if (ip)
906 gopt_combo_int_set_val(c, *ip);
907 } else {
908 unsigned int *ip = NULL;
909 struct gopt_int *i;
910
911 if (o->off1)
912 ip = td_var(to, o->off1);
913
914 i = container_of(gopt, struct gopt_int, gopt);
915 if (ip)
916 gopt_int_set_val(i, *ip);
Jens Axboe28db2562012-03-28 10:27:42 +0200917 }
Jens Axboec27d66b2013-04-09 20:49:34 +0200918 break;
Jens Axboe28db2562012-03-28 10:27:42 +0200919 case FIO_OPT_STR_SET:
920 case FIO_OPT_BOOL: {
921 unsigned int *ip = NULL;
922 struct gopt_bool *b;
923
924 if (o->off1)
925 ip = td_var(to, o->off1);
926
927 b = container_of(gopt, struct gopt_bool, gopt);
928 if (ip)
929 gopt_bool_set_val(b, *ip);
930 break;
931 }
932 case FIO_OPT_STR: {
933 if (o->posval[0].ival) {
934 unsigned int *ip = NULL;
935 struct gopt_combo *c;
936
937 if (o->off1)
938 ip = td_var(to, o->off1);
939
940 c = container_of(gopt, struct gopt_combo, gopt);
941 if (ip)
942 gopt_combo_int_set_val(c, *ip);
943 } else {
944 struct gopt_str *s;
945 char *text = NULL;
946
947 if (o->off1) {
948 char **p = td_var(to, o->off1);
949
950 text = *p;
951 }
952
953 s = container_of(gopt, struct gopt_str, gopt);
954 gopt_str_store_set_val(s, text);
955 }
956
957 break;
958 }
959 case FIO_OPT_STR_STORE: {
960 struct gopt_combo *c;
961 char *text = NULL;
962
963 if (o->off1) {
964 char **p = td_var(to, o->off1);
965 text = *p;
966 }
967
968 if (!o->posval[0].ival) {
969 struct gopt_str *s;
970
971 s = container_of(gopt, struct gopt_str, gopt);
972 gopt_str_store_set_val(s, text);
973 break;
974 }
975
976 c = container_of(gopt, struct gopt_combo, gopt);
977 if (text)
978 gopt_combo_str_set_val(c, text);
979 break;
980 }
981 case FIO_OPT_STR_MULTI:
982 /* HANDLE ME */
983 break;
984 case FIO_OPT_RANGE: {
985 struct gopt_range *r;
986 unsigned int *ip[4] = { td_var(to, o->off1),
987 td_var(to, o->off2),
988 td_var(to, o->off3),
989 td_var(to, o->off4) };
990
991 r = container_of(gopt, struct gopt_range, gopt);
992 gopt_int_range_set_val(r, *ip);
993 break;
994 }
995 /* still need to handle this one */
996 case FIO_OPT_FLOAT_LIST:
997 break;
998 case FIO_OPT_DEPRECATED:
999 break;
1000 default:
1001 printf("ignore type %u\n", o->type);
1002 break;
1003 }
1004}
1005
Jens Axboe753e9e62012-03-24 20:22:29 +01001006static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
1007 struct fio_option *o, unsigned int opt_index,
1008 struct thread_options *to)
Jens Axboe9af4a242012-03-16 10:13:49 +01001009{
1010 struct gopt *go = NULL;
1011
1012 switch (o->type) {
Jens Axboe7fc35ff2012-03-20 09:32:35 +01001013 case FIO_OPT_STR_VAL: {
1014 unsigned long long *ullp = NULL;
1015
1016 if (o->off1)
1017 ullp = td_var(to, o->off1);
1018
Jens Axboe753e9e62012-03-24 20:22:29 +01001019 go = gopt_new_str_val(gjv, o, ullp, opt_index);
Jens Axboe7fc35ff2012-03-20 09:32:35 +01001020 break;
1021 }
Jens Axboe39f04332012-03-16 16:34:06 +01001022 case FIO_OPT_STR_VAL_TIME: {
1023 unsigned long long *ullp = NULL;
Jens Axboe789f4cc2012-03-16 14:56:44 +01001024
Jens Axboe39f04332012-03-16 16:34:06 +01001025 if (o->off1)
1026 ullp = td_var(to, o->off1);
1027
Jens Axboe753e9e62012-03-24 20:22:29 +01001028 go = gopt_new_ullong(gjv, o, ullp, opt_index);
Jens Axboe9af4a242012-03-16 10:13:49 +01001029 break;
Jens Axboe789f4cc2012-03-16 14:56:44 +01001030 }
Jens Axboec27d66b2013-04-09 20:49:34 +02001031 case FIO_OPT_INT:
1032 if (o->posval[0].ival) {
1033 unsigned int *ip = NULL;
Jens Axboe39f04332012-03-16 16:34:06 +01001034
Jens Axboec27d66b2013-04-09 20:49:34 +02001035 if (o->off1)
1036 ip = td_var(to, o->off1);
Jens Axboe39f04332012-03-16 16:34:06 +01001037
Jens Axboec27d66b2013-04-09 20:49:34 +02001038 go = gopt_new_combo_int(gjv, o, ip, opt_index);
1039 } else {
1040 unsigned int *ip = NULL;
1041
1042 if (o->off1)
1043 ip = td_var(to, o->off1);
1044
1045 go = gopt_new_int(gjv, o, ip, opt_index);
Jens Axboe39f04332012-03-16 16:34:06 +01001046 }
Jens Axboec27d66b2013-04-09 20:49:34 +02001047 break;
Jens Axboe9af4a242012-03-16 10:13:49 +01001048 case FIO_OPT_STR_SET:
Jens Axboe39f04332012-03-16 16:34:06 +01001049 case FIO_OPT_BOOL: {
1050 unsigned int *ip = NULL;
1051
1052 if (o->off1)
1053 ip = td_var(to, o->off1);
1054
Jens Axboe753e9e62012-03-24 20:22:29 +01001055 go = gopt_new_bool(gjv, o, ip, opt_index);
Jens Axboe9af4a242012-03-16 10:13:49 +01001056 break;
Jens Axboe39f04332012-03-16 16:34:06 +01001057 }
1058 case FIO_OPT_STR: {
Jens Axboed872fb42012-03-19 19:17:49 +01001059 if (o->posval[0].ival) {
1060 unsigned int *ip = NULL;
Jens Axboe39f04332012-03-16 16:34:06 +01001061
Jens Axboed872fb42012-03-19 19:17:49 +01001062 if (o->off1)
1063 ip = td_var(to, o->off1);
Jens Axboe39f04332012-03-16 16:34:06 +01001064
Jens Axboe753e9e62012-03-24 20:22:29 +01001065 go = gopt_new_combo_int(gjv, o, ip, opt_index);
Jens Axboed872fb42012-03-19 19:17:49 +01001066 } else {
1067 /* TODO: usually ->cb, or unsigned int pointer */
Jens Axboe753e9e62012-03-24 20:22:29 +01001068 go = gopt_new_str_store(gjv, o, NULL, opt_index);
Jens Axboed872fb42012-03-19 19:17:49 +01001069 }
1070
Jens Axboe39f04332012-03-16 16:34:06 +01001071 break;
1072 }
1073 case FIO_OPT_STR_STORE: {
1074 char *text = NULL;
1075
Jens Axboed3944492012-03-16 18:53:32 +01001076 if (o->off1) {
Jens Axboe39f04332012-03-16 16:34:06 +01001077 char **p = td_var(to, o->off1);
1078 text = *p;
1079 }
1080
Jens Axboe9af4a242012-03-16 10:13:49 +01001081 if (!o->posval[0].ival) {
Jens Axboe753e9e62012-03-24 20:22:29 +01001082 go = gopt_new_str_store(gjv, o, text, opt_index);
Jens Axboe9af4a242012-03-16 10:13:49 +01001083 break;
1084 }
Jens Axboe39f04332012-03-16 16:34:06 +01001085
Jens Axboe753e9e62012-03-24 20:22:29 +01001086 go = gopt_new_combo_str(gjv, o, text, opt_index);
Jens Axboe39f04332012-03-16 16:34:06 +01001087 break;
1088 }
Jens Axboe9af4a242012-03-16 10:13:49 +01001089 case FIO_OPT_STR_MULTI:
Jens Axboe753e9e62012-03-24 20:22:29 +01001090 go = gopt_new_str_multi(gjv, o, opt_index);
Jens Axboe9af4a242012-03-16 10:13:49 +01001091 break;
Jens Axboe39f04332012-03-16 16:34:06 +01001092 case FIO_OPT_RANGE: {
1093 unsigned int *ip[4] = { td_var(to, o->off1),
1094 td_var(to, o->off2),
1095 td_var(to, o->off3),
1096 td_var(to, o->off4) };
1097
Jens Axboe753e9e62012-03-24 20:22:29 +01001098 go = gopt_new_int_range(gjv, o, ip, opt_index);
Jens Axboe9af4a242012-03-16 10:13:49 +01001099 break;
Jens Axboe39f04332012-03-16 16:34:06 +01001100 }
Jens Axboe9af4a242012-03-16 10:13:49 +01001101 /* still need to handle this one */
1102 case FIO_OPT_FLOAT_LIST:
1103 break;
1104 case FIO_OPT_DEPRECATED:
1105 break;
1106 default:
1107 printf("ignore type %u\n", o->type);
1108 break;
1109 }
1110
1111 if (go) {
Jens Axboee8b0e952012-03-19 14:37:08 +01001112 GtkWidget *dest;
1113
Jens Axboe9af4a242012-03-16 10:13:49 +01001114 if (o->help)
1115 gtk_widget_set_tooltip_text(go->box, o->help);
Jens Axboee8b0e952012-03-19 14:37:08 +01001116
Jens Axboec504ee52012-03-20 11:29:09 +01001117 o->gui_data = go;
Jens Axboee8b0e952012-03-19 14:37:08 +01001118
Jens Axboe753e9e62012-03-24 20:22:29 +01001119 dest = gopt_get_group_frame(gjv, hbox, o->group);
Jens Axboee8b0e952012-03-19 14:37:08 +01001120 if (!dest)
1121 gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
1122 else
1123 gtk_box_pack_start(GTK_BOX(dest), go->box, FALSE, FALSE, 5);
Jens Axboe9af4a242012-03-16 10:13:49 +01001124 }
1125}
1126
Jens Axboe753e9e62012-03-24 20:22:29 +01001127static void gopt_add_options(struct gopt_job_view *gjv,
1128 struct thread_options *to)
Jens Axboe9af4a242012-03-16 10:13:49 +01001129{
1130 GtkWidget *hbox = NULL;
1131 int i;
1132
Jens Axboe90265352012-03-19 20:29:44 +01001133 /*
1134 * First add all options
1135 */
Jens Axboe9af4a242012-03-16 10:13:49 +01001136 for (i = 0; fio_options[i].name; i++) {
1137 struct fio_option *o = &fio_options[i];
1138 unsigned int mask = o->category;
1139 struct opt_group *og;
Jens Axboe753e9e62012-03-24 20:22:29 +01001140
1141 while ((og = opt_group_from_mask(&mask)) != NULL) {
1142 GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)];
1143
1144 hbox = gtk_hbox_new(FALSE, 3);
1145 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
1146 gopt_add_option(gjv, hbox, o, i, to);
1147 }
1148 }
1149}
1150
Jens Axboe28db2562012-03-28 10:27:42 +02001151static void gopt_set_options(struct gopt_job_view *gjv,
1152 struct thread_options *to)
1153{
1154 int i;
1155
1156 for (i = 0; fio_options[i].name; i++) {
1157 struct fio_option *o = &fio_options[i];
1158 struct gopt *gopt = gjv->gopts[i];
1159
1160 gopt_set_option(gjv, o, gopt, to);
1161 }
1162}
1163
Jens Axboe753e9e62012-03-24 20:22:29 +01001164static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name)
1165{
1166 GtkWidget *box, *vbox, *scroll;
1167
1168 scroll = gtk_scrolled_window_new(NULL, NULL);
1169 gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
1170 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1171
1172 vbox = gtk_vbox_new(FALSE, 3);
1173 box = gtk_hbox_new(FALSE, 0);
1174 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
1175 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
1176 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(name));
1177 return vbox;
1178}
1179
1180static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
1181{
1182 return gopt_add_tab(notebook, og->name);
1183}
1184
1185static void gopt_add_group_tabs(GtkWidget *notebook, struct gopt_job_view *gjv)
1186{
1187 struct opt_group *og;
1188 unsigned int i;
1189
1190 i = 0;
1191 do {
1192 unsigned int mask = (1U << i);
1193
1194 og = opt_group_from_mask(&mask);
1195 if (!og)
1196 break;
1197 gjv->vboxes[i] = gopt_add_group_tab(notebook, og);
1198 i++;
1199 } while (1);
1200}
1201
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001202static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
1203 struct gopt_str_multi *m,
1204 struct fio_option *o)
1205{
1206 unsigned int *ip = td_var(gjv->o, o->off1);
Jens Axboe456fed92012-03-26 12:38:33 +02001207 struct value_pair *vp;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001208 gboolean set;
1209 guint val = 0;
1210 int i;
1211
1212 i = 0;
Jens Axboe456fed92012-03-26 12:38:33 +02001213 vp = &o->posval[0];
1214 while (vp->ival) {
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001215 if (!m->checks[i])
1216 break;
1217 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i]));
1218 if (set) {
Jens Axboe456fed92012-03-26 12:38:33 +02001219 if (vp->or)
1220 val |= vp->oval;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001221 else
Jens Axboe456fed92012-03-26 12:38:33 +02001222 val = vp->oval;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001223 }
1224 i++;
Jens Axboe456fed92012-03-26 12:38:33 +02001225 vp++;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001226 }
1227
1228 if (o->off1)
1229 *ip = val;
1230}
1231
1232static void gopt_handle_range_changed(struct gopt_job_view *gjv,
1233 struct gopt_range *r,
1234 struct fio_option *o)
1235{
1236 unsigned int *ip[4] = { td_var(gjv->o, o->off1),
1237 td_var(gjv->o, o->off2),
1238 td_var(gjv->o, o->off3),
1239 td_var(gjv->o, o->off4) };
1240 gint val;
1241 int i;
1242
1243 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
1244 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[i]));
1245 *ip[i] = val;
1246 }
1247}
1248
1249static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
1250 struct gopt_str_val *s,
1251 struct fio_option *o)
1252{
1253 unsigned long long *ullp = td_var(gjv->o, o->off1);
1254 GtkAdjustment *adj;
1255 gint index;
1256
1257 if (!ullp)
1258 return;
1259
1260 /*
1261 * Numerical value
1262 */
1263 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(s->spin));
1264 *ullp = gtk_adjustment_get_value(adj);
1265
1266 /*
1267 * Multiplier
1268 */
1269 index = gtk_combo_box_get_active(GTK_COMBO_BOX(s->combo));
1270 while (index--)
1271 *ullp *= 1024ULL;
1272}
1273
1274static void gopt_handle_str_changed(struct gopt_job_view *gjv,
1275 struct gopt_str *s, struct fio_option *o)
1276{
1277 char **p = td_var(gjv->o, o->off1);
1278
1279 if (*p)
1280 free(*p);
1281
1282 *p = strdup(gtk_entry_get_text(GTK_ENTRY(s->entry)));
1283}
1284
1285static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
1286 struct gopt_bool *b, struct fio_option *o)
1287{
1288 unsigned int *ip = td_var(gjv->o, o->off1);
1289 gboolean set;
1290
1291 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
1292 *ip = set;
1293}
1294
1295static void gopt_handle_int_changed(struct gopt_job_view *gjv,
1296 struct gopt_int *i, struct fio_option *o)
1297{
1298 unsigned int *ip = td_var(gjv->o, o->off1);
1299 GtkAdjustment *adj;
1300 guint val;
1301
1302 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(i->spin));
1303 val = gtk_adjustment_get_value(adj);
1304 *ip = val;
1305}
1306
1307static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv,
1308 struct gopt_combo *c,
1309 struct fio_option *o)
1310{
1311 char **p = td_var(gjv->o, o->off1);
1312
1313 if (*p)
1314 free(*p);
1315
Jens Axboef762cef2012-03-26 13:51:11 +02001316 *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo)));
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001317}
1318
1319static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv,
1320 struct gopt_combo *c,
1321 struct fio_option *o)
1322{
1323 unsigned int *ip = td_var(gjv->o, o->off1);
1324 gint index;
1325
1326 index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
1327 *ip = o->posval[index].oval;
1328}
1329
1330static void gopt_handle_changed(struct gopt *gopt)
1331{
1332 struct fio_option *o = &fio_options[gopt->opt_index];
1333 struct gopt_job_view *gjv = gopt->gjv;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001334
1335 switch (gopt->opt_type) {
1336 case GOPT_COMBO_INT: {
1337 struct gopt_combo *c;
1338
1339 c = container_of(gopt, struct gopt_combo, gopt);
1340 gopt_handle_combo_int_changed(gjv, c, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001341 break;
1342 }
1343 case GOPT_COMBO_STR: {
1344 struct gopt_combo *c;
1345
1346 c = container_of(gopt, struct gopt_combo, gopt);
1347 gopt_handle_combo_str_changed(gjv, c, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001348 break;
1349 }
1350 case GOPT_INT: {
1351 struct gopt_int *i;
1352
1353 i = container_of(gopt, struct gopt_int, gopt);
1354 gopt_handle_int_changed(gjv, i, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001355 break;
1356 }
1357 case GOPT_BOOL: {
1358 struct gopt_bool *b;
1359
1360 b = container_of(gopt, struct gopt_bool, gopt);
1361 gopt_handle_bool_changed(gjv, b, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001362 break;
1363 }
1364 case GOPT_STR: {
1365 struct gopt_str *s;
1366
1367 s = container_of(gopt, struct gopt_str, gopt);
1368 gopt_handle_str_changed(gjv, s, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001369 break;
1370 }
1371 case GOPT_STR_VAL: {
1372 struct gopt_str_val *s;
1373
1374 s = container_of(gopt, struct gopt_str_val, gopt);
1375 gopt_handle_str_val_changed(gjv, s, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001376 break;
1377 }
1378 case GOPT_RANGE: {
1379 struct gopt_range *r;
1380
1381 r = container_of(gopt, struct gopt_range, gopt);
1382 gopt_handle_range_changed(gjv, r, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001383 break;
1384 }
1385 case GOPT_STR_MULTI: {
1386 struct gopt_str_multi *m;
1387
1388 m = container_of(gopt, struct gopt_str_multi, gopt);
1389 gopt_handle_str_multi_changed(gjv, m, o);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001390 break;
1391 }
1392 default:
Jens Axboecf7cade2013-04-16 21:10:46 +02001393 log_err("gfio: bad option type: %d\n", gopt->opt_type);
1394 break;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001395 }
Jens Axboe28db2562012-03-28 10:27:42 +02001396}
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001397
Jens Axboe28db2562012-03-28 10:27:42 +02001398static void gopt_report_update_status(struct gopt_job_view *gjv)
1399{
1400 struct gfio_client *gc = gjv->client;
1401 char tmp[80];
1402
1403 sprintf(tmp, "\nCompleted with error: %d\n", gc->update_job_status);
1404 gfio_report_info(gc->ge->ui, "Update job", tmp);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001405}
1406
Jens Axboe40c60512012-03-27 16:03:04 +02001407static int gopt_handle_changed_options(struct gopt_job_view *gjv)
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001408{
Jens Axboe40c60512012-03-27 16:03:04 +02001409 struct gfio_client *gc = gjv->client;
Jens Axboe28db2562012-03-28 10:27:42 +02001410 struct flist_head *entry;
Jens Axboe40c60512012-03-27 16:03:04 +02001411 uint64_t waitid = 0;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001412 struct gopt *gopt;
Jens Axboe40c60512012-03-27 16:03:04 +02001413 int ret;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001414
Jens Axboe28db2562012-03-28 10:27:42 +02001415 flist_for_each(entry, &gjv->changed_list) {
1416 gopt = flist_entry(entry, struct gopt, changed_list);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001417 gopt_handle_changed(gopt);
1418 }
Jens Axboe40c60512012-03-27 16:03:04 +02001419
Jens Axboe28db2562012-03-28 10:27:42 +02001420 gc->update_job_status = 0;
1421 gc->update_job_done = 0;
Jens Axboe40c60512012-03-27 16:03:04 +02001422
1423 ret = fio_client_update_options(gc->client, gjv->o, &waitid);
1424 if (ret)
Jens Axboe28db2562012-03-28 10:27:42 +02001425 goto done;
Jens Axboe40c60512012-03-27 16:03:04 +02001426
Jens Axboe28db2562012-03-28 10:27:42 +02001427 ret = fio_client_wait_for_reply(gc->client, waitid);
1428 if (ret)
1429 goto done;
1430
1431 assert(gc->update_job_done);
1432 if (gc->update_job_status)
1433 goto done;
1434
1435 while (!flist_empty(&gjv->changed_list)) {
1436 gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list);
1437 flist_del_init(&gopt->changed_list);
1438 }
1439
1440done:
1441 gopt_dialog_update_apply_button(gjv);
1442 return ret;
Jens Axboe40c60512012-03-27 16:03:04 +02001443}
1444
1445static gint gopt_dialog_cancel(gint response)
1446{
1447 switch (response) {
1448 case GTK_RESPONSE_NONE:
1449 case GTK_RESPONSE_REJECT:
1450 case GTK_RESPONSE_DELETE_EVENT:
1451 case GTK_RESPONSE_CANCEL:
1452 case GTK_RESPONSE_NO:
1453 return 1;
1454 default:
1455 return 0;
1456 }
1457}
1458
1459static gint gopt_dialog_done(gint response)
1460{
1461 switch (response) {
1462 case GTK_RESPONSE_ACCEPT:
1463 case GTK_RESPONSE_OK:
1464 case GTK_RESPONSE_YES:
1465 return 1;
1466 default:
1467 return 0;
1468 }
1469}
1470
Jens Axboe28db2562012-03-28 10:27:42 +02001471static void gopt_handle_option_dialog(struct gopt_job_view *gjv)
Jens Axboe40c60512012-03-27 16:03:04 +02001472{
Jens Axboe40c60512012-03-27 16:03:04 +02001473 gint response;
1474
1475 do {
Jens Axboe28db2562012-03-28 10:27:42 +02001476 response = gtk_dialog_run(GTK_DIALOG(gjv->dialog));
1477
1478 if (gopt_dialog_cancel(response) ||
1479 gopt_dialog_done(response))
Jens Axboe40c60512012-03-27 16:03:04 +02001480 break;
1481
Jens Axboe28db2562012-03-28 10:27:42 +02001482 /*
1483 * Apply
1484 */
1485 gopt_handle_changed_options(gjv);
1486 gopt_report_update_status(gjv);
Jens Axboe40c60512012-03-27 16:03:04 +02001487 } while (1);
1488
1489 if (gopt_dialog_cancel(response))
1490 return;
1491
Jens Axboe28db2562012-03-28 10:27:42 +02001492 gopt_handle_changed_options(gjv);
1493}
Jens Axboe40c60512012-03-27 16:03:04 +02001494
Jens Axboe28db2562012-03-28 10:27:42 +02001495static void gopt_job_changed(GtkComboBox *box, gpointer data)
1496{
1497 struct gopt_job_view *gjv = (struct gopt_job_view *) data;
1498 struct gfio_client_options *gco = NULL;
1499 struct gfio_client *gc = gjv->client;
1500 struct flist_head *entry;
1501 gchar *job;
Jens Axboe40c60512012-03-27 16:03:04 +02001502
Jens Axboe28db2562012-03-28 10:27:42 +02001503 /*
1504 * The switch act should be sensitized appropriately, so that we
1505 * never get here with modified options.
1506 */
1507 if (!flist_empty(&gjv->changed_list)) {
1508 gfio_report_info(gc->ge->ui, "Internal Error", "Modified options on job switch.\nThat should not be possible!\n");
1509 return;
Jens Axboe40c60512012-03-27 16:03:04 +02001510 }
Jens Axboe28db2562012-03-28 10:27:42 +02001511
1512 job = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(gjv->job_combo));
1513 flist_for_each(entry, &gc->o_list) {
1514 const char *name;
1515
1516 gco = flist_entry(entry, struct gfio_client_options, list);
1517 name = gco->o.name;
1518 if (!name || !strlen(name))
1519 name = "Default job";
1520
1521 if (!strcmp(name, job))
1522 break;
1523
1524 gco = NULL;
1525 }
1526
1527 if (!gco) {
1528 gfio_report_info(gc->ge->ui, "Internal Error", "Could not find job description.\nThat should not be possible!\n");
1529 return;
1530 }
1531
1532 gjv->in_job_switch = 1;
1533 gopt_set_options(gjv, &gco->o);
1534 gjv->in_job_switch = 0;
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001535}
1536
Jens Axboe753e9e62012-03-24 20:22:29 +01001537void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc)
1538{
Jens Axboe28db2562012-03-28 10:27:42 +02001539 GtkWidget *dialog, *notebook, *vbox, *topvbox, *combo;
Jens Axboe753e9e62012-03-24 20:22:29 +01001540 struct gfio_client_options *gco;
Jens Axboe753e9e62012-03-24 20:22:29 +01001541 struct flist_head *entry;
1542 struct gopt_job_view *gjv;
Jens Axboe753e9e62012-03-24 20:22:29 +01001543
1544 dialog = gtk_dialog_new_with_buttons("Fio options",
1545 GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
1546 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
Jens Axboe40c60512012-03-27 16:03:04 +02001547 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
Jens Axboe753e9e62012-03-24 20:22:29 +01001548 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
1549
Jens Axboe28db2562012-03-28 10:27:42 +02001550 combo = gtk_combo_box_text_new();
Jens Axboe753e9e62012-03-24 20:22:29 +01001551 flist_for_each(entry, &gc->o_list) {
Jens Axboe28db2562012-03-28 10:27:42 +02001552 struct thread_options *o;
Jens Axboe753e9e62012-03-24 20:22:29 +01001553 const char *name;
1554
1555 gco = flist_entry(entry, struct gfio_client_options, list);
1556 o = &gco->o;
1557 name = o->name;
1558 if (!name || !strlen(name))
1559 name = "Default job";
1560
Jens Axboe28db2562012-03-28 10:27:42 +02001561 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), name);
Jens Axboe753e9e62012-03-24 20:22:29 +01001562 }
Jens Axboe28db2562012-03-28 10:27:42 +02001563 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
1564
1565 gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768);
1566
1567 topvbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1568 gtk_box_pack_start(GTK_BOX(topvbox), combo, FALSE, FALSE, 5);
1569
1570 vbox = gtk_vbox_new(TRUE, 5);
1571 gtk_box_pack_start(GTK_BOX(topvbox), vbox, TRUE, TRUE, 5);
1572
1573 notebook = gtk_notebook_new();
1574 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
1575 gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
1576 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5);
1577
1578 gjv = calloc(1, sizeof(*gjv));
1579 INIT_FLIST_HEAD(&gjv->changed_list);
1580 gco = flist_entry(gc->o_list.next, struct gfio_client_options, list);
1581 gjv->o = &gco->o;
1582 gjv->dialog = dialog;
1583 gjv->client = gc;
1584 gjv->job_combo = combo;
1585 gopt_add_group_tabs(notebook, gjv);
1586 gopt_add_options(gjv, &gco->o);
1587 gopt_dialog_update_apply_button(gjv);
1588
1589 g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(gopt_job_changed), gjv);
Jens Axboe753e9e62012-03-24 20:22:29 +01001590
1591 gtk_widget_show_all(dialog);
1592
Jens Axboe28db2562012-03-28 10:27:42 +02001593 gopt_handle_option_dialog(gjv);
Jens Axboea3fc0ff2012-03-26 12:18:23 +02001594
1595 gtk_widget_destroy(dialog);
Jens Axboe28db2562012-03-28 10:27:42 +02001596 free(gjv);
Jens Axboe753e9e62012-03-24 20:22:29 +01001597}
1598
1599/*
1600 * Build n-ary option dependency tree
1601 */
1602void gopt_init(void)
1603{
1604 int i;
1605
1606 gopt_dep_tree = g_node_new(NULL);
1607
1608 for (i = 0; fio_options[i].name; i++) {
1609 struct fio_option *o = &fio_options[i];
Jens Axboec504ee52012-03-20 11:29:09 +01001610 GNode *node, *nparent;
1611
1612 /*
1613 * Insert node with either the root parent, or an
1614 * option parent.
1615 */
1616 node = g_node_new(o);
1617 nparent = gopt_dep_tree;
1618 if (o->parent) {
1619 struct fio_option *parent;
1620
1621 parent = fio_option_find(o->parent);
1622 nparent = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
1623 if (!nparent) {
1624 log_err("fio: did not find parent %s for opt %s\n", o->name, o->parent);
1625 nparent = gopt_dep_tree;
1626 }
1627 }
1628
1629 g_node_insert(nparent, -1, node);
Jens Axboe9af4a242012-03-16 10:13:49 +01001630 }
1631}
1632
Jens Axboe753e9e62012-03-24 20:22:29 +01001633void gopt_exit(void)
Jens Axboe9af4a242012-03-16 10:13:49 +01001634{
Jens Axboec504ee52012-03-20 11:29:09 +01001635 g_node_destroy(gopt_dep_tree);
1636 gopt_dep_tree = NULL;
Jens Axboe9af4a242012-03-16 10:13:49 +01001637}