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;
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2012-08-18 17:41:27 +02:00
|
|
|
DEFINE_EVENT_TYPE(wxEVT_COMMAND_VALIDATION_COMPLETED);
|
2012-08-15 14:45:24 +02:00
|
|
|
|
2009-11-06 18:06:12 +01:00
|
|
|
ValidationThread::ValidationThread (
|
2012-08-15 14:45:24 +02:00
|
|
|
wxEvtHandler *handler,
|
2009-11-06 18:06:12 +01:00
|
|
|
const char *buffer,
|
|
|
|
const char *system,
|
|
|
|
const char *catalogPath,
|
2012-08-15 14:45:24 +02:00
|
|
|
const char *catalogUtilityPath )
|
|
|
|
: wxThread ( wxTHREAD_JOINABLE )
|
2012-08-27 14:25:08 +02:00
|
|
|
, mStopping ( false )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2012-08-15 14:45:24 +02:00
|
|
|
if ( buffer == NULL )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
2012-08-15 14:45:24 +02:00
|
|
|
myEventHandler = handler;
|
2009-11-06 18:06:12 +01:00
|
|
|
myBuffer = buffer;
|
|
|
|
mySystem = system;
|
|
|
|
myCatalogPath = catalogPath;
|
|
|
|
myCatalogUtilityPath = catalogUtilityPath;
|
2012-08-15 14:45:24 +02:00
|
|
|
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
|
|
|
}
|
2012-08-15 14:45:24 +02: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 );
|
2012-08-15 14:45:24 +02:00
|
|
|
|
|
|
|
if ( TestDestroy() )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2012-08-15 14:45:24 +02:00
|
|
|
return NULL;
|
2009-11-06 18:06:12 +01:00
|
|
|
}
|
|
|
|
|
2012-08-15 14:45:24 +02:00
|
|
|
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
|
|
|
|
|
|
|
if ( myIsSucceeded )
|
2009-11-06 18:06:12 +01:00
|
|
|
{
|
2012-08-15 14:45:24 +02: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-15 14:45:24 +02:00
|
|
|
|
2012-08-27 14:25:08 +02:00
|
|
|
if ( !TestDestroy() )
|
|
|
|
{
|
|
|
|
wxCommandEvent event ( wxEVT_COMMAND_VALIDATION_COMPLETED );
|
|
|
|
wxPostEvent ( myEventHandler, event );
|
|
|
|
}
|
2012-08-15 14:45:24 +02:00
|
|
|
|
|
|
|
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 );
|
|
|
|
}
|