From 0836a6e06f86e366017da3b2b2c132b3a4f2c877 Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 13 Jun 2005 20:38:19 +0000 Subject: Added some logfile code. Enhanced the file object... now ready to hook into mov_encoder --- src/Makefile.am | 1 + src/file.cc | 27 ++++++++++++++++--- src/file.h | 11 +++++++- src/info.cc | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/info.h | 17 +++++++++++- src/info_console.cc | 4 ++- src/info_console.h | 4 ++- src/info_gui.cc | 5 ++++ src/info_gui.h | 1 - 9 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 src/info.cc (limited to 'src') diff --git a/src/Makefile.am b/src/Makefile.am index 007f61b..9c7d187 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -17,6 +17,7 @@ miav_SOURCES = $(shell if [ $QT_CXXFLAGS ] ; then ../tools/MocList cc; fi ) \ frame.cc \ img_encoder.cc \ img_file.cc \ + info.cc \ info_console.cc \ info_gui.cc \ mainwindow.cc \ diff --git a/src/file.cc b/src/file.cc index ce06d67..1a94150 100644 --- a/src/file.cc +++ b/src/file.cc @@ -31,6 +31,10 @@ /* * $Log$ + * Revision 1.2 2005/06/13 20:38:19 deva + * Added some logfile code. + * Enhanced the file object... now ready to hook into mov_encoder + * * Revision 1.1 2005/06/09 17:54:00 deva * New file object, that takes care of uniqueness and counts up number in * filename, when grown too big. @@ -51,10 +55,12 @@ #include -File::File(char *fn, char* ext) +File::File(char *fn, char* ext, Info *i) { char path[256]; + info = i; + filename = (char*)malloc(strlen(fn) + 1); extension = (char*)malloc(strlen(ext) + 1); @@ -62,6 +68,7 @@ File::File(char *fn, char* ext) strcpy(extension, ext); num = 0; + seqnum = 0; fd = -1; int pos = (int)strrchr(filename, '/'); @@ -92,18 +99,29 @@ int File::Open() fd = -1; while(fd == -1) { - sprintf(fname, "%s%.3d.%s", filename, num, extension); + if(seqnum) { + // A sequence number > 0 + sprintf(fname, "%s%.3d-%d.%s", filename, num, seqnum, extension); + } else { + // A sequence number of 0 + sprintf(fname, "%s%.3d.%s", filename, num, extension); + } fd = open(fname, O_CREAT | O_WRONLY | O_SYNC | O_EXCL, //| O_LARGEFILE S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); num ++; // If more than 1000 files are created in one day, something is terribly wrong! if(num > 1000) { - fprintf(stderr, "Something is wrong with tha path [%s]!\n", fname); + info->error("Something is wrong with the path [%s]!\n", fname); exit(1); } } + + seqnum ++; + + info->log("Opened the file %s for output.\n", fname); + return 0; } @@ -114,10 +132,11 @@ int File::Write(void* data, int size) w = write(fd, data, size); if(w != size) { + info->log("Wrapping file.\n"); Open(); w = write(fd, data, size); if(w != size) { - fprintf(stderr, "Out of diskspace!\n"); + info->error("Out of diskspace!\n"); exit(1); } } diff --git a/src/file.h b/src/file.h index e093da9..6326528 100644 --- a/src/file.h +++ b/src/file.h @@ -31,6 +31,10 @@ /* * $Log$ + * Revision 1.2 2005/06/13 20:38:19 deva + * Added some logfile code. + * Enhanced the file object... now ready to hook into mov_encoder + * * Revision 1.1 2005/06/09 17:54:00 deva * New file object, that takes care of uniqueness and counts up number in * filename, when grown too big. @@ -41,22 +45,27 @@ #ifndef __MIAV_FILE_H__ #define __MIAV_FILE_H__ +#include "info.h" + #include using namespace std; class File { public: - File(char *filename, char* ext); + File(char *filename, char* ext, Info* info); ~File(); int Write(void* data, int size); private: + Info* info; + int Open(); int fd; int num; + int seqnum; char* filename; char* extension; diff --git a/src/info.cc b/src/info.cc new file mode 100644 index 0000000..4278326 --- /dev/null +++ b/src/info.cc @@ -0,0 +1,74 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/*************************************************************************** + * info.cc + * + * Mon Jun 13 22:16:18 CEST 2005 + * Copyright 2005 Bent Bisballe + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of MIaV. + * + * MIaV 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. + * + * MIaV 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 MIaV; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ + +/* + * $Id$ + */ + +/* + * $Log$ + * Revision 1.1 2005/06/13 20:38:19 deva + * Added some logfile code. + * Enhanced the file object... now ready to hook into mov_encoder + * + */ + +#include +#include "info.h" + +Info::Info() { + pthread_mutex_init (&mutex, NULL); +} + +void Info::log(char *fmt, ...) +{ + // const time_t t; + FILE *fp; + char buf[1024]; + + pthread_mutex_lock(&mutex); + // Beginning of safezone + + fp = fopen(log_filename.c_str(), "a"); + if(!fp) { + fprintf(stderr, "Log file %s could not be opened in writemode.\n", log_filename.c_str()); + return; + } + + va_list argp; + va_start(argp, fmt); + vsprintf(buf, fmt, argp); + va_end(argp); + + time_t t = time(NULL); + fprintf(fp, "%s miav[%d]", ctime(&t), buf, getpid()); + + fclose(fp); + + // End of safezone + pthread_mutex_unlock(&mutex); +} diff --git a/src/info.h b/src/info.h index 7a9147b..b142a33 100644 --- a/src/info.h +++ b/src/info.h @@ -37,14 +37,29 @@ #ifndef __MIAV_INFO_H__ #define __MIAV_INFO_H__ +#include +#include +#include +#include +#include +#include +#include +using namespace std; + class Info { public: - Info() {} + Info(); + virtual ~Info() {} virtual void error(char* fmt, ...) = 0; virtual void warn(char* fmt, ...) = 0; virtual void info(char* fmt, ...) = 0; + void log(char* fmt, ...); + +protected: + pthread_mutex_t mutex; + string log_filename; }; #endif/*__MIAV_INFO_H__*/ diff --git a/src/info_console.cc b/src/info_console.cc index a0ca236..f703a3f 100644 --- a/src/info_console.cc +++ b/src/info_console.cc @@ -36,12 +36,14 @@ #include #include "info_console.h" +#include "miav_config.h" + #include #include InfoConsole::InfoConsole(): Info() { - pthread_mutex_init (&mutex, NULL); + log_filename = *config->readString("server_log_file"); } InfoConsole::~InfoConsole() diff --git a/src/info_console.h b/src/info_console.h index 019c8b7..5422235 100644 --- a/src/info_console.h +++ b/src/info_console.h @@ -42,6 +42,9 @@ #include #include +#include +using namespace std; + class InfoConsole: public Info { public: InfoConsole(); @@ -52,7 +55,6 @@ public: void info(char* fmt, ...); private: - pthread_mutex_t mutex; }; #endif/*__MIAV_INFO_CONSOLE_H__*/ diff --git a/src/info_gui.cc b/src/info_gui.cc index db23827..2559402 100644 --- a/src/info_gui.cc +++ b/src/info_gui.cc @@ -38,6 +38,8 @@ #include "info_gui.h" +#include "miav_config.h" + #include #include @@ -59,6 +61,8 @@ bool InfoEventHandler::eventFilter( QObject *o, QEvent *e ) InfoGui::InfoGui(QApplication *a, QWidget *p): Info() { + log_filename = *config->readString("client_log_file"); + qapp = a; parent = p; @@ -140,4 +144,5 @@ void InfoGui::info(char *fmt, ...) showmsg(buf, TXT_INFO_TITLE, ICON_INFO); } + #endif/*USE_GUI*/ diff --git a/src/info_gui.h b/src/info_gui.h index 8df1985..44729c2 100644 --- a/src/info_gui.h +++ b/src/info_gui.h @@ -86,7 +86,6 @@ private: QApplication *qapp; QWidget *parent; - pthread_mutex_t mutex; }; #endif/*__MIAV_INFO_GUI_H__*/ -- cgit v1.2.3