1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0031785: [REGRESSION] Application Framework - application crashes on reading XBF document in background thread

Class CDF_Session is removed.

Integrated previously but not described:

0029195: OCAF - ensure thread safety for different documents.

Static local variables are eliminated in PCDM package.
Global documents metadata look-up table and directory of opened documents are removed.
Look-up table is maintained now as field in instances of the CDM_Application class.
Methods providing iteration by components are removed from class CDF_Store; signature of methods returned Standard_ExtString is changed to return Handle(TCollection_HExtendedString).
Support of different "Presentations" of documents is eliminated.
This commit is contained in:
abv
2020-09-22 15:24:54 +03:00
committed by bugmaster
parent 0e57793fc6
commit 8a39adb7d8
33 changed files with 230 additions and 479 deletions

View File

@@ -18,7 +18,6 @@
#include <CDF_Application.hxx>
#include <CDF_Directory.hxx>
#include <CDF_Session.hxx>
#include <CDF_FWOSDriver.hxx>
#include <CDM_CanCloseStatus.hxx>
#include <CDM_Document.hxx>
@@ -42,7 +41,7 @@ IMPLEMENT_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
CDF_Application::CDF_Application():myRetrievableStatus(PCDM_RS_OK)
{
myDirectory = new CDF_Directory();
myMetaDataDriver = new CDF_FWOSDriver;
myMetaDataDriver = new CDF_FWOSDriver (MetaDataLookUpTable());
}
//=======================================================================
@@ -270,7 +269,7 @@ Handle(CDM_Document) CDF_Application::Retrieve (const Handle(CDM_MetaData)& aMet
SetReferenceCounter(theDocument,PCDM_RetrievalDriver::ReferenceCounter(aMetaData->FileName(), MessageDriver()));
SetDocumentVersion(theDocument,aMetaData);
myMetaDataDriver->ReferenceIterator()->LoadReferences(theDocument,aMetaData,this,UseStorageConfiguration);
myMetaDataDriver->ReferenceIterator(MessageDriver())->LoadReferences(theDocument,aMetaData,this,UseStorageConfiguration);
try {
OCC_CATCH_SIGNALS
@@ -284,7 +283,8 @@ Handle(CDM_Document) CDF_Application::Retrieve (const Handle(CDM_MetaData)& aMet
throw Standard_Failure(aMsg.str().c_str());
}
}
myRetrievableStatus = theReader->GetStatus();
myRetrievableStatus = theReader->GetStatus();
theDocument->Open (this); // must be done before SetMetaData
theDocument->SetMetaData(aMetaData);
theDocumentToReturn=theDocument;

View File

@@ -28,7 +28,6 @@
#include <NCollection_IndexedDataMap.hxx>
class Standard_NoSuchObject;
class CDF_Session;
class Standard_GUID;
class CDM_Document;
class TCollection_ExtendedString;
@@ -172,9 +171,6 @@ public:
//! returns MetaDatdDriver of this application
Standard_EXPORT Handle(CDF_MetaDataDriver) MetaDataDriver() const;
friend class CDF_Session;
DEFINE_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
Handle(CDF_MetaDataDriver) myMetaDataDriver;

View File

@@ -17,7 +17,6 @@
#include <CDF_Directory.hxx>
#include <CDF_DirectoryIterator.hxx>
#include <CDF_Session.hxx>
#include <CDM_Document.hxx>
#include <Standard_NoSuchObject.hxx>

View File

@@ -48,7 +48,10 @@ static void PutSlash (TCollection_ExtendedString& anXSTRING) {
//function : CDF_FWOSDriver
//purpose :
//==============================================================================
CDF_FWOSDriver::CDF_FWOSDriver() {}
CDF_FWOSDriver::CDF_FWOSDriver(CDM_MetaDataLookUpTable& theLookUpTable)
: myLookUpTable (&theLookUpTable)
{
}
//==============================================================================
//function : Find
@@ -107,7 +110,7 @@ Handle(CDM_MetaData) CDF_FWOSDriver::MetaData(const TCollection_ExtendedString&
const TCollection_ExtendedString& /*aVersion*/)
{
TCollection_ExtendedString p = Concatenate(aFolder,aName);
return CDM_MetaData::LookUp(aFolder,aName,p,p,UTL::IsReadOnly(p));
return CDM_MetaData::LookUp (*myLookUpTable, aFolder, aName, p, p, UTL::IsReadOnly(p));
}
//==============================================================================
@@ -117,7 +120,7 @@ Handle(CDM_MetaData) CDF_FWOSDriver::MetaData(const TCollection_ExtendedString&
Handle(CDM_MetaData) CDF_FWOSDriver::CreateMetaData(const Handle(CDM_Document)& aDocument,
const TCollection_ExtendedString& aFileName)
{
return CDM_MetaData::LookUp(aDocument->RequestedFolder(),aDocument->RequestedName(),
return CDM_MetaData::LookUp(*myLookUpTable, aDocument->RequestedFolder(), aDocument->RequestedName(),
Concatenate(aDocument->RequestedFolder(),aDocument->RequestedName()),
aFileName,UTL::IsReadOnly(aFileName));
}
@@ -193,23 +196,6 @@ TCollection_ExtendedString CDF_FWOSDriver::DefaultFolder()
return theDefaultFolder;
}
//==============================================================================
//function : BuildMetaData
//purpose :
//==============================================================================
Handle(CDM_MetaData) CDF_FWOSDriver::BuildMetaData(const TCollection_ExtendedString& aFileName)
{
OSD_Path p = UTL::Path(aFileName);
TCollection_ExtendedString f = UTL::Trek(p);
TCollection_ExtendedString n = UTL::Name(p);
n +=".";
n += UTL::Extension(p);
return CDM_MetaData::LookUp(f,n,aFileName,aFileName,UTL::IsReadOnly(aFileName));
}
//==============================================================================
//function : SetName
//purpose :

View File

@@ -21,6 +21,8 @@
#include <Standard_Type.hxx>
#include <CDF_MetaDataDriver.hxx>
#include <CDM_MetaDataLookUpTable.hxx>
#include <Standard_Boolean.hxx>
class TCollection_ExtendedString;
class CDM_MetaData;
@@ -36,9 +38,10 @@ class CDF_FWOSDriver : public CDF_MetaDataDriver
public:
//! initializes the MetaDatadriver with its specific name.
Standard_EXPORT CDF_FWOSDriver();
//! Initializes the MetaDatadriver connected to specified look-up table.
//! Note that the created driver will keep reference to the table,
//! thus it must have life time longer than this object.
Standard_EXPORT CDF_FWOSDriver(CDM_MetaDataLookUpTable& theLookUpTable);
//! indicate whether a file exists corresponding to the folder and the name
Standard_EXPORT Standard_Boolean Find (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion) Standard_OVERRIDE;
@@ -58,30 +61,16 @@ public:
DEFINE_STANDARD_RTTIEXT(CDF_FWOSDriver,CDF_MetaDataDriver)
protected:
private:
Standard_EXPORT Handle(CDM_MetaData) MetaData (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion) Standard_OVERRIDE;
Standard_EXPORT Handle(CDM_MetaData) CreateMetaData (const Handle(CDM_Document)& aDocument, const TCollection_ExtendedString& aFileName) Standard_OVERRIDE;
Standard_EXPORT static TCollection_ExtendedString Concatenate (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName);
Standard_EXPORT Handle(CDM_MetaData) BuildMetaData (const TCollection_ExtendedString& aFileName);
private:
CDM_MetaDataLookUpTable* myLookUpTable;
};
#endif // _CDF_FWOSDriver_HeaderFile

View File

@@ -17,12 +17,12 @@
#include <CDF_Application.hxx>
#include <CDF_MetaDataDriver.hxx>
#include <CDF_Session.hxx>
#include <CDM_Document.hxx>
#include <CDM_MetaData.hxx>
#include <PCDM_ReferenceIterator.hxx>
#include <Standard_NotImplemented.hxx>
#include <Standard_Type.hxx>
#include <Standard_NullObject.hxx>
#include <TCollection_ExtendedString.hxx>
#include <OSD_Thread.hxx>
@@ -77,11 +77,9 @@ void CDF_MetaDataDriver::CreateReference(const Handle(CDM_MetaData)& ,
//purpose :
//=======================================================================
Handle(PCDM_ReferenceIterator) CDF_MetaDataDriver::ReferenceIterator() {
Standard_ThreadId anID = OSD_Thread::Current();
Handle(CDF_Application) anApp;
CDF_Session::CurrentSession()->FindApplication(anID, anApp);
return new PCDM_ReferenceIterator(anApp->MessageDriver());
Handle(PCDM_ReferenceIterator) CDF_MetaDataDriver::ReferenceIterator(const Handle(Message_Messenger)& theMessageDriver)
{
return new PCDM_ReferenceIterator(theMessageDriver);
}
//=======================================================================

View File

@@ -17,18 +17,14 @@
#ifndef _CDF_MetaDataDriver_HeaderFile
#define _CDF_MetaDataDriver_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx>
class Standard_NotImplemented;
class CDM_MetaData;
class TCollection_ExtendedString;
class CDM_Document;
class PCDM_ReferenceIterator;
class Message_Messenger;
class CDF_MetaDataDriver;
DEFINE_STANDARD_HANDLE(CDF_MetaDataDriver, Standard_Transient)
@@ -100,7 +96,7 @@ public:
Standard_EXPORT virtual TCollection_ExtendedString DefaultFolder() = 0;
Standard_EXPORT virtual Handle(PCDM_ReferenceIterator) ReferenceIterator();
Standard_EXPORT virtual Handle(PCDM_ReferenceIterator) ReferenceIterator(const Handle(Message_Messenger)& theMessageDriver);
//! calls Find with an empty version
Standard_EXPORT Standard_Boolean Find (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName);

View File

@@ -1,135 +0,0 @@
// Created on: 1997-08-08
// Created by: Jean-Louis Frenkel
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <CDF_Application.hxx>
#include <CDF_Directory.hxx>
#include <CDF_FWOSDriver.hxx>
#include <CDF_MetaDataDriver.hxx>
#include <CDF_MetaDataDriverFactory.hxx>
#include <CDF_Session.hxx>
#include <PCDM.hxx>
#include <PCDM_Reader.hxx>
#include <Plugin.hxx>
#include <Standard_ErrorHandler.hxx>
#include <Standard_Failure.hxx>
#include <Standard_GUID.hxx>
#include <Standard_MultiplyDefined.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
static Handle(CDF_Session) THE_CS;
static Standard_Mutex THE_MUTEX;
//=======================================================================
//function :
//purpose :
//=======================================================================
CDF_Session::CDF_Session ()
{
Standard_MultiplyDefined_Raise_if(!THE_CS.IsNull()," a session already exists");
}
//=======================================================================
//function :
//purpose :
//=======================================================================
Handle(CDF_Session) CDF_Session::Create()
{
Standard_Mutex::Sentry aLocker(THE_MUTEX);
if (THE_CS.IsNull())
THE_CS = new CDF_Session;
return THE_CS;
}
//=======================================================================
//function : Exists
//purpose :
//=======================================================================
Standard_Boolean CDF_Session::Exists() {
return !THE_CS.IsNull();
}
//=======================================================================
//function : CurrentSession
//purpose :
//=======================================================================
Handle(CDF_Session) CDF_Session::CurrentSession() {
Standard_NoSuchObject_Raise_if(THE_CS.IsNull(), "no session has been created");
return THE_CS;
}
//=======================================================================
//function : AddApplication
//purpose : adds the application to the session with unique name
//=======================================================================
Standard_Boolean CDF_Session::AddApplication(const Handle(CDF_Application)& theApp,
const Standard_ThreadId theID)
{
return AddApplication(theApp.get(), theID);
}
//=======================================================================
//function : AddApplication
//purpose : adds the application to the session with unique name
//=======================================================================
Standard_Boolean CDF_Session::AddApplication(const CDF_Application* theApp,
const Standard_ThreadId theID)
{
Standard_Boolean aRetValue(Standard_False);
if (theApp)
{
Standard_Mutex::Sentry aLocker(THE_MUTEX);
if (!myAppDirectory.IsBound(theID))
{
Handle(CDF_Application) anApp(theApp);
aRetValue = myAppDirectory.Bind(theID, anApp);
}
}
return aRetValue;
}
//=======================================================================
//function : FindApplication
//purpose :
//=======================================================================
Standard_Boolean CDF_Session::FindApplication(const Standard_ThreadId theID, Handle(CDF_Application)& theApp) const
{
Standard_Mutex::Sentry aLocker(THE_MUTEX);
if (myAppDirectory.IsBound(theID))
{
theApp = Handle(CDF_Application)::DownCast (myAppDirectory.Find(theID));
return ! theApp.IsNull();
}
return Standard_False;
}
//=======================================================================
//function : RemoveApplication
//purpose : removes the application with name=<theName> from the session
//=======================================================================
Standard_Boolean CDF_Session::RemoveApplication(const Standard_ThreadId theID)
{
Standard_Boolean aRetValue(Standard_False);
Standard_Mutex::Sentry aLocker(THE_MUTEX);
if (myAppDirectory.IsBound(theID))
{
aRetValue = myAppDirectory.UnBind(theID);
}
return aRetValue;
}

View File

@@ -1,92 +0,0 @@
// Created on: 1997-08-07
// Created by: Jean-Louis Frenkel
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _CDF_Session_HeaderFile
#define _CDF_Session_HeaderFile
#include <Standard.hxx>
#include <Standard_Type.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Mutex.hxx>
#include <CDM_ApplicationDirectory.hxx>
class CDF_Directory;
class CDF_Application;
class CDF_MetaDataDriver;
class Standard_NoSuchObject;
class Standard_MultiplyDefined;
class CDF_Session;
DEFINE_STANDARD_HANDLE(CDF_Session, Standard_Transient)
class CDF_Session : public Standard_Transient
{
public:
//! returns true if a session has been created.
Standard_EXPORT static Standard_Boolean Exists();
//! Creates a session if it does not exists yet
Standard_EXPORT static Handle(CDF_Session) Create();
//! returns the only one instance of Session
//! that has been created.
Standard_EXPORT static Handle(CDF_Session) CurrentSession();
//! returns true if theApp is added to the session
Standard_EXPORT Standard_Boolean AddApplication(const Handle(CDF_Application)& theApp, const Standard_ThreadId theID);
//! returns true if theApp is added to the session
Standard_EXPORT Standard_Boolean AddApplication(const CDF_Application* theApp, const Standard_ThreadId theID);
//! returns true if theApp is removed from the session
Standard_EXPORT Standard_Boolean RemoveApplication(const Standard_ThreadId theID);
//! returns true if theApp is removed from the session
Standard_EXPORT Standard_Boolean FindApplication(const Standard_ThreadId, Handle(CDF_Application)& theApp) const;
friend class CDF_Application;
DEFINE_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
protected:
//! Use "Create" session for creation of an instance
CDF_Session();
private:
CDM_ApplicationDirectory myAppDirectory;
Handle(CDF_MetaDataDriver) myMetaDataDriver;
};
#endif // _CDF_Session_HeaderFile

View File

@@ -15,7 +15,6 @@
#include <CDF_Application.hxx>
#include <CDF_MetaDataDriver.hxx>
#include <CDF_Session.hxx>
#include <CDF_Store.hxx>
#include <CDF_StoreList.hxx>
#include <CDF_StoreSetNameStatus.hxx>

View File

@@ -18,7 +18,6 @@
#include <CDF_Application.hxx>
#include <CDF_MetaDataDriver.hxx>
#include <CDF_MetaDataDriverError.hxx>
#include <CDF_Session.hxx>
#include <CDF_StoreList.hxx>
#include <CDM_Document.hxx>
#include <CDM_MetaData.hxx>

View File

@@ -11,8 +11,6 @@ CDF_MetaDataDriver.hxx
CDF_MetaDataDriverError.hxx
CDF_MetaDataDriverFactory.cxx
CDF_MetaDataDriverFactory.hxx
CDF_Session.cxx
CDF_Session.hxx
CDF_Store.cxx
CDF_Store.hxx
CDF_StoreList.cxx