[Xfce4-commits] <xfce4-taskmanager:master> Add words about adding support for a new OS

Mike Massonnet noreply at xfce.org
Wed May 26 06:56:01 CEST 2010


Updating branch refs/heads/master
         to 00082540559e1aceb6fae0a17e1b60a6304a3667 (commit)
       from 27c2c0cc766814eeb2488fef9386c87793242ca7 (commit)

commit 00082540559e1aceb6fae0a17e1b60a6304a3667
Author: Mike Massonnet <mmassonnet at xfce.org>
Date:   Wed May 26 06:54:37 2010 +0200

    Add words about adding support for a new OS
    
    Add a skel file (task-manager-skel.c) and make it possible in the
    build-env to build the task manager with this file (--with-skel).

 README.OS-implementation |   39 ++++++++++++++++++++
 configure.ac.in          |   37 +++++++++++++------
 src/Makefile.am          |    3 ++
 src/task-manager-skel.c  |   87 ++++++++++++++++++++++++++++++++++++++++++++++
 src/task-manager.h       |   38 +++++++++-----------
 5 files changed, 171 insertions(+), 33 deletions(-)

diff --git a/README.OS-implementation b/README.OS-implementation
new file mode 100644
index 0000000..3c61671
--- /dev/null
+++ b/README.OS-implementation
@@ -0,0 +1,39 @@
+If you are reading this file it's good news, it may imply you are interested in coding, but
+maybe even into adding support for a new operating system.
+
+The bare minimum to implement can be copied from the file src/task-manager-skel.c, knowing
+the existing implementations can serve as good examples. All the needed headers are declared
+inside the file src/task-manager.h.
+
+If you have trouble to add compilation to the build-env (autotools) you can run the
+configure script (./autogen.sh or ./configure) with the flag --with-skel and put your
+modifications inside the task-manager-skel.c file directly.
+
+When done, send a patch to Bugzilla (bugzilla.xfce.org).
+
+Some tips
+---------
+
+You may cache values, declare 'static <TYPE> <VARIABLE>' under the includes for global
+access, or inside functions for local access.
+
+You may need a local function to calculate the CPU usage in percent for the system and/or
+the processes, for this have a look at the function get_cpu_percent() from the linux and
+solaris files.
+
+The refresh rate can be different than one second, make sure the CPU keeps correct by
+changing it.
+
+Implementing the function pid_is_sleeping() is needed to show either the signal Stop or
+Continue inside the graphical interface.
+
+The function get_task_list provides an empty but initialized GArray pointer as argument that
+just has to be filled in with the current list of tasks.
+
+If there are information you are unable to provide because unexistent on the system, fill in
+these values with 0. A good example is the swap (sometimes because there is no swap set,
+doesn't mean we have to show swap information), when the total equals to zero it is hidden
+from the interface. The same can be applied to some of the CPU (system or user may be
+useless) and memory information (buffer and/or cache may be left out).
+
+That's it!
diff --git a/configure.ac.in b/configure.ac.in
index 2a7e891..61d3407 100644
--- a/configure.ac.in
+++ b/configure.ac.in
@@ -66,36 +66,48 @@ dnl ***********************************
 XDT_CHECK_PACKAGE([GTK], [gtk+-2.0], [2.12.0])
 
 dnl ***********************************
+dnl ********** Check for skel *********
+dnl ***********************************
+AC_ARG_WITH([skel],
+		AC_HELP_STRING([--with-skel], [build with task-manager-skel.c]),
+		[ac_skel="$withval"],
+		[ac_skel=no])
+
+dnl ***********************************
 dnl ******* Check for OS family *******
 dnl ***********************************
-case "$target_os" in
-	freebsd*)
+if test x"$ac_skel" = x"yes"; then
+	ac_os_implementation="skel"
+else
+	case "$target_os" in
+		freebsd*)
 		ac_os_implementation="freebsd"
 		AC_CHECK_LIB([kvm], [kvm_openfiles])
 		AC_CHECK_HEADERS([fcntl.h kvm.h paths.h pwd.h sys/param.h sys/proc.h \
 				sys/sysctl.h sys/types.h sys/user.h unistd.h])
-	;;
-	dragonfly*|netbsd*|openbsd*|darwin*)
+		;;
+		dragonfly*|netbsd*|openbsd*|darwin*)
 		ac_os_implementation="bsd"
 		AC_CHECK_HEADERS([err.h pwd.h stdlib.h string.h sys/param.h sys/sched.h \
 				sys/swap.h sys/sysctl.h sys/types.h unistd.h])
-	;;
-	solaris*)
+		;;
+		solaris*)
 		ac_os_implementation="solaris"
 		AC_CHECK_LIB([kstat], [kstat_open])
 		AC_CHECK_HEADERS([fcntl.h kstat.h procfs.h pwd.h stdlib.h string.h \
 				sys/procfs.h sys/stat.h sys/swap.h sys/types.h])
-	;;
-	linux*)
+		;;
+		linux*)
 		ac_os_implementation="linux"
 		AC_CHECK_HEADERS([pwd.h signal.h stdio.h string.h sys/resource.h \
 				sys/stat.h sys/types.h unistd.h])
-	;;
-	*)
+		;;
+		*)
 		AC_MSG_CHECKING([for OS implementation])
 		AC_MSG_ERROR([no OS implementation for $target_os is available])
