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