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

79 lines
1.5 KiB
C++
Raw Normal View History

#include <wx/wx.h>
#include <wx/textbuf.h>
2009-11-06 18:06:12 +01:00
#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 wxString &system )
: 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;
myIsSucceeded = false;
2009-11-06 18:06:12 +01:00
}
void *ValidationThread::Entry()
{
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
2009-11-06 18:06:12 +01:00
2012-08-27 14:25:08 +02:00
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
2013-10-29 11:52:22 +01:00
myBuffer.clear();
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(),
mySystem,
this,
// Don't be too harsh to new created documents, which may haven't
// associated any schema yet
/*forceCheckGrammar*/false,
wxTextBuffer::GetEOL() );
2013-10-29 11:52:22 +01:00
myBuffer.clear();
if ( TestDestroy() )
2009-11-06 18:06:12 +01:00
{
return NULL;
2009-11-06 18:06:12 +01:00
}
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
myPosition = validator->getErrorPosition();
myMessage = validator->getLastError();
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 );
}