5 #include "processlist.h"
8 /*****************************************************************************
9 * Methods to synchronize process list *
10 *****************************************************************************/
12 /* Enumeration of the columns */
23 gint
process_sort_func ( GtkTreeModel
*model
,
30 memset(&a
, 0, sizeof(GValue
));
31 memset(&b
, 0, sizeof(GValue
));
34 gtk_tree_model_get_value( model
,
39 gtk_tree_model_get_value( model
,
44 if(G_VALUE_TYPE(&a
) == G_TYPE_UINT
45 && G_VALUE_TYPE(&b
) == G_TYPE_UINT
)
47 if(g_value_get_uint(&a
) > g_value_get_uint(&b
))
53 if(g_value_get_uint(&a
) < g_value_get_uint(&b
))
65 /* Order by birth second */
66 gtk_tree_model_get_value( model
,
71 gtk_tree_model_get_value( model
,
77 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
78 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
80 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
86 if(g_value_get_ulong(&a
) < g_value_get_ulong(&b
))
98 /* Order by birth nanosecond */
99 gtk_tree_model_get_value( model
,
104 gtk_tree_model_get_value( model
,
110 if(G_VALUE_TYPE(&a
) == G_TYPE_ULONG
111 && G_VALUE_TYPE(&b
) == G_TYPE_ULONG
)
113 if(g_value_get_ulong(&a
) > g_value_get_ulong(&b
))
120 //if(g_value_get_ulong(&a) < g_value_get_ulong(&b))
122 // g_value_unset(&a);
123 // g_value_unset(&b);
136 guint
hash_fct(gconstpointer key
)
138 return ((ProcessInfo
*)key
)->pid
;
141 gboolean
equ_fct(gconstpointer a
, gconstpointer b
)
143 if(((ProcessInfo
*)a
)->pid
!= ((ProcessInfo
*)b
)->pid
)
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
)
148 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_sec,((ProcessInfo*)b)->birth.tv_sec);
150 if(((ProcessInfo
*)a
)->birth
.tv_nsec
!= ((ProcessInfo
*)b
)->birth
.tv_nsec
)
152 // g_critical("compare %u and %u",((ProcessInfo*)a)->birth.tv_nsec,((ProcessInfo*)b)->birth.tv_nsec);
157 void destroy_hash_key(gpointer key
);
159 void destroy_hash_data(gpointer data
);
164 ProcessList
*processlist_construct(void)
166 GtkTreeViewColumn
*column
;
167 GtkCellRenderer
*renderer
;
169 ProcessList
* process_list
= g_new(ProcessList
,1);
171 process_list
->number_of_process
= 0;
173 /* Create the Process list */
174 process_list
->list_store
= gtk_list_store_new ( N_COLUMNS
,
181 process_list
->process_list_widget
=
182 gtk_tree_view_new_with_model
183 (GTK_TREE_MODEL (process_list
->list_store
));
185 g_object_unref (G_OBJECT (process_list
->list_store
));
187 gtk_tree_sortable_set_sort_func(
188 GTK_TREE_SORTABLE(process_list
->list_store
),
194 gtk_tree_sortable_set_sort_column_id(
195 GTK_TREE_SORTABLE(process_list
->list_store
),
199 process_list
->process_hash
= g_hash_table_new_full(
201 destroy_hash_key
, destroy_hash_data
205 gtk_tree_view_set_headers_visible(
206 GTK_TREE_VIEW(process_list
->process_list_widget
), FALSE
);
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",
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
);
222 column
= gtk_tree_view_column_new_with_attributes ( "PID",
227 gtk_tree_view_append_column (
228 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
231 column
= gtk_tree_view_column_new_with_attributes ( "Birth sec",
236 gtk_tree_view_append_column (
237 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
239 //gtk_tree_view_column_set_visible(column, 0);
241 column
= gtk_tree_view_column_new_with_attributes ( "Birth nsec",
246 gtk_tree_view_append_column (
247 GTK_TREE_VIEW (process_list
->process_list_widget
), column
);
249 //gtk_tree_view_column_set_visible(column, 0);
251 g_object_set_data_full(
252 G_OBJECT(process_list
->process_list_widget
),
255 (GDestroyNotify
)processlist_destroy
);
259 void processlist_destroy(ProcessList
*process_list
)
261 g_hash_table_destroy(process_list
->process_hash
);
262 process_list
->process_hash
= NULL
;
264 g_free(process_list
);
267 GtkWidget
*processlist_get_widget(ProcessList
*process_list
)
269 return process_list
->process_list_widget
;
274 gint
get_cell_height(GtkTreeView
*tree_view
)
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;
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);
288 void destroy_hash_key(gpointer key
)
293 void destroy_hash_data(gpointer data
)
298 int processlist_add( ProcessList
*process_list
,
303 HashedProcessData
**pm_hashed_process_data
)
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
;
310 Process_Info
->pid
= pid
;
311 Process_Info
->birth
= *birth
;
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
;
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),
364 gtk_list_store_set ( process_list
->list_store
, &iter
,
365 PROCESS_COLUMN
, name
,
367 BIRTH_S_COLUMN
, birth
->tv_sec
,
368 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
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
),
375 g_hash_table_insert( process_list
->process_hash
,
376 (gpointer
)Process_Info
,
377 (gpointer
)hashed_process_data
);
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),
383 process_list
->number_of_process
++;
385 *height
= get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
386 * process_list
->number_of_process
;
393 int processlist_remove( ProcessList
*process_list
,
397 ProcessInfo Process_Info
;
399 HashedProcessData
*hashed_process_data
;
402 Process_Info
.pid
= pid
;
403 Process_Info
.birth
= *birth
;
406 if(hashed_process_data
=
407 (HashedProcessData
*)g_hash_table_lookup(
408 process_list
->process_hash
,
411 gtk_tree_model_get_iter (
412 GTK_TREE_MODEL(process_list
->list_store
),
414 gtk_tree_row_reference_get_path(
415 (GtkTreeRowReference
*)hashed_process_data
->row_ref
)
418 gtk_list_store_remove (process_list
->list_store
, &iter
);
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
);
437 g_hash_table_remove(process_list
->process_hash
,
440 process_list
->number_of_process
--;
449 guint
processlist_get_height(ProcessList
*process_list
)
451 return get_cell_height(GTK_TREE_VIEW(process_list
->process_list_widget
))
452 * process_list
->number_of_process
;
456 gint
processlist_get_process_pixels( ProcessList
*process_list
,
457 guint pid
, LttTime
*birth
,
460 HashedProcessData
**pm_hashed_process_data
)
462 ProcessInfo Process_Info
;
464 GtkTreePath
*tree_path
;
465 HashedProcessData
*hashed_process_data
= NULL
;
467 Process_Info
.pid
= pid
;
468 Process_Info
.birth
= *birth
;
470 if(hashed_process_data
=
471 (HashedProcessData
*)g_hash_table_lookup(
472 process_list
->process_hash
,
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
);
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
;
485 *pm_hashed_process_data
= hashed_process_data
;
492 gint
processlist_get_pixels_from_data( ProcessList
*process_list
,
493 ProcessInfo
*process_info
,
494 HashedProcessData
*hashed_process_data
,
499 GtkTreePath
*tree_path
;
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
);
505 *height
= get_cell_height(
506 GTK_TREE_VIEW(process_list
->process_list_widget
));
507 *y
= *height
* path_indices
[0];