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
->Store_M
= gtk_list_store_new ( N_COLUMNS
,
180 Process_List
->Process_List_VC
=
181 gtk_tree_view_new_with_model
182 (GTK_TREE_MODEL (Process_List
->Store_M
));
184 g_object_unref (G_OBJECT (Process_List
->Store_M
));
186 gtk_tree_sortable_set_sort_func(
187 GTK_TREE_SORTABLE(Process_List
->Store_M
),
193 gtk_tree_sortable_set_sort_column_id(
194 GTK_TREE_SORTABLE(Process_List
->Store_M
),
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_VC
), 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_VC
), 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_VC
), 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_VC
), 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_VC
), column
);
248 //gtk_tree_view_column_set_visible(column, 0);
250 g_object_set_data_full(
251 G_OBJECT(Process_List
->Process_List_VC
),
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_getWidget(ProcessList
*Process_List
)
268 return Process_List
->Process_List_VC
;
273 gint
get_cell_height(GtkTreeView
*TreeView
)
276 GtkTreeViewColumn
*Column
= gtk_tree_view_get_column(TreeView
, 0);
277 GList
*Render_List
= gtk_tree_view_column_get_cell_renderers(Column
);
278 GtkCellRenderer
*Renderer
= g_list_first(Render_List
)->data
;
280 gtk_tree_view_column_cell_get_size(Column
, NULL
, NULL
, NULL
, NULL
, &height
);
281 g_critical("cell 0 height : %u",height
);
286 void Destroy_hash_key(gpointer key
)
291 void Destroy_hash_data(gpointer data
)
296 int ProcessList_add( ProcessList
*Process_List
,
302 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
303 GtkTreeRowReference
*RowRef
;
305 Process_Info
->pid
= pid
;
306 Process_Info
->birth
= *birth
;
308 /* Add a new row to the model */
309 gtk_list_store_append ( Process_List
->Store_M
, &iter
);
310 g_critical ( "iter before : %s", gtk_tree_path_to_string (
311 gtk_tree_model_get_path (
312 GTK_TREE_MODEL(Process_List
->Store_M
),
314 gtk_list_store_set ( Process_List
->Store_M
, &iter
,
315 PROCESS_COLUMN
, "name",
317 BIRTH_S_COLUMN
, birth
->tv_sec
,
318 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
320 RowRef
= gtk_tree_row_reference_new (
321 GTK_TREE_MODEL(Process_List
->Store_M
),
322 gtk_tree_model_get_path(
323 GTK_TREE_MODEL(Process_List
->Store_M
),
326 g_hash_table_insert( Process_List
->Process_Hash
,
327 (gpointer
)Process_Info
,
330 g_critical ( "iter after : %s", gtk_tree_path_to_string (
331 gtk_tree_model_get_path (
332 GTK_TREE_MODEL(Process_List
->Store_M
),
334 Process_List
->Number_Of_Process
++;
336 *height
= get_cell_height(GTK_TREE_VIEW(Process_List
->Process_List_VC
))
337 * Process_List
->Number_Of_Process
;
344 int ProcessList_remove( ProcessList
*Process_List
,
348 ProcessInfo Process_Info
;
350 GtkTreeRowReference
*got_RowRef
;
353 Process_Info
.pid
= pid
;
354 Process_Info
.birth
= *birth
;
357 (GtkTreeRowReference
*)g_hash_table_lookup(
358 Process_List
->Process_Hash
,
361 gtk_tree_model_get_iter (
362 GTK_TREE_MODEL(Process_List
->Store_M
),
364 gtk_tree_row_reference_get_path(
365 (GtkTreeRowReference
*)got_RowRef
)
368 gtk_list_store_remove (Process_List
->Store_M
, &iter
);
370 g_hash_table_remove(Process_List
->Process_Hash
,
373 Process_List
->Number_Of_Process
--;
382 guint
ProcessList_get_height(ProcessList
*Process_List
)
384 return get_cell_height(GTK_TREE_VIEW(Process_List
->Process_List_VC
))
385 * Process_List
->Number_Of_Process
;
389 gint
ProcessList_get_process_pixels( ProcessList
*Process_List
,
390 guint pid
, LttTime
*birth
,
394 ProcessInfo Process_Info
;
396 GtkTreeRowReference
*got_RowRef
;
398 Process_Info
.pid
= pid
;
399 Process_Info
.birth
= *birth
;
402 (GtkTreeRowReference
*)g_hash_table_lookup(
403 Process_List
->Process_Hash
,
406 path_indices
= gtk_tree_path_get_indices (
407 gtk_tree_row_reference_get_path(
408 (GtkTreeRowReference
*)got_RowRef
)
411 *height
= get_cell_height(
412 GTK_TREE_VIEW(Process_List
->Process_List_VC
));
413 *x
= *height
* path_indices
[0];