diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile.am | 3 | ||||
-rw-r--r-- | Makefile.in | 10 | ||||
-rw-r--r-- | lcd4linux.conf.sample | 6 | ||||
-rw-r--r-- | plugin.c | 9 | ||||
-rw-r--r-- | plugin_seti.c | 158 | ||||
-rw-r--r-- | seti.c | 192 | ||||
-rw-r--r-- | seti.h | 48 |
7 files changed, 179 insertions, 247 deletions
diff --git a/Makefile.am b/Makefile.am index 100aebd..88e9b18 100644 --- a/Makefile.am +++ b/Makefile.am @@ -49,7 +49,8 @@ plugin_dvb.c \ plugin_i2c_sensors.c \ plugin_imon.c \ plugin_xmms.c \ -plugin_mysql.c +plugin_mysql.c \ +plugin_seti.c #liblcd4linux_la_DEPENDENCIES = @DRIVERS@ #liblcd4linux_la_LDFLAGS = -version-info 9:12:9 diff --git a/Makefile.in b/Makefile.in index 4239b24..081f277 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,7 +106,7 @@ lcd4linux_LDADD = @DRIVERS@ @DRVLIBS@ #remove next line for liblcd4linux lcd4linux_DEPENDENCIES = @DRIVERS@ -lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h lock.c lock.h pid.c pid.h timer.c timer.h udelay.c udelay.h qprintf.c qprintf.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_imon.c plugin_xmms.c plugin_mysql.c +lcd4linux_SOURCES = lcd4linux.c cfg.c cfg.h debug.c debug.h drv.c drv.h evaluator.c evaluator.h hash.c hash.h layout.c layout.h lock.c lock.h pid.c pid.h timer.c timer.h udelay.c udelay.h qprintf.c qprintf.h widget.c widget.h widget_text.c widget_text.h widget_bar.c widget_bar.h widget_icon.c widget_icon.h plugin.c plugin.h plugin_math.c plugin_string.c plugin_cfg.c plugin_uname.c plugin_loadavg.c plugin_proc_stat.c plugin_cpuinfo.c plugin_meminfo.c plugin_netdev.c plugin_ppp.c plugin_dvb.c plugin_i2c_sensors.c plugin_imon.c plugin_xmms.c plugin_mysql.c plugin_seti.c #liblcd4linux_la_DEPENDENCIES = @DRIVERS@ @@ -146,7 +146,7 @@ plugin_uname.$(OBJEXT) plugin_loadavg.$(OBJEXT) \ plugin_proc_stat.$(OBJEXT) plugin_cpuinfo.$(OBJEXT) \ plugin_meminfo.$(OBJEXT) plugin_netdev.$(OBJEXT) plugin_ppp.$(OBJEXT) \ plugin_dvb.$(OBJEXT) plugin_i2c_sensors.$(OBJEXT) plugin_imon.$(OBJEXT) \ -plugin_xmms.$(OBJEXT) plugin_mysql.$(OBJEXT) +plugin_xmms.$(OBJEXT) plugin_mysql.$(OBJEXT) plugin_seti.$(OBJEXT) CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -174,9 +174,9 @@ DEP_FILES = .deps/BeckmannEgle.P .deps/MilfordInstruments.P \ .deps/plugin_dvb.P .deps/plugin_i2c_sensors.P .deps/plugin_imon.P \ .deps/plugin_loadavg.P .deps/plugin_math.P .deps/plugin_meminfo.P \ .deps/plugin_mysql.P .deps/plugin_netdev.P .deps/plugin_ppp.P \ -.deps/plugin_proc_stat.P .deps/plugin_string.P .deps/plugin_uname.P \ -.deps/plugin_xmms.P .deps/qprintf.P .deps/timer.P .deps/udelay.P \ -.deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ +.deps/plugin_proc_stat.P .deps/plugin_seti.P .deps/plugin_string.P \ +.deps/plugin_uname.P .deps/plugin_xmms.P .deps/qprintf.P .deps/timer.P \ +.deps/udelay.P .deps/widget.P .deps/widget_bar.P .deps/widget_icon.P \ .deps/widget_text.P SOURCES = $(lcd4linux_SOURCES) $(EXTRA_lcd4linux_SOURCES) OBJECTS = $(lcd4linux_OBJECTS) diff --git a/lcd4linux.conf.sample b/lcd4linux.conf.sample index 707e7d7..e5a3f48 100644 --- a/lcd4linux.conf.sample +++ b/lcd4linux.conf.sample @@ -95,6 +95,12 @@ Display XWindow { Halfground '#70c000' } + +Plugin Seti { + Directory '/root/setiathome-3.08.i686-pc-linux-gnu' +} + + Widget OS { class 'Text' expression '*** '.uname('sysname').' '.uname('release').' ***' @@ -1,4 +1,4 @@ -/* $Id: plugin.c,v 1.21 2004/03/10 07:16:15 reinelt Exp $ +/* $Id: plugin.c,v 1.22 2004/03/13 06:49:20 reinelt Exp $ * * plugin handler for the Evaluator * @@ -22,6 +22,9 @@ * * * $Log: plugin.c,v $ + * Revision 1.22 2004/03/13 06:49:20 reinelt + * seti@home plugin ported to NextGeneration + * * Revision 1.21 2004/03/10 07:16:15 reinelt * MySQL plugin from Javier added * @@ -160,6 +163,7 @@ int plugin_init_i2c_sensors (void); int plugin_init_xmms (void); int plugin_init_imon(void); int plugin_init_mysql(void); +int plugin_init_seti(void); void plugin_exit_math (void); @@ -177,6 +181,7 @@ void plugin_exit_i2c_sensors (void); void plugin_exit_xmms (void); void plugin_exit_imon(void); void plugin_exit_mysql(void); +void plugin_exit_seti(void); int plugin_init (void) { @@ -195,6 +200,7 @@ int plugin_init (void) plugin_init_xmms(); plugin_init_imon(); plugin_init_mysql(); + plugin_init_seti(); return 0; } @@ -215,6 +221,7 @@ void plugin_exit(void) { plugin_exit_xmms(); plugin_exit_imon(); plugin_exit_mysql(); + plugin_exit_seti(); DeleteFunctions(); DeleteVariables(); diff --git a/plugin_seti.c b/plugin_seti.c new file mode 100644 index 0000000..c1d2d6a --- /dev/null +++ b/plugin_seti.c @@ -0,0 +1,158 @@ +/* $Id: plugin_seti.c,v 1.1 2004/03/13 06:49:20 reinelt Exp $ + * + * plugin for seti@home status reporting + * + * Copyright 2004 Michael Reinelt <reinelt@eunet.at> + * Copyright 2004 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net> + * + * based on the old seti client which is + * Copyright 2001 Axel Ehnert <axel@ehnert.net> + * + * + * This file is part of LCD4Linux. + * + * LCD4Linux 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, or (at your option) + * any later version. + * + * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * + * $Log: plugin_seti.c,v $ + * Revision 1.1 2004/03/13 06:49:20 reinelt + * seti@home plugin ported to NextGeneration + * + */ + +/* + * exported functions: + * + * int plugin_init_seti (void) + * adds functions to access /seti/state.sah + * + */ + + +#include "config.h" + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#include <ctype.h> +#include <errno.h> + +#include "debug.h" +#include "plugin.h" +#include "hash.h" +#include "cfg.h" + +#define SECTION "Plugin:Seti" +#define DIRKEY "Directory" +#define STATEFILE "state.sah" + +static HASH SETI = { 0, }; +static int fatal = 0; +static char *dir = NULL; + + +static int parse_seti (void) +{ + static char fn[256] = ""; + FILE *stream; + int age; + + // if a fatal error occured, do nothing + if (fatal != 0) return -1; + + // reread every 100 msec only + age=hash_age(&SETI, NULL, NULL); + if (age>0 && age<=100) return 0; + + if (fn[0] == '\0') { + char *dir = cfg_get (SECTION, DIRKEY, NULL); + if (dir == NULL || *dir == '\0') { + error ("no '%s.%s' entry from %s\n", SECTION, DIRKEY, cfg_source()); + fatal = 1; + return -1; + } + if (strlen(dir) > sizeof(fn)-sizeof(STATEFILE)-2) { + error ("entry '%s.%s' too long from %s!\n", SECTION, DIRKEY, cfg_source()); + fatal = 1; + free (dir); + return -1; + } + strcpy (fn, dir); + if (fn[strlen(fn)-1]!='/') + strcat (fn, "/"); + strcat (fn, STATEFILE); + free (dir); + } + + stream = fopen(fn, "r"); + if (stream == NULL) { + error ("fopen(%s) failed: %s", fn, strerror(errno)); + return -1; + } + + while (!feof(stream)) { + char buffer[256]; + char *c, *key, *val; + fgets (buffer, sizeof(buffer), stream); + c=strchr(buffer, '='); + if (c==NULL) continue; + key=buffer; val=c+1; + // strip leading blanks from key + while (isspace(*key)) *key++='\0'; + // strip trailing blanks from key + do *c='\0'; while (isspace(*--c)); + // strip leading blanks from value + while (isspace(*val)) *val++='\0'; + // strip trailing blanks from value + for (c=val; *c!='\0';c++); + while (isspace(*--c)) *c='\0'; + // add entry to hash table + hash_set (&SETI, key, val); + } + + fclose (stream); + + return 0; +} + + +static void my_seti (RESULT *result, RESULT *arg1) +{ + char *key, *val; + + if (parse_seti()<0) { + SetResult(&result, R_STRING, ""); + return; + } + + key=R2S(arg1); + val=hash_get(&SETI, key); + if (val==NULL) val=""; + + SetResult(&result, R_STRING, val); +} + + +int plugin_init_seti (void) +{ + AddFunction ("seti", 1, my_seti); + return 0; +} + + +void plugin_exit_seti(void) +{ + hash_destroy(&SETI); +} @@ -1,192 +0,0 @@ -/* $Id: seti.c,v 1.14 2004/03/03 03:47:04 reinelt Exp $ - * - * seti@home specific functions - * - * Copyright 2001 Axel Ehnert <axel@ehnert.net> - * - * This file is part of LCD4Linux. - * - * LCD4Linux 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, or (at your option) - * any later version. - * - * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * $Log: seti.c,v $ - * Revision 1.14 2004/03/03 03:47:04 reinelt - * big patch from Martin Hejl: - * - use qprintf() where appropriate - * - save CPU cycles on gettimeofday() - * - add quit() functions to free allocated memory - * - fixed lots of memory leaks - * - * Revision 1.13 2004/01/29 04:40:03 reinelt - * every .c file includes "config.h" now - * - * Revision 1.12 2004/01/09 04:16:06 reinelt - * added 'section' argument to cfg_get(), but NULLed it on all calls by now. - * - * Revision 1.11 2004/01/06 22:33:14 reinelt - * Copyright statements cleaned up - * - * Revision 1.10 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.9 2003/08/24 05:17:58 reinelt - * liblcd4linux patch from Patrick Schemitz - * - * Revision 1.8 2003/06/13 05:11:11 reinelt - * error message cosmetics - * - * Revision 1.7 2003/02/22 07:53:10 reinelt - * cfg_get(key,defval) - * - * Revision 1.6 2001/09/12 05:37:22 reinelt - * - * fixed a bug in seti.c (file was never closed, lcd4linux run out of fd's - * - * improved socket debugging - * - * Revision 1.5 2001/08/05 17:13:29 reinelt - * - * cleaned up inlude of sys/time.h and time.h - * - * Revision 1.4 2001/03/08 09:02:04 reinelt - * - * seti client cleanup - * - * Revision 1.3 2001/02/19 00:15:46 reinelt - * - * integrated mail and seti client - * major rewrite of parser and tokenizer to support double-byte tokens - * - * Revision 1.2 2001/02/18 21:16:06 reinelt - * *** empty log message *** - * - * Revision 1.1 2001/02/18 21:15:15 reinelt - * - * added setiathome client - * - */ - -/* - * exported functions: - * - * Seti (int *perc, int *cput) - * returns 0 if ok, -1 if error - * sets *perc to the percentage completed by seti@home client - * sets *perc to the cpu time used - * - */ - - -#define STATEFILE "state.sah" - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> -#include <errno.h> -#include <time.h> -#include <sys/ioctl.h> -#include <sys/types.h> - -#include "cfg.h" -#include "debug.h" -#include "seti.h" - - -int Seti (double *perc, double *cput) -{ - static char fn[256]; - static time_t now=0; - static int fd=-2; - static double v1=0; - static double v2=0; - char buffer[8192], *p; - - *perc=v1; - *cput=v2; - - if (fd==-1) return -1; - - if (time(NULL)==now) return 0; - time(&now); - - if (fd==-2) { - char *dir=cfg_get(NULL, "SetiDir", NULL); - if (dir==NULL || *dir=='\0') { - error ("no 'SetiDir' entry in %s!\n", cfg_source()); - fd=-1; - free(dir); - return -1; - } - if (strlen(dir)>sizeof(fn)-sizeof(STATEFILE)-2) { - error ("entry 'SetiDir' too long in %s!\n", cfg_source()); - fd=-1; - free(dir); - return -1; - } - strcpy(fn, dir); - strcat(fn, "/"); - strcat(fn, STATEFILE); - free(dir); - } - - fd = open(fn, O_RDONLY); - if (fd==-1) { - error ("open(%s) failed: %s", fn, strerror(errno)); - return -1; - } - - if (read (fd, &buffer, sizeof(buffer)-1)==-1) { - error ("read(%s) failed: %s", fn, strerror(errno)); - close (fd); - fd=-1; - return -1; - } - - close (fd); - - p=strstr(buffer, "prog="); - if (p==NULL) { - error ("parse(%s) failed: no 'prog=' line", fn); - fd=-1; - return -1; - } - if (sscanf(p+5, "%lf", &v1)!=1) { - error ("parse(%s) failed: unknown 'prog=' format", fn); - fd=-1; - return -1; - } - - p=strstr(buffer, "cpu="); - if (p==NULL) { - error ("parse(%s) failed: no 'cpu=' line", fn); - fd=-1; - return -1; - } - if (sscanf(p+4, "%lf", &v2)!=1) { - error ("parse(%s) failed: unknown 'cpu=' format", fn); - fd=-1; - return -1; - } - - *perc=v1; - *cput=v2; - - return 0; - -} @@ -1,48 +0,0 @@ -/* $Id: seti.h,v 1.4 2003/10/05 17:58:50 reinelt Exp $ - * - * seti@home specific functions - * - * Copyright 2001 Axel Ehnert <axel@ehnert.net> - * - * This file is part of LCD4Linux. - * - * LCD4Linux 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, or (at your option) - * any later version. - * - * LCD4Linux 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * - * $Log: seti.h,v $ - * Revision 1.4 2003/10/05 17:58:50 reinelt - * libtool junk; copyright messages cleaned up - * - * Revision 1.3 2001/03/08 09:02:04 reinelt - * - * seti client cleanup - * - * Revision 1.2 2001/02/19 00:15:46 reinelt - * - * integrated mail and seti client - * major rewrite of parser and tokenizer to support double-byte tokens - * - * Revision 1.1 2001/02/18 21:15:15 reinelt - * - * added setiathome client - * - */ - -#ifndef _SETI_H_ -#define _SETI_H_ - -int Seti (double *perc, double *cput); - -#endif |