4 #include "Process_List.h"
7 /*****************************************************************************
8 * Methods to synchronize process list *
9 *****************************************************************************/
11 /* Enumeration of the columns */
22 gint
process_sort_func ( GtkTreeModel
*model
,
29 memset(&a
, 0, sizeof(GValue
));
30 memset(&b
, 0, sizeof(GValue
));
33 gtk_tree_model_get_value( model
,
38 gtk_tree_model_get_value( model
,
43 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
44 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
46 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
52 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
64 /* Order by birth second */
65 gtk_tree_model_get_value( model
,
70 gtk_tree_model_get_value( model
,
76 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
77 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
79 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
85 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
97 /* Order by birth nanosecond */
98 gtk_tree_model_get_value( model
,
103 gtk_tree_model_get_value( model
,
109 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
110 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
112 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
119 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
121 // g_value_unset(&a);
122 // g_value_unset(&b);
135 guint
hash_fct(gconstpointer key
)
137 return ((ProcessInfo
*)key
)->pid
;
140 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
142 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
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
)
147 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
149 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
151 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
156 void destroy_hash_key(gpointer key
);
158 void destroy_hash_data(gpointer data
);
163 ProcessList
*processlist_construct(void)
165 GtkTreeViewColumn
*column
;
166 GtkCellRenderer
*renderer
;
168 ProcessList
* process_list
= g_new(ProcessList
,1);
170 process_list
->number_of_process
= 0;
172 /* Create the Process list */
173 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
180 process_list
->process_list_widget
=
181 gtk_tree_view_new_with_model
182 (GTK_TREE_MODEL (process_list
->list_store
));
184 g_object_unref (G_OBJECT (process_list
->list_store
));
186 gtk_tree_sortable_set_sort_func(
187 GTK_TREE_SORTABLE(process_list
->list_store
),
193 gtk_tree_sortable_set_sort_column_id(
194 GTK_TREE_SORTABLE(process_list
->list_store
),
198 process_list
->process_hash
= g_hash_table_new_full(
200 destroy_hash_key
, destroy_hash_data
204 gtk_tree_view_set_headers_visible(
205 GTK_TREE_VIEW(process_list
->process_list_widget
), FALSE
);
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",
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_widget
), column
);
221 column
= gtk_tree_view_column_new_with_attributes ( "PID",
226 gtk_tree_view_append_column (
227 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
230 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
235 gtk_tree_view_append_column (
236 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
238 //gtk_tree_view_column_set_visible(column, 0);
240 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
245 gtk_tree_view_append_column (
246 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
248 //gtk_tree_view_column_set_visible(column, 0);
250 g_object_set_data_full(
251 G_OBJECT(process_list
->process_list_widget
),
254 (GDestroyNotify
)processlist_destroy
);
258 void processlist_destroy(ProcessList
*process_list
)
260 g_hash_table_destroy(process_list
->process_hash
);
261 process_list
->process_hash
= NULL
;
263 g_free(process_list
);
266 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
268 return process_list
->process_list_widget
;
273 gint
get_cell_height(GtkTreeView
*tree_view
)
276 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(tree_view
, 0);
277 //GList *Render_List = gtk_tree_view_column_get_cell_renderers(Column);
278 //GtkCellRenderer *Renderer = g_list_first(Render_List)->data;
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);
287 void destroy_hash_key(gpointer key
)
292 void destroy_hash_data(gpointer data
)
297 int processlist_add( ProcessList
*process_list
,
302 HashedProcessData
**pm_hashed_process_data
)
305 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
306 HashedProcessData
*hashed_process_data
= g_new(HashedProcessData
, 1);
307 *pm_hashed_process_data
= hashed_process_data
;
309 Process_Info
->pid
= pid
;
310 Process_Info
->birth
= *birth
;
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
;
357 /* Add a new row to the model */
358 gtk_list_store_append ( process_list
->list_store
, &iter
);
359 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
360 // gtk_tree_model_get_path (
361 // GTK_TREE_MODEL(process_list->list_store),
363 gtk_list_store_set ( process_list
->list_store
, &iter
,
364 PROCESS_COLUMN
, name
,
366 BIRTH_S_COLUMN
, birth
->tv_sec
,
367 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
369 hashed_process_data
->row_ref
= gtk_tree_row_reference_new (
370 GTK_TREE_MODEL(process_list
->list_store
),
371 gtk_tree_model_get_path(
372 GTK_TREE_MODEL(process_list
->list_store
),
374 g_hash_table_insert( process_list
->process_hash
,
375 (gpointer
)Process_Info
,
376 (gpointer
)hashed_process_data
);
378 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
379 // gtk_tree_model_get_path (
380 // GTK_TREE_MODEL(process_list->list_store),
382 process_list
->number_of_process
++;
384 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
385 * process_list
->number_of_process
;
392 int processlist_remove( ProcessList
*process_list
,
396 ProcessInfo Process_Info
;
398 HashedProcessData
*hashed_process_data
;
401 Process_Info
.pid
= pid
;
402 Process_Info
.birth
= *birth
;
405 if(hashed_process_data
=
406 (HashedProcessData
*)g_hash_table_lookup(
407 process_list
->process_hash
,
410 gtk_tree_model_get_iter (
411 GTK_TREE_MODEL(process_list
->list_store
),
413 gtk_tree_row_reference_get_path(
414 (GtkTreeRowReference
*)hashed_process_data
->row_ref
)
417 gtk_list_store_remove (process_list
->list_store
, &iter
);
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
);
436 g_hash_table_remove(process_list
->process_hash
,
439 process_list
->number_of_process
--;
448 guint
processlist_get_height(ProcessList
*process_list
)
450 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
451 * process_list
->number_of_process
;
455 gint
processlist_get_process_pixels( ProcessList
*process_list
,
456 guint pid
, LttTime
*birth
,
459 HashedProcessData
**pm_hashed_process_data
)
461 ProcessInfo Process_Info
;
463 GtkTreePath
*tree_path
;
464 HashedProcessData
*hashed_process_data
= NULL
;
466 Process_Info
.pid
= pid
;
467 Process_Info
.birth
= *birth
;
469 if(hashed_process_data
=
470 (HashedProcessData
*)g_hash_table_lookup(
471 process_list
->process_hash
,
474 tree_path
= gtk_tree_row_reference_get_path(
475 hashed_process_data
->row_ref
);
476 path_indices
= gtk_tree_path_get_indices (tree_path
);
478 *height
= get_cell_height(
479 GTK_TREE_VIEW(process_list
->process_list_widget
));
480 *y
= *height
* path_indices
[0];
481 *pm_hashed_process_data
= hashed_process_data
;
484 *pm_hashed_process_data
= hashed_process_data
;
491 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
492 ProcessInfo
*process_info
,
493 HashedProcessData
*hashed_process_data
,
498 GtkTreePath
*tree_path
;
500 tree_path
= gtk_tree_row_reference_get_path(
501 hashed_process_data
->row_ref
);
502 path_indices
= gtk_tree_path_get_indices (tree_path
);
504 *height
= get_cell_height(
505 GTK_TREE_VIEW(process_list
->process_list_widget
));
506 *y
= *height
* path_indices
[0];