]> git.webhop.me Git - lcd4linux.git/commitdiff
[lcd4linux @ 2004-03-13 06:49:20 by reinelt]
authorreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 13 Mar 2004 06:49:20 +0000 (06:49 +0000)
committerreinelt <reinelt@3ae390bd-cb1e-0410-b409-cd5a39f66f1f>
Sat, 13 Mar 2004 06:49:20 +0000 (06:49 +0000)
seti@home plugin ported to NextGeneration

git-svn-id: https://ssl.bulix.org/svn/lcd4linux/trunk@395 3ae390bd-cb1e-0410-b409-cd5a39f66f1f

Makefile.am
Makefile.in
lcd4linux.conf.sample
plugin.c
plugin_seti.c [new file with mode: 0644]
seti.c [deleted file]
seti.h [deleted file]

index 100aebda73b602b88e1b2e9b29e6e7adda011e81..88e9b183fdd1846e1b648378437f0a32a4c57f03 100644 (file)
@@ -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
index 4239b2485ea8476bd31e7551b41a575402f5c67b..081f2773f0d76066c2e4971da6e93a52ba81f0c3 100644 (file)
@@ -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)
index 707e7d7fdcc9dc1592160ca282976924b02e803d..e5a3f483a0090a9380a3dacdf74db23d112554f3 100644 (file)
@@ -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').' ***'
index 86ce1ebfbc5112183aaad611fa4c13c6cb3fcaaa..6e499660466708b09971bc8f5d4e404684c4c0d2 100644 (file)
--- a/plugin.c
+++ b/plugin.c
@@ -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 (file)
index 0000000..c1d2d6a
--- /dev/null
@@ -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);
+}
diff --git a/seti.c b/seti.c
deleted file mode 100644 (file)
index 72332bf..0000000
--- a/seti.c
+++ /dev/null
@@ -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;
-
-}
diff --git a/seti.h b/seti.h
deleted file mode 100644 (file)
index 44dbe87..0000000
--- a/seti.h
+++ /dev/null
@@ -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