| 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; |
| 18 | gulong sig_handler; |
| 19 | struct gopt_job_view *gjv; |
| 20 | struct flist_head changed_list; |
| 21 | }; |
| 22 | |
| 23 | struct gopt_combo { |
| 24 | struct gopt gopt; |
| 25 | GtkWidget *combo; |
| 26 | }; |
| 27 | |
| 28 | struct gopt_int { |
| 29 | struct gopt gopt; |
| 30 | unsigned int lastval; |
| 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 | |
| 44 | struct gopt_str_val { |
| 45 | struct gopt gopt; |
| 46 | GtkWidget *spin; |
| 47 | GtkWidget *combo; |
| 48 | unsigned int maxindex; |
| 49 | }; |
| 50 | |
| 51 | #define GOPT_RANGE_SPIN 4 |
| 52 | |
| 53 | struct gopt_range { |
| 54 | struct gopt gopt; |
| 55 | GtkWidget *spins[GOPT_RANGE_SPIN]; |
| 56 | }; |
| 57 | |
| 58 | struct gopt_str_multi { |
| 59 | struct gopt gopt; |
| 60 | GtkWidget *checks[PARSE_MAX_VP]; |
| 61 | }; |
| 62 | |
| 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 | |
| 74 | struct gopt_frame_widget { |
| 75 | GtkWidget *vbox[2]; |
| 76 | unsigned int nr; |
| 77 | }; |
| 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]; |
| 84 | GtkWidget *dialog; |
| 85 | struct gfio_client *client; |
| 86 | struct flist_head changed_list; |
| 87 | struct thread_options *o; |
| 88 | }; |
| 89 | |
| 90 | static GNode *gopt_dep_tree; |
| 91 | |
| 92 | static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv, |
| 93 | GtkWidget *box, unsigned int groupmask) |
| 94 | { |
| 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); |
| 109 | gfw = &gjv->g_widgets[group]; |
| 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); |
| 119 | } |
| 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; |
| 124 | } |
| 125 | |
| 126 | /* |
| 127 | * Mark children as invisible, if needed. |
| 128 | */ |
| 129 | static void gopt_set_children_visible(struct gopt_job_view *gjv, |
| 130 | struct fio_option *parent, |
| 131 | gboolean visible) |
| 132 | { |
| 133 | GNode *child, *node; |
| 134 | |
| 135 | if (parent->hide_on_set) |
| 136 | visible = !visible; |
| 137 | |
| 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; |
| 143 | |
| 144 | /* |
| 145 | * Recurse into child, if it also has children |
| 146 | */ |
| 147 | if (g_node_n_children(child)) |
| 148 | gopt_set_children_visible(gjv, o, visible); |
| 149 | |
| 150 | if (gjv->widgets[g->opt_index]) |
| 151 | gtk_widget_set_sensitive(gjv->widgets[g->opt_index], visible); |
| 152 | |
| 153 | child = g_node_next_sibling(child); |
| 154 | } |
| 155 | } |
| 156 | |
| 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 | |
| 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 | |
| 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 | */ |
| 187 | if (flist_empty(&gopt->changed_list)) { |
| 188 | flist_add_tail(&gopt->changed_list, &gjv->changed_list); |
| 189 | gopt_dialog_update_apply(gjv); |
| 190 | } |
| 191 | } |
| 192 | |
| 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 | |
| 200 | gopt_changed(&s->gopt); |
| 201 | |
| 202 | text = gtk_entry_get_text(GTK_ENTRY(s->entry)); |
| 203 | set = strcmp(text, "") != 0; |
| 204 | |
| 205 | gopt_set_children_visible(s->gopt.gjv, o, set); |
| 206 | } |
| 207 | |
| 208 | static void gopt_str_destroy(GtkWidget *w, gpointer data) |
| 209 | { |
| 210 | struct gopt_str *s = (struct gopt_str *) data; |
| 211 | |
| 212 | free(s); |
| 213 | gtk_widget_destroy(w); |
| 214 | } |
| 215 | |
| 216 | static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv, |
| 217 | struct fio_option *o, const char *text, |
| 218 | unsigned int idx) |
| 219 | { |
| 220 | struct gopt_str *s; |
| 221 | GtkWidget *label; |
| 222 | |
| 223 | s = calloc(1, sizeof(*s)); |
| 224 | |
| 225 | s->gopt.box = gtk_hbox_new(FALSE, 3); |
| 226 | if (!o->lname) |
| 227 | label = gtk_label_new(o->name); |
| 228 | else |
| 229 | label = gtk_label_new(o->lname); |
| 230 | |
| 231 | s->entry = gtk_entry_new(); |
| 232 | gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR); |
| 233 | if (text) |
| 234 | gtk_entry_set_text(GTK_ENTRY(s->entry), text); |
| 235 | gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1); |
| 236 | |
| 237 | if (o->def) |
| 238 | gtk_entry_set_text(GTK_ENTRY(s->entry), o->def); |
| 239 | |
| 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); |
| 242 | |
| 243 | gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0); |
| 244 | gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0); |
| 245 | return &s->gopt; |
| 246 | } |
| 247 | |
| 248 | static void gopt_combo_changed(GtkComboBox *box, gpointer data) |
| 249 | { |
| 250 | struct gopt_combo *c = (struct gopt_combo *) data; |
| 251 | struct fio_option *o = &fio_options[c->gopt.opt_index]; |
| 252 | unsigned int index; |
| 253 | |
| 254 | gopt_changed(&c->gopt); |
| 255 | |
| 256 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo)); |
| 257 | |
| 258 | gopt_set_children_visible(c->gopt.gjv, o, index); |
| 259 | } |
| 260 | |
| 261 | static void gopt_combo_destroy(GtkWidget *w, gpointer data) |
| 262 | { |
| 263 | struct gopt_combo *c = (struct gopt_combo *) data; |
| 264 | |
| 265 | free(c); |
| 266 | gtk_widget_destroy(w); |
| 267 | } |
| 268 | |
| 269 | static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv, |
| 270 | struct fio_option *o, |
| 271 | unsigned int idx, int type) |
| 272 | { |
| 273 | struct gopt_combo *c; |
| 274 | GtkWidget *label; |
| 275 | |
| 276 | c = calloc(1, sizeof(*c)); |
| 277 | |
| 278 | c->gopt.box = gtk_hbox_new(FALSE, 3); |
| 279 | if (!o->lname) |
| 280 | label = gtk_label_new(o->name); |
| 281 | else |
| 282 | label = gtk_label_new(o->lname); |
| 283 | |
| 284 | c->combo = gtk_combo_box_text_new(); |
| 285 | gopt_mark_index(gjv, &c->gopt, idx, type); |
| 286 | g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c); |
| 287 | |
| 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 | |
| 291 | return c; |
| 292 | } |
| 293 | |
| 294 | static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv, |
| 295 | struct fio_option *o, const char *text, |
| 296 | unsigned int idx) |
| 297 | { |
| 298 | struct gopt_combo *c; |
| 299 | struct value_pair *vp; |
| 300 | int i, active = 0; |
| 301 | |
| 302 | c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR); |
| 303 | |
| 304 | i = 0; |
| 305 | vp = &o->posval[0]; |
| 306 | while (vp->ival) { |
| 307 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); |
| 308 | if (o->def && !strcmp(vp->ival, o->def)) |
| 309 | active = i; |
| 310 | if (text && !strcmp(vp->ival, text)) |
| 311 | active = i; |
| 312 | vp++; |
| 313 | i++; |
| 314 | } |
| 315 | |
| 316 | gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); |
| 317 | c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); |
| 318 | return &c->gopt; |
| 319 | } |
| 320 | |
| 321 | static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv, |
| 322 | struct fio_option *o, unsigned int *ip, |
| 323 | unsigned int idx) |
| 324 | { |
| 325 | struct gopt_combo *c; |
| 326 | struct value_pair *vp; |
| 327 | int i, active = 0; |
| 328 | |
| 329 | c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT); |
| 330 | |
| 331 | i = 0; |
| 332 | vp = &o->posval[0]; |
| 333 | while (vp->ival) { |
| 334 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival); |
| 335 | if (ip && vp->oval == *ip) |
| 336 | active = i; |
| 337 | vp++; |
| 338 | i++; |
| 339 | } |
| 340 | |
| 341 | gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active); |
| 342 | c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c); |
| 343 | return &c->gopt; |
| 344 | } |
| 345 | |
| 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 | |
| 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 | |
| 361 | static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv, |
| 362 | struct fio_option *o, unsigned int idx) |
| 363 | { |
| 364 | struct gopt_str_multi *m; |
| 365 | struct value_pair *vp; |
| 366 | GtkWidget *frame, *hbox; |
| 367 | int i; |
| 368 | |
| 369 | m = calloc(1, sizeof(*m)); |
| 370 | m->gopt.box = gtk_hbox_new(FALSE, 3); |
| 371 | gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI); |
| 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); |
| 388 | g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m); |
| 389 | vp++; |
| 390 | i++; |
| 391 | } |
| 392 | |
| 393 | g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m); |
| 394 | return &m->gopt; |
| 395 | } |
| 396 | |
| 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]; |
| 401 | GtkAdjustment *adj; |
| 402 | int value, delta; |
| 403 | |
| 404 | gopt_changed(&i->gopt); |
| 405 | |
| 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) { |
| 412 | struct gopt *b_inv = o->inv_opt->gui_data; |
| 413 | struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt); |
| 414 | int cur_val; |
| 415 | |
| 416 | assert(o->type == o->inv_opt->type); |
| 417 | |
| 418 | cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin)); |
| 419 | cur_val -= delta; |
| 420 | g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler); |
| 421 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val); |
| 422 | g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | static void gopt_int_destroy(GtkWidget *w, gpointer data) |
| 427 | { |
| 428 | struct gopt_int *i = (struct gopt_int *) data; |
| 429 | |
| 430 | free(i); |
| 431 | gtk_widget_destroy(w); |
| 432 | } |
| 433 | |
| 434 | static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv, |
| 435 | struct fio_option *o, |
| 436 | unsigned long long *p, unsigned int idx) |
| 437 | { |
| 438 | unsigned long long defval; |
| 439 | struct gopt_int *i; |
| 440 | guint maxval, interval; |
| 441 | GtkWidget *label; |
| 442 | |
| 443 | i = calloc(1, sizeof(*i)); |
| 444 | i->gopt.box = gtk_hbox_new(FALSE, 3); |
| 445 | if (!o->lname) |
| 446 | label = gtk_label_new(o->name); |
| 447 | else |
| 448 | label = gtk_label_new(o->lname); |
| 449 | |
| 450 | maxval = o->maxval; |
| 451 | if (!maxval) |
| 452 | maxval = UINT_MAX; |
| 453 | |
| 454 | defval = 0; |
| 455 | if (p) |
| 456 | defval = *p; |
| 457 | else if (o->def) { |
| 458 | long long val; |
| 459 | |
| 460 | check_str_bytes(o->def, &val, NULL); |
| 461 | defval = val; |
| 462 | } |
| 463 | |
| 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); |
| 469 | gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT); |
| 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); |
| 472 | i->lastval = defval; |
| 473 | i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i); |
| 474 | g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i); |
| 475 | |
| 476 | gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0); |
| 477 | gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0); |
| 478 | |
| 479 | return i; |
| 480 | } |
| 481 | |
| 482 | static struct gopt *gopt_new_int(struct gopt_job_view *gjv, |
| 483 | struct fio_option *o, unsigned int *ip, |
| 484 | unsigned int idx) |
| 485 | { |
| 486 | unsigned long long ullp; |
| 487 | struct gopt_int *i; |
| 488 | |
| 489 | if (ip) { |
| 490 | ullp = *ip; |
| 491 | i = __gopt_new_int(gjv, o, &ullp, idx); |
| 492 | } else |
| 493 | i = __gopt_new_int(gjv, o, NULL, idx); |
| 494 | |
| 495 | return &i->gopt; |
| 496 | } |
| 497 | |
| 498 | static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv, |
| 499 | struct fio_option *o, unsigned long long *p, |
| 500 | unsigned int idx) |
| 501 | { |
| 502 | struct gopt_int *i; |
| 503 | |
| 504 | i = __gopt_new_int(gjv, o, p, idx); |
| 505 | return &i->gopt; |
| 506 | } |
| 507 | |
| 508 | static void gopt_bool_toggled(GtkToggleButton *button, gpointer data) |
| 509 | { |
| 510 | struct gopt_bool *b = (struct gopt_bool *) data; |
| 511 | struct fio_option *o = &fio_options[b->gopt.opt_index]; |
| 512 | gboolean set; |
| 513 | |
| 514 | gopt_changed(&b->gopt); |
| 515 | |
| 516 | set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check)); |
| 517 | |
| 518 | if (o->inv_opt) { |
| 519 | struct gopt *g_inv = o->inv_opt->gui_data; |
| 520 | struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt); |
| 521 | |
| 522 | assert(o->type == o->inv_opt->type); |
| 523 | |
| 524 | g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler); |
| 525 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set); |
| 526 | g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler); |
| 527 | } |
| 528 | |
| 529 | gopt_set_children_visible(b->gopt.gjv, o, set); |
| 530 | } |
| 531 | |
| 532 | static void gopt_bool_destroy(GtkWidget *w, gpointer data) |
| 533 | { |
| 534 | struct gopt_bool *b = (struct gopt_bool *) data; |
| 535 | |
| 536 | free(b); |
| 537 | gtk_widget_destroy(w); |
| 538 | } |
| 539 | |
| 540 | static struct gopt *gopt_new_bool(struct gopt_job_view *gjv, |
| 541 | struct fio_option *o, unsigned int *val, |
| 542 | unsigned int idx) |
| 543 | { |
| 544 | struct gopt_bool *b; |
| 545 | GtkWidget *label; |
| 546 | int defstate = 0; |
| 547 | |
| 548 | b = calloc(1, sizeof(*b)); |
| 549 | b->gopt.box = gtk_hbox_new(FALSE, 3); |
| 550 | if (!o->lname) |
| 551 | label = gtk_label_new(o->name); |
| 552 | else |
| 553 | label = gtk_label_new(o->lname); |
| 554 | |
| 555 | b->check = gtk_check_button_new(); |
| 556 | gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL); |
| 557 | if (val) |
| 558 | defstate = *val; |
| 559 | else if (o->def && !strcmp(o->def, "1")) |
| 560 | defstate = 1; |
| 561 | |
| 562 | if (o->neg) |
| 563 | defstate = !defstate; |
| 564 | |
| 565 | gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate); |
| 566 | b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b); |
| 567 | g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b); |
| 568 | |
| 569 | gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0); |
| 570 | gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0); |
| 571 | return &b->gopt; |
| 572 | } |
| 573 | |
| 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 | |
| 585 | gopt_changed(&r->gopt); |
| 586 | |
| 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 | |
| 616 | static void gopt_range_destroy(GtkWidget *w, gpointer data) |
| 617 | { |
| 618 | struct gopt_range *r = (struct gopt_range *) data; |
| 619 | |
| 620 | free(r); |
| 621 | gtk_widget_destroy(w); |
| 622 | } |
| 623 | |
| 624 | static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv, |
| 625 | struct fio_option *o, unsigned int **ip, |
| 626 | unsigned int idx) |
| 627 | { |
| 628 | struct gopt_range *r; |
| 629 | gint maxval, defval; |
| 630 | GtkWidget *label; |
| 631 | guint interval; |
| 632 | int i; |
| 633 | |
| 634 | r = calloc(1, sizeof(*r)); |
| 635 | r->gopt.box = gtk_hbox_new(FALSE, 3); |
| 636 | gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE); |
| 637 | if (!o->lname) |
| 638 | label = gtk_label_new(o->name); |
| 639 | else |
| 640 | label = gtk_label_new(o->lname); |
| 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 | |
| 654 | interval = 1.0; |
| 655 | if (o->interval) |
| 656 | interval = o->interval; |
| 657 | |
| 658 | for (i = 0; i < GOPT_RANGE_SPIN; i++) { |
| 659 | r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval); |
| 660 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID); |
| 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); |
| 665 | |
| 666 | gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0); |
| 667 | g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r); |
| 668 | } |
| 669 | |
| 670 | gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0); |
| 671 | g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r); |
| 672 | return &r->gopt; |
| 673 | } |
| 674 | |
| 675 | static void gopt_str_val_destroy(GtkWidget *w, gpointer data) |
| 676 | { |
| 677 | struct gopt_str_val *g = (struct gopt_str_val *) data; |
| 678 | |
| 679 | free(g); |
| 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) { |
| 697 | index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo)); |
| 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; |
| 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 | |
| 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 | |
| 721 | static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv, |
| 722 | struct fio_option *o, |
| 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", "" }; |
| 727 | unsigned long long val; |
| 728 | GtkWidget *label; |
| 729 | int i; |
| 730 | |
| 731 | g = calloc(1, sizeof(*g)); |
| 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); |
| 737 | gopt_mark_index(gjv, &g->gopt, idx, GOPT_STR_VAL); |
| 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); |
| 745 | g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g); |
| 746 | |
| 747 | g->combo = gtk_combo_box_text_new(); |
| 748 | i = 0; |
| 749 | while (strlen(postfix[i])) { |
| 750 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]); |
| 751 | i++; |
| 752 | } |
| 753 | g->maxindex = i - 1; |
| 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 | |
| 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 | |
| 778 | g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g); |
| 779 | return &g->gopt; |
| 780 | } |
| 781 | |
| 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) |
| 785 | { |
| 786 | struct gopt *go = NULL; |
| 787 | |
| 788 | switch (o->type) { |
| 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 | |
| 795 | go = gopt_new_str_val(gjv, o, ullp, opt_index); |
| 796 | break; |
| 797 | } |
| 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); |
| 803 | |
| 804 | go = gopt_new_ullong(gjv, o, ullp, opt_index); |
| 805 | break; |
| 806 | } |
| 807 | case FIO_OPT_INT: { |
| 808 | unsigned int *ip = NULL; |
| 809 | |
| 810 | if (o->off1) |
| 811 | ip = td_var(to, o->off1); |
| 812 | |
| 813 | go = gopt_new_int(gjv, o, ip, opt_index); |
| 814 | break; |
| 815 | } |
| 816 | case FIO_OPT_STR_SET: |
| 817 | case FIO_OPT_BOOL: { |
| 818 | unsigned int *ip = NULL; |
| 819 | |
| 820 | if (o->off1) |
| 821 | ip = td_var(to, o->off1); |
| 822 | |
| 823 | go = gopt_new_bool(gjv, o, ip, opt_index); |
| 824 | break; |
| 825 | } |
| 826 | case FIO_OPT_STR: { |
| 827 | if (o->posval[0].ival) { |
| 828 | unsigned int *ip = NULL; |
| 829 | |
| 830 | if (o->off1) |
| 831 | ip = td_var(to, o->off1); |
| 832 | |
| 833 | go = gopt_new_combo_int(gjv, o, ip, opt_index); |
| 834 | } else { |
| 835 | /* TODO: usually ->cb, or unsigned int pointer */ |
| 836 | go = gopt_new_str_store(gjv, o, NULL, opt_index); |
| 837 | } |
| 838 | |
| 839 | break; |
| 840 | } |
| 841 | case FIO_OPT_STR_STORE: { |
| 842 | char *text = NULL; |
| 843 | |
| 844 | if (o->off1) { |
| 845 | char **p = td_var(to, o->off1); |
| 846 | text = *p; |
| 847 | } |
| 848 | |
| 849 | if (!o->posval[0].ival) { |
| 850 | go = gopt_new_str_store(gjv, o, text, opt_index); |
| 851 | break; |
| 852 | } |
| 853 | |
| 854 | go = gopt_new_combo_str(gjv, o, text, opt_index); |
| 855 | break; |
| 856 | } |
| 857 | case FIO_OPT_STR_MULTI: |
| 858 | go = gopt_new_str_multi(gjv, o, opt_index); |
| 859 | break; |
| 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 | |
| 866 | go = gopt_new_int_range(gjv, o, ip, opt_index); |
| 867 | break; |
| 868 | } |
| 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) { |
| 880 | GtkWidget *dest; |
| 881 | |
| 882 | if (o->help) |
| 883 | gtk_widget_set_tooltip_text(go->box, o->help); |
| 884 | |
| 885 | o->gui_data = go; |
| 886 | |
| 887 | dest = gopt_get_group_frame(gjv, hbox, o->group); |
| 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); |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | static void gopt_add_options(struct gopt_job_view *gjv, |
| 896 | struct thread_options *to) |
| 897 | { |
| 898 | GtkWidget *hbox = NULL; |
| 899 | int i; |
| 900 | |
| 901 | /* |
| 902 | * First add all options |
| 903 | */ |
| 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) { |
| 910 | GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)]; |
| 911 | |
| 912 | hbox = gtk_hbox_new(FALSE, 3); |
| 913 | gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5); |
| 914 | gopt_add_option(gjv, hbox, o, i, to); |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
| 919 | static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name) |
| 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); |
| 931 | gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(name)); |
| 932 | return vbox; |
| 933 | } |
| 934 | |
| 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) |
| 941 | { |
| 942 | struct opt_group *og; |
| 943 | unsigned int i; |
| 944 | |
| 945 | i = 0; |
| 946 | do { |
| 947 | unsigned int mask = (1U << i); |
| 948 | |
| 949 | og = opt_group_from_mask(&mask); |
| 950 | if (!og) |
| 951 | break; |
| 952 | gjv->vboxes[i] = gopt_add_group_tab(notebook, og); |
| 953 | i++; |
| 954 | } while (1); |
| 955 | } |
| 956 | |
| 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); |
| 962 | struct value_pair *vp; |
| 963 | gboolean set; |
| 964 | guint val = 0; |
| 965 | int i; |
| 966 | |
| 967 | i = 0; |
| 968 | vp = &o->posval[0]; |
| 969 | while (vp->ival) { |
| 970 | if (!m->checks[i]) |
| 971 | break; |
| 972 | set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i])); |
| 973 | if (set) { |
| 974 | if (vp->or) |
| 975 | val |= vp->oval; |
| 976 | else |
| 977 | val = vp->oval; |
| 978 | } |
| 979 | i++; |
| 980 | vp++; |
| 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 | |
| 1071 | *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo))); |
| 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; |
| 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); |
| 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); |
| 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); |
| 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); |
| 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); |
| 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); |
| 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); |
| 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); |
| 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)); |
| 1153 | } |
| 1154 | |
| 1155 | static int gopt_handle_changed_options(struct gopt_job_view *gjv) |
| 1156 | { |
| 1157 | struct gfio_client *gc = gjv->client; |
| 1158 | uint64_t waitid = 0; |
| 1159 | struct gopt *gopt; |
| 1160 | int ret; |
| 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 | } |
| 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 | } |
| 1236 | } |
| 1237 | |
| 1238 | void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc) |
| 1239 | { |
| 1240 | GtkWidget *dialog, *notebook, *topnotebook, *vbox; |
| 1241 | struct gfio_client_options *gco; |
| 1242 | struct thread_options *o; |
| 1243 | struct flist_head *entry; |
| 1244 | struct gopt_job_view *gjv; |
| 1245 | FLIST_HEAD(gjv_list); |
| 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)); |
| 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, |
| 1257 | GTK_STOCK_APPLY, GTK_RESPONSE_APPLY, |
| 1258 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); |
| 1259 | |
| 1260 | gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768); |
| 1261 | |
| 1262 | topnotebook = gtk_notebook_new(); |
| 1263 | gtk_notebook_set_scrollable(GTK_NOTEBOOK(topnotebook), 1); |
| 1264 | gtk_notebook_popup_enable(GTK_NOTEBOOK(topnotebook)); |
| 1265 | vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); |
| 1266 | gtk_box_pack_start(GTK_BOX(vbox), topnotebook, TRUE, TRUE, 5); |
| 1267 | |
| 1268 | flist_for_each(entry, &gc->o_list) { |
| 1269 | const char *name; |
| 1270 | |
| 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"; |
| 1276 | |
| 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); |
| 1286 | INIT_FLIST_HEAD(&gjv->changed_list); |
| 1287 | gjv->o = o; |
| 1288 | gjv->dialog = dialog; |
| 1289 | gjv->client = gc; |
| 1290 | flist_add_tail(&gjv->list, &gjv_list); |
| 1291 | gopt_add_group_tabs(notebook, gjv); |
| 1292 | gopt_add_options(gjv, o); |
| 1293 | gopt_dialog_update_apply(gjv); |
| 1294 | } |
| 1295 | |
| 1296 | gtk_widget_show_all(dialog); |
| 1297 | |
| 1298 | gopt_handle_option_dialog(dialog, &gjv_list); |
| 1299 | |
| 1300 | gtk_widget_destroy(dialog); |
| 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 | { |
| 1339 | g_node_destroy(gopt_dep_tree); |
| 1340 | gopt_dep_tree = NULL; |
| 1341 | } |