[Goodies-commits] r3431 - xfce4-sensors-plugin/trunk/panel-plugin

Fabian Nowak timystery at xfce.org
Tue Oct 23 19:42:23 CEST 2007


Author: timystery
Date: 2007-10-23 17:42:23 +0000 (Tue, 23 Oct 2007)
New Revision: 3431

Added:
   xfce4-sensors-plugin/trunk/panel-plugin/acpi.c
   xfce4-sensors-plugin/trunk/panel-plugin/acpi.h
   xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c
   xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h
   xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c
   xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h
   xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c
   xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h
Log:
added forgotten files.


Added: xfce4-sensors-plugin/trunk/panel-plugin/acpi.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/acpi.c	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/acpi.c	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,187 @@
+/*  Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#include "acpi.h"
+#include "types.h"
+
+#include <glib/gmessages.h>
+#include <glib/gmem.h>
+#include <glib/gprintf.h>
+#include <glib/gstrfuncs.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <unistd.h>
+
+int initialize_ACPI (GPtrArray *chips)
+{
+    DIR *d;
+    struct dirent *de;
+    int entries = 0;
+    t_chip *chip;
+    double value;
+    t_chipfeature *chipfeature;
+
+    TRACE ("enters initialize_ACPI");
+
+    chip = g_new0 (t_chip, 1);
+    chip->name = g_strdup (_("ACPI"));
+    chip->description = g_strdup (_("Advanced Configuration and Power Interface"));
+    chip->sensorId = g_strdup("ACPI");
+
+    chip->type = ACPI;
+
+    chip->chip_name = (const sensors_chip_name *)
+                            ( g_strdup(_("ACPI")), 0, 0, g_strdup(_("ACPI")) );
+
+    chip->chip_features = g_ptr_array_new ();
+
+    chip->num_features = 0;
+
+    if ((chdir (ACPI_PATH) == 0) && (chdir ("thermal_zone") == 0)) {
+        d = opendir (".");
+        if (!d) return -1;
+
+        while ((de = readdir (d))) {
+            if (acpi_ignore_directory_entry (de))
+                continue;
+            entries++;
+
+            chipfeature = g_new0 (t_chipfeature, 1);
+            value = get_acpi_zone_value (de->d_name);
+            chipfeature->raw_value = value;
+            chipfeature->color = "#0000B0";
+            chipfeature->formatted_value = g_strdup_printf ("%+5.1f", value);
+            chipfeature->name = g_strdup (de->d_name);
+            chipfeature->valid = TRUE;
+            chipfeature->min_value = 20.0;
+            chipfeature->max_value = 60.0;
+            chipfeature->class = TEMPERATURE;
+
+            g_ptr_array_add (chip->chip_features, chipfeature);
+
+            chip->num_features++;
+        }
+    }
+
+    g_ptr_array_add (chips, chip);
+
+    TRACE ("leaves initialize_ACPI");
+
+    return 4;
+}
+
+void
+refresh_acpi (gpointer chip_feature, gpointer data)
+{
+    t_chipfeature *cf;
+
+    TRACE ("enters refresh_acpi");
+
+    g_assert(chip_feature!=NULL);
+
+    cf = (t_chipfeature *) chip_feature;
+
+    TRACE ("leaves refresh_acpi");
+}
+
+
+int
+acpi_ignore_directory_entry (struct dirent *de)
+{
+    TRACE ("enters and leaves acpi_ignore_directory_entry");
+
+    return !strcmp(de->d_name, ".") || !strcmp(de->d_name, "..");
+}
+
+
+char *
+get_acpi_value (char *filename)
+{
+    FILE *file;
+    char buf [1024];
+    char *p;
+
+    TRACE ("enters get_acpi_value for %s", filename);
+
+    file = fopen (filename, "r");
+    if (!file) return NULL;
+
+    fgets (buf, 1024, file);
+    fclose (file);
+
+    p = buf;
+
+    /* Skip everything before the ':' */
+    while (*(p++)) {
+        if (*p == ':') {
+            break;
+        }
+    }
+    p++;
+    /* Skip all the spaces */
+    while (*(p++)) {
+        if (*p != ' ') {
+            break;
+        }
+    }
+
+    TRACE ("leaves get_acpi_value with %s", p);
+
+    /* Have read the data */
+    return g_strdup (p);
+}
+
+
+char *
+get_acpi_info ()
+{
+    char *filename;
+
+    TRACE ("enters get_acpi_info");
+
+    filename = g_strdup_printf ("%s/%s", ACPI_PATH, ACPI_INFO);
+
+    TRACE ("leaves get_acpi_info");
+
+    return get_acpi_value (filename);
+}
+
+
+double
+get_acpi_zone_value (char *zone)
+{
+    char *filename, *value;
+
+    TRACE ("enters get_acpi_zone_value for %s", info);
+
+    filename = g_strdup_printf ("%s/%s/%s/%s", ACPI_PATH, ACPI_DIR,
+                                                        zone, ACPI_FILE);
+    value = get_acpi_value (filename);
+
+    if (!value) return 0.0;
+
+    TRACE ("leaves get_acpi_zone_value");
+
+    /* Return it as a double */
+    return strtod (value, NULL);
+}
+

