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

85 lines
1.6 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>
2012-08-27 14:25:08 +02:00
#include "threadreaper.h"
2009-11-06 18:06:12 +01:00
2012-08-27 14:25:08 +02:00
extern wxCriticalSection xmlcopyeditorCriticalSection;
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 )
2012-08-27 14:25:08 +02:00
, mStopping ( false )
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 ) );
2012-08-27 14:25:08 +02:00
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
2012-08-27 14:25:08 +02:00
return NULL;
2009-11-06 18:06:12 +01:00
}
myIsSucceeded = validator->validateMemory (
2009-11-06 18:06:12 +01:00
myBuffer.c_str(),
2012-08-27 14:25:08 +02:00
myBuffer.size(),
2009-11-06 18:06:12 +01:00
mySystem.c_str(),
2012-08-27 14:25:08 +02:00
this );
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
return NULL;
2009-11-06 18:06:12 +01:00
}
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
}
2012-08-27 14:25:08 +02:00
if ( !TestDestroy() )
{
wxCommandEvent event ( wxEVT_COMMAND_VALIDATION_COMPLETED );
wxPostEvent ( myEventHandler, event );
}
return NULL;
2009-11-06 18:06:12 +01:00
}
2012-08-27 14:25:08 +02:00
void ValidationThread::PendingDelete ()
{
Cancel();
ThreadReaper::get().add ( this );
}