outsource ibm-acpi stuff into it's own source file
authorPhil Sutter <phil@nwl.cc>
Sat, 3 Jan 2009 23:00:52 +0000 (00:00 +0100)
committerPhil Sutter <phil@nwl.cc>
Sun, 22 Feb 2009 01:58:29 +0000 (02:58 +0100)
Despite this is actually not much code and could stay inside linux.c as
well, this makes sense as I want to combine smapi and ibm-acpi
functionality. Virtually every user of a notebook made by IBM/Lenovo
will want both, so this should be a feature not a bug.

Besides making the ibm-acpi objects being built optionally, this should
not change anything to the code flow.

ChangeLog
configure.ac.in
src/Makefile.am
src/conky.c
src/conky.h
src/ibm.c [new file with mode: 0644]
src/ibm.h [new file with mode: 0644]
src/linux.c
src/linux.h
src/text_object.h

index 316ec97..e0776ca 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -34,6 +34,9 @@
        * Refactor top code, add top_time to sort by process cpu time (thanks
        sohalt).
 
+2009-01-04
+       * Make ibm-acpi objects optional (--enable-ibm)
+
 2008-12-20
        * Add if_match object comparing strings, floats and ints
 
index c771c94..84e460d 100644 (file)
@@ -170,6 +170,25 @@ fi
 
 
 dnl
+dnl Support for IBM/Lenovo notebooks
+dnl
+
+AC_ARG_ENABLE([ibm],
+             AC_HELP_STRING([--enable-ibm], [enable if you want support for IBM/Lenovo notebooks @<:default=no@:>@]),
+             [want_ibm="$enableval"], [want_ibm=no])
+
+AM_CONDITIONAL(BUILD_IBM, test x$want_ibm = xyes)
+if test x$want_ibm = xyes; then
+       if test x"$uname" != xLinux; then
+               AC_MSG_NOTICE([support for IBM/Lenovo notebooks not supported on $uname... disabling])
+               want_ibm=no
+       else
+               AC_DEFINE(IBM, 1, [Define if you want support for IBM/Lenovo notebooks])
+       fi
+fi
+
+
+dnl
 dnl Hddtemp
 dnl
 
@@ -723,6 +742,7 @@ $PACKAGE $VERSION configured successfully:
   RSS:              $want_rss
   wireless:         $want_wlan
   SMAPI:            $want_smapi
+  IBM:              $want_ibm
   nvidia:           $want_nvidia
   eve-online:       $want_eve
   config-output:    $want_config_output
index d656e5d..058e473 100644 (file)
@@ -47,6 +47,10 @@ if BUILD_BMPX
 bmpx = bmpx.c
 endif
 
+if BUILD_IBM
+ibm = ibm.c ibm.h
+endif
+
 if BUILD_MPD
 mpd = mpd.c libmpdclient.c
 endif
@@ -142,6 +146,7 @@ conky_SOURCES =             \
        $(x11)                  \
        $(xmms2)                \
        $(smapi)                \
+       $(ibm)                  \
        temphelper.c            \
        temphelper.h            \
        text_object.h           \
@@ -191,6 +196,9 @@ EXTRA_DIST =                        \
        xmms2.c                 \
        xmms2.h                 \
        smapi.c                 \
+       smapi.h                 \
+       ibm.c                   \
+       ibm.h                   \
        users.c
 
 