Added: xfce4-sensors-plugin/trunk/panel-plugin/acpi.h
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/acpi.h	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/acpi.h	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,58 @@
+/*  Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#ifndef XFCE4_SENSORS_ACPI_H
+#define XFCE4_SENSORS_ACPI_H
+
+#define ACPI_PATH    "/proc/acpi"
+#define ACPI_DIR     "thermal_zone"
+#define ACPI_FILE    "temperature"
+#define ACPI_INFO    "info"
+
+#include <glib/garray.h>
+
+#include <dirent.h>    /* directory listing and reading */
+
+/*
+ * Initialize ACPI by ?
+ * @Return: Number of initialized chips
+ * @Param: Pointer to array of chips
+ */
+int initialize_ACPI (GPtrArray *chips);
+
+
+/*
+ * Refreshs an ACPI chip's feature in sense of raw and formatted value
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_acpi (gpointer chip_feature, gpointer data);
+
+
+double get_acpi_zone_value (char *zone);
+
+
+char *get_acpi_info ();
+
+
+char *get_acpi_value (char *filename);
+
+
+int acpi_ignore_directory_entry (struct dirent *de);
+
+#endif /* XFCE4_SENSORS_ACPI_H */

Added: xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.c	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,261 @@
+/*  Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#include "hddtemp.h"
+#include "types.h"
+
+#include <glib/garray.h>
+#include <glib/gdir.h>
+#include <glib/gerror.h>
+#include <glib/gmem.h>
+#include <glib/gmessages.h>
+#include <glib/gprintf.h>
+#include <glib/gspawn.h>
+#include <glib/gstrfuncs.h>
+
+/* #include <stdio.h> */
+#include <stdlib.h>
+#include <string.h>
+
+#include <sys/utsname.h>
+
+void
+read_disks_linux24 (t_chip *chip)
+{
+    GError *error;
+    GDir *gdir;
+    gchar * disk;
+    t_chipfeature *chipfeature;
+    const gchar* dirname;
+
+    TRACE ("enters read_disks_linux24");
+
+    /* read from /proc/ide */
+    error = NULL;
+    gdir = g_dir_open ("/proc/ide/", 0, &error);
+
+    while ( (dirname = g_dir_read_name (gdir))!=NULL ) {
+        if ( strncmp (dirname, "hd", 2)==0 || strncmp (dirname, "sd", 2)==0) {
+            disk = g_strconcat ("/dev/", dirname, NULL);
+            /* TODO: look, if /dev/dirname exists? */
+            chipfeature = g_new0 (t_chipfeature, 1);
+            chipfeature->name = disk;
+            g_ptr_array_add (chip->chip_features, chipfeature);
+            chip->num_features++;
+        }
+    }
+    /* FIXME: read SCSI info from where? SATA?  */
+
+    TRACE ("leaves read_disks_linux24");
+}
+
+
+void
+read_disks_linux26 (t_chip *chip)
+{
+    GError *error;
+    GDir *gdir;
+    gchar * disk;
+    t_chipfeature *chipfeature;
+    const gchar* dirname;
+
+    TRACE ("enters read_disks_linux26");
+
+    /* read from /sys/block */
+    error = NULL;
+    gdir = g_dir_open ("/sys/block/", 0, &error);
+    while ( (dirname = g_dir_read_name (gdir))!=NULL ) {
+        if ( strncmp (dirname, "ram", 3)!=0 &&
+             strncmp (dirname, "loop", 4)!=0 ) {
+            disk = g_strconcat ("/dev/", dirname, NULL);
+            /* TODO: look, if /dev/dirname exists? */
+            chipfeature = g_new0 (t_chipfeature, 1);
+            chipfeature->name = disk; /* /proc/ide/hda/model ?? */
+            g_ptr_array_add (chip->chip_features, chipfeature);
+            chip->num_features++;
+        }
+    }
+
+    TRACE ("leaves read_disks_linux26");
+}
+
+
+void
+remove_unmonitored_drives (t_chip *chip)
+{
+    int i;
+    t_chipfeature *chipfeature;
+
+    TRACE ("enters remove_unmonitored_drives");
+
+    for (i=0; i<chip->num_features; i++) {
+        chipfeature = g_ptr_array_index (chip->chip_features, i);
+        if ( get_hddtemp_value (chipfeature->name)==0.0) {
+            g_ptr_array_remove_index (chip->chip_features, i);
+            i--;
+            chip->num_features--;
+        }
+    }
+
+    TRACE ("leaves remove_unmonitored_drives");
+}
+
+
+void
+populate_detected_drives (t_chip *chip)
+{
+    int diskIndex;
+    /* double value; */
+    t_chipfeature *chipfeature;
+
+    TRACE ("enters populate_detected_drives");
+
+    chip->sensorId = g_strdup(_("Hard disks"));
+
+    for (diskIndex=0; diskIndex < chip->num_features; diskIndex++)
+    {
+       chipfeature = g_ptr_array_index (chip->chip_features, diskIndex);
+       g_assert  (chipfeature!=NULL);
+
+       chipfeature->address = diskIndex;
+
+       chipfeature->color = "#B000B0";
+       chipfeature->valid = TRUE;
+       chipfeature->formatted_value = g_strdup ("0.0"); /* _printf("%+5.1f", 0.0); */
+       chipfeature->raw_value = 0.0;
+
+       chipfeature->class = TEMPERATURE;
+       chipfeature->min_value = 10.0;
+       chipfeature->max_value = 50.0;
+
+       chipfeature->show = FALSE;
+    }
+
+    TRACE ("leaves populate_detected_drives");
+}
+
+
+int
+initialize_hddtemp (GPtrArray *chips)
+{
+    int generation, major, result, retval;
+    struct utsname *p_uname;
+    t_chip *chip;
+
+    g_assert (chips!=NULL);
+
+    TRACE ("enters initialize_hddtemp");
+
+    chip = g_new (t_chip, 1);
+
+    chip->chip_name = (const sensors_chip_name *)
+            ( g_strdup(_("Hard disks")), 0, 0, g_strdup(_("Hard disks")) );
+
+    chip->chip_features = g_ptr_array_new ();
+    chip->num_features = 0;
+    chip->description = g_strdup (_("S.M.A.R.T. harddisk temperatures"));
+    chip->name = g_strdup (_("Hard disks"));
+    chip->type = HDD;
+
+    p_uname = (struct utsname *) malloc (sizeof(struct utsname));
+    result =  uname (p_uname);
+    if (result!=0)
+        return -1;
+
+    generation = atoi ( p_uname->release ); /* this might cause trouble on */
+    major = atoi ( p_uname->release+2 );      /* other systems than Linux! */
+                /* actually, wanted to use build time configuration therefore /*
+
+    /* Note: This is actually supposed to be carried out by ifdef HAVE_LINUX
+     and major/minor number stuff from compile time*/
+    if (strcmp(p_uname->sysname, "Linux")==0 && major>=5)
+        read_disks_linux26 (chip);
+    else
+        read_disks_linux24 (chip); /* hopefully, that's a safe variant */
+
+    remove_unmonitored_drives (chip);
+
+    if ( chip->num_features>0 ) {  /* if (1) */
+        populate_detected_drives (chip);
+        g_ptr_array_add (chips, chip);
+        retval = 2;
+    }
+    else {
+        retval = 0;
+    }
+
+    TRACE ("leaves initialize_hddtemp");
+
+    return retval;
+}
+
+
+double
+get_hddtemp_value (char* disk)
+{
+    gchar *standard_output, *standard_error, *cmd_line;
+    gint exit_status=0;
+    double value;
+    gboolean result;
+
+    TRACE ("enters get_hddtemp_value for %s", disk);
+
+    /*    FIXME: On self-installed systems, this is /usr/local/sbin!    */
+    cmd_line = g_strdup_printf ( "/usr/sbin/hddtemp -n -q %s", disk);
+    result = g_spawn_command_line_sync (cmd_line,
+            &standard_output, &standard_error, &exit_status, NULL);
+
+    /* filter those with no sensors out */
+    if (!result || exit_status!=0 /* || error!=NULL */ ) {
+        return 0.0;
+    }
+
+    /* hddtemp does not return floating values, but only integer ones.
+      So have an easier life with atoi. */
+    value = (double) (atoi ( (const char*) standard_output) );
+
+    g_free (cmd_line);
+    g_free (standard_output);
+    g_free (standard_error);
+
+    TRACE ("leaves get_hddtemp_value");
+
+    return value;
+}
+
+
+void
+refresh_hddtemp (gpointer chip_feature, gpointer data)
+{
+    t_chipfeature *cf;
+    double value;
+
+    g_assert (chip_feature!=NULL);
+
+    TRACE ("enters refresh_hddtemp");
+
+    cf = (t_chipfeature *) chip_feature;
+
+    value = get_hddtemp_value (cf->name);
+
+    cf->formatted_value = g_strdup_printf("%+5.2f", value);
+    cf->raw_value = value;
+
+    TRACE ("leaves refresh_hddtemp");
+}

