From 29ff2e254871ebc359af344d6ee453047e8ad2ec Mon Sep 17 00:00:00 2001 From: deva Date: Sun, 27 Mar 2005 10:18:02 +0000 Subject: Reimplemented the error object as a stack. --- src/camera.cc | 9 ++------- src/camera.h | 3 +-- src/decoder.cc | 14 +++++++------- src/error.cc | 45 ++++++++++++++++++++++++++++++--------------- src/error.h | 19 ++++++++++++++----- src/mainwindow.cc | 6 ++++-- src/mainwindow.h | 4 ++++ src/player.cc | 4 ++-- 8 files changed, 64 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/camera.cc b/src/camera.cc index ac23fc9..0ba3da9 100644 --- a/src/camera.cc +++ b/src/camera.cc @@ -142,14 +142,9 @@ void Camera::snapshot() encoder->shoot(); } -bool Camera::hasError() +Error *Camera::errorObject() { - return errorstatus->hasError(); -} - -string Camera::getErrorString() -{ - return errorstatus->getErrorString(); + return errorstatus; } #endif/* USE_GUI */ diff --git a/src/camera.h b/src/camera.h index 44901aa..4f58d7e 100644 --- a/src/camera.h +++ b/src/camera.h @@ -71,8 +71,7 @@ public: void snapshot(); // Status methods - bool hasError(); - string getErrorString(); + Error *errorObject(); private: // Error object passed to all sub objects. diff --git a/src/decoder.cc b/src/decoder.cc index eae0f76..dfddd87 100644 --- a/src/decoder.cc +++ b/src/decoder.cc @@ -51,7 +51,7 @@ Decoder::Decoder(Error* err, memset(&dvpars, 0, sizeof(dvpars)); if(!(iformat = av_find_input_format("dv1394"))) { - errobj->setError("Failed to get input format dv1394"); + errobj->pushError("Failed to get input format dv1394."); exit(1); } @@ -60,23 +60,23 @@ Decoder::Decoder(Error* err, dvpars.standard = "pal"; if(av_open_input_file(&ifc, "", iformat, 0, &dvpars) < 0) { - errobj->setError("Device is in use."); + errobj->pushError("Device is in use."); fc = NULL; return; } if(av_find_stream_info(ifc) < 0) { - errobj->setError("Could not find enough parameters."); + errobj->pushError("Could not find enough parameters."); fc = NULL; return; } dump_format(ifc, 1, "", 0); if(!(dec_codec = avcodec_find_decoder(ifc->streams[0]->codec.codec_id))) { - errobj->setError("Unsupported codec for input stream "); + errobj->pushError("Unsupported codec for input stream."); fc = NULL; return; } if(avcodec_open(&ifc->streams[0]->codec, dec_codec) < 0) { - errobj->setError("Error while opening codec for input stream"); + errobj->pushError("Error while opening codec for input stream."); fc = NULL; return; } @@ -92,7 +92,7 @@ Decoder::~Decoder() void Decoder::decode() { if(fc == NULL) { - errobj->setError("Decoder not initialized."); + errobj->pushError("Decoder not initialized."); return; } @@ -125,7 +125,7 @@ void Decoder::decode() fff->frame, &got_picture, ptr, len); if(ret < 0) { - errobj->setError("Error while decoding stream"); + errobj->pushError("Error while decoding stream."); exit(1); } diff --git a/src/error.cc b/src/error.cc index 4056aa9..b166042 100644 --- a/src/error.cc +++ b/src/error.cc @@ -29,7 +29,7 @@ Error::Error() { // Initialize - removeError(); + lastError = NULL; } Error::~Error() @@ -38,36 +38,51 @@ Error::~Error() bool Error::hasError() { - return error; + return lastError != NULL; } -string Error::getErrorString() +/* // Perhaps! +string Error::popAllErrorStrings() { string le = lastError; removeError(); return le; } +*/ -void Error::setError(char* errstr) +string Error::popErrorString() +{ + if(lastError == NULL) return string(""); + + _err_entry *err = lastError; + string le = err->errstr; + lastError = err->prev; + delete err; + return le; +} + +void Error::pushError(char* errstr) { printf("New Error: [%s]\n", errstr); - error = true; - lastError.append(errstr); - lastError.append("\n"); + _err_entry *err = new _err_entry; - printf("All Errors: [%s]\n", lastError.c_str()); + err->errstr = errstr; + err->prev = lastError; + lastError = err; } -void Error::setError(string &errstr) +void Error::pushError(string &errstr) { - error = true; - lastError.append(errstr); - lastError.append("\n"); + _err_entry *err = new _err_entry; + + err->errstr = errstr; + err->prev = lastError; + lastError = err; } -void Error::removeError() +void Error::removeAllErrors() { - error = false; - lastError = string(""); + while(lastError) popErrorString(); + } diff --git a/src/error.h b/src/error.h index 09cfbb9..8b26471 100644 --- a/src/error.h +++ b/src/error.h @@ -30,6 +30,15 @@ #include using namespace std; +/** + * This struct contains one error, and a pointer to the previous one. + */ +typedef struct __err_entry { + string errstr; + struct __err_entry *prev; +} _err_entry; + + class Error { public: Error(); @@ -37,17 +46,17 @@ public: // Status methods bool hasError(); - string getErrorString(); + string popErrorString(); // Set methods - void setError(char* errstr); - void setError(string &errstr); - void removeError(); + void pushError(char* errstr); + void pushError(string &errstr); + void removeAllErrors(); private: // Used to save the state of the network and camera connections. bool error; - string lastError; + _err_entry *lastError; }; #endif/*__MIAV_ERROR_H__*/ diff --git a/src/mainwindow.cc b/src/mainwindow.cc index 869d5c3..e779c19 100644 --- a/src/mainwindow.cc +++ b/src/mainwindow.cc @@ -94,8 +94,10 @@ MainWindow::MainWindow( QWidget* parent, const char* name ) camera->connect(cfg.readString("server_addr")->c_str(), cfg.readInt("server_port")); - if(camera->hasError()) { - MessageBox(this, "", camera->getErrorString().c_str(), TYPE_OK, ICON_ERROR).exec(); + cam_error = camera->errorObject(); + cam_error->pushError("fisk"); + while(cam_error->hasError()) { + MessageBox(this, "", cam_error->popErrorString().c_str(), TYPE_OK, ICON_ERROR).exec(); } recording = false; diff --git a/src/mainwindow.h b/src/mainwindow.h index 51cdcca..9955cb4 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -40,6 +40,8 @@ using namespace std; #include "camera.h" #include "cprquerydialog.h" +#include "error.h" + #define NUM_HISTORY 3 class MainWindow : public QWidget @@ -62,6 +64,8 @@ private: void createGui(); Camera *camera; + Error *cam_error; + AboutWindow *aboutwindow; QPixmap *pix_camera; diff --git a/src/player.cc b/src/player.cc index 9a697f9..1cc0dce 100644 --- a/src/player.cc +++ b/src/player.cc @@ -43,7 +43,7 @@ Player::Player(Error *err, if(SDL_Init(SDL_INIT_VIDEO) < 0) { sprintf(errbuf, "Unable to init SDL: %s\n", SDL_GetError()); - errobj->setError(errbuf); + errobj->pushError(errbuf); return; } screen = SDL_SetVideoMode(DISPLAYWIDTH, @@ -53,7 +53,7 @@ Player::Player(Error *err, if(!screen) { sprintf(errbuf, "Unable to set %dx%d video: %s\n", DISPLAYWIDTH, DISPLAYHEIGHT, SDL_GetError()); - errobj->setError(errbuf); + errobj->pushError(errbuf); return; } -- cgit v1.2.3