file names mod part 2
[lttv.git] / ltt / branches / poly / lttv / modules / gui / ControlFlow / processlist.c
1
2 #include <gtk/gtk.h>
3 #include <glib.h>
4
5 #include "processlist.h"
6 #include "drawitem.h"
7
8 /*****************************************************************************
9 * Methods to synchronize process list *
10 *****************************************************************************/
11
12 /* Enumeration of the columns */
13 enum
14 {
15 PROCESS_COLUMN,
16 PID_COLUMN,
17 BIRTH_S_COLUMN,
18 BIRTH_NS_COLUMN,
19 N_COLUMNS
20 };
21
22
23 gint process_sort_func ( GtkTreeModel *model,
24 GtkTreeIter *it_a,
25 GtkTreeIter *it_b,
26 gpointer user_data)
27 {
28 GValue a, b;
29
30 memset(&a, 0, sizeof(GValue));
31 memset(&b, 0, sizeof(GValue));
32
33 /* Order by PID */
34 gtk_tree_model_get_value( model,
35 it_a,
36 PID_COLUMN,
37 &a);
38
39 gtk_tree_model_get_value( model,
40 it_b,
41 PID_COLUMN,
42 &b);
43
44 if(G_VALUE_TYPE(&a) == G_TYPE_UINT
45 && G_VALUE_TYPE(&b) == G_TYPE_UINT )
46 {
47 if(g_value_get_uint(&a) > g_value_get_uint(&b))
48 {
49 g_value_unset(&a);
50 g_value_unset(&b);
51 return 1;
52 }
53 if(g_value_get_uint(&a) < g_value_get_uint(&b))
54 {
55 g_value_unset(&a);
56 g_value_unset(&b);
57 return 0;
58 }
59 }
60
61 g_value_unset(&a);
62 g_value_unset(&b);
63
64
65 /* Order by birth second */
66 gtk_tree_model_get_value( model,
67 it_a,
68 BIRTH_S_COLUMN,
69 &a);
70
71 gtk_tree_model_get_value( model,
72 it_b,
73 BIRTH_S_COLUMN,
74 &b);
75
76
77 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
78 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
79 {
80 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
81 {
82 g_value_unset(&a);
83 g_value_unset(&b);
84 return 1;
85 }
86 if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
87 {
88 g_value_unset(&a);
89 g_value_unset(&b);
90 return 0;
91 }
92
93 }
94
95 g_value_unset(&a);
96 g_value_unset(&b);
97
98 /* Order by birth nanosecond */
99 gtk_tree_model_get_value( model,
100 it_a,
101 BIRTH_NS_COLUMN,
102 &a);
103
104 gtk_tree_model_get_value( model,
105 it_b,
106 BIRTH_NS_COLUMN,
107 &b);
108
109
110 if(G_VALUE_TYPE(&a) == G_TYPE_ULONG
111 && G_VALUE_TYPE(&b) == G_TYPE_ULONG )
112 {
113 if(g_value_get_ulong(&a) > g_value_get_ulong(&b))
114 {
115 g_value_unset(&a);
116 g_value_unset(&b);
117 return 1;
118 }
119 // Final condition
120 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
121 //{
122 // g_value_unset(&a);
123 // g_value_unset(&b);
124 // return 0;
125 //}
126
127 }
128
129 g_value_unset(&a);
130 g_value_unset(&b);
131
132 return 0;
133
134 }
135
136 guint hash_fct(gconstpointer key)
137 {
138 return ((ProcessInfo*)key)->pid;
139 }
140
141 gboolean equ_fct(gconstpointer a, gconstpointer b)
142 {
143 if(((ProcessInfo*)a)->pid != ((ProcessInfo*)b)->pid)
144 return 0;
145 // g_critical("compare %u and %u",((ProcessInfo*)a)->pid,((ProcessInfo*)b)->pid);
146 if(((ProcessInfo*)a)->birth.tv_sec != ((ProcessInfo*)b)->birth.tv_sec)
147 return 0;
148 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
149
150 if(((ProcessInfo*)a)->birth.tv_nsec != ((ProcessInfo*)b)->birth.tv_nsec)
151 return 0;
152 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
153
154 return 1;
155 }
156
157 void destroy_hash_key(gpointer key);
158
159 void destroy_hash_data(gpointer data);
160
161
162
163
164 ProcessList *processlist_construct(void)
165 {
166 GtkTreeViewColumn *column;
167 GtkCellRenderer *renderer;
168
169 ProcessList* process_list = g_new(ProcessList,1);
170
171 process_list->number_of_process = 0;
172
173 /* Create the Process list */
174 process_list->list_store = gtk_list_store_new ( N_COLUMNS,
175 G_TYPE_STRING,
176 G_TYPE_UINT,
177 G_TYPE_ULONG,
178 G_TYPE_ULONG);
179
180
181 process_list->process_list_widget =
182 gtk_tree_view_new_with_model
183 (GTK_TREE_MODEL (process_list->list_store));
184
185 g_object_unref (G_OBJECT (process_list->list_store));
186
187 gtk_tree_sortable_set_sort_func(
188 GTK_TREE_SORTABLE(process_list->list_store),
189 PID_COLUMN,
190 process_sort_func,
191 NULL,
192 NULL);
193
194 gtk_tree_sortable_set_sort_column_id(
195 GTK_TREE_SORTABLE(process_list->list_store),
196 PID_COLUMN,
197 GTK_SORT_ASCENDING);
198
199 process_list->process_hash = g_hash_table_new_full(
200 hash_fct, equ_fct,
201 destroy_hash_key, destroy_hash_data
202 );
203
204
205 gtk_tree_view_set_headers_visible(
206 GTK_TREE_VIEW(process_list->process_list_widget), FALSE);
207
208 /* Create a column, associating the "text" attribute of the
209 * cell_renderer to the first column of the model */
210 /* Columns alignment : 0.0 : Left 0.5 : Center 1.0 : Right */
211 renderer = gtk_cell_renderer_text_new ();
212 column = gtk_tree_view_column_new_with_attributes ( "Process",
213 renderer,
214 "text",
215 PROCESS_COLUMN,
216 NULL);
217 gtk_tree_view_column_set_alignment (column, 0.0);
218 gtk_tree_view_column_set_fixed_width (column, 45);
219 gtk_tree_view_append_column (
220 GTK_TREE_VIEW (process_list->process_list_widget), column);
221
222 column = gtk_tree_view_column_new_with_attributes ( "PID",
223 renderer,
224 "text",
225 PID_COLUMN,
226 NULL);
227 gtk_tree_view_append_column (
228 GTK_TREE_VIEW (process_list->process_list_widget), column);
229
230
231 column = gtk_tree_view_column_new_with_attributes ( "Birth sec",
232 renderer,
233 "text",
234 BIRTH_S_COLUMN,
235 NULL);
236 gtk_tree_view_append_column (
237 GTK_TREE_VIEW (process_list->process_list_widget), column);
238
239 //gtk_tree_view_column_set_visible(column, 0);
240 //
241 column = gtk_tree_view_column_new_with_attributes ( "Birth nsec",
242 renderer,
243 "text",
244 BIRTH_NS_COLUMN,
245 NULL);
246 gtk_tree_view_append_column (
247 GTK_TREE_VIEW (process_list->process_list_widget), column);
248
249 //gtk_tree_view_column_set_visible(column, 0);
250
251 g_object_set_data_full(
252 G_OBJECT(process_list->process_list_widget),
253 "process_list_Data",
254 process_list,
255 (GDestroyNotify)processlist_destroy);
256
257 return process_list;
258 }
259 void processlist_destroy(ProcessList *process_list)
260 {
261 g_hash_table_destroy(process_list->process_hash);
262 process_list->process_hash = NULL;
263
264 g_free(process_list);
265 }
266
267 GtkWidget *processlist_get_widget(ProcessList *process_list)
268 {
269 return process_list->process_list_widget;
270 }
271
272
273
274 gint get_cell_height(GtkTreeView *tree_view)
275 {
276 gint height;
277 GtkTreeViewColumn *Column = gtk_tree_view_get_column(tree_view, 0);
278 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
279 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
280
281 //g_list_free(Render_List);
282 gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height);
283 //g_critical("cell 0 height : %u",height);
284
285 return height;
286 }
287
288 void destroy_hash_key(gpointer key)
289 {
290 g_free(key);
291 }
292
293 void destroy_hash_data(gpointer data)
294 {
295 g_free(data);
296 }
297
298 int processlist_add( ProcessList *process_list,
299 guint pid,
300 LttTime *birth,
301 gchar *name,
302 guint *height,
303 HashedProcessData **pm_hashed_process_data)
304 {
305 GtkTreeIter iter ;
306 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
307 HashedProcessData *hashed_process_data = g_new(HashedProcessData, 1);
308 *pm_hashed_process_data = hashed_process_data;
309
310 Process_Info->pid = pid;
311 Process_Info->birth = *birth;
312
313 hashed_process_data->draw_context = g_new(DrawContext, 1);
314 hashed_process_data->draw_context->drawable = NULL;
315 hashed_process_data->draw_context->gc = NULL;
316 hashed_process_data->draw_context->pango_layout = NULL;
317 hashed_process_data->draw_context->current = g_new(DrawInfo,1);
318 hashed_process_data->draw_context->current->over = g_new(ItemInfo,1);
319 hashed_process_data->draw_context->current->over->x = -1;
320 hashed_process_data->draw_context->current->over->y = -1;
321 hashed_process_data->draw_context->current->middle = g_new(ItemInfo,1);
322 hashed_process_data->draw_context->current->middle->x = -1;
323 hashed_process_data->draw_context->current->middle->y = -1;
324 hashed_process_data->draw_context->current->under = g_new(ItemInfo,1);
325 hashed_process_data->draw_context->current->under->x = -1;
326 hashed_process_data->draw_context->current->under->y = -1;
327 hashed_process_data->draw_context->current->modify_over = g_new(ItemInfo,1);
328 hashed_process_data->draw_context->current->modify_over->x = -1;
329 hashed_process_data->draw_context->current->modify_over->y = -1;
330 hashed_process_data->draw_context->current->modify_middle = g_new(ItemInfo,1);
331 hashed_process_data->draw_context->current->modify_middle->x = -1;
332 hashed_process_data->draw_context->current->modify_middle->y = -1;
333 hashed_process_data->draw_context->current->modify_under = g_new(ItemInfo,1);
334 hashed_process_data->draw_context->current->modify_under->x = -1;
335 hashed_process_data->draw_context->current->modify_under->y = -1;
336 hashed_process_data->draw_context->current->status = LTTV_STATE_UNNAMED;
337 hashed_process_data->draw_context->previous = g_new(DrawInfo,1);
338 hashed_process_data->draw_context->previous->over = g_new(ItemInfo,1);
339 hashed_process_data->draw_context->previous->over->x = -1;
340 hashed_process_data->draw_context->previous->over->y = -1;
341 hashed_process_data->draw_context->previous->middle = g_new(ItemInfo,1);
342 hashed_process_data->draw_context->previous->middle->x = -1;
343 hashed_process_data->draw_context->previous->middle->y = -1;
344 hashed_process_data->draw_context->previous->under = g_new(ItemInfo,1);
345 hashed_process_data->draw_context->previous->under->x = -1;
346 hashed_process_data->draw_context->previous->under->y = -1;
347 hashed_process_data->draw_context->previous->modify_over = g_new(ItemInfo,1);
348 hashed_process_data->draw_context->previous->modify_over->x = -1;
349 hashed_process_data->draw_context->previous->modify_over->y = -1;
350 hashed_process_data->draw_context->previous->modify_middle = g_new(ItemInfo,1);
351 hashed_process_data->draw_context->previous->modify_middle->x = -1;
352 hashed_process_data->draw_context->previous->modify_middle->y = -1;
353 hashed_process_data->draw_context->previous->modify_under = g_new(ItemInfo,1);
354 hashed_process_data->draw_context->previous->modify_under->x = -1;
355 hashed_process_data->draw_context->previous->modify_under->y = -1;
356 hashed_process_data->draw_context->previous->status = LTTV_STATE_UNNAMED;
357
358 /* Add a new row to the model */
359 gtk_list_store_append ( process_list->list_store, &iter);
360 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
361 // gtk_tree_model_get_path (
362 // GTK_TREE_MODEL(process_list->list_store),
363 // &iter)));
364 gtk_list_store_set ( process_list->list_store, &iter,
365 PROCESS_COLUMN, name,
366 PID_COLUMN, pid,
367 BIRTH_S_COLUMN, birth->tv_sec,
368 BIRTH_NS_COLUMN, birth->tv_nsec,
369 -1);
370 hashed_process_data->row_ref = gtk_tree_row_reference_new (
371 GTK_TREE_MODEL(process_list->list_store),
372 gtk_tree_model_get_path(
373 GTK_TREE_MODEL(process_list->list_store),
374 &iter));
375 g_hash_table_insert( process_list->process_hash,
376 (gpointer)Process_Info,
377 (gpointer)hashed_process_data);
378
379 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
380 // gtk_tree_model_get_path (
381 // GTK_TREE_MODEL(process_list->list_store),
382 // &iter)));
383 process_list->number_of_process++;
384
385 *height = get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
386 * process_list->number_of_process ;
387
388
389 return 0;
390
391 }
392
393 int processlist_remove( ProcessList *process_list,
394 guint pid,
395 LttTime *birth)
396 {
397 ProcessInfo Process_Info;
398 gint *path_indices;
399 HashedProcessData *hashed_process_data;
400 GtkTreeIter iter;
401
402 Process_Info.pid = pid;
403 Process_Info.birth = *birth;
404
405
406 if(hashed_process_data =
407 (HashedProcessData*)g_hash_table_lookup(
408 process_list->process_hash,
409 &Process_Info))
410 {
411 gtk_tree_model_get_iter (
412 GTK_TREE_MODEL(process_list->list_store),
413 &iter,
414 gtk_tree_row_reference_get_path(
415 (GtkTreeRowReference*)hashed_process_data->row_ref)
416 );
417
418 gtk_list_store_remove (process_list->list_store, &iter);
419
420 g_free(hashed_process_data->draw_context->previous->modify_under);
421 g_free(hashed_process_data->draw_context->previous->modify_middle);
422 g_free(hashed_process_data->draw_context->previous->modify_over);
423 g_free(hashed_process_data->draw_context->previous->under);
424 g_free(hashed_process_data->draw_context->previous->middle);
425 g_free(hashed_process_data->draw_context->previous->over);
426 g_free(hashed_process_data->draw_context->previous);
427 g_free(hashed_process_data->draw_context->current->modify_under);
428 g_free(hashed_process_data->draw_context->current->modify_middle);
429 g_free(hashed_process_data->draw_context->current->modify_over);
430 g_free(hashed_process_data->draw_context->current->under);
431 g_free(hashed_process_data->draw_context->current->middle);
432 g_free(hashed_process_data->draw_context->current->over);
433 g_free(hashed_process_data->draw_context->current);
434 g_free(hashed_process_data->draw_context);
435 g_free(hashed_process_data);
436
437 g_hash_table_remove(process_list->process_hash,
438 &Process_Info);
439
440 process_list->number_of_process--;
441
442 return 0;
443 } else {
444 return 1;
445 }
446 }
447
448
449 guint processlist_get_height(ProcessList *process_list)
450 {
451 return get_cell_height(GTK_TREE_VIEW(process_list->process_list_widget))
452 * process_list->number_of_process ;
453 }
454
455
456 gint processlist_get_process_pixels( ProcessList *process_list,
457 guint pid, LttTime *birth,
458 guint *y,
459 guint *height,
460 HashedProcessData **pm_hashed_process_data)
461 {
462 ProcessInfo Process_Info;
463 gint *path_indices;
464 GtkTreePath *tree_path;
465 HashedProcessData *hashed_process_data = NULL;
466
467 Process_Info.pid = pid;
468 Process_Info.birth = *birth;
469
470 if(hashed_process_data =
471 (HashedProcessData*)g_hash_table_lookup(
472 process_list->process_hash,
473 &Process_Info))
474 {
475 tree_path = gtk_tree_row_reference_get_path(
476 hashed_process_data->row_ref);
477 path_indices = gtk_tree_path_get_indices (tree_path);
478
479 *height = get_cell_height(
480 GTK_TREE_VIEW(process_list->process_list_widget));
481 *y = *height * path_indices[0];
482 *pm_hashed_process_data = hashed_process_data;
483 return 0;
484 } else {
485 *pm_hashed_process_data = hashed_process_data;
486 return 1;
487 }
488
489 }
490
491
492 gint processlist_get_pixels_from_data( ProcessList *process_list,
493 ProcessInfo *process_info,
494 HashedProcessData *hashed_process_data,
495 guint *y,
496 guint *height)
497 {
498 gint *path_indices;
499 GtkTreePath *tree_path;
500
501 tree_path = gtk_tree_row_reference_get_path(
502 hashed_process_data->row_ref);
503 path_indices = gtk_tree_path_get_indices (tree_path);
504
505 *height = get_cell_height(
506 GTK_TREE_VIEW(process_list->process_list_widget));
507 *y = *height * path_indices[0];
508
509 return 0;
510
511 }
This page took 0.044723 seconds and 4 git commands to generate.