Added: xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/hddtemp.h	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,43 @@
+/*  Copyright 2004-2007 Fabian Nowak (timystery at arcor.de)
+ *
+ *  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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+/* Note for programmers and editors: Try to use 4 spaces instead of Tab! */
+
+#ifndef XFCE4_SENSORS_HDDTEMP_H
+#define XFCE4_SENSORS_HDDTEMP_H
+
+#include <glib/garray.h>
+
+/*
+ * Initialize hddtemp by finding disks to monitor
+ * @Return: Number of initialized chips
+ * @Param: Pointer to array of chips
+ */
+int initialize_hddtemp (GPtrArray *chips);
+
+
+/*
+ * Refreshs a hddtemp chip's feature in sense of raw and formatted value
+
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_hddtemp (gpointer chip_feature, gpointer data);
+
+
+double get_hddtemp_value (char* disk);
+
+#endif /* XFCE4_SENSORS_HDDTEMP_H */

Added: xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.c	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,185 @@
+
+#include "lmsensors.h"
+#include "middlelayer.h"
+#include "types.h"
+
+#include <errno.h>
+
+#include <glib/garray.h>
+#include <glib/gmessages.h>
+#include <glib/gmem.h>
+#include <glib/gprintf.h>
+#include <glib/gstrfuncs.h>
+
+#include <stdio.h>
+#include <string.h>
+
+/* Unused
+int get_number_chip_features (const sensors_chip_name *name)
+{
+    int nr1 = 0, nr2 = 0, numer = 0;
+    const sensors_feature_data *sfd;
+
+    TRACE("enters get_number_chip_features");
+
+    do {
+        sfd = sensors_get_all_features (*name, &nr1, &nr2);
+        if (sfd!=NULL)
+            number++;
+    } while (sfd!=NULL);
+
+    TRACE("leaves get_number_chip_features");
+
+    return number-1;
+} */
+
+
+t_chip *setup_chip (GPtrArray *chips, const sensors_chip_name *name, int num_sensorchips)
+{
+    t_chip* chip;
+
+    TRACE("enters setup_chip");
+
+    chip = g_new0 (t_chip, 1);
+
+    g_ptr_array_add (chips, chip);
+
+    chip->chip_name = (sensors_chip_name *) g_malloc (sizeof(sensors_chip_name));
+    memcpy ( (void *) (chip->chip_name), (void *) name, sizeof(sensors_chip_name) );
+
+    chip->sensorId = g_strdup_printf ("%s-%x-%x", name->prefix, name->bus, name->addr);
+    chip->num_features=0;
+    chip->name = g_strdup (_("LM Sensors"));
+    chip->chip_features = g_ptr_array_new();
+
+    chip->description = g_strdup (sensors_get_adapter_name (num_sensorchips-1));
+
+    TRACE("leaves setup_chip");
+
+    return chip;
+}
+
+
+void setup_chipfeature (t_chipfeature *chipfeature, int number, double sensorFeature)
+{
+    TRACE("enters setup_chipfeature");
+
+    chipfeature->color = "#00B000";
+    chipfeature->valid = TRUE;
+    chipfeature->formatted_value = g_strdup_printf("%+5.1f", sensorFeature);
+    chipfeature->raw_value = sensorFeature;
+    chipfeature->address = number;
+    chipfeature->show = FALSE;
+
+    categorize_sensor_type (chipfeature);
+
+    TRACE("leaves setup_chipfeature");
+}
+
+
+t_chipfeature *find_chipfeature    (const sensors_chip_name *name, t_chip *chip, int number)
+{
+    int res;
+    double sensorFeature;
+    t_chipfeature *chipfeature;
+
+    TRACE("enters find_chipfeature");
+
+    chipfeature = g_new0 (t_chipfeature, 1);
+
+    if (sensors_get_ignored (*(name), number)==1) {
+        res = sensors_get_label(*(name), number,
+                                &(chipfeature->name));
+
+        if (res==0) {
+            res = sensors_get_feature (*(name), number,
+                                        &sensorFeature);
+
+            if (res==0) {
+                setup_chipfeature (chipfeature, number, sensorFeature);
+                chip->num_features++;
+                TRACE("leaves find_chipfeature");
+                return chipfeature;
+            }
+        }
+    }
+
+    TRACE("leaves find_chipfeature with null");
+    return NULL;
+}
+
+
+int initialize_libsensors (GPtrArray *chips)
+{
+    int sensorsInit, nr1, nr2, num_sensorchips; /*    , numchips;  */
+    t_chip *chip;
+    t_chipfeature *chipfeature; /* , *furtherchipfeature; */
+    FILE *file;
+    const sensors_chip_name *detected_chip;
+    const sensors_feature_data *sfd;
+
+    TRACE("enters initialize_libsensors");
+
+    errno = 0;
+    file = fopen("/etc/sensors.conf", "r");
+
+    if (errno != ENOENT) /* the file actually exists */
+    {
+        sensorsInit = sensors_init(file);
+        if (sensorsInit != 0)
+        {
+            g_printf(_("Error: Could not connect to sensors!"));
+            /* FIXME: better popup window? write to special logfile? */
+            return -2;
+        }
+
+        num_sensorchips = 0;
+        detected_chip = sensors_get_detected_chips ( &num_sensorchips);
+
+        /* iterate over chips on mainboard */
+        while (detected_chip!=NULL)
+        {
+            chip = setup_chip (chips, detected_chip, num_sensorchips);
+
+            nr1 = 0;
+            nr2 = 0;
+            /* iterate over chip features, i.e. id, cpu temp, mb temp... */
+            /* numchips = get_number_chip_features (detected_chip); */
+            sfd = sensors_get_all_features (*detected_chip, &nr1, &nr2);
+            while (sfd != NULL)
+            {
+                chipfeature = find_chipfeature (detected_chip, chip, sfd->number);
+                if (chipfeature!=NULL) {
+                    g_ptr_array_add (chip->chip_features, chipfeature);
+                }
+                sfd = sensors_get_all_features (*detected_chip, &nr1, &nr2);
+            }
+
+            detected_chip = sensors_get_detected_chips (&num_sensorchips);
+        } /* end while sensor chipNames */
+
+        fclose (file);
+        TRACE ("leaves initialize_libsensors with 1");
+        return 1;
+    }
+    else {
+        fclose (file);
+        TRACE ("leaves initialize_libsensors with -1");
+        return -1;
+    }
+}
+
+
+void
+refresh_lmsensors (gpointer chip_feature, gpointer data)
+{
+    t_chipfeature *cf;
+
+    TRACE ("leaves refresh_lmsensors");
+
+    g_assert(chip_feature!=NULL);
+
+    cf = (t_chipfeature *) chip_feature;
+
+    TRACE ("leaves refresh_lmsensors");
+}

