1 /*
2  * Copyright (c) 2010 Mike Massonnet, <mmassonnet@xfce.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  */
9 
10 #ifndef TASK_MANAGER_H
11 #define TASK_MANAGER_H
12 
13 #ifdef HAVE_CONFIG_H
14 #include <config.h>
15 #endif
16 
17 #include <glib-object.h>
18 #include <gtk/gtk.h>
19 
20 /**
21  * Task struct used as elements of a task list GArray.
22  */
23 
24 typedef struct _Task Task;
25 struct _Task
26 {
27 	guint		uid;
28 	GPid		pid;
29 	GPid		ppid;
30 	gchar		name[256];
31 	gchar		cmdline[1024];
32 	gchar		state[16];
33 	gfloat		cpu_user;
34 	gfloat		cpu_system;
35 	guint64		vsz;
36 	guint64		rss;
37 	gshort		prio;
38 };
39 
40 /**
41  * OS specific implementation.
42  *
43  * memory_available = free + cache + buffers + an-OS-specific-value
44  */
45 
46 gboolean	get_memory_usage	(guint64 *memory_total, guint64 *memory_available, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free);
47 gboolean	get_cpu_usage		(gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system);
48 gboolean	get_task_list		(GArray *task_list);
49 gboolean	pid_is_sleeping		(GPid pid);
50 
51 /**
52  * GObject class used to update the graphical widgets.
53  */
54 
55 #define XTM_TYPE_TASK_MANAGER			(xtm_task_manager_get_type ())
56 #define XTM_TASK_MANAGER(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManager))
57 #define XTM_TASK_MANAGER_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
58 #define XTM_IS_TASK_MANAGER(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), XTM_TYPE_TASK_MANAGER))
59 #define XTM_IS_TASK_MANAGER_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), XTM_TYPE_TASK_MANAGER))
60 #define XTM_TASK_MANAGER_GET_CLASS(obj)		(G_TYPE_INSTANCE_GET_CLASS ((obj), XTM_TYPE_TASK_MANAGER, XtmTaskManagerClass))
61 
62 typedef struct _XtmTaskManager XtmTaskManager;
63 
64 GType			xtm_task_manager_get_type			(void);
65 XtmTaskManager *	xtm_task_manager_new				(GtkTreeModel *model);
66 void			xtm_task_manager_get_system_info		(XtmTaskManager *manager, guint *num_processes, gfloat *cpu,
67 									 guint64 *memory_used, guint64 *memory_total,
68 									 guint64 *swap_used, guint64 *swap_total);
69 void			xtm_task_manager_get_swap_usage			(XtmTaskManager *manager, guint64 *swap_free, guint64 *swap_total);
70 const GArray *		xtm_task_manager_get_task_list			(XtmTaskManager *manager);
71 void			xtm_task_manager_update_model			(XtmTaskManager *manager);
72 
73 /**
74  * Helper functions.
75  */
76 
77 enum
78 {
79 	XTM_SIGNAL_TERMINATE = 0,
80 	XTM_SIGNAL_STOP,
81 	XTM_SIGNAL_CONTINUE,
82 	XTM_SIGNAL_KILL,
83 };
84 
85 enum
86 {
87 	XTM_PRIORITY_VERY_LOW = 0,
88 	XTM_PRIORITY_LOW,
89 	XTM_PRIORITY_NORMAL,
90 	XTM_PRIORITY_HIGH,
91 	XTM_PRIORITY_VERY_HIGH,
92 };
93 
94 gchar *		get_uid_name		(guint uid);
95 gboolean	send_signal_to_pid	(GPid pid, gint xtm_signal);
96 gint		task_pid_compare_fn	(gconstpointer a, gconstpointer b);
97 gboolean	set_priority_to_pid	(GPid pid, gint priority);
98 
99 
100 #ifndef __unused
101 #	define __unused				__attribute__((__unused__))
102 #endif
103 
104 #if DEBUG
105 #	define G_DEBUG_FMT(fmt, args...)	g_debug((fmt), ##args)
106 #else
107 #	define G_DEBUG_FMT(fmt, args...)
108 #endif
109 
110 
111 #endif /* !TASK_MANAGER_H */
112