1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-09-03 14:10:33 +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

View File

@@ -137,9 +137,9 @@ TCollection_AsciiString CDM_Application::Version() const
//function : MetaDataLookUpTable
//purpose : returns the MetaData LookUpTable
//=======================================================================
CDM_MetaDataLookUpTable* CDM_Application::MetaDataLookUpTable()
CDM_MetaDataLookUpTable& CDM_Application::MetaDataLookUpTable()
{
return &myMetaDataLookUpTable;
return myMetaDataLookUpTable;
}
//=======================================================================

View File

@@ -70,7 +70,7 @@ public:
Standard_EXPORT virtual TCollection_AsciiString Version() const;
//! Returns MetaData LookUpTable
Standard_EXPORT virtual CDM_MetaDataLookUpTable* MetaDataLookUpTable();
Standard_EXPORT virtual CDM_MetaDataLookUpTable& MetaDataLookUpTable();
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;

View File

@@ -1,30 +0,0 @@
// Created on: 1997-05-06
// Created by: Jean-Louis Frenkel, Remi Lequette
// 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 CDM_ApplicationDirectory_HeaderFile
#define CDM_ApplicationDirectory_HeaderFile
#include <CDM_Application.hxx>
#include <TColStd_MapIntegerHasher.hxx>
#include <NCollection_DataMap.hxx>
#include <Standard_ThreadId.hxx>
#include <NCollection_DefaultHasher.hxx>
typedef NCollection_DefaultHasher<Standard_ThreadId> CDM_MapThreadIDHasher;
typedef NCollection_DataMap<Standard_ThreadId,Handle(CDM_Application),CDM_MapThreadIDHasher> CDM_ApplicationDirectory;
typedef NCollection_DataMap<Standard_ThreadId,Handle(CDM_Application),CDM_MapThreadIDHasher>::Iterator CDM_DataMapIteratorOfApplicationDirectory;
#endif

View File