index f164730..e617e48 100644 (file)
@@ -1806,6 +1806,7 @@ static struct text_object *construct_text_object(const char *s,
        END OBJ(i8k_right_fan_rpm, INFO_I8K)
        END OBJ(i8k_ac_status, INFO_I8K)
        END OBJ(i8k_buttons_status, INFO_I8K)
+#if defined(IBM)
        END OBJ(ibm_fan, 0)
        END OBJ(ibm_temps, 0)
                if (!arg) {
@@ -1819,6 +1820,7 @@ static struct text_object *construct_text_object(const char *s,
                obj->data.sensor = atoi(&arg[0]);
        END OBJ(ibm_volume, 0)
        END OBJ(ibm_brightness, 0)
+#endif
        END OBJ_IF(if_up, 0)
                if (!arg) {
                        ERR("if_up needs an argument");
@@ -4166,6 +4168,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(i8k_buttons_status) {
                                snprintf(p, p_max_size, "%s", i8k.buttons_status);
                        }
+#if defined(IBM)
                        OBJ(ibm_fan) {
                                get_ibm_acpi_fan(p, p_max_size);
                        }
@@ -4180,6 +4183,7 @@ static void generate_text_internal(char *p, int p_max_size,
                        OBJ(ibm_brightness) {
                                get_ibm_acpi_brightness(p, p_max_size);
                        }
+#endif /* IBM */
                        OBJ(if_up) {
                                if ((obj->data.ifblock.s)
                                                && (!interface_up(obj->data.ifblock.s))) {
index 5f651ae..274e837 100644 (file)
@@ -102,6 +102,10 @@ char *strndup(const char *s, size_t n);
 #include "xmms2.h"
 #endif
 
+#ifdef IBM
+#include "ibm.h"
+#endif
+
 /* A size for temporary, static buffers to use when
  * one doesn't know what to choose. Defaults to 256.  */
 extern unsigned int text_buffer_size;
diff --git a/src/ibm.c b/src/ibm.c
new file mode 100644 (file)
index 0000000..d31e379
--- /dev/null
+++ b/src/ibm.c
@@ -0,0 +1,263 @@
+/* Conky, a system monitor, based on torsmo
+ *
+ * Any original torsmo code is licensed under the BSD license
+ *
+ * All code written since the fork of torsmo is licensed under the GPL
+ *
+ * Please see COPYING for details
+ *
+ * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
+ * Copyright (c) 2007 Toni Spets
+ * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
+ *     (see AUTHORS)
+ * All rights reserved.
+ *
+ * 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 3 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, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include "conky.h"
+#include "config.h"
+#include "ibm.h"
+#include "logging.h"
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <stdlib.h>
+
+/* Here come the IBM ACPI-specific things. For reference, see
+ * http://ibm-acpi.sourceforge.net/README
+ * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
+bay
+beep
+bluetooth
+brightness
+cmos
+dock
+driver
+ecdump
+fan
+hotkey
+led
+light
+thermal
+video
+volume
+ * The content of these files is described in detail in the aforementioned
+ * README - some of them also in the following functions accessing them.
+ * Peter Tarjan (ptarjan@citromail.hu) */
+
+#define IBM_ACPI_DIR "/proc/acpi/ibm"
+
+/* get fan speed on IBM/Lenovo laptops running the ibm acpi.
+ * /proc/acpi/ibm/fan looks like this (3 lines):
+status:         disabled
+speed:          2944
+commands:       enable, disable
+ * Peter Tarjan (ptarjan@citromail.hu) */
+
+void get_ibm_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
+{
+       FILE *fp;
+       unsigned int speed = 0;
+       char fan[128];
+
+       if (!p_client_buffer || client_buffer_size <= 0) {
+               return;
+       }
+
+       snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
+
+       fp = fopen(fan, "r");
+       if (fp != NULL) {
+               while (!feof(fp)) {
+                       char line[256];
+
+                       if (fgets(line, 255, fp) == NULL) {
+                               break;
+                       }
+                       if (sscanf(line, "speed: %u", &speed)) {
+                               break;
+                       }
+               }
+       } else {
+               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
+                       "ibm* from your "PACKAGE_NAME" config file.", fan, strerror(errno));
+       }
+
+       fclose(fp);
+       snprintf(p_client_buffer, client_buffer_size, "%d", speed);
+}
+
+/* get the measured temperatures from the temperature sensors
+ * on IBM/Lenovo laptops running the ibm acpi.
+ * There are 8 values in /proc/acpi/ibm/thermal, and according to
+ * http://ibm-acpi.sourceforge.net/README
+ * these mean the following (at least on an IBM R51...)
+ * 0:  CPU (also on the T series laptops)
+ * 1:  Mini PCI Module (?)
+ * 2:  HDD (?)
+ * 3:  GPU (also on the T series laptops)
+ * 4:  Battery (?)
+ * 5:  N/A
+ * 6:  Battery (?)
+ * 7:  N/A
+ * I'm not too sure about those with the question mark, but the values I'm
+ * reading from *my* thermal file (on a T42p) look realistic for the
+ * hdd and the battery.
+ * #5 and #7 are always -128.
+ * /proc/acpi/ibm/thermal looks like this (1 line):
+temperatures:   41 43 31 46 33 -128 29 -128
+ * Peter Tarjan (ptarjan@citromail.hu) */
+
+static double last_ibm_acpi_temp_time;
+void get_ibm_acpi_temps(void)
+{
+
+       FILE *fp;
+       char thermal[128];
+
+       /* don't update too often */
+       if (current_update_time - last_ibm_acpi_temp_time < 10.00) {
+               return;
+       }
+       last_ibm_acpi_temp_time = current_update_time;
+
+       /* if (!p_client_buffer || client_buffer_size <= 0) {
+               return;
+       } */
+
+       snprintf(thermal, 127, "%s/thermal", IBM_ACPI_DIR);
+       fp = fopen(thermal, "r");
+
+       if (fp != NULL) {
+               while (!feof(fp)) {
+                       char line[256];
+
+                       if (fgets(line, 255, fp) == NULL) {
+                               break;
+                       }
+                       if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
+                                       &ibm_acpi.temps[0], &ibm_acpi.temps[1], &ibm_acpi.temps[2],
+                                       &ibm_acpi.temps[3], &ibm_acpi.temps[4], &ibm_acpi.temps[5],
+                                       &ibm_acpi.temps[6], &ibm_acpi.temps[7])) {
+                               break;
+                       }
+               }
+       } else {
+               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
+                       "ibm* from your "PACKAGE_NAME" config file.", thermal, strerror(errno));
+       }
+
+       fclose(fp);
+}
+
+/* get volume (0-14) on IBM/Lenovo laptops running the ibm acpi.
+ * "Volume" here is none of the mixer volumes, but a "master of masters"
+ * volume adjusted by the IBM volume keys.
+ * /proc/acpi/ibm/fan looks like this (4 lines):
+level:          4
+mute:           off
+commands:       up, down, mute
+commands:       level <level> (<level> is 0-15)
+ * Peter Tarjan (ptarjan@citromail.hu) */
+
+void get_ibm_acpi_volume(char *p_client_buffer, size_t client_buffer_size)
+{
+       FILE *fp;
+       char volume[128];
+       unsigned int vol = -1;
+       char mute[3] = "";
+
+       if (!p_client_buffer || client_buffer_size <= 0) {
+               return;
+       }
+
+       snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
+
+       fp = fopen(volume, "r");
+       if (fp != NULL) {
+               while (!feof(fp)) {
+                       char line[256];
+                       unsigned int read_vol = -1;
+
+                       if (fgets(line, 255, fp) == NULL) {
+                               break;
+                       }
+                       if (sscanf(line, "level: %u", &read_vol)) {
+                               vol = read_vol;
+                               continue;
+                       }
+                       if (sscanf(line, "mute: %s", mute)) {
+                               break;
+                       }
+               }
+       } else {
+               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
+                       "ibm* from your "PACKAGE_NAME" config file.", volume, strerror(errno));
+       }
+
+       fclose(fp);
+
+       if (strcmp(mute, "on") == 0) {
+               snprintf(p_client_buffer, client_buffer_size, "%s", "mute");
+               return;
+       } else {
+               snprintf(p_client_buffer, client_buffer_size, "%d", vol);
+               return;
+       }
+}
+
+/* static FILE *fp = NULL; */
+
+/* get LCD brightness on IBM/Lenovo laptops running the ibm acpi.
+ * /proc/acpi/ibm/brightness looks like this (3 lines):
+level:          7
+commands:       up, down
+commands:       level <level> (<level> is 0-7)
+ * Peter Tarjan (ptarjan@citromail.hu) */
+
+void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
+{
+       FILE *fp;
+       unsigned int brightness = 0;
+       char filename[128];
+
+       if (!p_client_buffer || client_buffer_size <= 0) {
+               return;
+       }
+
+       snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
+
+       fp = fopen(filename, "r");
+       if (fp != NULL) {
+               while (!feof(fp)) {
+                       char line[256];
+
+                       if (fgets(line, 255, fp) == NULL) {
+                               break;
+                       }
+                       if (sscanf(line, "level: %u", &brightness)) {
+                               break;
+                       }
+               }
+       } else {
+               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
+                       "ibm* from your "PACKAGE_NAME" config file.", filename, strerror(errno));
+       }
+
+       fclose(fp);
+
+       snprintf(p_client_buffer, client_buffer_size, "%d", brightness);
+}
+
diff --git a/src/ibm.h b/src/ibm.h
new file mode 100644 (file)
index 0000000..58cf63d
--- /dev/null
+++ b/src/ibm.h
@@ -0,0 +1,17 @@
+#ifndef _IBM_H
+#define _IBM_H
+
+#include <sys/types.h>
+
+struct ibm_acpi_struct {
+       int temps[8];
+};
+
+struct ibm_acpi_struct ibm_acpi;
+
+void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
+void get_ibm_acpi_temps(void);
+void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
+void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
+
+#endif /* _IBM_H */
index 8a9386a..32bedc8 100644 (file)
@@ -2104,232 +2104,6 @@ void update_top(void)
        info.first_process = get_first_process();
 }
 
