updated copyright end date to 2013
[psensor.git] / src / lib / cpu.c
index e6ed3f3..e7704f2 100644 (file)
@@ -1,22 +1,21 @@
 /*
-    Copyright (C) 2010-2011 jeanfi@gmail.com
-
-    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.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-    02110-1301 USA
-*/
-
+ * Copyright (C) 2010-2014 jeanfi@gmail.com
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
 #include <locale.h>
 #include <libintl.h>
 #define _(str) gettext(str)
@@ -31,7 +30,7 @@ static glibtop_cpu *cpu;
 static float last_used;
 static float last_total;
 
-static struct psensor *create_sensor(int measures_len)
+struct psensor *create_cpu_usage_sensor(int measures_len)
 {
        char *label;
        int type;
@@ -42,7 +41,7 @@ static struct psensor *create_sensor(int measures_len)
        label = strdup("cpu usage");
        type = SENSOR_TYPE_CPU_USAGE;
 
-       psensor = psensor_create(id, label, type, measures_len);
+       psensor = psensor_create(id, label, strdup("CPU"), type, measures_len);
 
        return psensor;
 }
@@ -52,7 +51,7 @@ cpu_psensor_list_add(struct psensor **sensors, int measures_len)
 {
        struct psensor *s;
 
-       s = create_sensor(measures_len);
+       s = create_cpu_usage_sensor(measures_len);
 
        return psensor_list_add(sensors, s);
 }
@@ -81,6 +80,11 @@ static double get_usage()
        return cpu_rate;
 }
 
+void cpu_usage_sensor_update(struct psensor *s)
+{
+       psensor_set_current_value(s, get_usage());
+}
+
 void cpu_psensor_list_update(struct psensor **sensors)
 {
        struct psensor **ss, *s;
@@ -89,8 +93,9 @@ void cpu_psensor_list_update(struct psensor **sensors)
        while (*ss) {
                s = *ss;
 
-               if (s->type == SENSOR_TYPE_CPU_USAGE)
-                       psensor_set_current_value(s, get_usage());
+               if (!(s->type & SENSOR_TYPE_REMOTE)
+                   && s->type == SENSOR_TYPE_CPU_USAGE)
+                       cpu_usage_sensor_update(s);
 
                ss++;
        }