Chart:
- Parsing config-files - test if an image should be regenerated git-svn-id: file:///home/jan/tmp/wetterstation/trunk@70 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
c73e7f591a
commit
3b26d8cdb9
|
|
@ -25,8 +25,7 @@ all: $(BIN_NAME)
|
||||||
# Binary Linken
|
# Binary Linken
|
||||||
$(BIN_NAME): $(OBJS)
|
$(BIN_NAME): $(OBJS)
|
||||||
@ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
@ echo Linke: $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
||||||
# @ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
@ $(LD) $(DEBUG) $(NOLOG) -L$$(pg_config --libdir)/pgsql -lpq $(LDFLAS) $(BIN_NAME) $(OBJS)
|
||||||
@ $(LD) $(DEBUG) $(NOLOG) $(LDFLAS) $(BIN_NAME) $(OBJS)
|
|
||||||
@ echo Binary $(BIN_NAME) ist fertig!
|
@ echo Binary $(BIN_NAME) ist fertig!
|
||||||
|
|
||||||
# Abhängigkeiten
|
# Abhängigkeiten
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,8 @@ fork yes
|
||||||
image_cfg_location image_file/
|
image_cfg_location image_file/
|
||||||
|
|
||||||
image_cfg testimage.conf
|
image_cfg testimage.conf
|
||||||
image_cfg bla
|
#image_cfg bla
|
||||||
image_cfg blo
|
#image_cfg blo
|
||||||
|
|
||||||
# Postgres-Einstellungen
|
# Postgres-Einstellungen
|
||||||
pg_host 141.30.228.39
|
pg_host 141.30.228.39
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
/* Fehlermeldungen ------------------------------------------------------*/
|
/* Fehlermeldungen ------------------------------------------------------*/
|
||||||
#define ERROR_SEIINST "Signal-Fehler: Kann Signalhandler zum beenden nicht installieren\n"
|
#define ERROR_SEIINST "Signal-Fehler: Kann Signalhandler zum beenden nicht installieren\n"
|
||||||
#define ERROR_FORK "Fork-Fehler: Kann keinen neuen Prozess anlegen\n"
|
#define ERROR_FORK "Fork-Fehler: Kann keinen neuen Prozess anlegen\n"
|
||||||
|
#define ERROR_STAT "Kann Stat nicht ausführen\n"
|
||||||
|
|
||||||
|
|
||||||
/* Puffergrößen -------------------------------------------------------- */
|
/* Puffergrößen -------------------------------------------------------- */
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
typedef struct image_cfg_t {
|
typedef struct image_cfg_t {
|
||||||
char *img_name;
|
char *file_name;
|
||||||
|
char *headline;
|
||||||
|
long gen_interval;
|
||||||
|
long show_interval;
|
||||||
|
long label_interval;
|
||||||
|
int label_sum;
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int sens_id;
|
||||||
} image_cfg;
|
} image_cfg;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,28 +27,83 @@
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
#include "image_common.h"
|
#include "image_common.h"
|
||||||
|
|
||||||
|
static int read_time(const char *, void *);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet
|
/* Zuordnung zwischen Schlüsselwörtern in der Config, Der Funktion, die diese auswertet
|
||||||
* und dem eld in der Options-Struktur */
|
* und dem eld in der Options-Struktur */
|
||||||
static const config_keyword keywords[] = {
|
static const config_keyword keywords[] = {
|
||||||
/* keyword handler variable address default */
|
/* keyword handler variable address default */
|
||||||
{"filename", read_str, &(img_cfg.img_name), ""},
|
{"filename", read_str, &(img_cfg.file_name), ""},
|
||||||
/* {"image_cfg", add_image_cfg, &(global_opts.image_cfg), ""},
|
{"headline", read_str, &(img_cfg.headline), ""},
|
||||||
{"image_cfg_location",read_str, &(global_opts.image_cfg_location), DEFAULT_PG_HOST},
|
{"gen_interval", read_time, &(img_cfg.gen_interval), ""},
|
||||||
*/
|
{"show_interval", read_time, &(img_cfg.show_interval), ""},
|
||||||
|
{"label_interval", read_time, &(img_cfg.label_interval), ""},
|
||||||
|
{"label_sum", read_yn, &(img_cfg.label_sum), ""},
|
||||||
|
{"width", read_int, &(img_cfg.width), ""},
|
||||||
|
{"height", read_int, &(img_cfg.height), ""},
|
||||||
|
{"sensor_id", read_int, &(img_cfg.sens_id), ""},
|
||||||
|
|
||||||
{"", NULL, NULL, ""}
|
{"", NULL, NULL, ""}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int get_image_cfg(char *file){
|
|
||||||
int ret_var;
|
|
||||||
char *buff;
|
|
||||||
|
|
||||||
buff = malloc(sizeof(char)*(strlen(file)+strlen(global_opts.image_cfg_location)+1));
|
|
||||||
buff = strcpy(buff, global_opts.image_cfg_location);
|
|
||||||
buff = strcat(buff, file);
|
|
||||||
|
|
||||||
DEBUGOUT2("Lese Config-File: '%s' \n", buff);
|
/* Ein Interval einlesen.
|
||||||
|
* wandelt Zeitangaben von der Form:
|
||||||
|
* 10s 10m 10h 10d 10y
|
||||||
|
* in Sekunden-Werte um */
|
||||||
|
static int read_time(const char *line, void *arg){
|
||||||
|
long *dest = arg;
|
||||||
|
long mult = 0;
|
||||||
|
char *p = NULL;
|
||||||
|
|
||||||
ret_var = read_config(buff, 1, keywords);
|
p = strchr(line, '\0');
|
||||||
return ret_var;
|
if(p != NULL){
|
||||||
|
switch( *(p - 1) ){
|
||||||
|
case 's':
|
||||||
|
mult = 1;
|
||||||
|
break;
|
||||||
|
case 'm':
|
||||||
|
mult = 60;
|
||||||
|
break;
|
||||||
|
case 'h':
|
||||||
|
mult = 3600;
|
||||||
|
break;
|
||||||
|
case 'd':
|
||||||
|
mult = 86400;
|
||||||
|
break;
|
||||||
|
case 'y':
|
||||||
|
mult = 31536000;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if( mult ){
|
||||||
|
strcpy(p - 1, "\0");
|
||||||
|
} else {
|
||||||
|
mult = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*dest = atol(line) * mult;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Liest ein Bild-Configfile */
|
||||||
|
int get_image_cfg(char *file){
|
||||||
|
int ret_var;
|
||||||
|
char *buff;
|
||||||
|
|
||||||
|
buff = malloc(sizeof(char)*(strlen(file)+strlen(global_opts.image_cfg_location)+1));
|
||||||
|
buff = strcpy(buff, global_opts.image_cfg_location);
|
||||||
|
buff = strcat(buff, file);
|
||||||
|
|
||||||
|
DEBUGOUT2("Lese Config-File: '%s' \n", buff);
|
||||||
|
|
||||||
|
ret_var = read_config(buff, 1, keywords);
|
||||||
|
return ret_var;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,9 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
#include "../definitions.h"
|
#include "../definitions.h"
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
#include "image_common.h"
|
#include "image_common.h"
|
||||||
|
|
@ -31,15 +34,50 @@
|
||||||
image_cfg img_cfg;
|
image_cfg img_cfg;
|
||||||
|
|
||||||
void process_image_cfg(char *image_cfg_file){
|
void process_image_cfg(char *image_cfg_file){
|
||||||
printf("%s\n",image_cfg_file);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
get_image_cfg(image_cfg_file);
|
get_image_cfg(image_cfg_file);
|
||||||
|
|
||||||
if (img_cfg.img_name != NULL){
|
if (img_cfg.file_name != NULL){
|
||||||
DEBUGOUT2("Image-Name = %s\n",img_cfg.img_name);
|
DEBUGOUT2("File-Name = %s\n", img_cfg.file_name);
|
||||||
|
DEBUGOUT2("Ueberschr. = %s\n", img_cfg.headline);
|
||||||
|
DEBUGOUT2("Gen.Interval = %d\n", img_cfg.gen_interval);
|
||||||
|
DEBUGOUT2("ShowInterval = %d\n", img_cfg.show_interval);
|
||||||
|
DEBUGOUT2("LabelInterval = %d\n", img_cfg.label_interval);
|
||||||
|
DEBUGOUT2("LabelSum = %d\n", img_cfg.label_sum);
|
||||||
|
DEBUGOUT2("Width = %d\n", img_cfg.width);
|
||||||
|
DEBUGOUT2("Height = %d\n", img_cfg.height);
|
||||||
|
DEBUGOUT2("SensorId = %d\n", img_cfg.sens_id);
|
||||||
|
DEBUGOUT1("\n");
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
check_file_interval();
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int check_file_interval(){
|
||||||
|
|
||||||
|
struct stat stat_buff;
|
||||||
|
time_t now;
|
||||||
|
long diff_sek;
|
||||||
|
|
||||||
|
if(access(img_cfg.file_name, F_OK) == -1){
|
||||||
|
DEBUGOUT2("Datei '%s' existiert nicht\n", img_cfg.file_name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
if ((stat(img_cfg.file_name, &stat_buff)) != -1){
|
||||||
|
|
||||||
|
now = time(NULL);
|
||||||
|
diff_sek = difftime(now, stat_buff.st_mtime);
|
||||||
|
|
||||||
|
DEBUGOUT3("Datei '%s' ist %d Sek. alt \n", img_cfg.file_name, diff_sek);
|
||||||
|
|
||||||
|
if(diff_sek > (img_cfg.gen_interval * 60))
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
exit_error(ERROR_STAT);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1 +1,9 @@
|
||||||
filename testbildl
|
filename /home/jan/Testbild.png
|
||||||
|
headline Testbild
|
||||||
|
gen_interval 15m
|
||||||
|
show_interval 1h
|
||||||
|
label_interval 10m
|
||||||
|
label_sum no
|
||||||
|
width 400
|
||||||
|
height 250
|
||||||
|
sensor_id 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue