OCAF persistence architecture modification to satisfy multi-threading criteria.
TCollection_ExtendedString aFormat = PCDM_ReadWriter::FileFormat (aFileStream, dData);
Read(aFileStream, dData, theNewDocument, theApplication, theProgress);
- if (theProgress->UserBreak())
+ if (!theProgress.IsNull() && theProgress->UserBreak())
{
myReaderStatus = PCDM_RS_UserBreak;
return;
+++ /dev/null
-// Created on: 1998-03-11
-// Created by: Jean-Louis Frenkel
-// Copyright (c) 1998-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.hxx>
-#include <Standard_Failure.hxx>
-
-static void CDF_InitApplication () {
-
- static Standard_Boolean FirstApplication = Standard_True;
-
- if(FirstApplication) {
- FirstApplication = Standard_False;
- }
-}
-void CDF::GetLicense(const Standard_Integer ){
-
- CDF_InitApplication();
-
-}
-
-Standard_Boolean CDF::IsAvailable(const Standard_Integer ) {
-
- CDF_InitApplication();
- return Standard_True;
-}
+++ /dev/null
-// 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_HeaderFile
-#define _CDF_HeaderFile
-
-#include <Standard.hxx>
-#include <Standard_DefineAlloc.hxx>
-#include <Standard_Handle.hxx>
-
-#include <Standard_Integer.hxx>
-#include <Standard_Boolean.hxx>
-class CDF_Directory;
-class CDF_DirectoryIterator;
-class CDF_Session;
-class CDF_Application;
-class CDF_StoreList;
-class CDF_Store;
-class CDF_MetaDataDriver;
-class CDF_FWOSDriver;
-class CDF_MetaDataDriverFactory;
-
-class CDF
-{
-public:
-
- Standard_EXPORT static void GetLicense (const Standard_Integer anApplicationIdentifier);
-
- Standard_EXPORT static Standard_Boolean IsAvailable (const Standard_Integer anApplicationIdentifier);
-};
-
-#endif // _CDF_HeaderFile
#include <CDF_Application.hxx>
#include <CDF_Directory.hxx>
-#include <CDF_MetaDataDriver.hxx>
#include <CDF_Session.hxx>
+#include <CDF_FWOSDriver.hxx>
#include <CDM_CanCloseStatus.hxx>
#include <CDM_Document.hxx>
#include <CDM_MetaData.hxx>
#include <Message_ProgressSentry.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDF_Application,CDM_Application)
-
-#define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
-
-
//=======================================================================
//function :
//purpose :
//=======================================================================
-CDF_Application::CDF_Application():myRetrievableStatus(PCDM_RS_OK) {}
+CDF_Application::CDF_Application():myRetrievableStatus(PCDM_RS_OK)
+{
+ myDirectory = new CDF_Directory();
+ myMetaDataDriver = new CDF_FWOSDriver;
+}
//=======================================================================
//function : Load
//purpose :
//=======================================================================
void CDF_Application::Open(const Handle(CDM_Document)& aDocument) {
- CDF_Session::CurrentSession()->Directory()->Add(aDocument);
+ myDirectory->Add(aDocument);
aDocument->Open(this);
Activate(aDocument,CDF_TOA_New);
}
//purpose :
//=======================================================================
void CDF_Application::Close(const Handle(CDM_Document)& aDocument) {
- CDF_Session::CurrentSession()->Directory()->Remove(aDocument);
+ myDirectory->Remove(aDocument);
aDocument->Close();
}
Handle(CDM_MetaData) theMetaData;
if(aVersion.Length() == 0)
- theMetaData=theMetaDataDriver->MetaData(aFolder,aName);
+ theMetaData=myMetaDataDriver->MetaData(aFolder,aName);
else
- theMetaData=theMetaDataDriver->MetaData(aFolder,aName,aVersion);
+ theMetaData=myMetaDataDriver->MetaData(aFolder,aName,aVersion);
CDF_TypeOfActivation theTypeOfActivation=TypeOfActivation(theMetaData);
Handle(CDM_Document) theDocument = Retrieve(theMetaData, UseStorageConfiguration,
Standard_False, theProgress);
- CDF_Session::CurrentSession()->Directory()->Add(theDocument);
+ myDirectory->Add(theDocument);
Activate(theDocument,theTypeOfActivation);
theDocument->Open(this);
//=======================================================================
PCDM_ReaderStatus CDF_Application::CanRetrieve(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aVersion) {
- if (!theMetaDataDriver->Find(aFolder,aName,aVersion))
+ if (!myMetaDataDriver->Find(aFolder,aName,aVersion))
return PCDM_RS_UnknownDocument;
- else if (!theMetaDataDriver->HasReadPermission(aFolder,aName,aVersion))
+ else if (!myMetaDataDriver->HasReadPermission(aFolder,aName,aVersion))
return PCDM_RS_PermissionDenied;
else {
- Handle(CDM_MetaData) theMetaData = theMetaDataDriver->MetaData(aFolder,aName,aVersion);
+ Handle(CDM_MetaData) theMetaData = myMetaDataDriver->MetaData(aFolder,aName,aVersion);
if(theMetaData->IsRetrieved()) {
return theMetaData->Document()->IsModified()
//=======================================================================
Standard_ExtString CDF_Application::DefaultFolder(){
if(myDefaultFolder.Length() == 0) {
- myDefaultFolder=CDF_Session::CurrentSession()->MetaDataDriver()->DefaultFolder();
+ myDefaultFolder=myMetaDataDriver->DefaultFolder();
}
return myDefaultFolder.ToExtString();
}
//purpose :
//=======================================================================
Standard_Boolean CDF_Application::SetDefaultFolder(const Standard_ExtString aFolder) {
- Standard_Boolean found = CDF_Session::CurrentSession()->MetaDataDriver()->FindFolder(aFolder);
+ Standard_Boolean found = myMetaDataDriver->FindFolder(aFolder);
if(found) myDefaultFolder=aFolder;
return found;
}
SetReferenceCounter(theDocument,PCDM_RetrievalDriver::ReferenceCounter(aMetaData->FileName(), MessageDriver()));
SetDocumentVersion(theDocument,aMetaData);
- theMetaDataDriver->ReferenceIterator()->LoadReferences(theDocument,aMetaData,this,UseStorageConfiguration);
+ myMetaDataDriver->ReferenceIterator()->LoadReferences(theDocument,aMetaData,this,UseStorageConfiguration);
try {
OCC_CATCH_SIGNALS
else
return CanRetrieve(aMetaData->Folder(),aMetaData->Name());
}
+
+//=======================================================================
+//function : MetaDataDriver
+//purpose :
+//=======================================================================
+Handle(CDF_MetaDataDriver) CDF_Application::MetaDataDriver() const {
+ Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(), "no metadatadriver has been provided; this application is not able to store or retrieve files.");
+ return myMetaDataDriver;
+}
#include <TCollection_ExtendedString.hxx>
#include <PCDM_ReaderStatus.hxx>
+#include <CDF_TypeOfActivation.hxx>
+#include <CDF_MetaDataDriver.hxx>
#include <CDM_Application.hxx>
#include <CDM_CanCloseStatus.hxx>
#include <TColStd_SequenceOfExtendedString.hxx>
-#include <CDF_TypeOfActivation.hxx>
#include <Standard_IStream.hxx>
#include <NCollection_IndexedDataMap.hxx>
class CDM_MetaData;
class PCDM_RetrievalDriver;
class PCDM_StorageDriver;
-
+class CDF_Directory;
class CDF_Application;
DEFINE_STANDARD_HANDLE(CDF_Application, CDM_Application)
Standard_EXPORT Standard_ExtString DefaultFolder();
Standard_EXPORT Standard_Boolean SetDefaultFolder (const Standard_ExtString aFolder);
-
+
+ //! 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;
+ Handle(CDF_Directory) myDirectory;
private:
}
void CDF_Directory::Remove(const Handle(CDM_Document)& aDocument) {
-
- CDM_ListIteratorOfListOfDocument it(myDocuments);
-
- Standard_Boolean found = Standard_False;
- for (; it.More() && !found;) {
- found = aDocument == it.Value();
- if(found)
+ for (CDM_ListIteratorOfListOfDocument it(myDocuments); it.More(); it.Next()) {
+ if (aDocument == it.Value()) {
myDocuments.Remove(it);
- else
- it.Next();
+ break;
+ }
}
}
-
Standard_Boolean CDF_Directory::Contains(const Handle(CDM_Document)& aDocument) const {
-
- CDM_ListIteratorOfListOfDocument it(myDocuments);
- Standard_Boolean found = Standard_False;
- for (; it.More() && !found; it.Next()) {
- found = aDocument == it.Value();
+ for (CDM_ListIteratorOfListOfDocument it(myDocuments); it.More(); it.Next()) {
+ if (aDocument == it.Value())
+ return Standard_True;
}
- return found;
+ return Standard_False;
}
-
Standard_Integer CDF_Directory::Length() const {
return myDocuments.Extent();
}
Standard_Boolean CDF_Directory::IsEmpty() const {
return myDocuments.IsEmpty();
}
+
Handle(CDM_Document) CDF_Directory::Last() {
Standard_NoSuchObject_Raise_if(IsEmpty(),"CDF_Directory::Last: the directory does not contain any document");
return myDocuments.Last();
#include <CDM_Document.hxx>
#include <Standard_NoSuchObject.hxx>
-CDF_DirectoryIterator::CDF_DirectoryIterator():myIterator(CDF_Session::CurrentSession()->Directory()->List()) {}
-
-
CDF_DirectoryIterator::CDF_DirectoryIterator(const Handle(CDF_Directory)& aDirectory):myIterator(aDirectory->List()) {}
#include <Standard_NotImplemented.hxx>
#include <Standard_Type.hxx>
#include <TCollection_ExtendedString.hxx>
+#include <OSD_Thread.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDF_MetaDataDriver,Standard_Transient)
//purpose :
//=======================================================================
-void CDF_MetaDataDriver::CreateReference(const Handle(CDM_MetaData)& ,const Handle(CDM_MetaData)& , const Standard_Integer , const Standard_Integer ) {}
+void CDF_MetaDataDriver::CreateReference(const Handle(CDM_MetaData)& ,
+ const Handle(CDM_MetaData)& , const Standard_Integer , const Standard_Integer ) {}
//=======================================================================
//function : ReferenceIterator
//=======================================================================
Handle(PCDM_ReferenceIterator) CDF_MetaDataDriver::ReferenceIterator() {
- return new PCDM_ReferenceIterator(CDF_Session::CurrentSession()->CurrentApplication()->MessageDriver());
+ Standard_ThreadId anID = OSD_Thread::Current();
+ Handle(CDF_Application) anApp;
+ CDF_Session::CurrentSession()->FindApplication(anID, anApp);
+ return new PCDM_ReferenceIterator(anApp->MessageDriver());
}
//=======================================================================
//purpose :
//=======================================================================
-Standard_Boolean CDF_MetaDataDriver::Find(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName) {
+Standard_Boolean CDF_MetaDataDriver::Find(const TCollection_ExtendedString& aFolder,
+ const TCollection_ExtendedString& aName)
+{
TCollection_ExtendedString aVersion;
return Find(aFolder,aName,aVersion);
}
IMPLEMENT_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
-static Handle(CDF_Session) CS;
+static Handle(CDF_Session) THE_CS;
+static Standard_Mutex THE_MUTEX;
//=======================================================================
//function :
//purpose :
//=======================================================================
-CDF_Session::CDF_Session () : myHasCurrentApplication(Standard_False)
+CDF_Session::CDF_Session ()
{
- Standard_MultiplyDefined_Raise_if(!CS.IsNull()," a session already exists");
- myDirectory = new CDF_Directory();
- CS = this;
+ Standard_MultiplyDefined_Raise_if(!THE_CS.IsNull()," a session already exists");
}
//=======================================================================
-//function : Exists
+//function :
//purpose :
//=======================================================================
-Standard_Boolean CDF_Session::Exists() {
- return !CS.IsNull();
+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 : Directory
+//function : Exists
//purpose :
//=======================================================================
-Handle(CDF_Directory) CDF_Session::Directory() const {
-
- return CS->myDirectory;
+Standard_Boolean CDF_Session::Exists() {
+ return !THE_CS.IsNull();
}
//=======================================================================
//purpose :
//=======================================================================
Handle(CDF_Session) CDF_Session::CurrentSession() {
- Standard_NoSuchObject_Raise_if(CS.IsNull(), "no session has been created");
- return CS;
-}
-
-//=======================================================================
-//function : HasCurrentApplication
-//purpose :
-//=======================================================================
-Standard_Boolean CDF_Session::HasCurrentApplication() const {
- return myHasCurrentApplication;
-}
-
-//=======================================================================
-//function : CurrentApplication
-//purpose :
-//=======================================================================
-Handle(CDF_Application) CDF_Session::CurrentApplication() const {
- Standard_NoSuchObject_Raise_if(!myHasCurrentApplication,"there is no current application in the session");
- return myCurrentApplication;
+ Standard_NoSuchObject_Raise_if(THE_CS.IsNull(), "no session has been created");
+ return THE_CS;
}
//=======================================================================
-//function : SetCurrentApplication
-//purpose :
+//function : AddApplication
+//purpose : adds the application to the session with unique name
//=======================================================================
-void CDF_Session::SetCurrentApplication(const Handle(CDF_Application)& anApplication) {
- myCurrentApplication = anApplication;
- myHasCurrentApplication = Standard_True;
+Standard_Boolean CDF_Session::AddApplication(const Handle(CDF_Application)& theApp,
+ const Standard_ThreadId theID)
+{
+ return AddApplication(theApp.get(), theID);
}
//=======================================================================
-//function : UnsetCurrentApplication
-//purpose :
-//=======================================================================
-void CDF_Session::UnsetCurrentApplication() {
- myHasCurrentApplication = Standard_False;
- myCurrentApplication.Nullify();
+//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 : MetaDataDriver
+//function : FindApplication
//purpose :
//=======================================================================
-Handle(CDF_MetaDataDriver) CDF_Session::MetaDataDriver() const {
- Standard_NoSuchObject_Raise_if(myMetaDataDriver.IsNull(),"no metadatadriver has been provided; this session is not able to store or retrieve files.");
- return myMetaDataDriver;
+Standard_Boolean CDF_Session::FindApplication(const Standard_ThreadId theID, Handle(CDF_Application)& theApp) const
+{
+ Standard_Mutex::Sentry aLocker(THE_MUTEX);
+ if (myAppDirectory.IsBound(theID))
+ {
+ return myAppDirectory.Find(theID, theApp);
+ }
+ return Standard_False;
}
-
//=======================================================================
-//function : LoadDriver
-//purpose :
+//function : RemoveApplication
+//purpose : removes the application with name=<theName> from the session
//=======================================================================
-void CDF_Session::LoadDriver() {
- if (myMetaDataDriver.IsNull()) {
- // for compatibility with old code, initialize useless driver directly
- // instead of loading it as plugin
- Handle(CDF_MetaDataDriverFactory) aFactory;
- myMetaDataDriver = new CDF_FWOSDriver;
+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;
}
#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)
public:
- Standard_EXPORT CDF_Session();
-
//! 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 the directory of the session;
- Standard_EXPORT Handle(CDF_Directory) Directory() const;
-
- Standard_EXPORT Standard_Boolean HasCurrentApplication() const;
-
- Standard_EXPORT Handle(CDF_Application) CurrentApplication() const;
-
- Standard_EXPORT void SetCurrentApplication (const Handle(CDF_Application)& anApplication);
-
- Standard_EXPORT void UnsetCurrentApplication();
-
- Standard_EXPORT Handle(CDF_MetaDataDriver) MetaDataDriver() const;
-
- Standard_EXPORT void LoadDriver();
+ //! 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;
protected:
+ //! Use "Create" session for creation of an instance
+ CDF_Session();
+
private:
- Handle(CDF_Directory) myDirectory;
- Handle(CDF_Application) myCurrentApplication;
- Standard_Boolean myHasCurrentApplication;
+ CDM_ApplicationDirectory myAppDirectory;
Handle(CDF_MetaDataDriver) myMetaDataDriver;
-
-
};
#include <PCDM_StorageDriver.hxx>
#include <PCDM_StoreStatus.hxx>
#include <Standard_ProgramError.hxx>
-#include <TCollection_ExtendedString.hxx>
-
-#define theMetaDataDriver CDF_Session::CurrentSession()->MetaDataDriver()
-
-
-static TCollection_ExtendedString blank("");
+#define theMetaDataDriver Handle(CDF_Application)::DownCast((myCurrentDocument->Application()))->MetaDataDriver()
+static const Handle(TCollection_HExtendedString) blank = new TCollection_HExtendedString("");
CDF_Store::CDF_Store()
: myHasSubComponents(Standard_False),
myCurrentDocument = myMainDocument;
}
-Standard_ExtString CDF_Store::Folder() const {
- static TCollection_ExtendedString retv;
+Handle(TCollection_HExtendedString) CDF_Store::Folder() const {
if(myCurrentDocument->HasRequestedFolder())
- retv = myCurrentDocument->RequestedFolder();
- else
- retv= blank;
- return retv.ToExtString();
+ return new TCollection_HExtendedString(myCurrentDocument->RequestedFolder());
+ return blank;
}
-Standard_ExtString CDF_Store::Name() const {
- static TCollection_ExtendedString retv;
- retv = myCurrentDocument->RequestedName();
- return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::Name() const {
+ return new TCollection_HExtendedString(myCurrentDocument->RequestedName());
}
Standard_ExtString CDF_Store::Path() const {
return myPath.ToExtString();
}
-Standard_ExtString CDF_Store::MetaDataPath() const {
- static TCollection_ExtendedString retv;
- retv="";
- if(myCurrentDocument->IsStored()) retv=myCurrentDocument->MetaData()->Path();
- return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::MetaDataPath() const {
+ if(myCurrentDocument->IsStored())
+ return new TCollection_HExtendedString(myCurrentDocument->MetaData()->Path());
+ return blank;
}
-Standard_ExtString CDF_Store::Description() const {
- static TCollection_ExtendedString retv;
-
+Handle(TCollection_HExtendedString) CDF_Store::Description() const {
if(myMainDocument->FindDescription())
- retv = myMainDocument->Description();
- else
- retv= blank;
-
- return retv.ToExtString();
+ return new TCollection_HExtendedString(myMainDocument->Description());
+ return blank;
}
Standard_Boolean CDF_Store::IsStored() const {
return myCurrentDocument->HasRequestedPreviousVersion();
}
-Standard_ExtString CDF_Store::PreviousVersion() const {
- static TCollection_ExtendedString retv;
+Handle(TCollection_HExtendedString) CDF_Store::PreviousVersion() const {
if(myCurrentDocument->HasRequestedPreviousVersion())
- retv= myCurrentDocument->RequestedPreviousVersion();
- else
- retv=blank;
- return retv.ToExtString();
+ return new TCollection_HExtendedString(myCurrentDocument->RequestedPreviousVersion());
+ return blank;
}
Standard_Boolean CDF_Store::SetPreviousVersion (const Standard_ExtString aPreviousVersion) {
return Standard_True;
}
-void CDF_Store::InitComponent() {
- myList->Init();
-}
-
-Standard_Boolean CDF_Store::MoreComponent() const {
- return myList->More();
-}
-
-void CDF_Store::NextComponent() {
- myList->Next();
-}
-void CDF_Store::SetCurrent() {
- myCurrentDocument = myList->Value();
- myIsMainDocument = myCurrentDocument == myMainDocument;
-
-
-}
-
-Standard_ExtString CDF_Store::Component() const {
-
- static TCollection_ExtendedString retv;
- retv=myList->Value()->Presentation();
- return retv.ToExtString();
-}
-Standard_Boolean CDF_Store::HasSubComponents () const {
- return myHasSubComponents;
-}
-
-void CDF_Store::SetCurrent(const Standard_ExtString aPresentation) {
- myCurrentDocument = CDM_Document::FindFromPresentation(aPresentation);
+void CDF_Store::SetCurrent(const Standard_ExtString /*aPresentation*/) {
myIsMainDocument = myCurrentDocument == myMainDocument;
}
void CDF_Store::SetMain() {
return myIsMainDocument;
}
-CDF_SubComponentStatus CDF_Store::SubComponentStatus(const Standard_ExtString aPresentation) const {
- Handle(CDM_Document) d = CDM_Document::FindFromPresentation(aPresentation);
-
- if(!d->IsStored())
- return d->HasRequestedFolder()? CDF_SCS_Consistent : CDF_SCS_Unconsistent;
-
- if(d->IsModified()) return CDF_SCS_Modified;
- return CDF_SCS_Stored;
-}
-
-
-
PCDM_StoreStatus CDF_Store::StoreStatus() const {
return myStatus;
}
void CDF_Store::FindDefault() {
if (!myCurrentDocument->IsStored ()) {
- myCurrentDocument->SetRequestedFolder(CDF_Session::CurrentSession()->CurrentApplication()->DefaultFolder());
-// myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->Presentation()));
+ myCurrentDocument->SetRequestedFolder(Handle(CDF_Application)::DownCast((myCurrentDocument->Application()))->DefaultFolder());
myCurrentDocument->SetRequestedName(theMetaDataDriver->SetName(myCurrentDocument,myCurrentDocument->RequestedName()));
}
}
myCurrentDocument->SetRequestedComment(aComment);
}
-Standard_ExtString CDF_Store::Comment() const {
- static TCollection_ExtendedString retv;
- retv=myCurrentDocument->RequestedComment();
- return retv.ToExtString();
+Handle(TCollection_HExtendedString) CDF_Store::Comment() const {
+ return new TCollection_HExtendedString(myCurrentDocument->RequestedComment());
}
#include <Standard_ExtString.hxx>
#include <CDF_StoreSetNameStatus.hxx>
#include <CDF_SubComponentStatus.hxx>
+#include <TCollection_HExtendedString.hxx>
#include <Message_ProgressIndicator.hxx>
Standard_EXPORT CDF_Store(const Handle(CDM_Document)& aDocument);
//! returns the folder in which the current document will be stored.
- Standard_EXPORT Standard_ExtString Folder() const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) Folder() const;
//! returns the name under which the current document will be stored
- Standard_EXPORT Standard_ExtString Name() const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) Name() const;
//! returns true if the current document is already stored
Standard_EXPORT Standard_Boolean IsStored() const;
Standard_EXPORT Standard_Boolean HasAPreviousVersion() const;
- Standard_EXPORT Standard_ExtString PreviousVersion() const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) PreviousVersion() const;
//! returns true if the currentdocument is the main one, ie the document
//! of the current selection.
Standard_EXPORT void SetComment (const Standard_ExtString aComment);
- Standard_EXPORT Standard_ExtString Comment() const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) Comment() const;
//! defines the name under which the document should be stored.
//! uses for example after modification of the folder.
//! returns the path of the previous store is the object
//! is already stored, otherwise an empty string;
- Standard_EXPORT Standard_ExtString MetaDataPath() const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) MetaDataPath() const;
//! returns the description of the format of the main object.
- Standard_EXPORT Standard_ExtString Description() const;
-
- //! Allows to Start a new Iteration from beginning
- Standard_EXPORT void InitComponent();
-
- //! Returns True if there are more entries to return
- Standard_EXPORT Standard_Boolean MoreComponent() const;
-
- //! Go to the next entry
- //! (if there is not, Value will raise an exception)
- Standard_EXPORT void NextComponent();
-
- Standard_EXPORT void SetCurrent();
-
- //! Returns item value of current entry
- Standard_EXPORT Standard_ExtString Component() const;
-
- Standard_EXPORT Standard_Boolean HasSubComponents() const;
-
- Standard_EXPORT CDF_SubComponentStatus SubComponentStatus (const Standard_ExtString aPresentation) const;
+ Standard_EXPORT Handle(TCollection_HExtendedString) Description() const;
Standard_EXPORT void SetCurrent (const Standard_ExtString aPresentation);
TCollection_ExtendedString& aStatusAssociatedText,
const Handle(Message_ProgressIndicator)& theProgress)
{
- Handle(CDF_MetaDataDriver) theMetaDataDriver = CDF_Session::CurrentSession()->MetaDataDriver();
+ Handle(CDF_MetaDataDriver) theMetaDataDriver = Handle(CDF_Application)::DownCast((myMainDocument->Application()))->MetaDataDriver();
PCDM_StoreStatus status = PCDM_SS_OK;
{
-CDF.cxx
-CDF.hxx
CDF_Application.cxx
CDF_Application.hxx
CDF_Directory.cxx
IMPLEMENT_STANDARD_RTTIEXT(CDM_Application,Standard_Transient)
+//=======================================================================
+//function : Constructor
+//purpose :
+//=======================================================================
+CDM_Application::CDM_Application()
+{
+ myMessenger = new Message_Messenger;
+}
//=======================================================================
//function : SetDocumentVersion
//purpose :
Handle(Message_Messenger) CDM_Application::MessageDriver()
{
- static Handle(Message_Messenger) theMessenger;
- if(theMessenger.IsNull())
- theMessenger = Message::DefaultMessenger();
- return theMessenger;
+ return myMessenger;
}
//=======================================================================
//purpose :
//=======================================================================
-void CDM_Application::BeginOfUpdate (const Handle(CDM_Document)& aDocument)
+void CDM_Application::BeginOfUpdate (const Handle(CDM_Document)& /*aDocument*/)
{
- TCollection_ExtendedString updating("Updating:");
- updating+=aDocument->Presentation();
+ TCollection_ExtendedString updating("Updating: ");
+ updating += "Document";
Write(updating.ToExtString());
}
//=======================================================================
void CDM_Application::EndOfUpdate
- (const Handle(CDM_Document)& aDocument,
+ (const Handle(CDM_Document)& /*aDocument*/,
const Standard_Boolean theStatus,
const TCollection_ExtendedString& /*ErrorString*/)
{
TCollection_ExtendedString message;
if (theStatus)
- message="Updated:";
+ message="Updated: ";
else
- message="Error during updating:";
+ message="Error during updating: ";
- message+=aDocument->Presentation();
+ message+="Document";
Write(message.ToExtString());
}
return TCollection_AsciiString();
}
+//=======================================================================
+//function : MetaDataLookUpTable
+//purpose : returns the MetaData LookUpTable
+//=======================================================================
+CDM_MetaDataLookUpTable* CDM_Application::MetaDataLookUpTable()
+{
+ return &myMetaDataLookUpTable;
+}
+
//=======================================================================
//function : DumpJson
//purpose :
#include <Standard_ExtString.hxx>
#include <TCollection_AsciiString.hxx>
#include <TCollection_ExtendedString.hxx>
+#include <CDM_MetaDataLookUpTable.hxx>
#include <Message_ProgressIndicator.hxx>
class CDM_Reference;
//! Returns the application version.
Standard_EXPORT virtual TCollection_AsciiString Version() const;
+ //! Returns MetaData LookUpTable
+ 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;
protected:
-
+ Standard_EXPORT CDM_Application();
+
Standard_EXPORT void SetDocumentVersion (const Handle(CDM_Document)& aDocument, const Handle(CDM_MetaData)& aMetaData) const;
Standard_EXPORT void SetReferenceCounter (const Handle(CDM_Document)& aDocument, const Standard_Integer aReferenceCounter);
-
-
private:
//! returns -1 if the metadata has no modification counter.
Standard_EXPORT virtual Standard_Integer DocumentVersion (const Handle(CDM_MetaData)& aMetaData) = 0;
-
+ Handle(Message_Messenger) myMessenger;
+ CDM_MetaDataLookUpTable myMetaDataLookUpTable;
};
--- /dev/null
+// 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
+++ /dev/null
-// Copyright (c) 2015 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_DataMapIteratorOfPresentationDirectory_HeaderFile
-#define CDM_DataMapIteratorOfPresentationDirectory_HeaderFile
-
-#include <CDM_PresentationDirectory.hxx>
-
-#endif
#include <CDM_ListOfDocument.hxx>
#include <CDM_MetaData.hxx>
#include <CDM_NamesDirectory.hxx>
-#include <CDM_PresentationDirectory.hxx>
#include <CDM_Reference.hxx>
#include <CDM_ReferenceIterator.hxx>
#include <Resource_Manager.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDM_Document,Standard_Transient)
-static CDM_PresentationDirectory& getPresentations() {
- static CDM_PresentationDirectory thePresentations;
- return thePresentations;
-}
-
//=======================================================================
//function : CDM_Document
//purpose :
CDM_Document::CDM_Document():
myResourcesAreLoaded (Standard_False),
- myValidPresentation (Standard_False),
myVersion (1),
myActualReferenceIdentifier (0),
myStorageVersion (0),
return theReference;
}
-static CDM_ListOfDocument& getListOfDocumentToUpdate() {
- static CDM_ListOfDocument theListOfDocumentToUpdate;
- return theListOfDocumentToUpdate;
-}
-
//=======================================================================
//function : IsInSession
//purpose :
//function : UpdateFromDocuments
//purpose :
//=======================================================================
-
void CDM_Document::UpdateFromDocuments(const Standard_Address aModifContext) const
{
- Standard_Boolean StartUpdateCycle=getListOfDocumentToUpdate().IsEmpty();
-
+ CDM_ListOfDocument aListOfDocumentsToUpdate;
+ Standard_Boolean StartUpdateCycle = aListOfDocumentsToUpdate.IsEmpty();
CDM_ListIteratorOfListOfReferences it(myFromReferences);
for(; it.More() ; it.Next()) {
Handle(CDM_Document) theFromDocument=it.Value()->FromDocument();
CDM_ListIteratorOfListOfDocument itUpdate;
-
for(; itUpdate.More(); itUpdate.Next()) {
if(itUpdate.Value() == theFromDocument) break;
-
+
if(itUpdate.Value()->ShallowReferences(theFromDocument)) {
- getListOfDocumentToUpdate().InsertBefore(theFromDocument,itUpdate);
+ aListOfDocumentsToUpdate.InsertBefore(theFromDocument,itUpdate);
break;
}
}
- if(!itUpdate.More()) getListOfDocumentToUpdate().Append(theFromDocument);
+ if(!itUpdate.More()) aListOfDocumentsToUpdate.Append(theFromDocument);
theFromDocument->Update(this,it.Value()->ReferenceIdentifier(),aModifContext);
}
Handle(CDM_Application) theApplication;
TCollection_ExtendedString ErrorString;
- while(!getListOfDocumentToUpdate().IsEmpty()) {
- theDocumentToUpdate=getListOfDocumentToUpdate().First();
+ while(!aListOfDocumentsToUpdate.IsEmpty()) {
+ theDocumentToUpdate = aListOfDocumentsToUpdate.First();
theApplication=theDocumentToUpdate->Application();
ErrorString.Clear();
theApplication->BeginOfUpdate(theDocumentToUpdate);
theApplication->EndOfUpdate (theDocumentToUpdate,
theDocumentToUpdate->Update(ErrorString),
ErrorString);
- getListOfDocumentToUpdate().RemoveFirst();
+ aListOfDocumentsToUpdate.RemoveFirst();
}
}
}
return myComments(1).ToExtString();
}
-//=======================================================================
-//function : Presentation
-//purpose :
-//=======================================================================
-
-Standard_ExtString CDM_Document::Presentation()
-{
- if(!myValidPresentation) ComputePresentation();
- return myPresentation.ToExtString();
-}
-
-//=======================================================================
-//function : UnvalidPresentation
-//purpose :
-//=======================================================================
-
-void CDM_Document::UnvalidPresentation()
-{
- if(myValidPresentation) {
- getPresentations().UnBind(myPresentation);
- myValidPresentation=Standard_False;
- }
-}
-
-//=======================================================================
-//function : ComputePresentation
-//purpose :
-//=======================================================================
-
-void CDM_Document::ComputePresentation()
-{
- TCollection_ExtendedString presentation("");
- static Standard_Integer theUnnamedDocuments(0);
- static CDM_NamesDirectory theNames;
-
- if(!myMetaData.IsNull()) {
- presentation += myMetaData->Name();
- if(!theNames.IsBound(presentation)) theNames.Bind(presentation,0);
- Standard_Integer range = theNames(presentation);
- range += 1;
- theNames(presentation) = range;
- if(range != 1) {
- presentation += "<";
- presentation += range;
- presentation += ">";
- }
- }
- else {
- presentation = "Document_";
- presentation += ++theUnnamedDocuments;
- }
-
- if(getPresentations().IsBound(presentation)) {
- TCollection_ExtendedString Test = presentation;
- Test += "!";
- Standard_Integer Count=0;
- while (getPresentations().IsBound(Test)) {
- Count++;
- Test = presentation; Test+= "!"; Test+= Count;
- }
- presentation = Test;
- }
-
-
- myPresentation = TCollection_ExtendedString(presentation);
- myValidPresentation = Standard_True;
- getPresentations().Bind(presentation,this);
-}
-
-//=======================================================================
-//function : FindFromPresentation
-//purpose :
-//=======================================================================
-
-Handle(CDM_Document) CDM_Document::FindFromPresentation
- (const TCollection_ExtendedString& aPresentation)
-{
- TCollection_ExtendedString x(aPresentation);
- if(!getPresentations().IsBound(x)) {
- Standard_SStream aMsg;
- aMsg <<"No document having this presentation: " << x << " does exist."
- << std::endl << (char)0;
- throw Standard_NoSuchObject(aMsg.str().c_str());
- }
- return getPresentations()(x);
-}
-
-//=======================================================================
-//function : FindPresentation
-//purpose :
-//=======================================================================
-
-Standard_Boolean CDM_Document::FindPresentation
- (const TCollection_ExtendedString& aPresentation)
-{
- return getPresentations().IsBound(aPresentation);
-}
-
//=======================================================================
//function : IsStored
//purpose :
aMetaData->SetDocument(this);
// Update the document refencing this MetaData:
- CDM_DataMapIteratorOfMetaDataLookUpTable it(CDM_MetaData::LookUpTable());
+ CDM_DataMapIteratorOfMetaDataLookUpTable it(*CDM_MetaData::LookUpTable());
for(;it.More();it.Next()) {
const Handle(CDM_MetaData)& theMetaData=it.Value();
if(theMetaData != aMetaData && theMetaData->IsRetrieved()) {
}
}
if(!myMetaData.IsNull()) {
- if(myMetaData->Name() != aMetaData->Name()) UnvalidPresentation();
myMetaData->UnsetDocument();
}
- else
- UnvalidPresentation();
}
myStorageVersion = Modifications();
{
if(!myMetaData.IsNull()) {
myMetaData->UnsetDocument();
-// myMetaData.Nullify();
}
}
if(!myMetaData.IsNull())
myRequestedName=myMetaData->Name();
else
- myRequestedName=Presentation();
+ myRequestedName="Document_";
}
myRequestedNameIsDefined=Standard_True;
return myRequestedName;
RemoveAllReferences();
UnsetIsStored();
myApplication.Nullify();
- UnvalidPresentation();
}
const TCollection_ExtendedString& aComment = aCommentIt.Value();
OCCT_DUMP_FIELD_VALUE_STRING (theOStream, aComment)
}
- OCCT_DUMP_FIELD_VALUE_STRING (theOStream, myPresentation)
- OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myValidPresentation)
for (CDM_ListOfReferences::Iterator aFromReferenceIt (myFromReferences); aFromReferenceIt.More(); aFromReferenceIt.Next())
{
#include <TColStd_SequenceOfExtendedString.hxx>
#include <TCollection_ExtendedString.hxx>
#include <Standard_OStream.hxx>
+#include <CDM_ListOfDocument.hxx>
class CDM_MetaData;
class CDM_Application;
//! the comment is an empty string.
Standard_EXPORT Standard_ExtString Comment() const;
- //! Returns an alphanumeric string identifying this document
- //! in a unique manner in the current process. The presentation
- //! may change when the document is stored.
- //! Tries to get the 'FileFormat`.Presentation resource
- //! This item is used to give a default presentation
- //! to the document.
- Standard_EXPORT Standard_ExtString Presentation();
-
- //! returns the document having the given alphanumeric presentation.
- Standard_EXPORT static Handle(CDM_Document) FindFromPresentation (const TCollection_ExtendedString& aPresentation);
-
- //! indicates whether a document having the given presentation
- //! does exist.
- Standard_EXPORT static Standard_Boolean FindPresentation (const TCollection_ExtendedString& aPresentation);
-
Standard_EXPORT Standard_Boolean IsStored() const;
//! returns the value of the modification counter at the
//! the manager returned by this method will be
//! used to search for the following resource items.
Standard_EXPORT Handle(Resource_Manager) StorageResource();
-
- Standard_EXPORT void ComputePresentation();
-
- Standard_EXPORT void UnvalidPresentation();
Standard_EXPORT void AddToReference (const Handle(CDM_Reference)& aReference);
Standard_EXPORT void RemoveFromReference (const Standard_Integer aReferenceIdentifier);
+
TColStd_SequenceOfExtendedString myComments;
- TCollection_ExtendedString myPresentation;
- Standard_Boolean myValidPresentation;
CDM_ListOfReferences myFromReferences;
CDM_ListOfReferences myToReferences;
Standard_Integer myVersion;
Standard_Boolean myDescriptionWasFound;
Handle(CDM_Application) myApplication;
Standard_Integer myStorageFormatVersion;
-
};
#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_Type.hxx>
#include <TCollection_ExtendedString.hxx>
+#include <OSD_Thread.hxx>
IMPLEMENT_STANDARD_RTTIEXT(CDM_MetaData,Standard_Transient)
-static CDM_MetaDataLookUpTable& getLookUpTable(){
- static CDM_MetaDataLookUpTable theLookUpTable;
- return theLookUpTable;
-}
CDM_MetaData::CDM_MetaData(const TCollection_ExtendedString& aFolder, const TCollection_ExtendedString& aName, const TCollection_ExtendedString& aPath,const TCollection_ExtendedString& aFileName,const Standard_Boolean ReadOnly):
myIsRetrieved(Standard_False),
myDocument(NULL),
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
- if(!getLookUpTable().IsBound(aConventionalPath)) {
+ CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
+ if (!aLookUpTable) return theMetaData;
+ if(!aLookUpTable->IsBound(aConventionalPath)) {
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aFileName,ReadOnly);
- getLookUpTable().Bind(aConventionalPath,theMetaData);
+ aLookUpTable->Bind(aConventionalPath, theMetaData);
}
else
- theMetaData = getLookUpTable()(aConventionalPath);
+ theMetaData = aLookUpTable->Find(aConventionalPath);
return theMetaData;
}
Handle(CDM_MetaData) theMetaData;
TCollection_ExtendedString aConventionalPath=aPath;
aConventionalPath.ChangeAll('\\','/');
- if(!getLookUpTable().IsBound(aConventionalPath)) {
+ CDM_MetaDataLookUpTable* aLookUpTable = LookUpTable();
+ if (!aLookUpTable) return theMetaData;
+ if(!aLookUpTable->IsBound(aConventionalPath)) {
theMetaData = new CDM_MetaData(aFolder,aName,aPath,aVersion,aFileName,ReadOnly);
- getLookUpTable().Bind(aConventionalPath,theMetaData);
+ aLookUpTable->Bind(aConventionalPath,theMetaData);
}
else
- theMetaData = getLookUpTable()(aConventionalPath);
+ theMetaData = aLookUpTable->Find(aConventionalPath);
return theMetaData;
}
Standard_OStream& CDM_MetaData::operator << (Standard_OStream& anOStream) {
return Print(anOStream);
}
-const CDM_MetaDataLookUpTable& CDM_MetaData::LookUpTable() {
- return getLookUpTable();
+
+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);
Standard_EXPORT void SetDocument (const Handle(CDM_Document)& aDocument);
- Standard_EXPORT static const CDM_MetaDataLookUpTable& LookUpTable();
+ Standard_EXPORT static CDM_MetaDataLookUpTable* LookUpTable();
Standard_EXPORT Standard_Integer DocumentVersion (const Handle(CDM_Application)& anApplication);
#include <TCollection_ExtendedString.hxx>
#include <NCollection_DataMap.hxx>
-
+class CDM_MetaData;
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_MetaData),TCollection_ExtendedString> CDM_MetaDataLookUpTable;
typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_MetaData),TCollection_ExtendedString>::Iterator CDM_DataMapIteratorOfMetaDataLookUpTable;
+++ /dev/null
-// 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_PresentationDirectory_HeaderFile
-#define CDM_PresentationDirectory_HeaderFile
-
-#include <TCollection_ExtendedString.hxx>
-#include <CDM_Document.hxx>
-#include <TCollection_ExtendedString.hxx>
-#include <NCollection_DataMap.hxx>
-
-typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_Document),TCollection_ExtendedString> CDM_PresentationDirectory;
-typedef NCollection_DataMap<TCollection_ExtendedString,Handle(CDM_Document),TCollection_ExtendedString>::Iterator CDM_DataMapIteratorOfPresentationDirectory;
-
-
-#endif
CDM_Application.hxx
CDM_CanCloseStatus.hxx
CDM_DataMapIteratorOfMetaDataLookUpTable.hxx
-CDM_DataMapIteratorOfPresentationDirectory.hxx
CDM_Document.cxx
CDM_Document.hxx
CDM_DocumentHasher.hxx
CDM_MetaData.hxx
CDM_MetaDataLookUpTable.hxx
CDM_NamesDirectory.hxx
-CDM_PresentationDirectory.hxx
+CDM_ApplicationDirectory.hxx
CDM_Reference.cxx
CDM_Reference.hxx
CDM_ReferenceIterator.cxx
Handle(PCDM_ReadWriter) PCDM_ReadWriter::Reader
(const TCollection_ExtendedString&)
{
- static Handle(PCDM_ReadWriter_1) theReader=new PCDM_ReadWriter_1;
- return theReader;
+ return (new PCDM_ReadWriter_1);
}
//=======================================================================
Handle(PCDM_ReadWriter) PCDM_ReadWriter::Writer ()
{
- static Handle(PCDM_ReadWriter_1) theWriter=new PCDM_ReadWriter_1;
- return theWriter;
+ return (new PCDM_ReadWriter_1);
}
//=======================================================================
if (PCDM::FileDriverType (theFileName, theFileDriver) == PCDM_TOFD_Unknown)
return ::TryXmlDriverType (theFileName);
- static Standard_Boolean theFileIsOpen;
- theFileIsOpen=Standard_False;
-
+ Standard_Boolean theFileIsOpen(Standard_False);
try {
OCC_CATCH_SIGNALS
Standard_Integer PCDM_ReadWriter_1::ReadReferenceCounter(const TCollection_ExtendedString& aFileName, const Handle(Message_Messenger)& theMsgDriver) const {
- static Standard_Integer theReferencesCounter ;
- theReferencesCounter=0;
- static Standard_Integer i ;
-
+ Standard_Integer theReferencesCounter(0) ;
+ Standard_Integer i ;
Handle(Storage_BaseDriver) theFileDriver;
TCollection_AsciiString aFileNameU(aFileName);
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
return theReferencesCounter;
- static Standard_Boolean theFileIsOpen ;
- theFileIsOpen=Standard_False;
-
+ Standard_Boolean theFileIsOpen(Standard_False);
try {
OCC_CATCH_SIGNALS
PCDM_ReadWriter::Open(theFileDriver,aFileName,Storage_VSRead);
TColStd_SequenceOfExtendedString& theUserInfo,
const Handle(Message_Messenger)&)
{
- static Standard_Integer i ;
+ Standard_Integer i ;
Handle(Storage_BaseDriver) theFileDriver;
TCollection_AsciiString aFileNameU(aFileName);
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
Standard_Integer PCDM_ReadWriter_1::ReadDocumentVersion(const TCollection_ExtendedString& aFileName, const Handle(Message_Messenger)& theMsgDriver) const {
- static Standard_Integer theVersion ;
- theVersion=-1;
-
+ Standard_Integer theVersion(-1);
Handle(Storage_BaseDriver) theFileDriver;
TCollection_AsciiString aFileNameU(aFileName);
if(PCDM::FileDriverType(aFileNameU, theFileDriver) == PCDM_TOFD_Unknown)
return theVersion;
- static Standard_Boolean theFileIsOpen ;
- theFileIsOpen =Standard_False;
+ Standard_Boolean theFileIsOpen(Standard_False);
try {
OCC_CATCH_SIGNALS
hd.Read (theFileDriver);
const TColStd_SequenceOfAsciiString &refUserInfo = hd.UserInfo();
- static Standard_Integer i ;
+ Standard_Integer i ;
for ( i =1; i<= refUserInfo.Length() ; i++) {
if(refUserInfo(i).Search(MODIFICATION_COUNTER) != -1) {
try { OCC_CATCH_SIGNALS theVersion=refUserInfo(i).Token(" ",2).IntegerValue();}
Handle(Storage_Data) theData = new Storage_Data;
- static Standard_Boolean Failure;
- Failure=Standard_False;
+ Standard_Boolean Failure(Standard_False);
Standard_SStream aMsg; aMsg << "error during Make:";
PCDM_SequenceOfDocument thePersistentDocuments;
{
#include <TDocStd_Application.hxx>
#include <TDocStd_Document.hxx>
#include <DDocStd.hxx>
-#include <CDF.hxx>
#include <Resource_Manager.hxx>
#include <TopoDS_Wire.hxx>
return 0;
}
+#include <Standard_Mutex.hxx>
+#include <NCollection_Sequence.hxx>
+#include <BinLDrivers.hxx>
+#include <BinDrivers.hxx>
+#include <XmlLDrivers.hxx>
+#include <XmlDrivers.hxx>
+#include <StdLDrivers.hxx>
+#include <StdDrivers.hxx>
+#include <TDF_ChildIterator.hxx>
+#include <TDocStd_PathParser.hxx>
+#include <OSD.hxx>
+#include <OSD_Thread.hxx>
+#include <OSD_Environment.hxx>
+typedef NCollection_Sequence <TCollection_AsciiString> SequenceOfDocNames;
+
+typedef struct
+{
+ Standard_ThreadId ID;
+ int iThread;
+ TCollection_AsciiString inFile[3];
+ TCollection_AsciiString outFile[2];
+ bool finished;
+ int* res;
+} Args;
+
+static void printMsg(const char* msg)
+{
+ printf("%s\n", msg);
+}
+
+static Standard_Integer nbREP(50);
+
+void* threadFunction(void* theArgs)
+{
+ Args* args = (Args*)theArgs;
+ try
+ {
+ if(args->inFile[0].IsEmpty())
+ {
+ *(args->res) = -1;
+ return args->res;
+ }
+
+ Handle(TDocStd_Application) anApp = new TDocStd_Application();
+ OCC_CATCH_SIGNALS;
+ BinLDrivers::DefineFormat(anApp);
+ BinDrivers::DefineFormat(anApp);
+ XmlLDrivers::DefineFormat(anApp);
+ XmlDrivers::DefineFormat(anApp);
+ StdLDrivers::DefineFormat(anApp);
+ StdDrivers::DefineFormat(anApp);
+
+ for (int aFileIndex = 0; aFileIndex < 3; aFileIndex++)
+ {
+ TCollection_AsciiString aDocName = args->inFile[aFileIndex];
+ Handle(TDocStd_Document) aDoc;
+ for (int i = 1; i <= nbREP; i++) {
+
+ PCDM_ReaderStatus aStatus = anApp->Open(aDocName, aDoc);
+ if (aStatus != PCDM_RS_OK) {
+ args->finished = true;
+ *(args->res) = -1;
+ return args->res;
+ }
+ else {
+ TDF_Label aLabel = aDoc->Main();
+ TDF_ChildIterator anIt(aLabel, Standard_True);
+ for (; anIt.More(); anIt.Next()) {
+ const TDF_Label& aLab = anIt.Value();
+ Handle(TDataStd_AsciiString) anAtt;
+ aLab.FindAttribute(TDataStd_AsciiString::GetID(), anAtt);
+ if (!anAtt.IsNull()) {
+ TCollection_AsciiString aStr = anAtt->Get();
+ if (aStr.IsEqual(aDocName)) {
+ *(args->res) = (int)aLab.Tag();
+ break;
+ }
+ }
+ }
+
+ if (aFileIndex != 2) {
+ TCollection_AsciiString anOutDocName = args->outFile[aFileIndex];
+ anApp->SaveAs(aDoc, anOutDocName);
+ }
+ anApp->Close(aDoc);
+ }
+ }
+ }
+ args->finished = true;
+ anApp->RemoveFromSession();
+ }
+ catch (...)
+ {
+ args->finished = true;
+ *(args->res) = -1;
+ return args->res;
+ }
+ args->finished = true;
+ return args->res;
+}
+
+int getNumCores()
+{
+#ifdef WIN32
+ SYSTEM_INFO sysinfo;
+ GetSystemInfo(&sysinfo);
+ return sysinfo.dwNumberOfProcessors;
+#elif MACOS
+ int nm[2];
+ size_t len = 4;
+ uint32_t count;
+
+ nm[0] = CTL_HW; nm[1] = HW_AVAILCPU;
+ sysctl(nm, 2, &count, &len, NULL, 0);
+
+ if (count < 1) {
+ nm[1] = HW_NCPU;
+ sysctl(nm, 2, &count, &len, NULL, 0);
+ if (count < 1) { count = 1; }
+ }
+ return count;
+#else
+ return sysconf(_SC_NPROCESSORS_ONLN);
+#endif
+}
+
+//=======================================================================
+//function : OCC29195
+//purpose :
+//=======================================================================
+static Standard_Integer OCC29195(Draw_Interpretor&, Standard_Integer theArgC, const char** theArgV)
+{
+ if (theArgC < 2)
+ {
+ std::cout << "\nOCC29195 [nbRep] doc1.cbf doc1.xml doc1.std outDoc1.cbf outDoc1.xml doc2.cbf doc2.xml doc2.std outDoc2.cbf outDoc2.xml ...], where:";
+ std::cout << "\nnbRep - number repetitions of a thread function (by default - 50)";
+ std::cout << "\ndocN - names (5 in each group) of OCAF documents names (3 input files, 2 output)\n" << std::endl;
+ return 1;
+ }
+ int iThread(0), nbThreads(0), off(0);
+ if (TCollection_AsciiString(theArgV[1]).IsIntegerValue())
+ {
+ nbREP = TCollection_AsciiString(theArgV[1]).IntegerValue();
+ off = 1;
+ }
+ if (theArgC - off - 1 < 5 || (theArgC - off - 1) % 5 != 0 )
+ {
+ printMsg("TEST is FAILED: number of arguments is invalid\n");
+ return 0;
+ }
+ Standard_Integer aNbFiles = (theArgC - off - 1) / 5;
+ nbThreads = getNumCores();
+ if (aNbFiles < nbThreads)
+ {
+ nbThreads = aNbFiles;
+ }
+ // Allocate data
+ Args* args = new Args[nbThreads];
+ OSD_Thread* threads = new OSD_Thread[nbThreads];
+ while (iThread < nbThreads)
+ {
+ if (iThread < aNbFiles)
+ {
+ args[iThread].inFile[0] = theArgV[iThread * 5 + off + 1];
+ args[iThread].inFile[1] = theArgV[iThread * 5 + off + 2];
+ args[iThread].inFile[2] = theArgV[iThread * 5 + off + 3];
+ args[iThread].outFile[0] = theArgV[iThread * 5 + off + 4];
+ args[iThread].outFile[1] = theArgV[iThread * 5 + off + 5];
+ }
+ args[iThread].iThread = iThread;
+ args[iThread].ID = threads[iThread].GetId();
+ args[iThread].finished = false;
+ args[iThread].res = new int;
+ threads[iThread].SetFunction(&threadFunction);
+ iThread++;
+ }
+ for (iThread = 0; iThread < nbThreads; iThread++)
+ {
+ args[iThread].finished = false;
+ threads[iThread].Run((void*)&(args[iThread]));
+ }
+ // Sleep while the threads are run.
+ bool finished = false;
+ while (!finished)
+ {
+ OSD::MilliSecSleep(100);
+ finished = true;
+ for (iThread = 0; iThread < nbThreads && finished; iThread++)
+ {
+ finished = args[iThread].finished;
+ }
+ }
+ OSD_Environment anEnv("Result29195");
+ for (iThread = 0; iThread < nbThreads; iThread++)
+ {
+ if (*(args[iThread].res) == -1)
+ {
+ printMsg("OCC29195 is FAILED\n");
+ anEnv.SetValue("FAILED_ERR");
+ break;
+ }
+ }
+ if (iThread == nbThreads)
+ {
+ printMsg("OCC29195 is finished OK\n");
+ anEnv.SetValue("OK");
+ }
+ anEnv.Build();
+ return 0;
+}
+
//=======================================================================
//function : QAStartsWith string startstring
//=======================================================================
theCommands.Add("OCC29807", "OCC29807 surface1 surface2 u1 v1 u2 v2", __FILE__, OCC29807, group);
theCommands.Add("OCC29311", "OCC29311 shape counter nbiter: check performance of OBB calculation", __FILE__, OCC29311, group);
theCommands.Add("OCC30391", "OCC30391 result face LenBeforeUfirst LenAfterUlast LenBeforeVfirst LenAfterVlast", __FILE__, OCC30391, group);
+ theCommands.Add("OCC29195", "OCC29195 [nbRep] doc1 [doc2 [doc3 [doc4]]]", __FILE__, OCC29195, group);
theCommands.Add("OCC30435", "OCC30435 result curve inverse nbit", __FILE__, OCC30435, group);
theCommands.Add("OCC30990", "OCC30990 surface", __FILE__, OCC30990, group);
#include <TDocStd.hxx>
-#include <CDF.hxx>
#include <OSD_Environment.hxx>
#include <TDocStd_XLink.hxx>
#include <TDocStd_Document.hxx>
#include <TDocStd_Owner.hxx>
#include <TDocStd_PathParser.hxx>
+#include <OSD_Thread.hxx>
#include<Message_ProgressSentry.hxx>
TDocStd_Application::TDocStd_Application()
: myIsDriverLoaded (Standard_True)
{
- myMessageDriver = CDM_Application::MessageDriver();
- Handle(CDF_Session) S;
- if (!CDF_Session::Exists()) S = new CDF_Session();
- else S = CDF_Session::CurrentSession();
- S->SetCurrentApplication(this);
- try
- {
- OCC_CATCH_SIGNALS
- S->LoadDriver();
- }
- catch (Plugin_Failure const&)
- {
+ AddToSession();
+ if(myMetaDataDriver.IsNull())
myIsDriverLoaded = Standard_False;
- }
}
return myIsDriverLoaded;
}
-//=======================================================================
-//function : MessageDriver
-//purpose :
-//=======================================================================
-Handle(Message_Messenger) TDocStd_Application::MessageDriver()
-{
- return myMessageDriver;
-}
-
//=======================================================================
//function : Resources
//purpose :
{
if (!CDF_Session::Exists())
throw Standard_DomainError("TDocStd_Application::NbDocuments");
- Handle(CDF_Session) S = CDF_Session::CurrentSession();
- return S->Directory()->Length();
+ return this->myDirectory->Length();
}
//=======================================================================
{
if (!CDF_Session::Exists())
throw Standard_DomainError("TDocStd_Application::NbDocuments");
- Handle(CDF_Session) S = CDF_Session::CurrentSession();
- CDF_DirectoryIterator it (S->Directory());
+ CDF_DirectoryIterator it (myDirectory);
Standard_Integer current = 0;
for (;it.MoreDocument();it.NextDocument()) {
current++;
// 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 :
//! Check if meta data driver was successfully loaded
//! by the application constructor
Standard_EXPORT Standard_Boolean IsDriverLoaded() const;
-
- //! Redefines message driver, by default outputs to std::cout.
- Standard_EXPORT virtual Handle(Message_Messenger) MessageDriver() Standard_OVERRIDE;
//! Returns resource manager defining supported persistent formats.
//!
//! Dumps the content of me into the stream
Standard_EXPORT void DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth = -1) const;
- DEFINE_STANDARD_RTTIEXT(TDocStd_Application,CDF_Application)
+ //! Remove this application from the current session
+ Standard_EXPORT Standard_Boolean RemoveFromSession();
+
+ DEFINE_STANDARD_RTTIEXT(TDocStd_Application, CDF_Application)
protected:
- Handle(Message_Messenger) myMessageDriver;
+
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
TKSTL
TKXml
TKTObj
+TKXmlL
+TKBin
+TKBinL
+TKStd
+TKStdL
CSF_gdi32
CSF_advapi32
CSF_user32
#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"
//function : GetInstance
//purpose :
//=======================================================================
-
Handle(TObj_Application) TObj_Application::GetInstance()
{
- static Handle(TObj_Application) anInstance = new TObj_Application;
- return anInstance;
+ Handle(CDF_Session) aSession = CDF_Session::Create();
+ Handle(CDF_Application) anApp;
+ if (aSession->FindApplication(OSD_Thread::Current(), anApp))
+ return Handle(TObj_Application)::DownCast(anApp);
+ return new TObj_Application;
}
//=======================================================================
void TObjDRAW::Factory(Draw_Interpretor& theDI)
{
// Initialize TObj OCAF formats
- Handle(TDocStd_Application) anApp = DDocStd::GetApplication();
+ Handle(TDocStd_Application) anApp = TObj_Application::GetInstance();//DDocStd::GetApplication();
BinTObjDrivers::DefineFormat(anApp);
XmlTObjDrivers::DefineFormat(anApp);
// define formats for TObj specific application
- anApp = TObj_Application::GetInstance();
BinTObjDrivers::DefineFormat(anApp);
XmlTObjDrivers::DefineFormat(anApp);
#include <Standard_Boolean.hxx>
#include <XmlObjMgt_Element.hxx>
#include <Standard_Integer.hxx>
+
class XmlMDF_ADriverTable;
class TCollection_ExtendedString;
class CDM_Document;
const Handle(Message_ProgressIndicator)& theProgress = NULL);
Handle(XmlMDF_ADriverTable) myDrivers;
- XmlObjMgt_SRelocationTable myRelocTable;
-
+ XmlObjMgt_SRelocationTable myRelocTable;
private:
--- /dev/null
+pload QAcommands
+##set imagedir [pwd]
+
+set aFile1 [locate_data_file bug29195_1.cbf]
+set aFile2 [locate_data_file bug29195_2.cbf]
+set aFile3 [locate_data_file bug29195_3.cbf]
+set aFile4 [locate_data_file bug29195_4.cbf]
+set aFile5 [locate_data_file bug29195_1.xml]
+set aFile6 [locate_data_file bug29195_2.xml]
+set aFile7 [locate_data_file bug29195_3.xml]
+set aFile8 [locate_data_file bug29195_4.xml]
+set aFile9 [locate_data_file bug29195_1.std]
+set aFile10 [locate_data_file bug29195_2.std]
+set aFile11 [locate_data_file bug29195_3.std]
+set aFile12 [locate_data_file bug29195_4.std]
+
+
+set aNew1 ${imagedir}/new_bug29195_1.cbf
+set aNew2 ${imagedir}/new_bug29195_2.cbf
+set aNew3 ${imagedir}/new_bug29195_3.cbf
+set aNew4 ${imagedir}/new_bug29195_4.cbf
+set aNew5 ${imagedir}/new_bug29195_1.xml
+set aNew6 ${imagedir}/new_bug29195_2.xml
+set aNew7 ${imagedir}/new_bug29195_3.xml
+set aNew8 ${imagedir}/new_bug29195_4.xml
+
+OCC29195 50 $aFile1 $aFile5 $aFile9 ${aNew1} ${aNew5} $aFile2 $aFile6 $aFile10 ${aNew2} ${aNew6} $aFile3 $aFile7 $aFile11 ${aNew3} ${aNew7} $aFile4 $aFile8 $aFile12 ${aNew4} ${aNew8}
+set RES [dgetenv Result29195]
+
+if { [file exists ${aNew1}] } {file delete ${aNew1}}
+if { [file exists ${aNew2}] } {file delete ${aNew2}}
+if { [file exists ${aNew3}] } {file delete ${aNew3}}
+if { [file exists ${aNew4}] } {file delete ${aNew4}}
+if { [file exists ${aNew5}] } {file delete ${aNew5}}
+if { [file exists ${aNew6}] } {file delete ${aNew6}}
+if { [file exists ${aNew7}] } {file delete ${aNew7}}
+if { [file exists ${aNew8}] } {file delete ${aNew8}}
+
+puts "OCC29195 is $RES"
#include <OSD_Directory.hxx>
#include <OSD_Environment.hxx>
#include <OSD_Protection.hxx>
-
+#include <OSD_Thread.hxx>
#include <inspector/View_Displayer.hxx>
#include <inspector/View_ToolBar.hxx>
#include <inspector/View_Viewer.hxx>
#include <inspector/ViewControl_Tools.hxx>
#include <Standard_WarningsDisable.hxx>
+#include <Standard_ThreadId.hxx>
#include <QAction>
#include <QApplication>
#include <QComboBox>
}
else
{
- if (anApplication.IsNull() && CDF_Session::Exists())
- anApplication = Handle(TDocStd_Application)::DownCast (CDF_Session::CurrentSession()->CurrentApplication());
+ if (anApplication.IsNull() && CDF_Session::Exists()) {
+ Standard_ThreadId anID = OSD_Thread::Current();
+ Handle(CDF_Application) anApp;
+ CDF_Session::CurrentSession()->FindApplication(anID, anApp);
+ anApplication = Handle(TDocStd_Application)::DownCast (anApp);
+ }
}
myModule = new DFBrowser_Module();
Handle(CDF_Session) aSession = CDF_Session::CurrentSession();
if (!aSession.IsNull())
{
- anApplication = Handle(TDocStd_Application)::DownCast (CDF_Session::CurrentSession()->CurrentApplication());
+ Standard_ThreadId anID = OSD_Thread::Current();
+ Handle(CDF_Application) anApp;
+ CDF_Session::CurrentSession()->FindApplication(anID, anApp);
+ anApplication = Handle(TDocStd_Application)::DownCast (anApp);
if (!anApplication.IsNull())
{
for (int aDocId = 1, aNbDocuments = anApplication->NbDocuments(); aDocId <= aNbDocuments; aDocId++)
// CDM_Document methods
theValues << "Comments" << convertToString (aComments)
- << "Presentation" << DFBrowserPane_Tools::ToString (aDocument->Presentation())
+ // << "Presentation" << DFBrowserPane_Tools::ToString (aDocument->Presentation())
<< "IsStored" << DFBrowserPane_Tools::BoolToStr (aDocument->IsStored())
<< "StorageVersion" << QString::number (aDocument->StorageVersion())
<< "Folder" << (aDocument->IsStored() ? DFBrowserPane_Tools::ToString (aDocument->Folder()) : "")