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

75 lines
1.5 KiB
C++
Raw Normal View History

2009-11-06 18:06:12 +01:00
#include "wx/wx.h"
#include "xmlctrl.h"
#include "validationthread.h"
#include "wrapxerces.h"
#include <stdexcept>
#include <memory>
DEFINE_EVENT_TYPE(wxEVT_COMMAND_VALIDATION_COMPLETED);
2009-11-06 18:06:12 +01:00
ValidationThread::ValidationThread (
wxEvtHandler *handler,
2009-11-06 18:06:12 +01:00
const char *buffer,
const char *system,
const char *catalogPath,
const char *catalogUtilityPath )
: wxThread ( wxTHREAD_JOINABLE )
2009-11-06 18:06:12 +01:00
{
if ( buffer == NULL )
2009-11-06 18:06:12 +01:00
{
throw;
}
myEventHandler = handler;
2009-11-06 18:06:12 +01:00
myBuffer = buffer;
mySystem = system;
myCatalogPath = catalogPath;
myCatalogUtilityPath = catalogUtilityPath;
myIsSucceeded = false;
2009-11-06 18:06:12 +01:00
}
void *ValidationThread::Entry()
{
std::auto_ptr<WrapXerces> validator ( new WrapXerces(
myCatalogPath,
myCatalogUtilityPath ) );
{
//wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
return NULL;
}
}
myIsSucceeded = validator->validateMemory (
2009-11-06 18:06:12 +01:00
myBuffer.c_str(),
mySystem.c_str(),
myBuffer.size() );
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
return NULL;
2009-11-06 18:06:12 +01:00
}
extern wxCriticalSection xmlcopyeditorCriticalSection;
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
if ( myIsSucceeded )
2009-11-06 18:06:12 +01:00
{
myPosition = std::make_pair ( 0, 0 );
myMessage = wxEmptyString;
}
else
{
myPosition = validator->getErrorPosition();
myMessage = validator->getLastError();
2009-11-06 18:06:12 +01:00
}
wxCommandEvent event ( wxEVT_COMMAND_VALIDATION_COMPLETED );
wxPostEvent ( myEventHandler, event );
return NULL;
2009-11-06 18:06:12 +01:00
}