-	;;
-esac
+		;;
+	esac
+fi
 AC_MSG_CHECKING([for OS implementation])
 AC_MSG_RESULT([$ac_os_implementation])
 
@@ -103,6 +115,7 @@ AM_CONDITIONAL([OS_FREEBSD], [test x"$ac_os_implementation" = x"freebsd"])
 AM_CONDITIONAL([OS_BSD], [test x"$ac_os_implementation" = x"bsd"])
 AM_CONDITIONAL([OS_SOLARIS], [test x"$ac_os_implementation" = x"solaris"])
 AM_CONDITIONAL([OS_LINUX], [test x"$ac_os_implementation" = x"linux"])
+AM_CONDITIONAL([OS_SKEL], [test x"$ac_os_implementation" = x"skel"])
 
 dnl ***********************************
 dnl *** Check for debugging support ***
diff --git a/src/Makefile.am b/src/Makefile.am
index 40a386e..386adee 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -36,6 +36,9 @@ endif
 if OS_LINUX
 xfce4_taskmanager_SOURCES += task-manager-linux.c
 endif
+if OS_SKEL
+xfce4_taskmanager_SOURCES += task-manager-skel.c
+endif
 
 if MAINTAINER_MODE
 BUILT_SOURCES = process-window_ui.h
diff --git a/src/task-manager-skel.c b/src/task-manager-skel.c
new file mode 100644
index 0000000..ca201db
--- /dev/null
+++ b/src/task-manager-skel.c
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) <YEAR>  <AUTHOR> <EMAIL>
+ *
+ * <LICENCE, BELOW IS GPL2+ AS EXAMPLE>
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+/* Add includes for system functions needed */
+/* Example:
+#include <stdio.h>
+#include <pwd.h>
+#include <unistd.h>
+#include <string.h>
+*/
+
+#include <glib.h>
+
+#include "task-manager.h"
+
+/* Cache some values */
+/* Example:
+static gushort _cpu_count = 0;
+*/
+
+gboolean
+get_memory_usage (guint64 *memory_total, guint64 *memory_free, guint64 *memory_cache, guint64 *memory_buffers, guint64 *swap_total, guint64 *swap_free)
+{
+	*memory_total = 0;
+	*memory_free = 0;
+	*memory_cache = 0;
+	*memory_buffers = 0;
+	*swap_total = 0;
+	*swap_free = 0;
+
+	return TRUE;
+}
+
+gboolean
+get_cpu_usage (gushort *cpu_count, gfloat *cpu_user, gfloat *cpu_system)
+{
+	*cpu_user = *cpu_system = 0.0;
+	*cpu_count = 0; /*_cpu_count;*/
+
+	return TRUE;
+}
+
+static gboolean
+get_task_details (guint pid, Task *task)
+{
+	g_snprintf (task->name, 256, "foo");
+	g_snprintf (task->cmdline, 1024, "foo -bar");
+	g_snprintf (task->uid_name, 256, "baz");
+
+	return TRUE;
+}
+
+gboolean
+get_task_list (GArray *task_list)
+{
+	guint pid;
+	Task task = { 0 };
+
+	//while (/* read all PIDs */)
+	{
+		// if (/* pid is valid */)
+		{
+			if (get_task_details (pid, &task))
+			{
+				g_array_append_val (task_list, task);
+			}
+		}
+	}
+
+	return TRUE;
+}
+
+gboolean
+pid_is_sleeping (guint pid)
+{
+	/* Read state of PID @pid... */
+
+	return FALSE; /* (state == sleeping) ? TRUE : FALSE;*/
+}
+
diff --git a/src/task-manager.h b/src/task-manager.h
index ab386a0..79e3112 100644
--- a/src/task-manager.h
+++ b/src/task-manager.h
@@ -39,27 +39,6 @@ struct _Task
 };
 
 /**
- * Enumerations of virtual values between the interface and the OS implementation.
- */
-
-enum
-{
-	XTM_SIGNAL_TERMINATE = 0,
-	XTM_SIGNAL_STOP,
-	XTM_SIGNAL_CONTINUE,
-	XTM_SIGNAL_KILL,
-};
-
-enum
-{
-	XTM_PRIORITY_VERY_LOW = 0,
-	XTM_PRIORITY_LOW,
-	XTM_PRIORITY_NORMAL,
-	XTM_PRIORITY_HIGH,
-	XTM_PRIORITY_VERY_HIGH,
-};
-
-/**
  * OS specific implementation.
  */
 
@@ -94,6 +73,23 @@ void			xtm_task_manager_update_model			(XtmTaskManager *manager);
  * Helper functions.
  */
 
+enum
+{
+	XTM_SIGNAL_TERMINATE = 0,
+	XTM_SIGNAL_STOP,
+	XTM_SIGNAL_CONTINUE,
+	XTM_SIGNAL_KILL,
+};
+
+enum
+{
+	XTM_PRIORITY_VERY_LOW = 0,
+	XTM_PRIORITY_LOW,
+	XTM_PRIORITY_NORMAL,
+	XTM_PRIORITY_HIGH,
+	XTM_PRIORITY_VERY_HIGH,
+};
+
 void		get_owner_uid		(guint *owner_uid, gchar **owner_uid_name);
 gchar *		get_hostname		();
 gboolean	send_signal_to_pid	(guint pid, gint signal);



More information about the Xfce4-commits mailing list