fio: link fio code with gui code
[fio.git] / gfio.c
CommitLineData
ff1f3280
SC
1/*
2 * gfio - gui front end for fio - the flexible io tester
3 *
4 * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com>
5 *
6 * The license below covers all files distributed with fio unless otherwise
7 * noted in the file itself.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 *
22 */
8232e285
SC
23#include <locale.h>
24
ff1f3280
SC
25#include <gtk/gtk.h>
26
8232e285
SC
27#include "fio_initialization.h"
28#include "fio.h"
29
30static struct client_ops *gfio_client_ops = &fio_client_ops;
31
f3074008
SC
32#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
33
34typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
35
36static void quit_clicked(GtkWidget *widget, gpointer data);
37static void start_job_clicked(GtkWidget *widget, gpointer data);
38
39static struct button_spec {
40 const char *buttontext;
41 clickfunction f;
42 const char *tooltiptext;
43} buttonspeclist[] = {
44#define START_JOB_BUTTON 0
45 { "Start Job",
46 start_job_clicked,
47 "Send current fio job to fio server to be executed" },
48#define QUIT_BUTTON 1
49 { "Quit", quit_clicked, "Quit gfio" },
50};
51
ff1f3280
SC
52struct gui {
53 GtkWidget *window;
f3074008
SC
54 GtkWidget *buttonbox;
55 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
ff1f3280
SC
56};
57
58static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
59 __attribute__((unused)) gpointer data)
60{
61 gtk_main_quit();
62}
63
f3074008
SC
64static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
65 __attribute__((unused)) gpointer data)
66{
67 printf("Start job button was clicked.\n");
68}
69
70static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
71 struct button_spec *buttonspec)
72{
73 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
74 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
75 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0);
76 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
77}
78
79static void add_buttons(struct gui *ui,
80 struct button_spec *buttonlist,
81 int nbuttons)
82{
83 int i;
84
85 ui->buttonbox = gtk_hbox_new(FALSE, 0);
86 gtk_container_add(GTK_CONTAINER (ui->window), ui->buttonbox);
87 for (i = 0; i < nbuttons; i++)
88 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
89}
90
ff1f3280
SC
91static void init_ui(int *argc, char **argv[], struct gui *ui)
92{
93 gtk_init(argc, argv);
94
95 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
96 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
97 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
98
99 g_signal_connect(ui->window, "delete-event", G_CALLBACK (quit_clicked), NULL);
100 g_signal_connect(ui->window, "destroy", G_CALLBACK (quit_clicked), NULL);
101
f3074008 102 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
ff1f3280
SC
103 gtk_widget_show_all(ui->window);
104}
105
8232e285 106int main(int argc, char *argv[], char *envp[])
ff1f3280
SC
107{
108 struct gui ui;
109
8232e285
SC
110 if (initialize_fio(envp))
111 return 1;
ff1f3280
SC
112 init_ui(&argc, &argv, &ui);
113 gtk_main();
114 return 0;
115}