@@ -536,8 +536,8 @@ void CDM_Document::SetMetaData(const Handle(CDM_MetaData)& aMetaData)
aMetaData->SetDocument(this);
// Update the document refencing this MetaData:
CDM_DataMapIteratorOfMetaDataLookUpTable it(*CDM_MetaData::LookUpTable());
// Update the document refencing this MetaData:
CDM_DataMapIteratorOfMetaDataLookUpTable it(Application()->MetaDataLookUpTable());
for(;it.More();it.Next()) {
const Handle(CDM_MetaData)& theMetaData=it.Value();
if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {

View File

@@ -20,10 +20,9 @@
#include <CDM_MetaData.hxx>
#include <CDM_MetaDataLookUpTable.hxx>
#include <CDM_Reference.hxx>
#include <CDF_Session.hxx>
#include <Standard_Dump.hxx>
#include <CDF_Application.hxx>
#include <Standard_NoSuchObject.hxx>
#include <Standard_NullObject.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
#include <OSD_Thread.hxx>
@@ -70,33 +69,48 @@ void CDM_MetaData::SetDocument(const Handle(CDM_Document)& aDocument) {
void CDM_MetaData::UnsetDocument() {
myIsRetrieved = Standard_False;
}
Handle(CDM_MetaData) CDM_MetaData::LookUp(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath,const TCollection_ExtendedString& aFileName,const Standard_Boolean ReadOnly) {
Handle(CDM_MetaData) CDM_MetaData::LookUp(CDM_MetaDataLookUpTable& theLookUpTable,
const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly)
{
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
if (!aLookUpTable) return theMetaData;
if(!aLookUpTable->IsBound(aConventionalPath)) {
if(!theLookUpTable.IsBound(aConventionalPath))
{
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aFileName,ReadOnly);
aLookUpTable->Bind(aConventionalPath, theMetaData);
theLookUpTable.Bind(aConventionalPath, theMetaData);
}
else
theMetaData = aLookUpTable->Find(aConventionalPath);
{
theMetaData = theLookUpTable.Find(aConventionalPath);
}
return theMetaData;
}
Handle(CDM_MetaData) CDM_MetaData::LookUp(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath, const TCollection_ExtendedString& aVersion, const TCollection_ExtendedString& aFileName,const Standard_Boolean ReadOnly) {
Handle(CDM_MetaData) CDM_MetaData::LookUp(CDM_MetaDataLookUpTable& theLookUpTable,
const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aVersion,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly)
{
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
if (!aLookUpTable) return theMetaData;
if(!aLookUpTable->IsBound(aConventionalPath)) {
if(!theLookUpTable.IsBound(aConventionalPath))
{
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aVersion,aFileName,ReadOnly);
aLookUpTable->Bind(aConventionalPath,theMetaData);
theLookUpTable.Bind(aConventionalPath,theMetaData);
}
else
theMetaData = aLookUpTable->Find(aConventionalPath);
{
theMetaData = theLookUpTable.Find(aConventionalPath);
}
return theMetaData;
}
@@ -134,14 +148,6 @@ Standard_OStream& CDM_MetaData::operator << (Standard_OStream& anOStream) {
return Print(anOStream);
}
CDM_MetaDataLookUpTable* CDM_MetaData::LookUpTable() {
Handle(CDF_Session) aSession = CDF_Session::Create();
Handle(CDF_Application) anApp;
CDM_MetaDataLookUpTable* pLookUpTable(NULL);
if (aSession->FindApplication(OSD_Thread::Current(), anApp))
return anApp->MetaDataLookUpTable();
return pLookUpTable;
}
Standard_Integer CDM_MetaData::DocumentVersion(const Handle(CDM_Application)& anApplication) {
if(myDocumentVersion==0) myDocumentVersion=anApplication->DocumentVersion(this);
return myDocumentVersion;

View File

@@ -45,11 +45,21 @@ class CDM_MetaData : public Standard_Transient
public:
Standard_EXPORT static Handle(CDM_MetaData) LookUp (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath, const TCollection_ExtendedString& aFileName, const Standard_Boolean ReadOnly);
Standard_EXPORT static Handle(CDM_MetaData) LookUp (const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath, const TCollection_ExtendedString& aVersion, const TCollection_ExtendedString& aFileName, const Standard_Boolean ReadOnly);
Standard_EXPORT static Handle(CDM_MetaData) LookUp (CDM_MetaDataLookUpTable& theLookUpTable,
const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly);
Standard_EXPORT static Handle(CDM_MetaData) LookUp (CDM_MetaDataLookUpTable& theLookUpTable,
const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aVersion,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly);
Standard_EXPORT Standard_Boolean IsRetrieved() const;
Standard_EXPORT Handle(CDM_Document) Document() const;
@@ -101,23 +111,26 @@ friend
DEFINE_STANDARD_RTTIEXT(CDM_MetaData,Standard_Transient)
protected:
private:
Standard_EXPORT CDM_MetaData(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath, const TCollection_ExtendedString& aFileName, const Standard_Boolean ReadOnly);
Standard_EXPORT CDM_MetaData(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath, const TCollection_ExtendedString& aVersion, const TCollection_ExtendedString& aFileName, const Standard_Boolean ReadOnly);
Standard_EXPORT void SetDocument (const Handle(CDM_Document)& aDocument);
Standard_EXPORT static CDM_MetaDataLookUpTable* LookUpTable();
Standard_EXPORT Standard_Integer DocumentVersion (const Handle(CDM_Application)& anApplication);
CDM_MetaData (const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly);
CDM_MetaData (const TCollection_ExtendedString& aFolder,
const TCollection_ExtendedString& aName,
const TCollection_ExtendedString& aPath,
const TCollection_ExtendedString& aVersion,
const TCollection_ExtendedString& aFileName,
const Standard_Boolean ReadOnly);
void SetDocument (const Handle(CDM_Document)& aDocument);
Standard_Integer DocumentVersion (const Handle(CDM_Application)& anApplication);
private:
Standard_Boolean myIsRetrieved;
CDM_DocumentPointer myDocument;

View File

@@ -16,7 +16,6 @@ CDM_MetaData.cxx
CDM_MetaData.hxx
CDM_MetaDataLookUpTable.hxx
CDM_NamesDirectory.hxx
CDM_ApplicationDirectory.hxx
CDM_Reference.cxx
CDM_Reference.hxx
CDM_ReferenceIterator.cxx

View File

@@ -13,8 +13,6 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <CDF_Session.hxx>
#include <DBRep.hxx>
#include <DDocStd.hxx>
#include <DDocStd_DrawDocument.hxx>

View File

@@ -53,9 +53,10 @@ void PCDM_ReferenceIterator::LoadReferences(const Handle(CDM_Document)& aDocumen
const Handle(CDM_MetaData)& aMetaData,
const Handle(CDM_Application)& anApplication,
const Standard_Boolean UseStorageConfiguration) {
for (Init(aMetaData);More();Next()) {
aDocument->CreateReference(MetaData(UseStorageConfiguration),ReferenceIdentifier(),
anApplication,DocumentVersion(),UseStorageConfiguration);
for (Init(aMetaData);More();Next())
{
aDocument->CreateReference(MetaData(anApplication->MetaDataLookUpTable(),UseStorageConfiguration),
ReferenceIdentifier(),anApplication,DocumentVersion(),UseStorageConfiguration);
}
}
@@ -96,7 +97,9 @@ void PCDM_ReferenceIterator::Next() {
//purpose :
//=======================================================================
Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) const {
Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(CDM_MetaDataLookUpTable& theLookUpTable,
const Standard_Boolean ) const
{
TCollection_ExtendedString theFolder,theName;
TCollection_ExtendedString theFile=myReferences(myIterator).FileName();
@@ -140,8 +143,9 @@ Handle(CDM_MetaData) PCDM_ReferenceIterator::MetaData(const Standard_Boolean ) c
theName = UTL::Name(p); theName+= UTL::Extension(p);
#endif // _WIN32
return CDM_MetaData::LookUp(theFolder,theName,theFile,theFile,UTL::IsReadOnly(theFile));
return CDM_MetaData::LookUp(theLookUpTable, theFolder, theName, theFile, theFile, UTL::IsReadOnly(theFile));
}
//=======================================================================
//function : ReferenceIdentifier
//purpose :

View File

@@ -21,15 +21,13 @@
#include <Standard_Type.hxx>
#include <PCDM_SequenceOfReference.hxx>
#include <Standard_Integer.hxx>
#include <Standard_Transient.hxx>
#include <Standard_Boolean.hxx>
#include <CDM_MetaDataLookUpTable.hxx>
class Message_Messenger;
class CDM_Document;
class CDM_MetaData;
class CDM_Application;
class PCDM_ReferenceIterator;
DEFINE_STANDARD_HANDLE(PCDM_ReferenceIterator, Standard_Transient)
@@ -64,18 +62,18 @@ private:
Standard_EXPORT virtual void Next();
Standard_EXPORT virtual Handle(CDM_MetaData) MetaData (const Standard_Boolean UseStorageConfiguration) const;
Standard_EXPORT virtual Handle(CDM_MetaData) MetaData (CDM_MetaDataLookUpTable& theLookUpTable,
const Standard_Boolean UseStorageConfiguration) const;
Standard_EXPORT virtual Standard_Integer ReferenceIdentifier() const;
//! returns the version of the document in the reference
Standard_EXPORT virtual Standard_Integer DocumentVersion() const;
private:
PCDM_SequenceOfReference myReferences;
Standard_Integer myIterator;
Handle(Message_Messenger) myMessageDriver;
};

View File

@@ -3065,7 +3065,6 @@ void* threadFunction(void* theArgs)
}
}
args->finished = true;
anApp->RemoveFromSession();
}
catch (...)
{
@@ -3794,6 +3793,83 @@ static Standard_Integer OCC31320(Draw_Interpretor& di, Standard_Integer argc, co
}
#include <BinXCAFDrivers.hxx>
#include <Message.hxx>
namespace
{
class QABugs_XdeLoader : public OSD_Thread
{
public:
QABugs_XdeLoader (const Handle(TDocStd_Application)& theXdeApp,
const Handle(TDocStd_Document)& theXdeDoc,
const TCollection_AsciiString& theFilePath)
: OSD_Thread (performThread),
myXdeApp (theXdeApp), myXdeDoc (theXdeDoc), myFilePath (theFilePath) {}
private:
void perform()
{
Handle(TDocStd_Document) aNewDoc;
const PCDM_ReaderStatus aReaderStatus = myXdeApp->Open (myFilePath, aNewDoc);
if (aReaderStatus != PCDM_RS_OK)
{
Message::SendFail ("Error occurred while reading the file");
return;
}
myXdeDoc = aNewDoc;
Message::SendInfo() << "Info: document has been opened";
}
static Standard_Address performThread (Standard_Address theData)
{
QABugs_XdeLoader* aLoader = (QABugs_XdeLoader* )theData;
OSD::SetThreadLocalSignal (OSD_SignalMode_Set, false);
try
{
OCC_CATCH_SIGNALS
aLoader->perform();
}
catch (Standard_Failure const& theExcep)
{
Message::SendFail() << "Error: unexpected exception " << theExcep;
return 0;
}
return 0;
}
private:
Handle(TDocStd_Application) myXdeApp;
Handle(TDocStd_Document) myXdeDoc;
TCollection_AsciiString myFilePath;
};
}
//=======================================================================
//function : OCC31785
//purpose : Try reading XBF file in background thread
//=======================================================================
static Standard_Integer OCC31785 (Draw_Interpretor& theDI,
Standard_Integer theNbArgs,
const char** theArgVec)
{
if (theNbArgs != 2)
{
theDI << "Syntax error: wrong number of arguments\n";
return 1;
}
TCollection_AsciiString aFileName (theArgVec[1]);
Handle(TDocStd_Application) anXdeApp = new TDocStd_Application();
BinXCAFDrivers::DefineFormat (anXdeApp);
Handle(TDocStd_Document) anXdeDoc;
anXdeApp->NewDocument (TCollection_ExtendedString ("BinXCAF"), anXdeDoc);
QABugs_XdeLoader aLoader (anXdeApp, anXdeDoc, aFileName);
aLoader.Run (&aLoader);
aLoader.Wait();
return 0;
}
void QABugs::Commands_20(Draw_Interpretor& theCommands) {
const char *group = "QABugs";
@@ -3865,5 +3941,9 @@ void QABugs::Commands_20(Draw_Interpretor& theCommands) {
theCommands.Add("OCC31320", "OCC31320 DocName ObjName : tests remove of the children GetFather method if father is removed", __FILE__, OCC31320, group);
theCommands.Add("OCC31785",
"OCC31785 file.xbf : test reading XBF file in another thread",
__FILE__, OCC31785, group);
return;
}

View File

@@ -18,7 +18,6 @@
#include <CDF_Directory.hxx>
#include <CDF_DirectoryIterator.hxx>
#include <CDF_Session.hxx>
#include <CDF_Store.hxx>
#include <PCDM_RetrievalDriver.hxx>
#include <PCDM_StorageDriver.hxx>
@@ -46,12 +45,10 @@ IMPLEMENT_STANDARD_RTTIEXT(TDocStd_Application,CDF_Application)
TDocStd_Application::TDocStd_Application()
: myIsDriverLoaded (Standard_True)
{
AddToSession();
if(myMetaDataDriver.IsNull())
myIsDriverLoaded = Standard_False;
}
//=======================================================================
//function : IsDriverLoaded
//purpose :
@@ -156,9 +153,7 @@ void TDocStd_Application::WritingFormats(TColStd_SequenceOfAsciiString &theForma
Standard_Integer TDocStd_Application::NbDocuments() const
{
if (!CDF_Session::Exists())
throw Standard_DomainError("TDocStd_Application::NbDocuments");
return this->myDirectory->Length();
return myDirectory->Length();
}
//=======================================================================
@@ -168,8 +163,6 @@ Standard_Integer TDocStd_Application::NbDocuments() const
void TDocStd_Application::GetDocument(const Standard_Integer index,Handle(TDocStd_Document)& aDoc) const
{
if (!CDF_Session::Exists())
throw Standard_DomainError("TDocStd_Application::NbDocuments");
CDF_DirectoryIterator it (myDirectory);
Standard_Integer current = 0;
for (;it.MoreDocument();it.NextDocument()) {
@@ -601,19 +594,6 @@ void TDocStd_Application::OnCommitTransaction (const Handle(TDocStd_Document)&)
// nothing to do on this level
}
//
void TDocStd_Application::AddToSession()
{
Handle(CDF_Session) S = CDF_Session::Create();
S->AddApplication(this, OSD_Thread::Current());
}
Standard_Boolean TDocStd_Application::RemoveFromSession()
{
Handle(CDF_Session) aSession = CDF_Session::Create();
return aSession->RemoveApplication(OSD_Thread::Current());
}
//=======================================================================
//function : DumpJson
//purpose :

View File

@@ -283,20 +283,12 @@ public:
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
//! Remove this application from the current session
Standard_EXPORT Standard_Boolean RemoveFromSession();
DEFINE_STANDARD_RTTIEXT(TDocStd_Application, CDF_Application)
protected:
Handle(Resource_Manager) myResources;
Standard_Boolean myIsDriverLoaded;
private:
//! Add this application to the current session (register in internal container)
void AddToSession();
};
#endif // _TDocStd_Application_HeaderFile

View File

@@ -27,6 +27,7 @@ TKIGES
TKXSBase
TKMesh
TKXCAF
TKBinXCAF
TKSTEP
TKSTEPBase
TKXDESTEP

View File

@@ -25,8 +25,6 @@
#include <Message_Msg.hxx>
#include <Message_MsgFile.hxx>
#include <Resource_Manager.hxx>
#include <CDF_Session.hxx>
#include <OSD_Thread.hxx>
#include <stdio.h>
#include "TObj_TObj_msg.pxx"
@@ -39,21 +37,8 @@ IMPLEMENT_STANDARD_RTTIEXT(TObj_Application,TDocStd_Application)
//=======================================================================
Handle(TObj_Application) TObj_Application::GetInstance()
{
Handle(CDF_Session) aSession = CDF_Session::Create();
Handle(CDF_Application) anApp;
if (aSession->FindApplication(OSD_Thread::Current(), anApp))
{
Handle(TObj_Application) aTObjApp = Handle(TObj_Application)::DownCast(anApp);
if (!aTObjApp.IsNull())
return aTObjApp;
// If in session application of another type is already registered, use this global
// application, alone, outside of the session (as a workaround for DRAW scripting where
// many kinds of applications can be required).
static Handle(TObj_Application) THE_TOBJ_APP(new TObj_Application);
return THE_TOBJ_APP;
}
// It will register this application in the session.
return new TObj_Application;
static Handle(TObj_Application) THE_TOBJ_APP(new TObj_Application);
return THE_TOBJ_APP;
}
//=======================================================================

View File

@@ -396,7 +396,8 @@ void XmlLDrivers_DocumentRetrievalDriver::ReadFromDomDocument
theName = UTL::Name(p); theName+= UTL::Extension(p);
#endif // _WIN32
Handle(CDM_MetaData) aMetaData = CDM_MetaData::LookUp(theFolder,theName,aPath,aPath,UTL::IsReadOnly(aFileName));
Handle(CDM_MetaData) aMetaData =
CDM_MetaData::LookUp(theApplication->MetaDataLookUpTable(), theFolder, theName, aPath, aPath, UTL::IsReadOnly(aFileName));
////////////
theNewDocument->CreateReference(aMetaData,aRefId,
theApplication,aDocumentVersion,Standard_False);