-/* Here come the IBM ACPI-specific things. For reference, see
- * http://ibm-acpi.sourceforge.net/README
- * If IBM ACPI is installed, /proc/acpi/ibm contains the following files:
-bay
-beep
-bluetooth
-brightness
-cmos
-dock
-driver
-ecdump
-fan
-hotkey
-led
-light
-thermal
-video
-volume
- * The content of these files is described in detail in the aforementioned
- * README - some of them also in the following functions accessing them.
- * Peter Tarjan (ptarjan@citromail.hu) */
-
-#define IBM_ACPI_DIR "/proc/acpi/ibm"
-
-/* get fan speed on IBM/Lenovo laptops running the ibm acpi.
- * /proc/acpi/ibm/fan looks like this (3 lines):
-status:         disabled
-speed:          2944
-commands:       enable, disable
- * Peter Tarjan (ptarjan@citromail.hu) */
-
-void get_ibm_acpi_fan(char *p_client_buffer, size_t client_buffer_size)
-{
-       FILE *fp;
-       unsigned int speed = 0;
-       char fan[128];
-
-       if (!p_client_buffer || client_buffer_size <= 0) {
-               return;
-       }
-
-       snprintf(fan, 127, "%s/fan", IBM_ACPI_DIR);
-
-       fp = fopen(fan, "r");
-       if (fp != NULL) {
-               while (!feof(fp)) {
-                       char line[256];
-
-                       if (fgets(line, 255, fp) == NULL) {
-                               break;
-                       }
-                       if (sscanf(line, "speed: %u", &speed)) {
-                               break;
-                       }
-               }
-       } else {
-               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
-                       "ibm* from your "PACKAGE_NAME" config file.", fan, strerror(errno));
-       }
-
-       fclose(fp);
-       snprintf(p_client_buffer, client_buffer_size, "%d", speed);
-}
-
-/* get the measured temperatures from the temperature sensors
- * on IBM/Lenovo laptops running the ibm acpi.
- * There are 8 values in /proc/acpi/ibm/thermal, and according to
- * http://ibm-acpi.sourceforge.net/README
- * these mean the following (at least on an IBM R51...)
- * 0:  CPU (also on the T series laptops)
- * 1:  Mini PCI Module (?)
- * 2:  HDD (?)
- * 3:  GPU (also on the T series laptops)
- * 4:  Battery (?)
- * 5:  N/A
- * 6:  Battery (?)
- * 7:  N/A
- * I'm not too sure about those with the question mark, but the values I'm
- * reading from *my* thermal file (on a T42p) look realistic for the
- * hdd and the battery.
- * #5 and #7 are always -128.
- * /proc/acpi/ibm/thermal looks like this (1 line):
-temperatures:   41 43 31 46 33 -128 29 -128
- * Peter Tarjan (ptarjan@citromail.hu) */
-
-static double last_ibm_acpi_temp_time;
-void get_ibm_acpi_temps(void)
-{
-
-       FILE *fp;
-       char thermal[128];
-
-       /* don't update too often */
-       if (current_update_time - last_ibm_acpi_temp_time < 10.00) {
-               return;
-       }
-       last_ibm_acpi_temp_time = current_update_time;
-
-       /* if (!p_client_buffer || client_buffer_size <= 0) {
-               return;
-       } */
-
-       snprintf(thermal, 127, "%s/thermal", IBM_ACPI_DIR);
-       fp = fopen(thermal, "r");
-
-       if (fp != NULL) {
-               while (!feof(fp)) {
-                       char line[256];
-
-                       if (fgets(line, 255, fp) == NULL) {
-                               break;
-                       }
-                       if (sscanf(line, "temperatures: %d %d %d %d %d %d %d %d",
-                                       &ibm_acpi.temps[0], &ibm_acpi.temps[1], &ibm_acpi.temps[2],
-                                       &ibm_acpi.temps[3], &ibm_acpi.temps[4], &ibm_acpi.temps[5],
-                                       &ibm_acpi.temps[6], &ibm_acpi.temps[7])) {
-                               break;
-                       }
-               }
-       } else {
-               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
-                       "ibm* from your "PACKAGE_NAME" config file.", thermal, strerror(errno));
-       }
-
-       fclose(fp);
-}
-
-/* get volume (0-14) on IBM/Lenovo laptops running the ibm acpi.
- * "Volume" here is none of the mixer volumes, but a "master of masters"
- * volume adjusted by the IBM volume keys.
- * /proc/acpi/ibm/fan looks like this (4 lines):
-level:          4
-mute:           off
-commands:       up, down, mute
-commands:       level <level> (<level> is 0-15)
- * Peter Tarjan (ptarjan@citromail.hu) */
-
-void get_ibm_acpi_volume(char *p_client_buffer, size_t client_buffer_size)
-{
-       FILE *fp;
-       char volume[128];
-       unsigned int vol = -1;
-       char mute[3] = "";
-
-       if (!p_client_buffer || client_buffer_size <= 0) {
-               return;
-       }
-
-       snprintf(volume, 127, "%s/volume", IBM_ACPI_DIR);
-
-       fp = fopen(volume, "r");
-       if (fp != NULL) {
-               while (!feof(fp)) {
-                       char line[256];
-                       unsigned int read_vol = -1;
-
-                       if (fgets(line, 255, fp) == NULL) {
-                               break;
-                       }
-                       if (sscanf(line, "level: %u", &read_vol)) {
-                               vol = read_vol;
-                               continue;
-                       }
-                       if (sscanf(line, "mute: %s", mute)) {
-                               break;
-                       }
-               }
-       } else {
-               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
-                       "ibm* from your "PACKAGE_NAME" config file.", volume, strerror(errno));
-       }
-
-       fclose(fp);
-
-       if (strcmp(mute, "on") == 0) {
-               snprintf(p_client_buffer, client_buffer_size, "%s", "mute");
-               return;
-       } else {
-               snprintf(p_client_buffer, client_buffer_size, "%d", vol);
-               return;
-       }
-}
-
-/* static FILE *fp = NULL; */
-
-/* get LCD brightness on IBM/Lenovo laptops running the ibm acpi.
- * /proc/acpi/ibm/brightness looks like this (3 lines):
-level:          7
-commands:       up, down
-commands:       level <level> (<level> is 0-7)
- * Peter Tarjan (ptarjan@citromail.hu) */
-
-void get_ibm_acpi_brightness(char *p_client_buffer, size_t client_buffer_size)
-{
-       FILE *fp;
-       unsigned int brightness = 0;
-       char filename[128];
-
-       if (!p_client_buffer || client_buffer_size <= 0) {
-               return;
-       }
-
-       snprintf(filename, 127, "%s/brightness", IBM_ACPI_DIR);
-
-       fp = fopen(filename, "r");
-       if (fp != NULL) {
-               while (!feof(fp)) {
-                       char line[256];
-
-                       if (fgets(line, 255, fp) == NULL) {
-                               break;
-                       }
-                       if (sscanf(line, "level: %u", &brightness)) {
-                               break;
-                       }
-               }
-       } else {
-               CRIT_ERR("can't open '%s': %s\nYou are not using the IBM ACPI. Remove "
-                       "ibm* from your "PACKAGE_NAME" config file.", filename, strerror(errno));
-       }
-
-       fclose(fp);
-
-       snprintf(p_client_buffer, client_buffer_size, "%d", brightness);
-}
-
 void update_entropy(void)
 {
        static int rep = 0;
index ec484cd..b9ea657 100644 (file)
@@ -3,10 +3,6 @@
 
 #include "common.h"
 
-void get_ibm_acpi_fan(char *buf, size_t client_buffer_size);
-void get_ibm_acpi_temps(void);
-void get_ibm_acpi_volume(char *buf, size_t client_buffer_size);
-void get_ibm_acpi_brightness(char *buf, size_t client_buffer_size);
 const char *get_disk_protect_queue(const char *);
 
 struct i8k_struct {
@@ -24,12 +20,6 @@ struct i8k_struct {
 
 struct i8k_struct i8k;
 
-struct ibm_acpi_struct {
-       int temps[8];
-};
-
-struct ibm_acpi_struct ibm_acpi;
-
 int interface_up(const char *dev);
 char *get_ioscheduler(char *);
 int get_laptop_mode(void);
index 571069f..8b61104 100644 (file)
@@ -132,10 +132,12 @@ enum text_object_type {
        OBJ_i8k_right_fan_rpm,
        OBJ_i8k_ac_status,
        OBJ_i8k_buttons_status,
+#if defined(IBM)
        OBJ_ibm_fan,
        OBJ_ibm_temps,
        OBJ_ibm_volume,
        OBJ_ibm_brightness,
+#endif /* IBM */
        OBJ_if_up,
        OBJ_if_gw,
        OBJ_ioscheduler,