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