Added: xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/lmsensors.h	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,20 @@
+#ifndef XFCE4_SENSORS_LMSENSORS_H
+#define XFCE4_SENSORS_LMSENSORS_H
+
+#include <glib/garray.h>
+
+/*
+ *  Initialize libsensors by reading sensor config and other stuff
+ * @Return: Number of found chip_features
+ * @Param: Pointer to array of chips
+ */
+int initialize_libsensors (GPtrArray *chips);
+
+/*
+ * Refreshs an lmsensors chip's feature in sense of raw and formatted value
+
+ * @Param chip_feature: Pointer to feature
+ */
+void refresh_lmsensors (gpointer chip_feature, gpointer data);
+
+#endif /* XFCE4_SENSORS_LMSENSORS_H */

Added: xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.c	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,184 @@
+/*
+ *      middlelayer.c
+ *
+ *      Copyright 2006, 2007 Fabian Nowak <timytery at arcor.de>
+ *
+ *      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 <config.h>
+
+#ifdef HAVE_LINUX
+#include <sys/utsname.h>
+#endif
+
+#include "middlelayer.h"
+
+#ifdef HAVE_LIBSENSORS
+    #include "lmsensors.h"
+#endif
+#ifdef HAVE_HDDTEMP
+    #include "hddtemp.h"
+#endif
+#ifdef HAVE_ACPI
+    #include "acpi.h"
+#endif
+
+int
+initialize_all (GPtrArray **chips)
+{
+    int res = 0;
+
+    TRACE ("enters initialize_all");
+
+    *chips = g_ptr_array_new();
+
+     #ifdef HAVE_LIBSENSORS
+    res += initialize_libsensors (*chips);
+    #endif
+
+    #ifdef HAVE_HDDTEMP
+    res += initialize_hddtemp (*chips);
+    #endif
+
+    #ifdef HAVE_ACPI
+    res += initialize_ACPI (*chips);
+    #endif
+
+    TRACE ("leaves initialize_all, chips->len=%d", (*chips)->len);
+
+    return res;
+}
+
+
+void
+refresh_chip (gpointer chip, gpointer data)
+{
+    t_chip *c;
+
+    g_assert (chip!=NULL);
+
+    TRACE ("enters refresh_chip");
+
+    c = (t_chip*) chip;
+
+    #ifdef HAVE_ACPI
+        if (c->type==ACPI) {
+            g_ptr_array_foreach (c->chip_features, refresh_acpi, NULL );
+            return;
+        }
+    #endif
+
+    #ifdef HAVE_LIBSENSORS
+        if (c->type==LMSENSOR) {
+            g_ptr_array_foreach (c->chip_features, refresh_lmsensors, NULL );
+        return;
+        }
+    #endif
+
+    #ifdef HAVE_HDDTEMP
+        if (c->type==HDD) {
+            g_ptr_array_foreach (c->chip_features, refresh_hddtemp, NULL );
+        return;
+        }
+    #endif
+
+    TRACE ("leaves refresh_chip");
+}
+
+
+void
+refresh_all_chips (GPtrArray *chips )
+{
+    TRACE ("enters refresh_all_chips");
+
+    g_ptr_array_foreach (chips, refresh_chip, NULL );
+
+    TRACE ("leaves refresh_all_chips");
+}
+
+
+void
+categorize_sensor_type (t_chipfeature* chipfeature)
+{
+    TRACE ("enters categorize_sensor_type");
+
+    /* categorize sensor type */
+   if ( strstr(chipfeature->name, "Temp")!=NULL
+    || strstr(chipfeature->name, "temp")!=NULL ) {
+         chipfeature->class = TEMPERATURE;
+         chipfeature->min_value = 0.0;
+         chipfeature->max_value = 80.0;
+   } else if ( strstr(chipfeature->name, "VCore")!=NULL
+      || strstr(chipfeature->name, "3V")!=NULL
+      || strstr(chipfeature->name, "5V")!=NULL
+      || strstr(chipfeature->name, "12V")!=NULL ) {
+         chipfeature->class = VOLTAGE;
+         chipfeature->min_value = 2.8;
+         chipfeature->max_value = 12.2;
+   } else if ( strstr(chipfeature->name, "Fan")!=NULL
+      || strstr(chipfeature->name, "fan")!=NULL ) {
+         chipfeature->class = SPEED;
+         chipfeature->min_value = 1000.0;
+         chipfeature->max_value = 3500.0;
+   } else {
+         chipfeature->class = OTHER;
+         chipfeature->min_value = 0.0;
+         chipfeature->max_value = 7000.0;
+   }
+
+   TRACE ("leaves categorize_sensor_type");
+}
+
+
+int
+sensors_get_feature_wrapper (t_chip *chip, int number, double *value)
+{
+    t_chipfeature *feature;
+    /* TRACE ("enters sensors_get_feature_wrapper %d", number); */
+
+    g_assert (chip!=NULL);
+
+    if (chip->type==LMSENSOR ) {
+        #ifdef HAVE_LIBSENSORS
+            return sensors_get_feature (*(chip->chip_name), number, value);
+        #else
+            return -1;
+        #endif
+    }
+    if (chip->type==HDD ) {
+        #ifdef HAVE_HDDTEMP
+            g_assert (number<chip->num_features);
+            feature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, number);
+            g_assert (feature!=NULL);
+            *value = get_hddtemp_value (feature->name);
+            return 0;
+        #else
+            return -1;
+        #endif
+    }
+    if (chip->type==ACPI ) {
+        #ifdef HAVE_ACPI
+            g_assert (number<chip->num_features);
+            feature = (t_chipfeature *) g_ptr_array_index (chip->chip_features, number);
+            g_assert (feature!=NULL);
+            *value = get_acpi_zone_value (feature->name);
+            return 0; /* HERE    I    AM,    I    WANNA    BE    FIXED    */
+        #else
+            return -1;
+        #endif
+    }
+    return -1;
+}

