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
);
256 Process_List
->Test_Process_Sent
= 0;
260 void processlist_destroy(ProcessList
*Process_List
)
262 g_hash_table_destroy(Process_List
->Process_Hash
);
263 Process_List
->Process_Hash
= NULL
;
265 g_free(Process_List
);
268 GtkWidget
*processlist_get_widget(ProcessList
*Process_List
)
270 return Process_List
->Process_List_VC
;
275 gint
get_cell_height(GtkTreeView
*TreeView
)
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;
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);
289 void destroy_hash_key(gpointer key
)
294 void destroy_hash_data(gpointer data
)
299 int processlist_add( ProcessList
*Process_List
,
303 HashedProcessData
**pmHashed_Process_Data
)
306 ProcessInfo
*Process_Info
= g_new(ProcessInfo
, 1);
307 HashedProcessData
*Hashed_Process_Data
= g_new(HashedProcessData
, 1);
308 *pmHashed_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
->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
->ts
= NULL
;
336 Hashed_Process_Data
->draw_context
->Current
->tfs
= NULL
;
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
->ts
= NULL
;
357 Hashed_Process_Data
->draw_context
->Previous
->tfs
= NULL
;
359 /* Add a new row to the model */
360 gtk_list_store_append ( Process_List
->Store_M
, &iter
);
361 //g_critical ( "iter before : %s", gtk_tree_path_to_string (
362 // gtk_tree_model_get_path (
363 // GTK_TREE_MODEL(Process_List->Store_M),
365 gtk_list_store_set ( Process_List
->Store_M
, &iter
,
366 PROCESS_COLUMN
, "name",
368 BIRTH_S_COLUMN
, birth
->tv_sec
,
369 BIRTH_NS_COLUMN
, birth
->tv_nsec
,
371 Hashed_Process_Data
->RowRef
= gtk_tree_row_reference_new (
372 GTK_TREE_MODEL(Process_List
->Store_M
),
373 gtk_tree_model_get_path(
374 GTK_TREE_MODEL(Process_List
->Store_M
),
376 g_hash_table_insert( Process_List
->Process_Hash
,
377 (gpointer
)Process_Info
,
378 (gpointer
)Hashed_Process_Data
);
380 //g_critical ( "iter after : %s", gtk_tree_path_to_string (
381 // gtk_tree_model_get_path (
382 // GTK_TREE_MODEL(Process_List->Store_M),
384 Process_List
->Number_Of_Process
++;
386 *height
= get_cell_height(GTK_TREE_VIEW(Process_List
->Process_List_VC
))
387 * Process_List
->Number_Of_Process
;
394 int processlist_remove( ProcessList
*Process_List
,
398 ProcessInfo Process_Info
;
400 HashedProcessData
*Hashed_Process_Data
;
403 Process_Info
.pid
= pid
;
404 Process_Info
.birth
= *birth
;
407 if(Hashed_Process_Data
=
408 (HashedProcessData
*)g_hash_table_lookup(
409 Process_List
->Process_Hash
,
412 gtk_tree_model_get_iter (
413 GTK_TREE_MODEL(Process_List
->Store_M
),
415 gtk_tree_row_reference_get_path(
416 (GtkTreeRowReference
*)Hashed_Process_Data
->RowRef
)
419 gtk_list_store_remove (Process_List
->Store_M
, &iter
);
421 g_free(Hashed_Process_Data
->draw_context
->Previous
->modify_under
);
422 g_free(Hashed_Process_Data
->draw_context
->Previous
->modify_middle
);
423 g_free(Hashed_Process_Data
->draw_context
->Previous
->modify_over
);
424 g_free(Hashed_Process_Data
->draw_context
->Previous
->under
);
425 g_free(Hashed_Process_Data
->draw_context
->Previous
->middle
);
426 g_free(Hashed_Process_Data
->draw_context
->Previous
->over
);
427 g_free(Hashed_Process_Data
->draw_context
->Previous
);
428 g_free(Hashed_Process_Data
->draw_context
->Current
->modify_under
);
429 g_free(Hashed_Process_Data
->draw_context
->Current
->modify_middle
);
430 g_free(Hashed_Process_Data
->draw_context
->Current
->modify_over
);
431 g_free(Hashed_Process_Data
->draw_context
->Current
->under
);
432 g_free(Hashed_Process_Data
->draw_context
->Current
->middle
);
433 g_free(Hashed_Process_Data
->draw_context
->Current
->over
);
434 g_free(Hashed_Process_Data
->draw_context
->Current
);
435 g_free(Hashed_Process_Data
->draw_context
);
436 g_free(Hashed_Process_Data
);
438 g_hash_table_remove(Process_List
->Process_Hash
,
441 Process_List
->Number_Of_Process
--;
450 guint
processlist_get_height(ProcessList
*Process_List
)
452 return get_cell_height(GTK_TREE_VIEW(Process_List
->Process_List_VC
))
453 * Process_List
->Number_Of_Process
;
457 gint
processlist_get_process_pixels( ProcessList
*Process_List
,
458 guint pid
, LttTime
*birth
,
461 HashedProcessData
**pmHashed_Process_Data
)
463 ProcessInfo Process_Info
;
465 GtkTreePath
*tree_path
;
466 HashedProcessData
*Hashed_Process_Data
= NULL
;
468 Process_Info
.pid
= pid
;
469 Process_Info
.birth
= *birth
;
471 if(Hashed_Process_Data
=
472 (HashedProcessData
*)g_hash_table_lookup(
473 Process_List
->Process_Hash
,
476 tree_path
= gtk_tree_row_reference_get_path(
477 Hashed_Process_Data
->RowRef
);
478 path_indices
= gtk_tree_path_get_indices (tree_path
);
480 *height
= get_cell_height(
481 GTK_TREE_VIEW(Process_List
->Process_List_VC
));
482 *y
= *height
* path_indices
[0];
483 *pmHashed_Process_Data
= Hashed_Process_Data
;
486 *pmHashed_Process_Data
= Hashed_Process_Data
;