Further improvements to background validation: critical section locks now in place.
This commit is contained in:
parent
361eed32b0
commit
8be8af2aa0
|
@ -30,31 +30,36 @@ ValidationThread::ValidationThread (
|
||||||
void *ValidationThread::Entry()
|
void *ValidationThread::Entry()
|
||||||
{
|
{
|
||||||
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
std::auto_ptr<WrapXerces> validator ( new WrapXerces() );
|
||||||
|
|
||||||
if ( *myReleasePtr || TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
Exit();
|
{
|
||||||
|
Exit();
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
bool res = validator->validateMemory (
|
bool res = validator->validateMemory (
|
||||||
myBuffer.c_str(),
|
myBuffer.c_str(),
|
||||||
mySystem.c_str(),
|
mySystem.c_str(),
|
||||||
myBuffer.size() );
|
myBuffer.size() );
|
||||||
|
|
||||||
if ( *myReleasePtr || TestDestroy() )
|
if ( *myReleasePtr || TestDestroy() )
|
||||||
Exit();
|
{
|
||||||
|
Exit();
|
||||||
if ( !res )
|
return NULL;
|
||||||
{
|
}
|
||||||
*mySuccessPtr = res;
|
|
||||||
*myPositionPtr = validator->getErrorPosition();
|
|
||||||
*myMessagePtr = validator->getLastError();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
*mySuccessPtr = true;
|
|
||||||
*myPositionPtr = std::make_pair ( 0, 0 );
|
|
||||||
*myMessagePtr = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if ( !res )
|
||||||
|
{
|
||||||
|
*mySuccessPtr = res;
|
||||||
|
*myPositionPtr = validator->getErrorPosition();
|
||||||
|
*myMessagePtr = validator->getLastError();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
*mySuccessPtr = true;
|
||||||
|
*myPositionPtr = std::make_pair ( 0, 0 );
|
||||||
|
*myMessagePtr = "";
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,7 +179,7 @@ BEGIN_EVENT_TABLE ( MyFrame, wxFrame )
|
||||||
#endif
|
#endif
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
IMPLEMENT_APP ( MyApp )
|
IMPLEMENT_APP ( MyApp)
|
||||||
|
|
||||||
MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
|
MyApp::MyApp() : checker ( NULL ), server ( NULL ), connection ( NULL ),
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
|
@ -1633,7 +1633,7 @@ void MyFrame::OnIdle ( wxIdleEvent& event )
|
||||||
if ( !parent.empty() && properties.validateAsYouType && doc->getValidationRequired() )
|
if ( !parent.empty() && properties.validateAsYouType && doc->getValidationRequired() )
|
||||||
{
|
{
|
||||||
// tbd: limit to parent element
|
// tbd: limit to parent element
|
||||||
doc->shallowValidate ( doc->LineFromPosition ( current ), true );
|
doc->backgroundValidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2742,7 +2742,7 @@ void MyFrame::newDocument ( const std::string& s, const std::string& path, bool
|
||||||
insertSiblingPanel->update ( doc, wxEmptyString );
|
insertSiblingPanel->update ( doc, wxEmptyString );
|
||||||
insertEntityPanel->update ( doc );
|
insertEntityPanel->update ( doc );
|
||||||
if ( properties.validateAsYouType )
|
if ( properties.validateAsYouType )
|
||||||
doc->shallowValidate();
|
doc->backgroundValidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyFrame::OnOpen ( wxCommandEvent& event )
|
void MyFrame::OnOpen ( wxCommandEvent& event )
|
||||||
|
@ -3114,7 +3114,7 @@ bool MyFrame::openFile ( wxString& fileName, bool largeFile )
|
||||||
if ( !largeFile && ( properties.validateAsYouType && doc->getGrammarFound() ) )
|
if ( !largeFile && ( properties.validateAsYouType && doc->getGrammarFound() ) )
|
||||||
{
|
{
|
||||||
statusProgress ( _T ( "Validating document..." ) );
|
statusProgress ( _T ( "Validating document..." ) );
|
||||||
doc->shallowValidate ( finalBuffer, doc->getFullFileName().mb_str(wxConvUTF8), finalBufferLen );
|
doc->backgroundValidate ( finalBuffer, doc->getFullFileName().mb_str(wxConvUTF8), finalBufferLen );
|
||||||
statusProgress ( wxEmptyString );
|
statusProgress ( wxEmptyString );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3629,7 +3629,7 @@ void MyFrame::OnValidateDTD ( wxCommandEvent& event )
|
||||||
doc->SetSelection ( cursorPos, cursorPos );
|
doc->SetSelection ( cursorPos, cursorPos );
|
||||||
|
|
||||||
// shallow validate all
|
// shallow validate all
|
||||||
doc->shallowValidate(); // has to come first as it deletes all indicators
|
doc->backgroundValidate(); // has to come first as it deletes all indicators
|
||||||
doc->setErrorIndicator ( posPair.first, posPair.second );
|
doc->setErrorIndicator ( posPair.first, posPair.second );
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
@ -4748,7 +4748,7 @@ bool MyFrame::saveFile ( XmlDoc *doc, wxString& fileName, bool checkLastModified
|
||||||
if ( properties.validateAsYouType && isXml )
|
if ( properties.validateAsYouType && isXml )
|
||||||
{
|
{
|
||||||
doc->clearErrorIndicators();
|
doc->clearErrorIndicators();
|
||||||
doc->shallowValidate ( utf8Buffer.c_str(), doc->getFullFileName().mb_str(wxConvUTF8), utf8Buffer.size() );
|
doc->backgroundValidate ( utf8Buffer.c_str(), doc->getFullFileName().mb_str(wxConvUTF8), utf8Buffer.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !unlimitedUndo )
|
if ( !unlimitedUndo )
|
||||||
|
|
|
@ -40,6 +40,9 @@ BEGIN_EVENT_TABLE ( XmlCtrl, wxStyledTextCtrl )
|
||||||
EVT_MIDDLE_DOWN ( XmlCtrl::OnMiddleDown )
|
EVT_MIDDLE_DOWN ( XmlCtrl::OnMiddleDown )
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
// global protection for validation threads
|
||||||
|
wxCriticalSection xmlcopyeditorCriticalSection;
|
||||||
|
|
||||||
XmlCtrl::XmlCtrl (
|
XmlCtrl::XmlCtrl (
|
||||||
wxWindow *parent,
|
wxWindow *parent,
|
||||||
XmlCtrlProperties propertiesParameter,
|
XmlCtrlProperties propertiesParameter,
|
||||||
|
@ -143,20 +146,24 @@ void XmlCtrl::OnIdle ( wxIdleEvent& event )
|
||||||
adjustNoColumnWidth(); // exits if unchanged
|
adjustNoColumnWidth(); // exits if unchanged
|
||||||
|
|
||||||
// poll validation thread output if any
|
// poll validation thread output if any
|
||||||
if (validationStarted && validationFinished)
|
|
||||||
{
|
{
|
||||||
validationStarted = false;
|
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
MyFrame *frame = (MyFrame *)GetGrandParent();
|
if (validationStarted && validationFinished)
|
||||||
if ( validationSuccess )
|
|
||||||
{
|
{
|
||||||
clearErrorIndicators ( GetLineCount() );
|
validationStarted = false;
|
||||||
frame->statusProgress ( wxEmptyString );
|
MyFrame *frame = (MyFrame *)GetGrandParent();
|
||||||
}
|
if ( validationSuccess )
|
||||||
else
|
{
|
||||||
{
|
clearErrorIndicators ( GetLineCount() );
|
||||||
clearErrorIndicators ( validationPosition.first -1 );
|
frame->statusProgress ( wxEmptyString );
|
||||||
setErrorIndicator ( validationPosition.first - 1, 0 );
|
}
|
||||||
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
|
else
|
||||||
|
{
|
||||||
|
clearErrorIndicators ( GetLineCount() );
|
||||||
|
setErrorIndicator ( validationPosition.first - 1, 0 );
|
||||||
|
frame->statusProgress ( wxString ( validationMessage.c_str(), wxConvUTF8, validationMessage.size() ) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1996,21 +2003,20 @@ std::string XmlCtrl::getElementStructure ( const wxString& element )
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlCtrl::shallowValidate ( int maxLine, bool segmentOnly )
|
bool XmlCtrl::backgroundValidate()
|
||||||
{
|
{
|
||||||
if ( !properties.validateAsYouType || type != FILE_TYPE_XML )
|
if ( !properties.validateAsYouType || type != FILE_TYPE_XML )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
clearErrorIndicators ( GetLineCount() );
|
|
||||||
std::string bufferUtf8 = myGetTextRaw();
|
std::string bufferUtf8 = myGetTextRaw();
|
||||||
|
|
||||||
return shallowValidate (
|
return backgroundValidate (
|
||||||
bufferUtf8.c_str(),
|
bufferUtf8.c_str(),
|
||||||
basePath.c_str(),
|
basePath.c_str(),
|
||||||
bufferUtf8.size() );
|
bufferUtf8.size() );
|
||||||
}
|
}
|
||||||
|
|
||||||
bool XmlCtrl::shallowValidate (
|
bool XmlCtrl::backgroundValidate (
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const char *system,
|
const char *system,
|
||||||
size_t bufferLen
|
size_t bufferLen
|
||||||
|
@ -2018,8 +2024,8 @@ bool XmlCtrl::shallowValidate (
|
||||||
{
|
{
|
||||||
if ( !validationRequired )
|
if ( !validationRequired )
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
|
||||||
|
wxCriticalSectionLocker locker ( xmlcopyeditorCriticalSection );
|
||||||
if ( validationStarted && !validationFinished )
|
if ( validationStarted && !validationFinished )
|
||||||
{
|
{
|
||||||
validationRelease = true;
|
validationRelease = true;
|
||||||
|
@ -2047,43 +2053,8 @@ bool XmlCtrl::shallowValidate (
|
||||||
|
|
||||||
validationStarted = true;
|
validationStarted = true;
|
||||||
validationFinished = false;
|
validationFinished = false;
|
||||||
|
|
||||||
validationThread->Run();
|
validationThread->Run();
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
/*
|
|
||||||
std::auto_ptr<XmlShallowValidator> validator ( new XmlShallowValidator (
|
|
||||||
elementMap,
|
|
||||||
attributeMap,
|
|
||||||
requiredAttributeMap,
|
|
||||||
entitySet,
|
|
||||||
maxLine,
|
|
||||||
segmentOnly ) );
|
|
||||||
|
|
||||||
bool res = validator->parse ( buffer, bufferLen, ( segmentOnly ) ? false : true );
|
|
||||||
if (
|
|
||||||
!validator->getOverrideFailure() &&
|
|
||||||
( !res || !validator->isValid() ) )
|
|
||||||
{
|
|
||||||
std::vector<std::pair<int, int> > positionVector = validator->getPositionVector();
|
|
||||||
|
|
||||||
if ( res == XML_STATUS_ERROR )
|
|
||||||
{
|
|
||||||
positionVector.push_back ( validator->getErrorPosition() );
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<std::pair<int, int> >::iterator it;
|
|
||||||
for ( it = positionVector.begin(); it != positionVector.end(); it++ )
|
|
||||||
{
|
|
||||||
int line, column;
|
|
||||||
line = ( it->first - 1 ) + startLine;
|
|
||||||
column = it->second + columnOffset;
|
|
||||||
setErrorIndicator ( line, column );
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string XmlCtrl::myGetTextRaw()
|
std::string XmlCtrl::myGetTextRaw()
|
||||||
|
@ -2106,12 +2077,6 @@ void XmlCtrl::setErrorIndicator ( int line, int column )
|
||||||
|
|
||||||
int length = endPos - startPos;
|
int length = endPos - startPos;
|
||||||
|
|
||||||
/*
|
|
||||||
from CellBuffer.cxx:
|
|
||||||
PLATFORM_ASSERT(lengthStyle == 0 ||
|
|
||||||
(lengthStyle > 0 && lengthStyle + position < length));
|
|
||||||
*/
|
|
||||||
|
|
||||||
if ( length == 0 || ( length > 0 && length + startPos < GetLength() ) )
|
if ( length == 0 || ( length > 0 && length + startPos < GetLength() ) )
|
||||||
{
|
{
|
||||||
SetStyling ( length, wxSTC_INDIC2_MASK );
|
SetStyling ( length, wxSTC_INDIC2_MASK );
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2005-2007 Gerald Schmidt.
|
* Copyright 2005-2007 Gerald Schmidt.
|
||||||
*
|
*
|
||||||
|
@ -145,8 +144,8 @@ class XmlCtrl: public wxStyledTextCtrl
|
||||||
bool canInsertAt ( int pos );
|
bool canInsertAt ( int pos );
|
||||||
int getTagStartPos ( int pos );
|
int getTagStartPos ( int pos );
|
||||||
void toggleLineBackground();
|
void toggleLineBackground();
|
||||||
bool shallowValidate ( int maxLine = 0, bool segmentOnly = false );
|
bool backgroundValidate ( );
|
||||||
bool shallowValidate (
|
bool backgroundValidate (
|
||||||
const char *buffer,
|
const char *buffer,
|
||||||
const char *system,
|
const char *system,
|
||||||
size_t bufferLen );
|
size_t bufferLen );
|
||||||
|
|
Loading…
Reference in New Issue