fixed some drawing details
[lttv.git] / ltt / branches / poly / lttv / modules / guiControlFlow / Process_List.c
1
2 #include <gtk/gtk.h>
3 #include <glib.h>
4 #include "Process_List.h"
5 #include "Draw_Item.h"
6
7 /*****************************************************************************
8 * Methods to synchronize process list *
9 *****************************************************************************/
10
11 /* Enumeration of the columns */
12 enum
13 {
14 PROCESS_COLUMN,
15 PID_COLUMN,
16 BIRTH_S_COLUMN,
17 BIRTH_NS_COLUMN,
18 N_COLUMNS
19 };
20
21
22 gint process_sort_func ( GtkTreeModel *model,
23 GtkTreeIter *it_a,
24 GtkTreeIter *it_b,
25 gpointer user_data)
26 {
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;
132
133 }
134
135 guint hash_fct(gconstpointer key)
136 {
137 return ((ProcessInfo*)key)->pid;
138 }
139
140 gboolean equ_fct(gconstpointer a, gconstpointer b)
141 {
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;
154 }
155
156 void destroy_hash_key(gpointer key);
157
158 void destroy_hash_data(gpointer data);
159
160
161
162
163 ProcessList *processlist_construct(void)
164 {
165 GtkTreeViewColumn *column;
166 GtkCellRenderer *renderer;
167
168 ProcessList* Process_List = g_new(ProcessList,1);
169
170 Process_List->Number_Of_Process = 0;
171
172 /* Create the Process list */
173 Process_List->Store_M = gtk_list_store_new ( N_COLUMNS,
174 G_TYPE_STRING,
175 G_TYPE_UINT,
176 G_TYPE_ULONG,
177 G_TYPE_ULONG);
178
179
180 Process_List->Process_List_VC =
181 gtk_tree_view_new_with_model
182 (GTK_TREE_MODEL (Process_List->Store_M));
183
184 g_object_unref (G_OBJECT (Process_List->Store_M));
185
186 gtk_tree_sortable_set_sort_func(
187 GTK_TREE_SORTABLE(Process_List->Store_M),
188 PID_COLUMN,
189 process_sort_func,
190 NULL,
191 NULL);
192
193 gtk_tree_sortable_set_sort_column_id(
194 GTK_TREE_SORTABLE(Process_List->Store_M),
195 PID_COLUMN,
196 GTK_SORT_ASCENDING);
197
198 Process_List->Process_Hash = g_hash_table_new_full(
199 hash_fct, equ_fct,
200 destroy_hash_key, destroy_hash_data
201 );
202
203
204 gtk_tree_view_set_headers_visible(
205 GTK_TREE_VIEW(Process_List->Process_List_VC), FALSE);
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 (
219 GTK_TREE_VIEW (Process_List->Process_List_VC), column);
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 (
227 GTK_TREE_VIEW (Process_List->Process_List_VC), column);
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 (
236 GTK_TREE_VIEW (Process_List->Process_List_VC), column);
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 (
246 GTK_TREE_VIEW (Process_List->Process_List_VC), column);
247
248 //gtk_tree_view_column_set_visible(column, 0);
249
250 g_object_set_data_full(
251 G_OBJECT(Process_List->Process_List_VC),
252 "Process_List_Data",
253 Process_List,
254 (GDestroyNotify)processlist_destroy);
255
256 Process_List->Test_Process_Sent = 0;
257
258 return Process_List;
259 }
260 void processlist_destroy(ProcessList *Process_List)
261 {
262 g_hash_table_destroy(Process_List->Process_Hash);
263 Process_List->Process_Hash = NULL;
264
265 g_free(Process_List);
266 }
267
268 GtkWidget *processlist_get_widget(ProcessList *Process_List)
269 {
270 return Process_List->Process_List_VC;
271 }
272
273
274
275 gint get_cell_height(GtkTreeView *TreeView)
276 {
277 gint height;
278 GtkTreeViewColumn *Column = gtk_tree_view_get_column(TreeView, 0);
279 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
280 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
281
282 //g_list_free(Render_List);
283 gtk_tree_view_column_cell_get_size(Column, NULL, NULL, NULL, NULL, &height);
284 //g_critical("cell 0 height : %u",height);
285
286 return height;
287 }
288
289 void destroy_hash_key(gpointer key)
290 {
291 g_free(key);
292 }
293
294 void destroy_hash_data(gpointer data)
295 {
296 g_free(data);
297 }
298
299 int processlist_add( ProcessList *Process_List,
300 guint pid,
301 LttTime *birth,
302 gchar *name,
303 guint *height,
304 HashedProcessData **pmHashed_Process_Data)
305 {
306 GtkTreeIter iter ;
307 ProcessInfo *Process_Info = g_new(ProcessInfo, 1);
308 HashedProcessData *Hashed_Process_Data = g_new(HashedProcessData, 1);
309 *pmHashed_Process_Data = Hashed_Process_Data;
310
311 Process_Info->pid = pid;
312 Process_Info->birth = *birth;
313
314 Hashed_Process_Data->draw_context = g_new(DrawContext, 1);
315 Hashed_Process_Data->draw_context->drawable = NULL;
316 Hashed_Process_Data->draw_context->gc = 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->ts = NULL;
337 Hashed_Process_Data->draw_context->Current->tfs = NULL;
338 Hashed_Process_Data->draw_context->Previous = g_new(DrawInfo,1);
339 Hashed_Process_Data->draw_context->Previous->over = g_new(ItemInfo,1);
340 Hashed_Process_Data->draw_context->Previous->over->x = -1;
341 Hashed_Process_Data->draw_context->Previous->over->y = -1;
342 Hashed_Process_Data->draw_context->Previous->middle = g_new(ItemInfo,1);
343 Hashed_Process_Data->draw_context->Previous->middle->x = -1;
344 Hashed_Process_Data->draw_context->Previous->middle->y = -1;
345 Hashed_Process_Data->draw_context->Previous->under = g_new(ItemInfo,1);
346 Hashed_Process_Data->draw_context->Previous->under->x = -1;
347 Hashed_Process_Data->draw_context->Previous->under->y = -1;
348 Hashed_Process_Data->draw_context->Previous->modify_over = g_new(ItemInfo,1);
349 Hashed_Process_Data->draw_context->Previous->modify_over->x = -1;
350 Hashed_Process_Data->draw_context->Previous->modify_over->y = -1;
351 Hashed_Process_Data->draw_context->Previous->modify_middle = g_new(ItemInfo,1);
352 Hashed_Process_Data->draw_context->Previous->modify_middle->x = -1;
353 Hashed_Process_Data->draw_context->Previous->modify_middle->y = -1;
354 Hashed_Process_Data->draw_context->Previous->modify_under = g_new(ItemInfo,1);
355 Hashed_Process_Data->draw_context->Previous->modify_under->x = -1;
356 Hashed_Process_Data->draw_context->Previous->modify_under->y = -1;
357 Hashed_Process_Data->draw_context->Previous->ts = NULL;
358 Hashed_Process_Data->draw_context->Previous->tfs = NULL;
359
360 /* Add a new row to the model */
361 gtk_list_store_append ( Process_List->Store_M, &iter);
362 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
363 // gtk_tree_model_get_path (
364 // GTK_TREE_MODEL(Process_List->Store_M),
365 // &iter)));
366 gtk_list_store_set ( Process_List->Store_M, &iter,
367 PROCESS_COLUMN, name,
368 PID_COLUMN, pid,
369 BIRTH_S_COLUMN, birth->tv_sec,
370 BIRTH_NS_COLUMN, birth->tv_nsec,
371 -1);
372 Hashed_Process_Data->RowRef = gtk_tree_row_reference_new (
373 GTK_TREE_MODEL(Process_List->Store_M),
374 gtk_tree_model_get_path(
375 GTK_TREE_MODEL(Process_List->Store_M),
376 &iter));
377 g_hash_table_insert( Process_List->Process_Hash,
378 (gpointer)Process_Info,
379 (gpointer)Hashed_Process_Data);
380
381 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
382 // gtk_tree_model_get_path (
383 // GTK_TREE_MODEL(Process_List->Store_M),
384 // &iter)));
385 Process_List->Number_Of_Process++;
386
387 *height = get_cell_height(GTK_TREE_VIEW(Process_List->Process_List_VC))
388 * Process_List->Number_Of_Process ;
389
390
391 return 0;
392
393 }
394
395 int processlist_remove( ProcessList *Process_List,
396 guint pid,
397 LttTime *birth)
398 {
399 ProcessInfo Process_Info;
400 gint *path_indices;
401 HashedProcessData *Hashed_Process_Data;
402 GtkTreeIter iter;
403
404 Process_Info.pid = pid;
405 Process_Info.birth = *birth;
406
407
408 if(Hashed_Process_Data =
409 (HashedProcessData*)g_hash_table_lookup(
410 Process_List->Process_Hash,
411 &Process_Info))
412 {
413 gtk_tree_model_get_iter (
414 GTK_TREE_MODEL(Process_List->Store_M),
415 &iter,
416 gtk_tree_row_reference_get_path(
417 (GtkTreeRowReference*)Hashed_Process_Data->RowRef)
418 );
419
420 gtk_list_store_remove (Process_List->Store_M, &iter);
421
422 g_free(Hashed_Process_Data->draw_context->Previous->modify_under);
423 g_free(Hashed_Process_Data->draw_context->Previous->modify_middle);
424 g_free(Hashed_Process_Data->draw_context->Previous->modify_over);
425 g_free(Hashed_Process_Data->draw_context->Previous->under);
426 g_free(Hashed_Process_Data->draw_context->Previous->middle);
427 g_free(Hashed_Process_Data->draw_context->Previous->over);
428 g_free(Hashed_Process_Data->draw_context->Previous);
429 g_free(Hashed_Process_Data->draw_context->Current->modify_under);
430 g_free(Hashed_Process_Data->draw_context->Current->modify_middle);
431 g_free(Hashed_Process_Data->draw_context->Current->modify_over);
432 g_free(Hashed_Process_Data->draw_context->Current->under);
433 g_free(Hashed_Process_Data->draw_context->Current->middle);
434 g_free(Hashed_Process_Data->draw_context->Current->over);
435 g_free(Hashed_Process_Data->draw_context->Current);
436 g_free(Hashed_Process_Data->draw_context);
437 g_free(Hashed_Process_Data);
438
439 g_hash_table_remove(Process_List->Process_Hash,
440 &Process_Info);
441
442 Process_List->Number_Of_Process--;
443
444 return 0;
445 } else {
446 return 1;
447 }
448 }
449
450
451 guint processlist_get_height(ProcessList *Process_List)
452 {
453 return get_cell_height(GTK_TREE_VIEW(Process_List->Process_List_VC))
454 * Process_List->Number_Of_Process ;
455 }
456
457
458 gint processlist_get_process_pixels( ProcessList *Process_List,
459 guint pid, LttTime *birth,
460 guint *y,
461 guint *height,
462 HashedProcessData **pmHashed_Process_Data)
463 {
464 ProcessInfo Process_Info;
465 gint *path_indices;
466 GtkTreePath *tree_path;
467 HashedProcessData *Hashed_Process_Data = NULL;
468
469 Process_Info.pid = pid;
470 Process_Info.birth = *birth;
471
472 if(Hashed_Process_Data =
473 (HashedProcessData*)g_hash_table_lookup(
474 Process_List->Process_Hash,
475 &Process_Info))
476 {
477 tree_path = gtk_tree_row_reference_get_path(
478 Hashed_Process_Data->RowRef);
479 path_indices = gtk_tree_path_get_indices (tree_path);
480
481 *height = get_cell_height(
482 GTK_TREE_VIEW(Process_List->Process_List_VC));
483 *y = *height * path_indices[0];
484 *pmHashed_Process_Data = Hashed_Process_Data;
485 return 0;
486 } else {
487 *pmHashed_Process_Data = Hashed_Process_Data;
488 return 1;
489 }
490
491 }
This page took 0.048387 seconds and 4 git commands to generate.