xml-copy-editor-code/src/validationthread.cpp

87 lines
1.7 KiB
C++
Raw Normal View History

#include "wx/wx.h"
#include "xmlctrl.h"
#include "validationthread.h"
#include "wrapxerces.h"
#include <stdexcept>
#include <memory>
ValidationThread::ValidationThread (
const char *buffer,
const char *system,
2009-01-17 23:52:54 +01:00
const char *catalogPath,
const char *catalogUtilityPath,
bool *finished,
bool *success,
2008-07-09 19:07:02 +02:00
bool *release,
std::pair<int, int> *position,
std::string *message ) : wxThread()
{
if (!buffer || !success || !position || !message )
{
throw;
}
myBuffer = buffer;
mySystem = system;
2009-01-17 23:52:54 +01:00
myCatalogPath = catalogPath;
myCatalogUtilityPath = catalogUtilityPath;
myFinishedPtr = finished;
mySuccessPtr = success;
2008-07-09 19:07:02 +02:00
myReleasePtr = release;
myPositionPtr = position;
myMessagePtr = message;
}
void *ValidationThread::Entry()
{
2009-01-17 23:52:54 +01:00
std::auto_ptr<WrapXerces> validator ( new WrapXerces(
myCatalogPath,
myCatalogUtilityPath ) );
{
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( *myReleasePtr || TestDestroy() )
{
Exit();
return NULL;
}
}
bool res = validator->validateMemory (
myBuffer.c_str(),
mySystem.c_str(),
myBuffer.size() );
{
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( *myReleasePtr || TestDestroy() )
{
Exit();
return NULL;
}
if ( !res )
{
*mySuccessPtr = res;
*myPositionPtr = validator->getErrorPosition();
*myMessagePtr = validator->getLastError();
}
else
{
*mySuccessPtr = true;
*myPositionPtr = std::make_pair ( 0, 0 );
*myMessagePtr = "";
}
}
return NULL;
}
void ValidationThread::OnExit()
{
{
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( *myReleasePtr )
return;
*myFinishedPtr = true;
}
}