1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
/* -*- c-file-style: "java"; indent-tabs-mode: nil; tab-width: 4; fill-column: 78 -*-
*
* distcc -- A simple distributed compiler system
*
* Copyright (C) 2003, 2004 by Martin Pool <mbp@samba.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*/
/**
* @file
*
* GtkCellRenderer subclass for drawing strip charts.
*
* Based on the example of gtkcellrendererpixbuf and hacked up.
*
* Each table cell corresponds to one execution slot for the client.
* Each host can have several slots. At most one task can run on each
* slot at any time. Therefore we can draw the history of tasks in
* this slot as a set of rectangles that do not overlap in time.
*
* The renderer looks directly at the list of running tasks to find
* the ones in its slot. It accesses the list through a global
* variable. This is pretty gross in terms of the Gtk object system,
* but it avoids worrying about memory management and filtering the
* tasks to put them on the right view of the model.
**/
#include <config.h>
#include <sys/types.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <pwd.h>
#include <unistd.h>
#include <glib.h>
#include <gtk/gtk.h>
#include "types.h"
#include "distcc.h"
#include "rpc.h"
#include "trace.h"
#include "exitcode.h"
#include "mon.h"
#include "netutil.h"
#include "renderer.h"
struct _DccCellRendererChart
{
GtkCellRenderer parent;
/** History of tasks for this slot. Exposed through the "history"
* property. */
struct dcc_history *history;
};
struct _DccCellRendererChartClass
{
GtkCellRendererClass parent_class;
};
enum {
PROP_ZERO,
PROP_HISTORY
};
/**
* Create a new cell renderer to display a chart of compilation jobs.
**/
GtkCellRenderer *
dcc_cell_renderer_chart_new (void)
{
return g_object_new (DCC_TYPE_CELL_RENDERER_CHART, NULL);
}
static void
dcc_cell_renderer_chart_set_property (GObject *object,
guint prop_id,
const GValue *value,
GParamSpec *pspec)
{
DccCellRendererChart *renderer;
renderer = DCC_CELL_RENDERER_CHART (object);
switch (prop_id)
{
case PROP_HISTORY:
renderer->history = g_value_get_pointer (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
static void
dcc_cell_renderer_chart_get_property (GObject *object,
guint prop_id,
GValue *value,
GParamSpec *pspec)
{
DccCellRendererChart *renderer;
renderer = DCC_CELL_RENDERER_CHART (object);
switch (prop_id)
{
case PROP_HISTORY:
g_value_set_pointer (value, renderer->history);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
}
/**
* Actually draw one cell (one strip chart) into a widget.
*
* I tried checking against the expose area to see whether we needed
* to repaint the whole thing, but it does not seem to help very much.
* GTK+ always tells us the whole cell is exposed when it updates the
* table, even if part of the cell is actually obscured by some other
* window. The refresh events are the performance-critical ones for
* us; the others don't matter nearly so much.
**/
static void
dcc_cell_renderer_chart_render (GtkCellRenderer *cell,
GdkWindow *window,
GtkWidget *UNUSED(widget),
GdkRectangle *UNUSED(background_area),
GdkRectangle *cell_area,
GdkRectangle *UNUSED(expose_area),
GtkCellRendererState UNUSED(flags))
{
const struct dcc_history *history;
enum dcc_phase state;
int x1, y1;
int bar_height;
int bar_width;
int i;
const enum dcc_phase *phases;
DccCellRendererChart *cellchart = (DccCellRendererChart *) cell;
history = cellchart->history;
g_return_if_fail (history); /* Perhaps we should just ignore this.. */
x1 = cell_area->x + cell->xpad;
y1 = cell_area->y + cell->ypad;
bar_height = cell_area->height - (2 * cell->ypad);
/* bar width is chosen such that the history roughly fills the cell
(but it must be at least 1). We use the full history, not just
the amount we currently have. Round up. */
bar_width = (cell_area->width + history->len - 1) / history->len;
if (bar_width < 1)
bar_width = 1;
phases = history->past_phases;
for (i = 0; i < history->len; i++)
{
state = phases[(history->len + history->now - i) % history->len];
g_return_if_fail (state <= DCC_PHASE_DONE);
if (state != DCC_PHASE_DONE)
{
gdk_draw_rectangle (window,
dcc_phase_gc[state],
TRUE, /* fill */
x1, y1, bar_width, bar_height);
}
x1 += bar_width;
}
}
/**
* Measure the size that we want to have allocated for this cell.
*/
static void
dcc_cell_renderer_chart_get_size (GtkCellRenderer *UNUSED(cell),
GtkWidget *UNUSED (widget),
GdkRectangle *UNUSED (cell_area),
gint *UNUSED (x_offset),
gint *UNUSED (y_offset),
gint *UNUSED (width),
gint *UNUSED (height))
{
/* default is fine */
}
static void
dcc_cell_renderer_chart_class_init (DccCellRendererChartClass *class)
{
GParamSpec *spec;
GObjectClass *object_class = G_OBJECT_CLASS (class);
GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (class);
object_class->get_property = dcc_cell_renderer_chart_get_property;
object_class->set_property = dcc_cell_renderer_chart_set_property;
cell_class->render = dcc_cell_renderer_chart_render;
cell_class->get_size = dcc_cell_renderer_chart_get_size;
spec = g_param_spec_pointer ("history",
"Slot history",
"",
G_PARAM_READABLE | G_PARAM_WRITABLE);
g_object_class_install_property (object_class,
PROP_HISTORY,
spec);
}
/* Instance initialization */
static void
dcc_cell_renderer_chart_init (DccCellRendererChart *cell)
{
cell->history = NULL;
}
/**
* Return metaobject info to GObject system. Or something.
**/
GType
dcc_cell_renderer_chart_get_type (void)
{
static GType cell_chart_type = 0;
if (!cell_chart_type)
{
static const GTypeInfo cell_chart_info =
{
sizeof (DccCellRendererChartClass),
NULL, /* base_init */
NULL, /* base_finalize */
(GClassInitFunc) dcc_cell_renderer_chart_class_init,
NULL, /* class_finalize */
NULL, /* class_data */
sizeof (DccCellRendererChart),
0, /* n_preallocs */
(GInstanceInitFunc) dcc_cell_renderer_chart_init,
NULL /* value_table */
};
cell_chart_type =
g_type_register_static (GTK_TYPE_CELL_RENDERER,
"DccCellRendererChart",
&cell_chart_info, 0);
}
return cell_chart_type;
}
|