Global part for graph-generation nearly compleeted
git-svn-id: file:///home/jan/tmp/wetterstation/trunk@64 dd492736-c11a-0410-ad51-8c26713eaf7f
This commit is contained in:
parent
bb1dfab7af
commit
27f0adec90
|
|
@ -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 drawing/process_image.o
|
OBJS = chart.o config.o common.o image_file/image_file.o
|
||||||
|
|
||||||
CONF_NAME = chart.conf
|
CONF_NAME = chart.conf
|
||||||
|
|
||||||
|
|
@ -29,9 +29,20 @@ $(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 drawing/process_image.h
|
chart.o: chart.c \
|
||||||
config.o: config.c config.h definitions.h chart.h
|
definitions.h \
|
||||||
drawing/process_image.o: drawing/process_image.c
|
config.h \
|
||||||
|
chart.h \
|
||||||
|
common.h \
|
||||||
|
image_file/image_file.h
|
||||||
|
common.o: common.c \
|
||||||
|
common.h
|
||||||
|
config.o: config.c \
|
||||||
|
config.h \
|
||||||
|
definitions.h \
|
||||||
|
common.h
|
||||||
|
image_file/image_file.o: image_file/image_file.c \
|
||||||
|
image_file/image_file.h
|
||||||
|
|
||||||
# Compillieren
|
# Compillieren
|
||||||
$(OBJS):
|
$(OBJS):
|
||||||
|
|
|
||||||
|
|
@ -25,23 +25,20 @@
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <errno.h>
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "chart.h"
|
#include "chart.h"
|
||||||
#include "drawing/process_image.h"
|
#include "common.h"
|
||||||
|
#include "image_file/image_file.h"
|
||||||
|
|
||||||
static int walk_image_cfg_list();
|
static int walk_image_cfg_list();
|
||||||
static void wait_for_childs();
|
static void wait_for_childs();
|
||||||
static void exit_sig_handler(int);
|
|
||||||
|
|
||||||
config global_opts;
|
config global_opts;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int walk_image_cfg_list(){
|
static int walk_image_cfg_list(){
|
||||||
int has_forked = 0;
|
int has_forked = 0;
|
||||||
pid_t pid = 0;
|
pid_t pid = 0;
|
||||||
|
|
@ -50,22 +47,26 @@ static int walk_image_cfg_list(){
|
||||||
for(; tmp_ptr; tmp_ptr = tmp_ptr->next){
|
for(; tmp_ptr; tmp_ptr = tmp_ptr->next){
|
||||||
if(global_opts.fork){
|
if(global_opts.fork){
|
||||||
if((pid = fork()) == 0){
|
if((pid = fork()) == 0){
|
||||||
process_image(tmp_ptr->image_cfg_file);
|
clear_clean();
|
||||||
|
process_image_cfg(tmp_ptr->image_cfg_file);
|
||||||
exit(EXIT_SUCCESS);
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
else if (pid == -1){
|
else if (pid == -1){
|
||||||
exit_error(ERROR_FORK);
|
exit_error(ERROR_FORK);
|
||||||
}
|
}
|
||||||
|
if(!has_forked){
|
||||||
|
add_clean(wait_for_childs, NULL);
|
||||||
|
}
|
||||||
has_forked++;
|
has_forked++;
|
||||||
DEBUGOUT2("Prozess %d angelegt\n",pid);
|
DEBUGOUT2("Prozess %d angelegt\n",pid);
|
||||||
} else {
|
} else {
|
||||||
process_image(tmp_ptr->image_cfg_file);
|
process_image_cfg(tmp_ptr->image_cfg_file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return has_forked;
|
return has_forked;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void wait_for_childs(){
|
static void wait_for_childs(void *dummy){
|
||||||
int ret_val;
|
int ret_val;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
while((pid = wait(&ret_val)) != -1){
|
while((pid = wait(&ret_val)) != -1){
|
||||||
|
|
@ -73,7 +74,6 @@ static void wait_for_childs(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]){
|
int main(int argc, char *argv[]){
|
||||||
DEBUGOUT1("Programm gestartet\n");
|
DEBUGOUT1("Programm gestartet\n");
|
||||||
|
|
||||||
|
|
@ -104,37 +104,9 @@ int main(int argc, char *argv[]){
|
||||||
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
|
DEBUGOUT2(" Datenbank = %s\n",global_opts.pg_database);
|
||||||
|
|
||||||
if(walk_image_cfg_list())
|
if(walk_image_cfg_list())
|
||||||
wait_for_childs();
|
wait_for_childs(NULL);
|
||||||
|
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Diese Funktion beendet das Programm mit einer Fehlermeldung. */
|
|
||||||
void exit_error(char* err){
|
|
||||||
DEBUGOUT1("\nEtwas unschoenes ist passiert\n");
|
|
||||||
if(errno != 0){
|
|
||||||
perror("Fehler");
|
|
||||||
}
|
|
||||||
write(STDOUT_FILENO, err, strlen(err));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wird bei Beendigungssignalen ausgefuehrt */
|
|
||||||
static void exit_sig_handler(int signr){
|
|
||||||
#ifdef DEBUG
|
|
||||||
DEBUGOUT1("\n");
|
|
||||||
switch (signr){
|
|
||||||
case SIGABRT:
|
|
||||||
DEBUGOUT1("SIGABRT Interupt erhalten!\n");
|
|
||||||
case SIGTERM:
|
|
||||||
DEBUGOUT1("SIGTERM Interupt erhalten!\n");
|
|
||||||
case SIGQUIT:
|
|
||||||
DEBUGOUT1("SIGQUIT Interupt erhalten!\n");
|
|
||||||
case SIGINT:
|
|
||||||
DEBUGOUT1("SIGINT Interupt erhalten!\n");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
DEBUGOUT1("Beende Programm...\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -20,27 +20,5 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct image_cfg_list_t *image_cfg_list_ptr;
|
|
||||||
typedef struct image_cfg_list_t {
|
|
||||||
char *image_cfg_file;
|
|
||||||
image_cfg_list_ptr next;
|
|
||||||
} image_cfg_list;
|
|
||||||
|
|
||||||
typedef struct config_t {
|
|
||||||
char *pg_host;
|
|
||||||
char *pg_database;
|
|
||||||
char *pg_user;
|
|
||||||
char *pg_pass;
|
|
||||||
char *image_cfg_location;
|
|
||||||
image_cfg_list_ptr image_cfg;
|
|
||||||
int fork;
|
|
||||||
} config;
|
|
||||||
|
|
||||||
extern config global_opts;
|
|
||||||
|
|
||||||
|
|
||||||
/* Funktionen -------------------------------------------------------------*/
|
|
||||||
|
|
||||||
/* Programm mit einem Fatalem Fehler beenden.
|
|
||||||
* Argument: Fehlermeldung */
|
|
||||||
void exit_error(char*);
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,112 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
common.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 <errno.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <unistd.h> /* STDOUT_FILENO */
|
||||||
|
#include "common.h"
|
||||||
|
#include "definitions.h"
|
||||||
|
|
||||||
|
static void clean();
|
||||||
|
|
||||||
|
|
||||||
|
clean_struct_ptr clean_ptr = NULL;
|
||||||
|
|
||||||
|
/* Ein neues Clean-Element anfuegen. Ein Clean-Element ist eine Datenstruktur, die
|
||||||
|
* einen Pointer auf eine Funktion vom Typ
|
||||||
|
* void func(void *data),
|
||||||
|
* einen Zeiger auf beliebige Daten und einen Zeiger auf das naechste Element haelt.
|
||||||
|
* Die Funktionen werden beim regulaeren beenden des Programmes aufgerufen um zum bsp.
|
||||||
|
* datenbankverbindungen zu schließen, etc. */
|
||||||
|
void add_clean(clean_func_t func, void *data){
|
||||||
|
clean_struct_ptr temp = (clean_struct_ptr) malloc(sizeof(clean_data));
|
||||||
|
|
||||||
|
temp->data = data;
|
||||||
|
temp->func = func;
|
||||||
|
temp->next = NULL;
|
||||||
|
|
||||||
|
if(clean_ptr == NULL){
|
||||||
|
clean_ptr = temp;
|
||||||
|
} else {
|
||||||
|
temp->next = clean_ptr;
|
||||||
|
clean_ptr = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void remove_clean(){
|
||||||
|
clean_struct_ptr temp = clean_ptr;
|
||||||
|
if (temp != NULL){
|
||||||
|
clean_ptr = temp->next;
|
||||||
|
free(temp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_clean(){
|
||||||
|
while(clean_ptr != NULL){
|
||||||
|
remove_clean();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 'Saeuberung' ausfuehren */
|
||||||
|
static void clean(){
|
||||||
|
DEBUGOUT1("\nRaeume auf...\n");
|
||||||
|
clean_struct_ptr p = clean_ptr;
|
||||||
|
while(p != NULL){
|
||||||
|
p->func(p->data);
|
||||||
|
p = p->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Diese Funktion beendet das Programm mit einer Fehlermeldung. */
|
||||||
|
void exit_error(char* err){
|
||||||
|
DEBUGOUT1("\nEtwas unschoenes ist passiert\n");
|
||||||
|
clean();
|
||||||
|
if(errno != 0){
|
||||||
|
perror("Fehler");
|
||||||
|
}
|
||||||
|
write(STDOUT_FILENO, err, strlen(err));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Wird bei Beendigungssignalen ausgefuehrt */
|
||||||
|
void exit_sig_handler(int signr){
|
||||||
|
#ifdef DEBUG
|
||||||
|
DEBUGOUT1("\n");
|
||||||
|
switch (signr){
|
||||||
|
case SIGABRT:
|
||||||
|
DEBUGOUT1("SIGABRT Interupt erhalten!\n");
|
||||||
|
case SIGTERM:
|
||||||
|
DEBUGOUT1("SIGTERM Interupt erhalten!\n");
|
||||||
|
case SIGQUIT:
|
||||||
|
DEBUGOUT1("SIGQUIT Interupt erhalten!\n");
|
||||||
|
case SIGINT:
|
||||||
|
DEBUGOUT1("SIGINT Interupt erhalten!\n");
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
clean();
|
||||||
|
DEBUGOUT1("Beende Programm...\n");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
|
||||||
|
common.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.
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct image_cfg_list_t *image_cfg_list_ptr;
|
||||||
|
typedef struct image_cfg_list_t {
|
||||||
|
char *image_cfg_file;
|
||||||
|
image_cfg_list_ptr next;
|
||||||
|
} image_cfg_list;
|
||||||
|
|
||||||
|
typedef struct config_t {
|
||||||
|
char *pg_host;
|
||||||
|
char *pg_database;
|
||||||
|
char *pg_user;
|
||||||
|
char *pg_pass;
|
||||||
|
char *image_cfg_location;
|
||||||
|
image_cfg_list_ptr image_cfg;
|
||||||
|
int fork;
|
||||||
|
} config;
|
||||||
|
|
||||||
|
typedef void (*clean_func_t)(void *data);
|
||||||
|
|
||||||
|
typedef struct clean_struct *clean_struct_ptr;
|
||||||
|
typedef struct clean_struct {
|
||||||
|
void *data;
|
||||||
|
clean_func_t func;
|
||||||
|
clean_struct_ptr next;
|
||||||
|
} clean_data;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
extern config global_opts;
|
||||||
|
|
||||||
|
/* Funktionen -------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* Programm mit einem Fatalem Fehler beenden.
|
||||||
|
* Argument: Fehlermeldung */
|
||||||
|
void exit_error(char*);
|
||||||
|
|
||||||
|
/* Signal-handler-Funktion zum beenden des Programmes */
|
||||||
|
void exit_sig_handler(int);
|
||||||
|
|
||||||
|
/* Eine (neuste) Clean-Funktion entfernen */
|
||||||
|
void remove_clean();
|
||||||
|
|
||||||
|
/* Eine Clean-Funktion hinzufügen */
|
||||||
|
void add_clean(clean_func_t , void *);
|
||||||
|
|
||||||
|
/* Alle clean-Funktionen entfernen */
|
||||||
|
void clear_clean();
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "definitions.h"
|
#include "definitions.h"
|
||||||
#include "chart.h"
|
#include "common.h"
|
||||||
|
|
||||||
/* Funktionsdefinitionen */
|
/* Funktionsdefinitionen */
|
||||||
static int read_int(const char *, void *);
|
static int read_int(const char *, void *);
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,9 @@
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include "process_image.h"
|
#include "image_file.h"
|
||||||
|
|
||||||
void process_image(char *image_cfg_file){
|
void process_image_cfg(char *image_cfg_file){
|
||||||
printf("%s\n",image_cfg_file);
|
printf("%s\n",image_cfg_file);
|
||||||
sleep(3);
|
sleep(3);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,4 +20,4 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void process_image(char *);
|
void process_image_cfg(char *);
|
||||||
|
|
|
||||||
|
|
@ -1,23 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <sys/types.h>
|
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
int main(){
|
|
||||||
int i;
|
|
||||||
pid_t p;
|
|
||||||
for(i=0; i<2; i++){
|
|
||||||
if((p = fork()) == 0){
|
|
||||||
sleep(10);
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
sleep(1);
|
|
||||||
printf("Process %i created\n",p);
|
|
||||||
}
|
|
||||||
while((p = wait(&i))!=-1){
|
|
||||||
printf("pid: %i\n",p);
|
|
||||||
}
|
|
||||||
printf("alle Prozesse beendet\n");
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue