1 // Created on: 1997-08-08
2 // Created by: Jean-Louis Frenkel
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <CDF_Application.hxx>
19 #include <CDF_Directory.hxx>
20 #include <CDF_FWOSDriver.hxx>
21 #include <CDF_MetaDataDriver.hxx>
22 #include <CDF_MetaDataDriverFactory.hxx>
23 #include <CDF_Session.hxx>
25 #include <PCDM_Reader.hxx>
27 #include <Standard_ErrorHandler.hxx>
28 #include <Standard_Failure.hxx>
29 #include <Standard_GUID.hxx>
30 #include <Standard_MultiplyDefined.hxx>
31 #include <Standard_NoSuchObject.hxx>
32 #include <Standard_Type.hxx>
33 #include <TCollection_ExtendedString.hxx>
35 IMPLEMENT_STANDARD_RTTIEXT(CDF_Session,Standard_Transient)
37 static Handle(CDF_Session) THE_CS;
38 static Standard_Mutex THE_MUTEX;
40 //=======================================================================
43 //=======================================================================
44 CDF_Session::CDF_Session ()
46 Standard_MultiplyDefined_Raise_if(!THE_CS.IsNull()," a session already exists");
49 //=======================================================================
52 //=======================================================================
53 Handle(CDF_Session) CDF_Session::Create()
55 Standard_Mutex::Sentry aLocker(THE_MUTEX);
57 THE_CS = new CDF_Session;
61 //=======================================================================
64 //=======================================================================
65 Standard_Boolean CDF_Session::Exists() {
66 return !THE_CS.IsNull();
69 //=======================================================================
70 //function : CurrentSession
72 //=======================================================================
73 Handle(CDF_Session) CDF_Session::CurrentSession() {
74 Standard_NoSuchObject_Raise_if(THE_CS.IsNull(), "no session has been created");
78 //=======================================================================
79 //function : AddApplication
80 //purpose : adds the application to the session with unique name
81 //=======================================================================
82 Standard_Boolean CDF_Session::AddApplication(const Handle(CDF_Application)& theApp,
83 const Standard_ThreadId theID)
85 return AddApplication(theApp.get(), theID);
88 //=======================================================================
89 //function : AddApplication
90 //purpose : adds the application to the session with unique name
91 //=======================================================================
92 Standard_Boolean CDF_Session::AddApplication(const CDF_Application* theApp,
93 const Standard_ThreadId theID)
95 Standard_Boolean aRetValue(Standard_False);
98 Standard_Mutex::Sentry aLocker(THE_MUTEX);
99 if (!myAppDirectory.IsBound(theID))
101 Handle(CDF_Application) anApp(theApp);
102 aRetValue = myAppDirectory.Bind(theID, anApp);
108 //=======================================================================
109 //function : FindApplication
111 //=======================================================================
112 Standard_Boolean CDF_Session::FindApplication(const Standard_ThreadId theID, Handle(CDF_Application)& theApp) const
114 Standard_Mutex::Sentry aLocker(THE_MUTEX);
115 if (myAppDirectory.IsBound(theID))
117 theApp = Handle(CDF_Application)::DownCast (myAppDirectory.Find(theID));
118 return ! theApp.IsNull();
120 return Standard_False;
122 //=======================================================================
123 //function : RemoveApplication
124 //purpose : removes the application with name=<theName> from the session
125 //=======================================================================
126 Standard_Boolean CDF_Session::RemoveApplication(const Standard_ThreadId theID)
128 Standard_Boolean aRetValue(Standard_False);
129 Standard_Mutex::Sentry aLocker(THE_MUTEX);
130 if (myAppDirectory.IsBound(theID))
132 aRetValue = myAppDirectory.UnBind(theID);