Commit | Line | Data |
---|---|---|
9af4a244 JA |
1 | #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" | |
12 | #include "parse.h" | |
13 | ||
14 | struct gopt { | |
15 | GtkWidget *box; | |
16 | unsigned int opt_index; | |
17 | unsigned int opt_type; | |
8f9e46ab | 18 | gulong sig_handler; |
753e9e64 | 19 | struct gopt_job_view *gjv; |
a3fc0ff4 | 20 | struct flist_head changed_list; |
9af4a244 JA |
21 | }; |
22 | ||
23 | struct gopt_combo { | |
24 | struct gopt gopt; | |
25 | GtkWidget *combo; | |
26 | }; | |
27 | ||
28 | struct gopt_int { | |
29 | struct gopt gopt; | |
90265353 | 30 | unsigned int lastval; |
9af4a244 JA |
31 | GtkWidget *spin; |
32 | }; | |
33 | ||
34 | struct gopt_bool { | |
35 | struct gopt gopt; | |
36 | GtkWidget *check; | |
37 | }; | |
38 | ||
39 | struct gopt_str { | |
40 | struct gopt gopt; | |
41 | GtkWidget *entry; | |
42 | }; | |
43 | ||
7fc35ff7 JA |
44 | struct gopt_str_val { |
45 | struct gopt gopt; | |
46 | GtkWidget *spin; | |
47 | GtkWidget *combo; | |
481c242b | 48 | unsigned int maxindex; |
7fc35ff7 JA |
49 | }; |
50 | ||
1da10c19 JA |
51 | #define GOPT_RANGE_SPIN 4 |
52 | ||
9af4a244 JA |
53 | struct gopt_range { |
54 | struct gopt gopt; | |
1da10c19 | 55 | GtkWidget *spins[GOPT_RANGE_SPIN]; |
9af4a244 JA |
56 | }; |
57 | ||
7386d4ae JA |
58 | struct gopt_str_multi { |
59 | struct gopt gopt; | |
60 | GtkWidget *checks[PARSE_MAX_VP]; | |
61 | }; | |
62 | ||
a3fc0ff4 JA |
63 | enum { |
64 | GOPT_COMBO_INT = 1, | |
65 | GOPT_COMBO_STR, | |
66 | GOPT_INT, | |
67 | GOPT_BOOL, | |
68 | GOPT_STR, | |
69 | GOPT_STR_VAL, | |
70 | GOPT_RANGE, | |
71 | GOPT_STR_MULTI, | |
72 | }; | |
73 | ||
e8b0e958 JA |
74 | struct gopt_frame_widget { |
75 | GtkWidget *vbox[2]; | |
76 | unsigned int nr; | |
77 | }; | |
753e9e64 JA |
78 | |
79 | struct gopt_job_view { | |
80 | struct flist_head list; | |
81 | struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR]; | |
82 | GtkWidget *widgets[FIO_MAX_OPTS]; | |
83 | GtkWidget *vboxes[__FIO_OPT_C_NR]; | |
40c60516 JA |
84 | GtkWidget *dialog; |
85 | struct gfio_client *client; | |
a3fc0ff4 JA |
86 | struct flist_head changed_list; |
87 | struct thread_options *o; | |
753e9e64 | 88 | }; |
ec0218ff | 89 | |
c504ee55 JA |
90 | static GNode *gopt_dep_tree; |
91 | ||
753e9e64 JA |
92 | static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv, |
93 | GtkWidget *box, unsigned int groupmask) | |
ec0218ff | 94 | { |
e8b0e958 JA |
95 | unsigned int mask, group; |
96 | struct opt_group *og; | |
97 | GtkWidget *frame, *hbox; | |
98 | struct gopt_frame_widget *gfw; | |
99 | ||
100 | if (!groupmask) | |
101 | return 0; | |
102 | ||
103 | mask = groupmask; | |
104 | og = opt_group_cat_from_mask(&mask); | |
105 | if (!og) | |
106 | return NULL; | |
107 | ||
108 | group = ffz(~groupmask); | |
753e9e64 | 109 | gfw = &gjv->g_widgets[group]; |
e8b0e958 JA |
110 | if (!gfw->vbox[0]) { |
111 | frame = gtk_frame_new(og->name); | |
112 | gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3); | |
113 | hbox = gtk_hbox_new(FALSE, 0); | |
114 | gtk_container_add(GTK_CONTAINER(frame), hbox); | |
115 | gfw->vbox[0] = gtk_vbox_new(TRUE, 5); | |
116 | gfw->vbox[1] = gtk_vbox_new(TRUE, 5); | |
117 | gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5); | |
118 | gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5); | |
ec0218ff | 119 | } |
e8b0e958 JA |
120 | |
121 | hbox = gtk_hbox_new(FALSE, 3); | |
122 | gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5); | |
123 | return hbox; | |
ec0218ff | 124 | } |
b6caa836 JA |
125 | |
126 | /* | |
127 | * Mark children as invisible, if needed. | |
128 | */ | |
19921181 JA |
129 | static void gopt_set_children_visible(struct gopt_job_view *gjv, |
130 | struct fio_option *parent, | |
231edf61 | 131 | gboolean visible) |
b6caa836 | 132 | { |
c504ee55 | 133 | GNode *child, *node; |
b6caa836 | 134 | |
a4ed77fe JA |
135 | if (parent->hide_on_set) |
136 | visible = !visible; | |
137 | ||
c504ee55 JA |
138 | node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent); |
139 | child = g_node_first_child(node); | |
140 | while (child) { | |
141 | struct fio_option *o = child->data; | |
142 | struct gopt *g = o->gui_data; | |
b6caa836 | 143 | |
c504ee55 JA |
144 | /* |
145 | * Recurse into child, if it also has children | |
146 | */ | |
147 | if (g_node_n_children(child)) | |
19921181 | 148 | gopt_set_children_visible(gjv, o, visible); |
b6caa836 | 149 | |
753e9e64 JA |
150 | if (gjv->widgets[g->opt_index]) |
151 | gtk_widget_set_sensitive(gjv->widgets[g->opt_index], visible); | |
c504ee55 JA |
152 | |
153 | child = g_node_next_sibling(child); | |
b6caa836 JA |
154 | } |
155 | } | |
156 | ||
a3fc0ff4 JA |
157 | static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt, |
158 | unsigned int idx, int type) | |
159 | { | |
160 | INIT_FLIST_HEAD(&gopt->changed_list); | |
161 | g_object_ref(G_OBJECT(gopt->box)); | |
162 | ||
163 | assert(!gjv->widgets[idx]); | |
164 | gopt->opt_index = idx; | |
165 | gopt->opt_type = type; | |
166 | gopt->gjv = gjv; | |
167 | gjv->widgets[idx] = gopt->box; | |
168 | } | |
169 | ||
40c60516 JA |
170 | static void gopt_dialog_update_apply(struct gopt_job_view *gjv) |
171 | { | |
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); | |
177 | } | |
178 | ||
a3fc0ff4 JA |
179 | static void gopt_changed(struct gopt *gopt) |
180 | { | |
181 | struct gopt_job_view *gjv = gopt->gjv; | |
182 | ||
183 | /* | |
184 | * Add to changed list. This also prevents the option from being | |
185 | * freed when the widget is destroyed. | |
186 | */ | |
40c60516 | 187 | if (flist_empty(&gopt->changed_list)) { |
a3fc0ff4 | 188 | flist_add_tail(&gopt->changed_list, &gjv->changed_list); |
40c60516 JA |
189 | gopt_dialog_update_apply(gjv); |
190 | } | |
a3fc0ff4 JA |
191 | } |
192 | ||
b6caa836 JA |
193 | static void gopt_str_changed(GtkEntry *entry, gpointer data) |
194 | { | |
195 | struct gopt_str *s = (struct gopt_str *) data; | |
196 | struct fio_option *o = &fio_options[s->gopt.opt_index]; | |
197 | const gchar *text; | |
198 | int set; | |
199 | ||
a3fc0ff4 JA |
200 | gopt_changed(&s->gopt); |
201 | ||
b6caa836 JA |
202 | text = gtk_entry_get_text(GTK_ENTRY(s->entry)); |
203 | set = strcmp(text, "") != 0; | |
19921181 JA |
204 | |
205 | gopt_set_children_visible(s->gopt.gjv, o, set); | |
b6caa836 JA |
206 | } |
207 | ||
231edf61 JA |
208 | static void gopt_str_destroy(GtkWidget *w, gpointer data) |
209 | { | |
210 | struct gopt_str *s = (struct gopt_str *) data; | |
211 | ||
c04942a2 | 212 | free(s); |
231edf61 JA |
213 | gtk_widget_destroy(w); |
214 | } | |
215 | ||
753e9e64 JA |
216 | static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv, |
217 | struct fio_option *o, const char *text, | |
231edf61 | 218 | unsigned int idx) |
9af4a244 JA |
219 | { |
220 | struct gopt_str *s; | |
221 | GtkWidget *label; | |
222 | ||
a3fc0ff4 | 223 | s = calloc(1, sizeof(*s)); |
9af4a244 JA |
224 | |
225 | s->gopt.box = gtk_hbox_new(FALSE, 3); | |
e8b0e958 JA |
226 | if (!o->lname) |
227 | label = gtk_label_new(o->name); | |
228 | else | |
229 | label = gtk_label_new(o->lname); | |
9af4a244 JA |
230 | |
231 | s->entry = gtk_entry_new(); | |
a3fc0ff4 | 232 | gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR); |
789f4ccd JA |
233 | if (text) |
234 | gtk_entry_set_text(GTK_ENTRY(s->entry), text); | |
f762cef9 | 235 | gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1); |
9af4a244 JA |
236 | |
237 | if (o->def) | |
238 | gtk_entry_set_text(GTK_ENTRY(s->entry), o->def); | |
239 | ||
a3fc0ff4 JA |
240 | s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s); |
241 | g_signal_connect(G_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s); | |
4fbcd659 | 242 | |
9af4a244 | 243 | gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0); |
e8b0e958 | 244 | gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0); |
9af4a244 JA |
245 | return &s->gopt; |
246 | } | |
247 | ||
b6caa836 | 248 | static void gopt_combo_changed(GtkComboBox *box, gpointer data) |
9af4a244 | 249 | { |
b6caa836 JA |
250 | struct gopt_combo *c = (struct gopt_combo *) data; |
251 | struct fio_option *o = &fio_options[c->gopt.opt_index]; | |
b2452a43 | 252 | unsigned int index; |
b6caa836 | 253 | |
a3fc0ff4 JA |
254 | gopt_changed(&c->gopt); |
255 | ||
b2452a43 | 256 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo)); |
19921181 JA |
257 | |
258 | gopt_set_children_visible(c->gopt.gjv, o, index); | |
b6caa836 JA |
259 | } |
260 | ||
231edf61 JA |
261 | static void gopt_combo_destroy(GtkWidget *w, gpointer data) |
262 | { | |
263 | struct gopt_combo *c = (struct gopt_combo *) data; | |
264 | ||
c04942a2 | 265 | free(c); |
231edf61 JA |
266 | gtk_widget_destroy(w); |
267 | } | |
268 | ||
753e9e64 JA |
269 | static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv, |
270 | struct fio_option *o, | |
a3fc0ff4 | 271 | unsigned int idx, int type) |
b6caa836 JA |
272 | { |
273 | struct gopt_combo *c; | |
9af4a244 | 274 | GtkWidget *label; |
9af4a244 | 275 | |
a3fc0ff4 | 276 | c = calloc(1, sizeof(*c)); |
9af4a244 | 277 | |
b6caa836 | 278 | c->gopt.box = gtk_hbox_new(FALSE, 3); |
e8b0e958 JA |
279 | if (!o->lname) |
280 | label = gtk_label_new(o->name); | |
281 | else | |
282 | label = gtk_label_new(o->lname); | |
9af4a244 | 283 | |
f762cef9 | 284 | c->combo = gtk_combo_box_text_new(); |
a3fc0ff4 JA |
285 | gopt_mark_index(gjv, &c->gopt, idx, type); |
286 | g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c); | |
b6caa836 | 287 | |
e8b0e958 JA |
288 | gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0); |
289 | gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0); | |
290 | ||
b6caa836 | 291 | return c; |
39f04336 JA |
292 | } |
293 | ||
753e9e64 JA |
294 | static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv, |
295 | struct fio_option *o, const char *text, | |
231edf61 | 296 | unsigned int idx) |
39f04336 | 297 | { |
4fbcd659 | 298 | struct gopt_combo *c; |
39f04336 JA |
299 | struct value_pair *vp; |
300 | int i, active = 0; | |
301 | ||
a3fc0ff4 | 302 | c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR); |
39f04336 | 303 | |
9af4a244 JA |
304 | i = 0; |
305 | vp = &o->posval[0]; | |
306 | while (vp->ival) { | |
f762cef9 | 307 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); |
9af4a244 JA |
308 | if (o->def && !strcmp(vp->ival, o->def)) |
309 | active = i; | |
39f04336 JA |
310 | if (text && !strcmp(vp->ival, text)) |
311 | active = i; | |
9af4a244 JA |
312 | vp++; |
313 | i++; | |
314 | } | |
315 | ||
4fbcd659 | 316 | gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); |
a3fc0ff4 | 317 | c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); |
4fbcd659 | 318 | return &c->gopt; |
9af4a244 JA |
319 | } |
320 | ||
753e9e64 JA |
321 | static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv, |
322 | struct fio_option *o, unsigned int *ip, | |
231edf61 | 323 | unsigned int idx) |
9af4a244 | 324 | { |
4fbcd659 | 325 | struct gopt_combo *c; |
39f04336 JA |
326 | struct value_pair *vp; |
327 | int i, active = 0; | |
328 | ||
a3fc0ff4 | 329 | c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT); |
39f04336 JA |
330 | |
331 | i = 0; | |
332 | vp = &o->posval[0]; | |
333 | while (vp->ival) { | |
f762cef9 | 334 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); |
39f04336 JA |
335 | if (ip && vp->oval == *ip) |
336 | active = i; | |
337 | vp++; | |
338 | i++; | |
339 | } | |
340 | ||
4fbcd659 | 341 | gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); |
a3fc0ff4 | 342 | c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); |
4fbcd659 | 343 | return &c->gopt; |
39f04336 JA |
344 | } |
345 | ||
a3fc0ff4 JA |
346 | static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data) |
347 | { | |
348 | struct gopt_str_multi *m = (struct gopt_str_multi *) data; | |
349 | ||
350 | gopt_changed(&m->gopt); | |
351 | } | |
352 | ||
bb3d3c4d JA |
353 | static void gopt_str_multi_destroy(GtkWidget *w, gpointer data) |
354 | { | |
355 | struct gopt_str_multi *m = (struct gopt_str_multi *) data; | |
356 | ||
357 | free(m); | |
358 | gtk_widget_destroy(w); | |
359 | } | |
360 | ||
753e9e64 JA |
361 | static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv, |
362 | struct fio_option *o, unsigned int idx) | |
7386d4ae JA |
363 | { |
364 | struct gopt_str_multi *m; | |
365 | struct value_pair *vp; | |
366 | GtkWidget *frame, *hbox; | |
367 | int i; | |
368 | ||
a3fc0ff4 | 369 | m = calloc(1, sizeof(*m)); |
7386d4ae | 370 | m->gopt.box = gtk_hbox_new(FALSE, 3); |
a3fc0ff4 | 371 | gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI); |
7386d4ae JA |
372 | |
373 | if (!o->lname) | |
374 | frame = gtk_frame_new(o->name); | |
375 | else | |
376 | frame = gtk_frame_new(o->lname); | |
377 | gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3); | |
378 | ||
379 | hbox = gtk_hbox_new(FALSE, 3); | |
380 | gtk_container_add(GTK_CONTAINER(frame), hbox); | |
381 | ||
382 | i = 0; | |
383 | vp = &o->posval[0]; | |
384 | while (vp->ival) { | |
385 | m->checks[i] = gtk_check_button_new_with_label(vp->ival); | |
386 | gtk_widget_set_tooltip_text(m->checks[i], vp->help); | |
387 | gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3); | |
a3fc0ff4 | 388 | g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m); |
456fed9b JA |
389 | vp++; |
390 | i++; | |
7386d4ae JA |
391 | } |
392 | ||
bb3d3c4d | 393 | g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m); |
7386d4ae JA |
394 | return &m->gopt; |
395 | } | |
396 | ||
b6caa836 JA |
397 | static void gopt_int_changed(GtkSpinButton *spin, gpointer data) |
398 | { | |
399 | struct gopt_int *i = (struct gopt_int *) data; | |
400 | struct fio_option *o = &fio_options[i->gopt.opt_index]; | |
90265353 JA |
401 | GtkAdjustment *adj; |
402 | int value, delta; | |
403 | ||
a3fc0ff4 JA |
404 | gopt_changed(&i->gopt); |
405 | ||
90265353 JA |
406 | adj = gtk_spin_button_get_adjustment(spin); |
407 | value = gtk_adjustment_get_value(adj); | |
408 | delta = value - i->lastval; | |
409 | i->lastval = value; | |
410 | ||
411 | if (o->inv_opt) { | |
c504ee55 JA |
412 | struct gopt *b_inv = o->inv_opt->gui_data; |
413 | struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt); | |
90265353 JA |
414 | int cur_val; |
415 | ||
a01a1bc5 JA |
416 | assert(o->type == o->inv_opt->type); |
417 | ||
90265353 JA |
418 | cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin)); |
419 | cur_val -= delta; | |
8f9e46ab | 420 | g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler); |
90265353 | 421 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val); |
8f9e46ab | 422 | g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler); |
90265353 | 423 | } |
b6caa836 JA |
424 | } |
425 | ||
231edf61 JA |
426 | static void gopt_int_destroy(GtkWidget *w, gpointer data) |
427 | { | |
428 | struct gopt_int *i = (struct gopt_int *) data; | |
429 | ||
c04942a2 | 430 | free(i); |
231edf61 JA |
431 | gtk_widget_destroy(w); |
432 | } | |
433 | ||
753e9e64 JA |
434 | static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, |
435 | struct fio_option *o, | |
231edf61 | 436 | unsigned long long *p, unsigned int idx) |
39f04336 JA |
437 | { |
438 | unsigned long long defval; | |
9af4a244 | 439 | struct gopt_int *i; |
20eb06bd | 440 | guint maxval, interval; |
9af4a244 JA |
441 | GtkWidget *label; |
442 | ||
a3fc0ff4 | 443 | i = calloc(1, sizeof(*i)); |
9af4a244 | 444 | i->gopt.box = gtk_hbox_new(FALSE, 3); |
e8b0e958 JA |
445 | if (!o->lname) |
446 | label = gtk_label_new(o->name); | |
447 | else | |
448 | label = gtk_label_new(o->lname); | |
9af4a244 JA |
449 | |
450 | maxval = o->maxval; | |
451 | if (!maxval) | |
39f04336 | 452 | maxval = UINT_MAX; |
9af4a244 JA |
453 | |
454 | defval = 0; | |
39f04336 JA |
455 | if (p) |
456 | defval = *p; | |
457 | else if (o->def) { | |
9af4a244 JA |
458 | long long val; |
459 | ||
460 | check_str_bytes(o->def, &val, NULL); | |
461 | defval = val; | |
462 | } | |
463 | ||
20eb06bd JA |
464 | interval = 1.0; |
465 | if (o->interval) | |
466 | interval = o->interval; | |
467 | ||
468 | i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval); | |
a3fc0ff4 | 469 | gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT); |
9af4a244 JA |
470 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID); |
471 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), defval); | |
90265353 | 472 | i->lastval = defval; |
8f9e46ab | 473 | i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i); |
231edf61 | 474 | g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i); |
9af4a244 JA |
475 | |
476 | gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0); | |
e8b0e958 | 477 | gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0); |
b6caa836 JA |
478 | |
479 | return i; | |
9af4a244 JA |
480 | } |
481 | ||
753e9e64 JA |
482 | static struct gopt *gopt_new_int(struct gopt_job_view *gjv, |
483 | struct fio_option *o, unsigned int *ip, | |
231edf61 | 484 | unsigned int idx) |
39f04336 JA |
485 | { |
486 | unsigned long long ullp; | |
b6caa836 | 487 | struct gopt_int *i; |
39f04336 JA |
488 | |
489 | if (ip) { | |
490 | ullp = *ip; | |
753e9e64 | 491 | i = __gopt_new_int(gjv, o, &ullp, idx); |
b6caa836 | 492 | } else |
753e9e64 | 493 | i = __gopt_new_int(gjv, o, NULL, idx); |
b6caa836 JA |
494 | |
495 | return &i->gopt; | |
496 | } | |
39f04336 | 497 | |
753e9e64 JA |
498 | static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv, |
499 | struct fio_option *o, unsigned long long *p, | |
b6caa836 JA |
500 | unsigned int idx) |
501 | { | |
502 | struct gopt_int *i; | |
503 | ||
753e9e64 | 504 | i = __gopt_new_int(gjv, o, p, idx); |
b6caa836 | 505 | return &i->gopt; |
39f04336 JA |
506 | } |
507 | ||
b6caa836 | 508 | static void gopt_bool_toggled(GtkToggleButton *button, gpointer data) |
39f04336 | 509 | { |
b6caa836 JA |
510 | struct gopt_bool *b = (struct gopt_bool *) data; |
511 | struct fio_option *o = &fio_options[b->gopt.opt_index]; | |
512 | gboolean set; | |
513 | ||
a3fc0ff4 JA |
514 | gopt_changed(&b->gopt); |
515 | ||
b6caa836 | 516 | set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check)); |
a01a1bc5 JA |
517 | |
518 | if (o->inv_opt) { | |
c504ee55 JA |
519 | struct gopt *g_inv = o->inv_opt->gui_data; |
520 | struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt); | |
a01a1bc5 JA |
521 | |
522 | assert(o->type == o->inv_opt->type); | |
523 | ||
8f9e46ab | 524 | g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler); |
a01a1bc5 | 525 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set); |
8f9e46ab | 526 | g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler); |
a01a1bc5 JA |
527 | } |
528 | ||
19921181 | 529 | gopt_set_children_visible(b->gopt.gjv, o, set); |
39f04336 JA |
530 | } |
531 | ||
231edf61 JA |
532 | static void gopt_bool_destroy(GtkWidget *w, gpointer data) |
533 | { | |
534 | struct gopt_bool *b = (struct gopt_bool *) data; | |
535 | ||
c04942a2 | 536 | free(b); |
231edf61 JA |
537 | gtk_widget_destroy(w); |
538 | } | |
539 | ||
753e9e64 JA |
540 | static struct gopt *gopt_new_bool(struct gopt_job_view *gjv, |
541 | struct fio_option *o, unsigned int *val, | |
231edf61 | 542 | unsigned int idx) |
9af4a244 JA |
543 | { |
544 | struct gopt_bool *b; | |
545 | GtkWidget *label; | |
546 | int defstate = 0; | |
547 | ||
a3fc0ff4 | 548 | b = calloc(1, sizeof(*b)); |
9af4a244 | 549 | b->gopt.box = gtk_hbox_new(FALSE, 3); |
e8b0e958 JA |
550 | if (!o->lname) |
551 | label = gtk_label_new(o->name); | |
552 | else | |
553 | label = gtk_label_new(o->lname); | |
9af4a244 JA |
554 | |
555 | b->check = gtk_check_button_new(); | |
a3fc0ff4 | 556 | gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL); |
39f04336 JA |
557 | if (val) |
558 | defstate = *val; | |
559 | else if (o->def && !strcmp(o->def, "1")) | |
9af4a244 JA |
560 | defstate = 1; |
561 | ||
d872fb4c JA |
562 | if (o->neg) |
563 | defstate = !defstate; | |
564 | ||
9af4a244 | 565 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate); |
8f9e46ab | 566 | b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b); |
231edf61 | 567 | g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b); |
9af4a244 JA |
568 | |
569 | gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0); | |
e8b0e958 | 570 | gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0); |
9af4a244 JA |
571 | return &b->gopt; |
572 | } | |
573 | ||
1da10c19 JA |
574 | /* |
575 | * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values. | |
576 | * If the max is made smaller than min, adjust min down. | |
577 | * If the min is made larger than max, adjust the max. | |
578 | */ | |
579 | static void range_value_changed(GtkSpinButton *spin, gpointer data) | |
580 | { | |
581 | struct gopt_range *r = (struct gopt_range *) data; | |
582 | int changed = -1, i; | |
583 | gint val, mval; | |
584 | ||
a3fc0ff4 JA |
585 | gopt_changed(&r->gopt); |
586 | ||
1da10c19 JA |
587 | for (i = 0; i < GOPT_RANGE_SPIN; i++) { |
588 | if (GTK_SPIN_BUTTON(r->spins[i]) == spin) { | |
589 | changed = i; | |
590 | break; | |
591 | } | |
592 | } | |
593 | ||
594 | assert(changed != -1); | |
595 | ||
596 | /* | |
597 | * Min changed | |
598 | */ | |
599 | if (changed == 0 || changed == 2) { | |
600 | GtkWidget *mspin = r->spins[changed + 1]; | |
601 | ||
602 | val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed])); | |
603 | mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin)); | |
604 | if (val > mval) | |
605 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val); | |
606 | } else { | |
607 | GtkWidget *mspin = r->spins[changed - 1]; | |
608 | ||
609 | val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed])); | |
610 | mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin)); | |
611 | if (val < mval) | |
612 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val); | |
613 | } | |
614 | } | |
615 | ||
231edf61 JA |
616 | static void gopt_range_destroy(GtkWidget *w, gpointer data) |
617 | { | |
618 | struct gopt_range *r = (struct gopt_range *) data; | |
619 | ||
c04942a2 | 620 | free(r); |
231edf61 JA |
621 | gtk_widget_destroy(w); |
622 | } | |
623 | ||
753e9e64 JA |
624 | static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, |
625 | struct fio_option *o, unsigned int **ip, | |
b6caa836 | 626 | unsigned int idx) |
9af4a244 JA |
627 | { |
628 | struct gopt_range *r; | |
629 | gint maxval, defval; | |
630 | GtkWidget *label; | |
20eb06bd | 631 | guint interval; |
9af4a244 JA |
632 | int i; |
633 | ||
a3fc0ff4 | 634 | r = calloc(1, sizeof(*r)); |
9af4a244 | 635 | r->gopt.box = gtk_hbox_new(FALSE, 3); |
a3fc0ff4 | 636 | gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE); |
e8b0e958 JA |
637 | if (!o->lname) |
638 | label = gtk_label_new(o->name); | |
639 | else | |
640 | label = gtk_label_new(o->lname); | |
9af4a244 JA |
641 | |
642 | maxval = o->maxval; | |
643 | if (!maxval) | |
644 | maxval = INT_MAX; | |
645 | ||
646 | defval = 0; | |
647 | if (o->def) { | |
648 | long long val; | |
649 | ||
650 | check_str_bytes(o->def, &val, NULL); | |
651 | defval = val; | |
652 | } | |
653 | ||
20eb06bd JA |
654 | interval = 1.0; |
655 | if (o->interval) | |
656 | interval = o->interval; | |
657 | ||
1da10c19 | 658 | for (i = 0; i < GOPT_RANGE_SPIN; i++) { |
20eb06bd | 659 | r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval); |
9af4a244 | 660 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID); |
39f04336 JA |
661 | if (ip) |
662 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), *ip[i]); | |
663 | else | |
664 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), defval); | |
9af4a244 JA |
665 | |
666 | gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0); | |
1da10c19 | 667 | g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r); |
9af4a244 JA |
668 | } |
669 | ||
e8b0e958 | 670 | gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0); |
231edf61 | 671 | g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r); |
9af4a244 JA |
672 | return &r->gopt; |
673 | } | |
674 | ||
7fc35ff7 JA |
675 | static void gopt_str_val_destroy(GtkWidget *w, gpointer data) |
676 | { | |
677 | struct gopt_str_val *g = (struct gopt_str_val *) data; | |
678 | ||
c04942a2 | 679 | free(g); |
7fc35ff7 JA |
680 | gtk_widget_destroy(w); |
681 | } | |
682 | ||
683 | static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data) | |
684 | { | |
685 | struct gopt_str_val *g = (struct gopt_str_val *) data; | |
686 | unsigned int val; | |
687 | GtkAdjustment *adj; | |
688 | gint index; | |
689 | ||
690 | adj = gtk_spin_button_get_adjustment(spin); | |
691 | val = gtk_adjustment_get_value(adj); | |
692 | ||
693 | /* | |
694 | * Can't rely on exact value, as fast changes increment >= 1 | |
695 | */ | |
696 | if (!val) { | |
7fc35ff7 | 697 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo)); |
481c242b JA |
698 | if (index + 1 <= g->maxindex) { |
699 | val = 1; | |
700 | gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index); | |
701 | } else | |
702 | val = 1023; | |
7fc35ff7 JA |
703 | gtk_spin_button_set_value(spin, val); |
704 | } else { | |
705 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo)); | |
706 | if (index) { | |
707 | gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), --index); | |
708 | gtk_spin_button_set_value(spin, 1023); | |
709 | } else | |
710 | gtk_spin_button_set_value(spin, 0); | |
711 | } | |
712 | } | |
713 | ||
a3fc0ff4 JA |
714 | static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data) |
715 | { | |
716 | struct gopt_str_val *g = (struct gopt_str_val *) data; | |
717 | ||
718 | gopt_changed(&g->gopt); | |
719 | } | |
720 | ||
753e9e64 JA |
721 | static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, |
722 | struct fio_option *o, | |
7fc35ff7 JA |
723 | unsigned long long *p, unsigned int idx) |
724 | { | |
725 | struct gopt_str_val *g; | |
726 | const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" }; | |
a3fc0ff4 | 727 | unsigned long long val; |
7fc35ff7 JA |
728 | GtkWidget *label; |
729 | int i; | |
730 | ||
a3fc0ff4 | 731 | g = calloc(1, sizeof(*g)); |
7fc35ff7 JA |
732 | g->gopt.box = gtk_hbox_new(FALSE, 3); |
733 | if (!o->lname) | |
734 | label = gtk_label_new(o->name); | |
735 | else | |
736 | label = gtk_label_new(o->lname); | |
a3fc0ff4 | 737 | gopt_mark_index(gjv, &g->gopt, idx, GOPT_STR_VAL); |
7fc35ff7 JA |
738 | |
739 | g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0); | |
740 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID); | |
741 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), 0); | |
742 | gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(g->spin), 1); | |
743 | gtk_box_pack_start(GTK_BOX(g->gopt.box), g->spin, FALSE, FALSE, 0); | |
744 | g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g); | |
a3fc0ff4 | 745 | g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g); |
7fc35ff7 | 746 | |
f762cef9 | 747 | g->combo = gtk_combo_box_text_new(); |
7fc35ff7 JA |
748 | i = 0; |
749 | while (strlen(postfix[i])) { | |
f762cef9 | 750 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]); |
7fc35ff7 JA |
751 | i++; |
752 | } | |
481c242b | 753 | g->maxindex = i - 1; |
7fc35ff7 JA |
754 | gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0); |
755 | gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0); | |
756 | gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3); | |
757 | ||
a3fc0ff4 JA |
758 | /* |
759 | * Set the value | |
760 | */ | |
761 | if (p) { | |
762 | val = *p; | |
763 | i = 0; | |
764 | do { | |
765 | if (!val || (val % 1024)) | |
766 | break; | |
767 | ||
768 | i++; | |
769 | val /= 1024; | |
770 | } while (1); | |
771 | ||
772 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val); | |
773 | gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i); | |
774 | } | |
775 | ||
776 | g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g); | |
777 | ||
7fc35ff7 | 778 | g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g); |
7fc35ff7 JA |
779 | return &g->gopt; |
780 | } | |
781 | ||
753e9e64 JA |
782 | static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox, |
783 | struct fio_option *o, unsigned int opt_index, | |
784 | struct thread_options *to) | |
9af4a244 JA |
785 | { |
786 | struct gopt *go = NULL; | |
787 | ||
788 | switch (o->type) { | |
7fc35ff7 JA |
789 | case FIO_OPT_STR_VAL: { |
790 | unsigned long long *ullp = NULL; | |
791 | ||
792 | if (o->off1) | |
793 | ullp = td_var(to, o->off1); | |
794 | ||
753e9e64 | 795 | go = gopt_new_str_val(gjv, o, ullp, opt_index); |
7fc35ff7 JA |
796 | break; |
797 | } | |
39f04336 JA |
798 | case FIO_OPT_STR_VAL_TIME: { |
799 | unsigned long long *ullp = NULL; | |
800 | ||
801 | if (o->off1) | |
802 | ullp = td_var(to, o->off1); | |
789f4ccd | 803 | |
753e9e64 | 804 | go = gopt_new_ullong(gjv, o, ullp, opt_index); |
9af4a244 | 805 | break; |
789f4ccd | 806 | } |
39f04336 JA |
807 | case FIO_OPT_INT: { |
808 | unsigned int *ip = NULL; | |
809 | ||
810 | if (o->off1) | |
811 | ip = td_var(to, o->off1); | |
812 | ||
753e9e64 | 813 | go = gopt_new_int(gjv, o, ip, opt_index); |
9af4a244 | 814 | break; |
39f04336 | 815 | } |
9af4a244 | 816 | case FIO_OPT_STR_SET: |
39f04336 JA |
817 | case FIO_OPT_BOOL: { |
818 | unsigned int *ip = NULL; | |
819 | ||
820 | if (o->off1) | |
821 | ip = td_var(to, o->off1); | |
822 | ||
753e9e64 | 823 | go = gopt_new_bool(gjv, o, ip, opt_index); |
39f04336 JA |
824 | break; |
825 | } | |
826 | case FIO_OPT_STR: { | |
d872fb4c JA |
827 | if (o->posval[0].ival) { |
828 | unsigned int *ip = NULL; | |
39f04336 | 829 | |
d872fb4c JA |
830 | if (o->off1) |
831 | ip = td_var(to, o->off1); | |
832 | ||
753e9e64 | 833 | go = gopt_new_combo_int(gjv, o, ip, opt_index); |
d872fb4c JA |
834 | } else { |
835 | /* TODO: usually ->cb, or unsigned int pointer */ | |
753e9e64 | 836 | go = gopt_new_str_store(gjv, o, NULL, opt_index); |
d872fb4c | 837 | } |
39f04336 | 838 | |
9af4a244 | 839 | break; |
39f04336 JA |
840 | } |
841 | case FIO_OPT_STR_STORE: { | |
842 | char *text = NULL; | |
843 | ||
d3944493 | 844 | if (o->off1) { |
39f04336 JA |
845 | char **p = td_var(to, o->off1); |
846 | text = *p; | |
847 | } | |
848 | ||
9af4a244 | 849 | if (!o->posval[0].ival) { |
753e9e64 | 850 | go = gopt_new_str_store(gjv, o, text, opt_index); |
9af4a244 JA |
851 | break; |
852 | } | |
39f04336 | 853 | |
753e9e64 | 854 | go = gopt_new_combo_str(gjv, o, text, opt_index); |
39f04336 JA |
855 | break; |
856 | } | |
9af4a244 | 857 | case FIO_OPT_STR_MULTI: |
753e9e64 | 858 | go = gopt_new_str_multi(gjv, o, opt_index); |
9af4a244 | 859 | break; |
39f04336 JA |
860 | case FIO_OPT_RANGE: { |
861 | unsigned int *ip[4] = { td_var(to, o->off1), | |
862 | td_var(to, o->off2), | |
863 | td_var(to, o->off3), | |
864 | td_var(to, o->off4) }; | |
865 | ||
753e9e64 | 866 | go = gopt_new_int_range(gjv, o, ip, opt_index); |
9af4a244 | 867 | break; |
39f04336 | 868 | } |
9af4a244 JA |
869 | /* still need to handle this one */ |
870 | case FIO_OPT_FLOAT_LIST: | |
871 | break; | |
872 | case FIO_OPT_DEPRECATED: | |
873 | break; | |
874 | default: | |
875 | printf("ignore type %u\n", o->type); | |
876 | break; | |
877 | } | |
878 | ||
879 | if (go) { | |
e8b0e958 JA |
880 | GtkWidget *dest; |
881 | ||
9af4a244 JA |
882 | if (o->help) |
883 | gtk_widget_set_tooltip_text(go->box, o->help); | |
e8b0e958 | 884 | |
c504ee55 | 885 | o->gui_data = go; |
e8b0e958 | 886 | |
753e9e64 | 887 | dest = gopt_get_group_frame(gjv, hbox, o->group); |
e8b0e958 JA |
888 | if (!dest) |
889 | gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5); | |
890 | else | |
891 | gtk_box_pack_start(GTK_BOX(dest), go->box, FALSE, FALSE, 5); | |
9af4a244 JA |
892 | } |
893 | } | |
894 | ||
753e9e64 JA |
895 | static void gopt_add_options(struct gopt_job_view *gjv, |
896 | struct thread_options *to) | |
9af4a244 JA |
897 | { |
898 | GtkWidget *hbox = NULL; | |
899 | int i; | |
900 | ||
90265353 JA |
901 | /* |
902 | * First add all options | |
903 | */ | |
9af4a244 JA |
904 | for (i = 0; fio_options[i].name; i++) { |
905 | struct fio_option *o = &fio_options[i]; | |
906 | unsigned int mask = o->category; | |
907 | struct opt_group *og; | |
908 | ||
909 | while ((og = opt_group_from_mask(&mask)) != NULL) { | |
753e9e64 | 910 | GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)]; |
9af4a244 JA |
911 | |
912 | hbox = gtk_hbox_new(FALSE, 3); | |
913 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); | |
753e9e64 | 914 | gopt_add_option(gjv, hbox, o, i, to); |
9af4a244 JA |
915 | } |
916 | } | |
917 | } | |
918 | ||
753e9e64 | 919 | static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name) |
9af4a244 JA |
920 | { |
921 | GtkWidget *box, *vbox, *scroll; | |
922 | ||
923 | scroll = gtk_scrolled_window_new(NULL, NULL); | |
924 | gtk_container_set_border_width(GTK_CONTAINER(scroll), 5); | |
925 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
926 | ||
927 | vbox = gtk_vbox_new(FALSE, 3); | |
928 | box = gtk_hbox_new(FALSE, 0); | |
929 | gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5); | |
930 | gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox); | |
753e9e64 | 931 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(name)); |
9af4a244 JA |
932 | return vbox; |
933 | } | |
934 | ||
753e9e64 JA |
935 | static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og) |
936 | { | |
937 | return gopt_add_tab(notebook, og->name); | |
938 | } | |
939 | ||
940 | static void gopt_add_group_tabs(GtkWidget *notebook, struct gopt_job_view *gjv) | |
9af4a244 JA |
941 | { |
942 | struct opt_group *og; | |
ec0218ff | 943 | unsigned int i; |
9af4a244 | 944 | |
ec0218ff | 945 | i = 0; |
9af4a244 JA |
946 | do { |
947 | unsigned int mask = (1U << i); | |
948 | ||
949 | og = opt_group_from_mask(&mask); | |
950 | if (!og) | |
951 | break; | |
753e9e64 | 952 | gjv->vboxes[i] = gopt_add_group_tab(notebook, og); |
9af4a244 JA |
953 | i++; |
954 | } while (1); | |
955 | } | |
956 | ||
a3fc0ff4 JA |
957 | static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv, |
958 | struct gopt_str_multi *m, | |
959 | struct fio_option *o) | |
960 | { | |
961 | unsigned int *ip = td_var(gjv->o, o->off1); | |
456fed9b | 962 | struct value_pair *vp; |
a3fc0ff4 JA |
963 | gboolean set; |
964 | guint val = 0; | |
965 | int i; | |
966 | ||
967 | i = 0; | |
456fed9b JA |
968 | vp = &o->posval[0]; |
969 | while (vp->ival) { | |
a3fc0ff4 JA |
970 | if (!m->checks[i]) |
971 | break; | |
972 | set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i])); | |
973 | if (set) { | |
456fed9b JA |
974 | if (vp->or) |
975 | val |= vp->oval; | |
a3fc0ff4 | 976 | else |
456fed9b | 977 | val = vp->oval; |
a3fc0ff4 JA |
978 | } |
979 | i++; | |
456fed9b | 980 | vp++; |
a3fc0ff4 JA |
981 | } |
982 | ||
983 | if (o->off1) | |
984 | *ip = val; | |
985 | } | |
986 | ||
987 | static void gopt_handle_range_changed(struct gopt_job_view *gjv, | |
988 | struct gopt_range *r, | |
989 | struct fio_option *o) | |
990 | { | |
991 | unsigned int *ip[4] = { td_var(gjv->o, o->off1), | |
992 | td_var(gjv->o, o->off2), | |
993 | td_var(gjv->o, o->off3), | |
994 | td_var(gjv->o, o->off4) }; | |
995 | gint val; | |
996 | int i; | |
997 | ||
998 | for (i = 0; i < GOPT_RANGE_SPIN; i++) { | |
999 | val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[i])); | |
1000 | *ip[i] = val; | |
1001 | } | |
1002 | } | |
1003 | ||
1004 | static void gopt_handle_str_val_changed(struct gopt_job_view *gjv, | |
1005 | struct gopt_str_val *s, | |
1006 | struct fio_option *o) | |
1007 | { | |
1008 | unsigned long long *ullp = td_var(gjv->o, o->off1); | |
1009 | GtkAdjustment *adj; | |
1010 | gint index; | |
1011 | ||
1012 | if (!ullp) | |
1013 | return; | |
1014 | ||
1015 | /* | |
1016 | * Numerical value | |
1017 | */ | |
1018 | adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(s->spin)); | |
1019 | *ullp = gtk_adjustment_get_value(adj); | |
1020 | ||
1021 | /* | |
1022 | * Multiplier | |
1023 | */ | |
1024 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(s->combo)); | |
1025 | while (index--) | |
1026 | *ullp *= 1024ULL; | |
1027 | } | |
1028 | ||
1029 | static void gopt_handle_str_changed(struct gopt_job_view *gjv, | |
1030 | struct gopt_str *s, struct fio_option *o) | |
1031 | { | |
1032 | char **p = td_var(gjv->o, o->off1); | |
1033 | ||
1034 | if (*p) | |
1035 | free(*p); | |
1036 | ||
1037 | *p = strdup(gtk_entry_get_text(GTK_ENTRY(s->entry))); | |
1038 | } | |
1039 | ||
1040 | static void gopt_handle_bool_changed(struct gopt_job_view *gjv, | |
1041 | struct gopt_bool *b, struct fio_option *o) | |
1042 | { | |
1043 | unsigned int *ip = td_var(gjv->o, o->off1); | |
1044 | gboolean set; | |
1045 | ||
1046 | set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check)); | |
1047 | *ip = set; | |
1048 | } | |
1049 | ||
1050 | static void gopt_handle_int_changed(struct gopt_job_view *gjv, | |
1051 | struct gopt_int *i, struct fio_option *o) | |
1052 | { | |
1053 | unsigned int *ip = td_var(gjv->o, o->off1); | |
1054 | GtkAdjustment *adj; | |
1055 | guint val; | |
1056 | ||
1057 | adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(i->spin)); | |
1058 | val = gtk_adjustment_get_value(adj); | |
1059 | *ip = val; | |
1060 | } | |
1061 | ||
1062 | static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv, | |
1063 | struct gopt_combo *c, | |
1064 | struct fio_option *o) | |
1065 | { | |
1066 | char **p = td_var(gjv->o, o->off1); | |
1067 | ||
1068 | if (*p) | |
1069 | free(*p); | |
1070 | ||
f762cef9 | 1071 | *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo))); |
a3fc0ff4 JA |
1072 | } |
1073 | ||
1074 | static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv, | |
1075 | struct gopt_combo *c, | |
1076 | struct fio_option *o) | |
1077 | { | |
1078 | unsigned int *ip = td_var(gjv->o, o->off1); | |
1079 | gint index; | |
1080 | ||
1081 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo)); | |
1082 | *ip = o->posval[index].oval; | |
1083 | } | |
1084 | ||
1085 | static void gopt_handle_changed(struct gopt *gopt) | |
1086 | { | |
1087 | struct fio_option *o = &fio_options[gopt->opt_index]; | |
1088 | struct gopt_job_view *gjv = gopt->gjv; | |
a3fc0ff4 JA |
1089 | |
1090 | switch (gopt->opt_type) { | |
1091 | case GOPT_COMBO_INT: { | |
1092 | struct gopt_combo *c; | |
1093 | ||
1094 | c = container_of(gopt, struct gopt_combo, gopt); | |
1095 | gopt_handle_combo_int_changed(gjv, c, o); | |
a3fc0ff4 JA |
1096 | break; |
1097 | } | |
1098 | case GOPT_COMBO_STR: { | |
1099 | struct gopt_combo *c; | |
1100 | ||
1101 | c = container_of(gopt, struct gopt_combo, gopt); | |
1102 | gopt_handle_combo_str_changed(gjv, c, o); | |
a3fc0ff4 JA |
1103 | break; |
1104 | } | |
1105 | case GOPT_INT: { | |
1106 | struct gopt_int *i; | |
1107 | ||
1108 | i = container_of(gopt, struct gopt_int, gopt); | |
1109 | gopt_handle_int_changed(gjv, i, o); | |
a3fc0ff4 JA |
1110 | break; |
1111 | } | |
1112 | case GOPT_BOOL: { | |
1113 | struct gopt_bool *b; | |
1114 | ||
1115 | b = container_of(gopt, struct gopt_bool, gopt); | |
1116 | gopt_handle_bool_changed(gjv, b, o); | |
a3fc0ff4 JA |
1117 | break; |
1118 | } | |
1119 | case GOPT_STR: { | |
1120 | struct gopt_str *s; | |
1121 | ||
1122 | s = container_of(gopt, struct gopt_str, gopt); | |
1123 | gopt_handle_str_changed(gjv, s, o); | |
a3fc0ff4 JA |
1124 | break; |
1125 | } | |
1126 | case GOPT_STR_VAL: { | |
1127 | struct gopt_str_val *s; | |
1128 | ||
1129 | s = container_of(gopt, struct gopt_str_val, gopt); | |
1130 | gopt_handle_str_val_changed(gjv, s, o); | |
a3fc0ff4 JA |
1131 | break; |
1132 | } | |
1133 | case GOPT_RANGE: { | |
1134 | struct gopt_range *r; | |
1135 | ||
1136 | r = container_of(gopt, struct gopt_range, gopt); | |
1137 | gopt_handle_range_changed(gjv, r, o); | |
a3fc0ff4 JA |
1138 | break; |
1139 | } | |
1140 | case GOPT_STR_MULTI: { | |
1141 | struct gopt_str_multi *m; | |
1142 | ||
1143 | m = container_of(gopt, struct gopt_str_multi, gopt); | |
1144 | gopt_handle_str_multi_changed(gjv, m, o); | |
a3fc0ff4 JA |
1145 | break; |
1146 | } | |
1147 | default: | |
1148 | log_err("gfio: bad option type %s/%d\n", gopt->opt_type); | |
1149 | return; | |
1150 | } | |
1151 | ||
1152 | g_object_unref(G_OBJECT(gopt->box)); | |
a3fc0ff4 JA |
1153 | } |
1154 | ||
40c60516 | 1155 | static int gopt_handle_changed_options(struct gopt_job_view *gjv) |
a3fc0ff4 | 1156 | { |
40c60516 JA |
1157 | struct gfio_client *gc = gjv->client; |
1158 | uint64_t waitid = 0; | |
a3fc0ff4 | 1159 | struct gopt *gopt; |
40c60516 | 1160 | int ret; |
a3fc0ff4 JA |
1161 | |
1162 | while (!flist_empty(&gjv->changed_list)) { | |
1163 | gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list); | |
1164 | flist_del(&gopt->changed_list); | |
1165 | gopt_handle_changed(gopt); | |
1166 | } | |
40c60516 JA |
1167 | |
1168 | gopt_dialog_update_apply(gjv); | |
1169 | ||
1170 | ret = fio_client_update_options(gc->client, gjv->o, &waitid); | |
1171 | if (ret) | |
1172 | return ret; | |
1173 | ||
1174 | return fio_client_wait_for_reply(gc->client, waitid); | |
1175 | } | |
1176 | ||
1177 | static gint gopt_dialog_cancel(gint response) | |
1178 | { | |
1179 | switch (response) { | |
1180 | case GTK_RESPONSE_NONE: | |
1181 | case GTK_RESPONSE_REJECT: | |
1182 | case GTK_RESPONSE_DELETE_EVENT: | |
1183 | case GTK_RESPONSE_CANCEL: | |
1184 | case GTK_RESPONSE_NO: | |
1185 | return 1; | |
1186 | default: | |
1187 | return 0; | |
1188 | } | |
1189 | } | |
1190 | ||
1191 | static gint gopt_dialog_done(gint response) | |
1192 | { | |
1193 | switch (response) { | |
1194 | case GTK_RESPONSE_ACCEPT: | |
1195 | case GTK_RESPONSE_OK: | |
1196 | case GTK_RESPONSE_YES: | |
1197 | return 1; | |
1198 | default: | |
1199 | return 0; | |
1200 | } | |
1201 | } | |
1202 | ||
1203 | ||
1204 | static void gopt_handle_option_dialog(GtkWidget *dialog, | |
1205 | struct flist_head *gjv_list) | |
1206 | { | |
1207 | struct flist_head *entry; | |
1208 | struct gopt_job_view *gjv; | |
1209 | gint response; | |
1210 | ||
1211 | do { | |
1212 | response = gtk_dialog_run(GTK_DIALOG(dialog)); | |
1213 | if (gopt_dialog_cancel(response)) | |
1214 | break; | |
1215 | else if (gopt_dialog_done(response)) | |
1216 | break; | |
1217 | ||
1218 | flist_for_each(entry, gjv_list) { | |
1219 | gjv = flist_entry(gjv_list->next, struct gopt_job_view, list); | |
1220 | ||
1221 | gopt_handle_changed_options(gjv); | |
1222 | } | |
1223 | } while (1); | |
1224 | ||
1225 | if (gopt_dialog_cancel(response)) | |
1226 | return; | |
1227 | ||
1228 | while (!flist_empty(gjv_list)) { | |
1229 | gjv = flist_entry(gjv_list->next, struct gopt_job_view, list); | |
1230 | ||
1231 | gopt_handle_changed_options(gjv); | |
1232 | ||
1233 | flist_del(&gjv->list); | |
1234 | free(gjv); | |
1235 | } | |
a3fc0ff4 JA |
1236 | } |
1237 | ||
cf3d8241 | 1238 | void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) |
9af4a244 | 1239 | { |
753e9e64 | 1240 | GtkWidget *dialog, *notebook, *topnotebook, *vbox; |
cf3d8241 JA |
1241 | struct gfio_client_options *gco; |
1242 | struct thread_options *o; | |
753e9e64 JA |
1243 | struct flist_head *entry; |
1244 | struct gopt_job_view *gjv; | |
1245 | FLIST_HEAD(gjv_list); | |
cf3d8241 JA |
1246 | |
1247 | /* | |
1248 | * Just choose the first item, we need to make each options | |
1249 | * entry the main notebook, with the below options view as | |
1250 | * a sub-notebook | |
1251 | */ | |
1252 | assert(!flist_empty(&gc->o_list)); | |
9af4a244 JA |
1253 | |
1254 | dialog = gtk_dialog_new_with_buttons("Fio options", | |
1255 | GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT, | |
1256 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | |
40c60516 | 1257 | GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, |
9af4a244 JA |
1258 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); |
1259 | ||
1260 | gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768); | |
1261 | ||
753e9e64 JA |
1262 | topnotebook = gtk_notebook_new(); |
1263 | gtk_notebook_set_scrollable(GTK_NOTEBOOK(topnotebook), 1); | |
1264 | gtk_notebook_popup_enable(GTK_NOTEBOOK(topnotebook)); | |
f762cef9 JA |
1265 | vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); |
1266 | gtk_box_pack_start(GTK_BOX(vbox), topnotebook, TRUE, TRUE, 5); | |
753e9e64 JA |
1267 | |
1268 | flist_for_each(entry, &gc->o_list) { | |
1269 | const char *name; | |
9af4a244 | 1270 | |
753e9e64 JA |
1271 | gco = flist_entry(entry, struct gfio_client_options, list); |
1272 | o = &gco->o; | |
1273 | name = o->name; | |
1274 | if (!name || !strlen(name)) | |
1275 | name = "Default job"; | |
9af4a244 | 1276 | |
753e9e64 JA |
1277 | vbox = gopt_add_tab(topnotebook, name); |
1278 | ||
1279 | notebook = gtk_notebook_new(); | |
1280 | gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1); | |
1281 | gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook)); | |
1282 | gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5); | |
1283 | ||
1284 | gjv = calloc(1, sizeof(*gjv)); | |
1285 | INIT_FLIST_HEAD(&gjv->list); | |
a3fc0ff4 JA |
1286 | INIT_FLIST_HEAD(&gjv->changed_list); |
1287 | gjv->o = o; | |
40c60516 JA |
1288 | gjv->dialog = dialog; |
1289 | gjv->client = gc; | |
753e9e64 JA |
1290 | flist_add_tail(&gjv->list, &gjv_list); |
1291 | gopt_add_group_tabs(notebook, gjv); | |
1292 | gopt_add_options(gjv, o); | |
40c60516 | 1293 | gopt_dialog_update_apply(gjv); |
753e9e64 | 1294 | } |
9af4a244 JA |
1295 | |
1296 | gtk_widget_show_all(dialog); | |
1297 | ||
40c60516 | 1298 | gopt_handle_option_dialog(dialog, &gjv_list); |
a3fc0ff4 JA |
1299 | |
1300 | gtk_widget_destroy(dialog); | |
753e9e64 JA |
1301 | } |
1302 | ||
1303 | /* | |
1304 | * Build n-ary option dependency tree | |
1305 | */ | |
1306 | void gopt_init(void) | |
1307 | { | |
1308 | int i; | |
1309 | ||
1310 | gopt_dep_tree = g_node_new(NULL); | |
1311 | ||
1312 | for (i = 0; fio_options[i].name; i++) { | |
1313 | struct fio_option *o = &fio_options[i]; | |
1314 | GNode *node, *nparent; | |
1315 | ||
1316 | /* | |
1317 | * Insert node with either the root parent, or an | |
1318 | * option parent. | |
1319 | */ | |
1320 | node = g_node_new(o); | |
1321 | nparent = gopt_dep_tree; | |
1322 | if (o->parent) { | |
1323 | struct fio_option *parent; | |
1324 | ||
1325 | parent = fio_option_find(o->parent); | |
1326 | nparent = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent); | |
1327 | if (!nparent) { | |
1328 | log_err("fio: did not find parent %s for opt %s\n", o->name, o->parent); | |
1329 | nparent = gopt_dep_tree; | |
1330 | } | |
1331 | } | |
1332 | ||
1333 | g_node_insert(nparent, -1, node); | |
1334 | } | |
1335 | } | |
1336 | ||
1337 | void gopt_exit(void) | |
1338 | { | |
c504ee55 JA |
1339 | g_node_destroy(gopt_dep_tree); |
1340 | gopt_dep_tree = NULL; | |
9af4a244 | 1341 | } |