1 /*
2  * Copyright (c) <YEAR>  <AUTHOR> <EMAIL>
3  *
4  * <LICENCE, BELOW IS GPL2+ AS EXAMPLE>
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  */
10 
11 /* Add includes for system functions needed */
12 /* Example:
13 #include <stdio.h>
14 #include <unistd.h>
15 #include <string.h>
16 */
17 
18 #include <glib.h>
19 
20 #include "task-manager.h"
21 
22 /* Cache some values */
23 /* Example:
24 static gushort _cpu_count = 0;
25 */
26 
27 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)28 get_memory_usage (guint64 *memory_total, guint64 *memory_available, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free)
29 {
30 	*memory_total = 0;
31 	*memory_free = 0;
32 	*memory_cache = 0;
33 	*memory_buffers = 0;
34 	*memory_available = 0;
35 	*swap_total = 0;
36 	*swap_free = 0;
37 
38 	return TRUE;
39 }
40 
41 gboolean
get_cpu_usage(gushort * cpu_count,gfloat * cpu_user,gfloat * cpu_system)42 get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
43 {
44 	*cpu_user = *cpu_system = 0.0f;
45 	*cpu_count = 0; /*_cpu_count;*/
46 
47 	return TRUE;
48 }
49 
50 static gboolean
get_task_details(GPid pid,Task * task)51 get_task_details (GPid pid, Task *task)
52 {
53 	memset(task, 0, sizeof(Task));
54 	g_snprintf (task->name, sizeof(task->name), "foo");
55 	g_snprintf (task->cmdline, sizeof(task->cmdline), "foo -bar");
56 	g_snprintf (task->uid_name, sizeof(task->uid_name), "baz");
57 
58 	return TRUE;
59 }
60 
61 gboolean
get_task_list(GArray * task_list)62 get_task_list (GArray *task_list)
63 {
64 	GPid pid = 0;
65 	Task task;
66 
67 	//while (/* read all PIDs */)
68 	{
69 		// if (/* pid is valid */)
70 		{
71 			if (get_task_details (pid, &task))
72 			{
73 				g_array_append_val (task_list, task);
74 			}
75 		}
76 	}
77 
78 	g_array_sort (task_list, task_pid_compare_fn);
79 
80 	return TRUE;
81 }
82 
83 gboolean
pid_is_sleeping(GPid pid)84 pid_is_sleeping (GPid pid)
85 {
86 	/* Read state of PID @pid... */
87 
88 	return FALSE; /* (state == sleeping) ? TRUE : FALSE;*/
89 }
90 
91