fio: add placeholder gui client ops
[fio.git] / gfio.c
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  */
23 #include <locale.h>
24
25 #include <gtk/gtk.h>
26
27 #include "fio_initialization.h"
28 #include "fio.h"
29
30 #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
31
32 typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
33
34 static void quit_clicked(GtkWidget *widget, gpointer data);
35 static void start_job_clicked(GtkWidget *widget, gpointer data);
36
37 static struct button_spec {
38         const char *buttontext;
39         clickfunction f;
40         const char *tooltiptext;
41 } buttonspeclist[] = {
42 #define START_JOB_BUTTON 0
43         { "Start Job",
44                 start_job_clicked,
45                 "Send current fio job to fio server to be executed" },
46 #define QUIT_BUTTON 1
47         { "Quit", quit_clicked, "Quit gfio" },
48 };
49
50 struct gui {
51         GtkWidget *window;
52         GtkWidget *buttonbox;
53         GtkWidget *button[ARRAYSIZE(buttonspeclist)];
54 };
55
56 static void gfio_text_op(struct fio_client *client,
57                 FILE *f, __u16 pdu_len, const char *buf)
58 {
59         printf("gfio_text_op called\n");
60         fio_client_ops.text_op(client, f, pdu_len, buf);
61 }
62
63 static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
64 {
65         printf("gfio_disk_util_op called\n");
66         fio_client_ops.disk_util(client, cmd);
67 }
68
69 static void gfio_thread_status_op(struct fio_net_cmd *cmd)
70 {
71         printf("gfio_thread_status_op called\n");
72         fio_client_ops.thread_status(cmd);
73 }
74
75 static void gfio_group_stats_op(struct fio_net_cmd *cmd)
76 {
77         printf("gfio_group_stats_op called\n");
78         fio_client_ops.group_stats(cmd);
79 }
80
81 static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd)
82 {
83         printf("gfio_eta_op called\n");
84         fio_client_ops.eta(client, cmd);
85 }
86
87 static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
88 {
89         printf("gfio_probe_op called\n");
90         fio_client_ops.probe(client, cmd);
91 }
92
93 struct client_ops gfio_client_ops = {
94         gfio_text_op,
95         gfio_disk_util_op,
96         gfio_thread_status_op,
97         gfio_group_stats_op,
98         gfio_eta_op,
99         gfio_probe_op,
100 };
101
102 static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
103                 __attribute__((unused)) gpointer data)
104 {
105         gtk_main_quit();
106 }
107
108 static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
109                 __attribute__((unused)) gpointer data)
110 {
111         printf("Start job button was clicked.\n");
112 }
113
114 static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
115                         struct button_spec *buttonspec)
116 {
117         ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
118         g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
119         gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0);
120         gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
121 }
122
123 static void add_buttons(struct gui *ui,
124                                 struct button_spec *buttonlist,
125                                 int nbuttons)
126 {
127         int i;
128
129         ui->buttonbox = gtk_hbox_new(FALSE, 0);
130         gtk_container_add(GTK_CONTAINER (ui->window), ui->buttonbox);
131         for (i = 0; i < nbuttons; i++)
132                 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
133 }
134
135 static void init_ui(int *argc, char **argv[], struct gui *ui)
136 {
137         gtk_init(argc, argv);
138         
139         ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
140         gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
141         gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
142
143         g_signal_connect(ui->window, "delete-event", G_CALLBACK (quit_clicked), NULL);
144         g_signal_connect(ui->window, "destroy", G_CALLBACK (quit_clicked), NULL);
145
146         add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
147         gtk_widget_show_all(ui->window);
148 }
149
150 int main(int argc, char *argv[], char *envp[])
151 {
152         struct gui ui;
153
154         if (initialize_fio(envp))
155                 return 1;
156
157         if (parse_options(argc, argv))
158                 return 1;
159
160         init_ui(&argc, &argv, &ui);
161         gtk_main();
162         return 0;
163 }