Added: xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h
===================================================================
--- xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h	                        (rev 0)
+++ xfce4-sensors-plugin/trunk/panel-plugin/middlelayer.h	2007-10-23 17:42:23 UTC (rev 3431)
@@ -0,0 +1,95 @@
+/*
+ *      middlelayer.h
+ *
+ *      Copyright 2006, 2007 Fabian Nowak <timytery at arcor.de>
+ *
+ *      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.
+ */
+
+
+#ifndef XFCE4_SENSORS_MIDDLELAYER_H
+#define XFCE4_SENSORS_MIDDLELAYER_H
+
+#include "types.h"
+
+#include <glib/garray.h>
+#include <glib/gdir.h>
+#include <glib/gerror.h>
+#include <glib/gmem.h>
+#include <glib/gmessages.h>
+#include <glib/gprintf.h>
+#include <glib/gtypes.h>
+
+#include <string.h>
+
+/*
+ * Initialize all sensors detected by iterating and calling init-routines
+ * @Return: Number of initialized features
+ * @Param: Double-pointer to array of chips
+ */
+int initialize_all (GPtrArray **chips);
+
+
+/*
+ * Refresh all features of a chip
+
+ * @Param chip: Pointer to chip
+ */
+void refresh_chip (gpointer chip, gpointer data);
+
+
+/*
+ * Refresh all features of a chip
+ * @Param: Pointer to chip pointers
+ */
+void refresh_all_chips (GPtrArray *chips);
+
+
+/*
+ * Classifies sensor type
+ * @Param: Pointer to feature
+ */
+void categorize_sensor_type (t_chipfeature* chipfeature);
+
+
+/* Gets value of specified number in chip_name
+ * @Param chip_name: takten from libsensors3, it specifies bus and stuff of
+ * the sensors chip feature
+ * @Param number: number of chipfeature to look for
+ * @Param value: address where double value can be stored
+ * @Return: 0 on success, >0 else.
+ */
+int sensors_get_feature_wrapper (t_chip *chip, int number, double *value);
+
+/*
+ * Returns temperature for parameter "/dev/hda" for example
+ */
+/* double get_hddtemp_value (char* disk);
+
+
+double get_acpi_zone_value (char *zone);
+
+
+char *get_acpi_info ();
+
+
+char *get_acpi_value (char *filename);
+
+
+int acpi_ignore_directory_entry (struct dirent *de); */
+
+
+
+#endif /* XFCE4_SENSORS_MIDDLELAYER_H */




More information about the Goodies-commits mailing list