diff --git a/src/validationthread.cpp b/src/validationthread.cpp new file mode 100644 index 0000000..e41c10e --- /dev/null +++ b/src/validationthread.cpp @@ -0,0 +1,62 @@ +#include "wx/wx.h" +#include "validationthread.h" +#include "wrapxerces.h" +#include +#include + +ValidationThread::ValidationThread ( + const char *buffer, + const char *system, + bool *finished, + bool *success, + std::pair *position, + std::string *message ) : wxThread() +{ + if (!buffer || !success || !position || !message ) + { + throw; + } + + myBuffer = buffer; + mySystem = system; + myFinishedPtr = finished; + mySuccessPtr = success; + myPositionPtr = position; + myMessagePtr = message; +} + +void *ValidationThread::Entry() +{ + std::auto_ptr validator ( new WrapXerces() ); + + if ( TestDestroy() ) + Exit(); + + bool res = validator->validateMemory ( + myBuffer.c_str(), + mySystem.c_str(), + myBuffer.size() ); + + if ( TestDestroy() ) + Exit(); + + if ( !res ) + { + *mySuccessPtr = res; + *myPositionPtr = validator->getErrorPosition(); + *myMessagePtr = validator->getLastError(); + } + else + { + *mySuccessPtr = true; + *myPositionPtr = std::make_pair ( 0, 0 ); + *myMessagePtr = ""; + } + *myFinishedPtr = true; + + return NULL; +} + +void ValidationThread::OnExit() +{ +} diff --git a/src/validationthread.h b/src/validationthread.h new file mode 100644 index 0000000..06b0fd3 --- /dev/null +++ b/src/validationthread.h @@ -0,0 +1,21 @@ +#ifndef VALIDATION_THREAD_H +#define VALIDATION_THREAD_H + +#include +#include +#include + +class ValidationThread : public wxThread +{ +public: + ValidationThread ( const char *buffer, const char *system, bool *finished, bool *success, std::pair *position, std::string *message ); + virtual void *Entry(); + virtual void OnExit(); +private: + std::string myBuffer, mySystem; + bool *myFinishedPtr, *mySuccessPtr; + std::pair *myPositionPtr; + std::string *myMessagePtr; +}; + +#endif