working...

git-svn-id: file:///home/jan/tmp/wetterstation/trunk@62 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
losinshi 2006-09-01 04:10:15 +00:00
parent 444f1a4f30
commit 9b7f61b4ee
6 changed files with 101 additions and 9 deletions

View File

@ -6,7 +6,7 @@ LDFLAS = -o
INCL = -I$$(pg_config --includedir) INCL = -I$$(pg_config --includedir)
BIN_NAME = chart BIN_NAME = chart
OBJS = chart.o config.o OBJS = chart.o config.o drawing/process_image.o
CONF_NAME = chart.conf CONF_NAME = chart.conf
@ -29,13 +29,14 @@ $(BIN_NAME): $(OBJS)
@ echo Binary $(BIN_NAME) ist fertig! @ echo Binary $(BIN_NAME) ist fertig!
# Abhängigkeiten # Abhängigkeiten
chart.o: chart.c definitions.h config.h chart.h chart.o: chart.c definitions.h config.h chart.h drawing/process_image.h
config.o: config.c config.h definitions.h chart.h config.o: config.c config.h definitions.h chart.h
drawing/process_image.o: drawing/process_image.c
# Compillieren # Compillieren
$(OBJS): $(OBJS):
@ echo "Kompilliere: "$(CC) $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c @ echo "Kompilliere: "$(CC) -o $@ $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c
@ $(CC) $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c @ $(CC) -o $@ $(DEBUG) $(NOLOG) $(INCL) $(CFLAGS) $*.c
# Programm mit debug-ausgabe bauen # Programm mit debug-ausgabe bauen
debug: debug:

View File

@ -32,11 +32,48 @@
#include "definitions.h" #include "definitions.h"
#include "config.h" #include "config.h"
#include "chart.h" #include "chart.h"
#include "drawing/process_image.h"
static int walk_image_cfg_list();
static void wait_for_childs();
static void exit_sig_handler(int); static void exit_sig_handler(int);
config global_opts; config global_opts;
static int walk_image_cfg_list(){
int has_forked = 0;
pid_t pid = 0;
image_cfg_list_ptr tmp_ptr = global_opts.image_cfg;
for(; tmp_ptr; tmp_ptr = tmp_ptr->next){
if(global_opts.fork){
if((pid = fork()) == 0){
process_image(tmp_ptr->image_cfg_file);
exit(EXIT_SUCCESS);
}
else if (pid == -1){
exit_error(ERROR_FORK);
}
has_forked++;
DEBUGOUT2("Prozess %d angelegt\n",pid);
} else {
process_image(tmp_ptr->image_cfg_file);
}
}
return has_forked;
}
static void wait_for_childs(){
int ret_val;
pid_t pid;
while((pid = wait(&ret_val)) != -1){
DEBUGOUT2("Prozess %d beendet\n", pid);
}
}
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
DEBUGOUT1("Programm gestartet\n"); DEBUGOUT1("Programm gestartet\n");
@ -66,6 +103,9 @@ int main(int argc, char *argv[]){
DEBUGOUT2(" Pass: = %s\n",global_opts.pg_pass); DEBUGOUT2(" Pass: = %s\n",global_opts.pg_pass);
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database); DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
if(walk_image_cfg_list())
wait_for_childs();
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View File

@ -1,7 +1,8 @@
fork yes fork yes
image_cfg bla
image_cfg_location blub/ image_cfg_location blub/
image_cfg bla
image_cfg blo
# Postgres-Einstellungen # Postgres-Einstellungen
pg_host 141.30.228.39 pg_host 141.30.228.39

View File

@ -1,8 +1,6 @@
/* /*
weatherdeamon -- Weather Data Capture Program for the definitions.h -- Part of Chart-generator for the weatherstation
'ELV-PC-Wettersensor-Empfänger'
definitions.h -- Part of the weatherdeamon
Copyright (C) 2006 Jan Losinski Copyright (C) 2006 Jan Losinski
@ -20,7 +18,6 @@
along with this program; if not, write to the Free Software along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
$Id: process.c v 1.00 11 Aug 2006 losinski $
*/ */
/* Default-Werte ----------------------------------------------------- */ /* Default-Werte ----------------------------------------------------- */
@ -37,6 +34,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"
/* Puffergrößen -------------------------------------------------------- */ /* Puffergrößen -------------------------------------------------------- */

View File

@ -0,0 +1,29 @@
/*
process_image.c -- Part of Chart-generator for the weatherstation
Copyright (C) 2006 Jan Losinski
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdio.h>
#include <stdlib.h>
#include "process_image.h"
void process_image(char *image_cfg_file){
printf("%s\n",image_cfg_file);
sleep(3);
}

View File

@ -0,0 +1,23 @@
/*
process_image.h -- Part of Chart-generator for the weatherstation
Copyright (C) 2006 Jan Losinski
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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
void process_image(char *);