From 18aa7102e93f78e87ac7ebcd04f4b69ce65a5bb3 Mon Sep 17 00:00:00 2001 From: azv Date: Sat, 27 Mar 2021 14:59:28 +0300 Subject: [PATCH] Implement mechanism to remove static variables related to STEP exchange plugin. --- .../IGESData_GlobalNodeOfSpecificLib.hxx | 5 ++- .../IGESData_GlobalNodeOfWriterLib.hxx | 5 ++- src/IGESData/IGESData_SpecificLib.hxx | 5 ++- src/IGESData/IGESData_WriterLib.hxx | 5 ++- src/Interface/Interface_GeneralLib.hxx | 5 ++- .../Interface_GlobalNodeOfGeneralLib.hxx | 5 ++- .../Interface_GlobalNodeOfReaderLib.hxx | 5 ++- src/Interface/Interface_ReaderLib.hxx | 5 ++- src/LibCtl/LibCtl_GlobalNode.gxx | 20 +++++++++ src/LibCtl/LibCtl_Library.gxx | 6 +++ src/RWStepAP214/RWStepAP214.cxx | 43 +++++++++++++++---- .../STEPCAFControl_Controller.cxx | 32 ++++++++++++-- .../StepData_GlobalNodeOfWriterLib.hxx | 5 ++- src/StepData/StepData_WriterLib.hxx | 5 ++- src/XSControl/XSControl_Controller.cxx | 7 +++ src/XSControl/XSControl_Controller.hxx | 11 +++++ 16 files changed, 146 insertions(+), 23 deletions(-) diff --git a/src/IGESData/IGESData_GlobalNodeOfSpecificLib.hxx b/src/IGESData/IGESData_GlobalNodeOfSpecificLib.hxx index e9db7ad2af..bf91d51998 100644 --- a/src/IGESData/IGESData_GlobalNodeOfSpecificLib.hxx +++ b/src/IGESData/IGESData_GlobalNodeOfSpecificLib.hxx @@ -46,7 +46,10 @@ public: //! match) and Same State (that is, IsEqual is not required) //! Once added, stores its attached Protocol in correspondance Standard_EXPORT void Add (const Handle(IGESData_SpecificModule)& amodule, const Handle(IGESData_Protocol)& aprotocol); - + + //! Removes a Module from the list + Standard_EXPORT void Remove(const Handle(IGESData_SpecificModule)& amodule); + //! Returns the Module stored in a given GlobalNode Standard_EXPORT const Handle(IGESData_SpecificModule)& Module() const; diff --git a/src/IGESData/IGESData_GlobalNodeOfWriterLib.hxx b/src/IGESData/IGESData_GlobalNodeOfWriterLib.hxx index cea9c9c7f3..c8f781f9a6 100644 --- a/src/IGESData/IGESData_GlobalNodeOfWriterLib.hxx +++ b/src/IGESData/IGESData_GlobalNodeOfWriterLib.hxx @@ -46,7 +46,10 @@ public: //! match) and Same State (that is, IsEqual is not required) //! Once added, stores its attached Protocol in correspondance Standard_EXPORT void Add (const Handle(IGESData_ReadWriteModule)& amodule, const Handle(IGESData_Protocol)& aprotocol); - + + //! Removes a Module from the list + Standard_EXPORT void Remove(const Handle(IGESData_ReadWriteModule)& amodule); + //! Returns the Module stored in a given GlobalNode Standard_EXPORT const Handle(IGESData_ReadWriteModule)& Module() const; diff --git a/src/IGESData/IGESData_SpecificLib.hxx b/src/IGESData/IGESData_SpecificLib.hxx index 99454e5adb..8f9e0e8004 100644 --- a/src/IGESData/IGESData_SpecificLib.hxx +++ b/src/IGESData/IGESData_SpecificLib.hxx @@ -43,7 +43,10 @@ public: //! Adds a couple (Module-Protocol) into the global definition set //! for this class of Library. Standard_EXPORT static void SetGlobal (const Handle(IGESData_SpecificModule)& amodule, const Handle(IGESData_Protocol)& aprotocol); - + + //! Releases a module from the global definition set. + Standard_EXPORT static void ReleaseGlobal(const Handle(IGESData_SpecificModule)& amodule); + //! Creates a Library which complies with a Protocol, that is : //! Same class (criterium IsInstance) //! This creation gets the Modules from the global set, those diff --git a/src/IGESData/IGESData_WriterLib.hxx b/src/IGESData/IGESData_WriterLib.hxx index d4f394f611..fc37284eb7 100644 --- a/src/IGESData/IGESData_WriterLib.hxx +++ b/src/IGESData/IGESData_WriterLib.hxx @@ -43,7 +43,10 @@ public: //! Adds a couple (Module-Protocol) into the global definition set //! for this class of Library. Standard_EXPORT static void SetGlobal (const Handle(IGESData_ReadWriteModule)& amodule, const Handle(IGESData_Protocol)& aprotocol); - + + //! Releases a module from the global definition set. + Standard_EXPORT static void ReleaseGlobal(const Handle(IGESData_ReadWriteModule)& amodule); + //! Creates a Library which complies with a Protocol, that is : //! Same class (criterium IsInstance) //! This creation gets the Modules from the global set, those diff --git a/src/Interface/Interface_GeneralLib.hxx b/src/Interface/Interface_GeneralLib.hxx index c7c0bf5112..8ddd9b0646 100644 --- a/src/Interface/Interface_GeneralLib.hxx +++ b/src/Interface/Interface_GeneralLib.hxx @@ -42,7 +42,10 @@ public: //! Adds a couple (Module-Protocol) into the global definition set //! for this class of Library. Standard_EXPORT static void SetGlobal (const Handle(Interface_GeneralModule)& amodule, const Handle(Interface_Protocol)& aprotocol); - + + //! Releases a module from the global definition set. + Standard_EXPORT static void ReleaseGlobal(const Handle(Interface_GeneralModule)& amodule); + //! Creates a Library which complies with a Protocol, that is : //! Same class (criterium IsInstance) //! This creation gets the Modules from the global set, those diff --git a/src/Interface/Interface_GlobalNodeOfGeneralLib.hxx b/src/Interface/Interface_GlobalNodeOfGeneralLib.hxx index 713425ef7c..f78cae3a04 100644 --- a/src/Interface/Interface_GlobalNodeOfGeneralLib.hxx +++ b/src/Interface/Interface_GlobalNodeOfGeneralLib.hxx @@ -46,7 +46,10 @@ public: //! match) and Same State (that is, IsEqual is not required) //! Once added, stores its attached Protocol in correspondance Standard_EXPORT void Add (const Handle(Interface_GeneralModule)& amodule, const Handle(Interface_Protocol)& aprotocol); - + + //! Removes a Module from the list + Standard_EXPORT void Remove(const Handle(Interface_GeneralModule)& amodule); + //! Returns the Module stored in a given GlobalNode Standard_EXPORT const Handle(Interface_GeneralModule)& Module() const; diff --git a/src/Interface/Interface_GlobalNodeOfReaderLib.hxx b/src/Interface/Interface_GlobalNodeOfReaderLib.hxx index 6d6c9eac51..5b3b3b78f5 100644 --- a/src/Interface/Interface_GlobalNodeOfReaderLib.hxx +++ b/src/Interface/Interface_GlobalNodeOfReaderLib.hxx @@ -46,7 +46,10 @@ public: //! match) and Same State (that is, IsEqual is not required) //! Once added, stores its attached Protocol in correspondance Standard_EXPORT void Add (const Handle(Interface_ReaderModule)& amodule, const Handle(Interface_Protocol)& aprotocol); - + + //! Removes a Module from the list + Standard_EXPORT void Remove(const Handle(Interface_ReaderModule)& amodule); + //! Returns the Module stored in a given GlobalNode Standard_EXPORT const Handle(Interface_ReaderModule)& Module() const; diff --git a/src/Interface/Interface_ReaderLib.hxx b/src/Interface/Interface_ReaderLib.hxx index 7d982d8e0b..85eef38955 100644 --- a/src/Interface/Interface_ReaderLib.hxx +++ b/src/Interface/Interface_ReaderLib.hxx @@ -42,7 +42,10 @@ public: //! Adds a couple (Module-Protocol) into the global definition set //! for this class of Library. Standard_EXPORT static void SetGlobal (const Handle(Interface_ReaderModule)& amodule, const Handle(Interface_Protocol)& aprotocol); - + + //! Releases a module from the global definition set. + Standard_EXPORT static void ReleaseGlobal(const Handle(Interface_ReaderModule)& amodule); + //! Creates a Library which complies with a Protocol, that is : //! Same class (criterium IsInstance) //! This creation gets the Modules from the global set, those diff --git a/src/LibCtl/LibCtl_GlobalNode.gxx b/src/LibCtl/LibCtl_GlobalNode.gxx index a989a1dad2..5c089d625a 100644 --- a/src/LibCtl/LibCtl_GlobalNode.gxx +++ b/src/LibCtl/LibCtl_GlobalNode.gxx @@ -38,6 +38,26 @@ LibCtl_GlobalNode::LibCtl_GlobalNode () { } else thenext->Add (amodule,aprotocol); } +void LibCtl_GlobalNode::Remove(const Handle(TheModule)& amodule) +{ + if (themod == amodule) + { + if (thenext.IsNull()) + { + themod = Handle(TheModule)(); + theprot = Handle(TheProtocol)(); + } + else + { + themod = thenext->themod; + theprot = thenext->theprot; + thenext = thenext->thenext; + } + } + else if (!thenext.IsNull()) + thenext->Remove(amodule); +} + const Handle(TheModule)& LibCtl_GlobalNode::Module () const { return themod; } diff --git a/src/LibCtl/LibCtl_Library.gxx b/src/LibCtl/LibCtl_Library.gxx index d7fcef9f2b..d6dca27d95 100644 --- a/src/LibCtl/LibCtl_Library.gxx +++ b/src/LibCtl/LibCtl_Library.gxx @@ -36,6 +36,12 @@ static Handle(LibCtl_Node) thelast; theglobal->Add(amodule,aprotocol); } +void LibCtl_Library::ReleaseGlobal(const Handle(TheModule)& amodule) +{ + if (!theglobal.IsNull()) + theglobal->Remove(amodule); +} + // Constructeur d apres Protocole LibCtl_Library::LibCtl_Library (const Handle(TheProtocol)& aprotocol) { diff --git a/src/RWStepAP214/RWStepAP214.cxx b/src/RWStepAP214/RWStepAP214.cxx index 6693363283..ca8a5b73a8 100644 --- a/src/RWStepAP214/RWStepAP214.cxx +++ b/src/RWStepAP214/RWStepAP214.cxx @@ -22,18 +22,43 @@ #include #include -static int THE_RWStepAP214_init = 0; +DEFINE_STANDARD_HANDLE(RWStepAP214_Mgr, Standard_Transient) + +class RWStepAP214_Mgr : public Standard_Transient +{ +public: + RWStepAP214_Mgr() + { + myProtocol = StepAP214::Protocol(); + myGeneralModule = new RWStepAP214_GeneralModule; + myRWModule = new RWStepAP214_ReadWriteModule; + Interface_GeneralLib::SetGlobal(myGeneralModule, myProtocol); + Interface_ReaderLib::SetGlobal(myRWModule, myProtocol); + StepData_WriterLib::SetGlobal(myRWModule, myProtocol); + } + + virtual ~RWStepAP214_Mgr() + { + Interface_GeneralLib::ReleaseGlobal(myGeneralModule); + Interface_ReaderLib::ReleaseGlobal(myRWModule); + StepData_WriterLib::ReleaseGlobal(myRWModule); + } + + DEFINE_STANDARD_RTTI_INLINE(RWStepAP214_Mgr, Standard_Transient) + +private: + Handle(StepAP214_Protocol) myProtocol; + Handle(RWStepAP214_ReadWriteModule) myRWModule; + Handle(RWStepAP214_GeneralModule) myGeneralModule; +}; + +static Handle(RWStepAP214_Mgr) THE_MGR; void RWStepAP214::Init() { - if (THE_RWStepAP214_init) + if (THE_MGR.IsNull()) { - return; + RWHeaderSection::Init(); + THE_MGR = new RWStepAP214_Mgr; } - THE_RWStepAP214_init = 1; - RWHeaderSection::Init(); - Handle(StepAP214_Protocol) proto = StepAP214::Protocol(); - Interface_GeneralLib::SetGlobal (new RWStepAP214_GeneralModule,proto); - Interface_ReaderLib::SetGlobal (new RWStepAP214_ReadWriteModule,proto); - StepData_WriterLib::SetGlobal (new RWStepAP214_ReadWriteModule,proto); } diff --git a/src/STEPCAFControl/STEPCAFControl_Controller.cxx b/src/STEPCAFControl/STEPCAFControl_Controller.cxx index 5e43b80697..be9addfcae 100644 --- a/src/STEPCAFControl/STEPCAFControl_Controller.cxx +++ b/src/STEPCAFControl/STEPCAFControl_Controller.cxx @@ -22,6 +22,33 @@ IMPLEMENT_STANDARD_RTTIEXT(STEPCAFControl_Controller,STEPControl_Controller) + +DEFINE_STANDARD_HANDLE(STEPCAF_Mgr, Standard_Transient) + +class STEPCAF_Mgr : public Standard_Transient +{ +public: + STEPCAF_Mgr() + { + myCtl = new STEPCAFControl_Controller; + // do something to avoid warnings... + myCtl->AutoRecord(); + } + + virtual ~STEPCAF_Mgr() + { + myCtl->AutoRelease(); + } + + DEFINE_STANDARD_RTTI_INLINE(STEPCAF_Mgr, Standard_Transient) + +private: + Handle(STEPCAFControl_Controller) myCtl; +}; + +static Handle(STEPCAF_Mgr) THE_MGR; + + //======================================================================= //function : STEPCAFControl_Controller //purpose : @@ -42,12 +69,9 @@ Standard_Boolean STEPCAFControl_Controller::Init () static Standard_Boolean inic = Standard_False; if (inic) return Standard_True; inic = Standard_True; - // self-registering - Handle(STEPCAFControl_Controller) STEPCTL = new STEPCAFControl_Controller; // do XSAlgo::Init, cause it does not called before. XSAlgo::Init(); - // do something to avoid warnings... - STEPCTL->AutoRecord(); + THE_MGR = new STEPCAF_Mgr; //----------------------------------------------------------- // Few variables for advanced control of translation process diff --git a/src/StepData/StepData_GlobalNodeOfWriterLib.hxx b/src/StepData/StepData_GlobalNodeOfWriterLib.hxx index ee99849f0f..08aebf8f2e 100644 --- a/src/StepData/StepData_GlobalNodeOfWriterLib.hxx +++ b/src/StepData/StepData_GlobalNodeOfWriterLib.hxx @@ -46,7 +46,10 @@ public: //! match) and Same State (that is, IsEqual is not required) //! Once added, stores its attached Protocol in correspondance Standard_EXPORT void Add (const Handle(StepData_ReadWriteModule)& amodule, const Handle(StepData_Protocol)& aprotocol); - + + //! Removes a Module from the list + Standard_EXPORT void Remove(const Handle(StepData_ReadWriteModule)& amodule); + //! Returns the Module stored in a given GlobalNode Standard_EXPORT const Handle(StepData_ReadWriteModule)& Module() const; diff --git a/src/StepData/StepData_WriterLib.hxx b/src/StepData/StepData_WriterLib.hxx index 6f0501e9ae..7682879f80 100644 --- a/src/StepData/StepData_WriterLib.hxx +++ b/src/StepData/StepData_WriterLib.hxx @@ -42,7 +42,10 @@ public: //! Adds a couple (Module-Protocol) into the global definition set //! for this class of Library. Standard_EXPORT static void SetGlobal (const Handle(StepData_ReadWriteModule)& amodule, const Handle(StepData_Protocol)& aprotocol); - + + //! Releases a module from the global definition set. + Standard_EXPORT static void ReleaseGlobal(const Handle(StepData_ReadWriteModule)& amodule); + //! Creates a Library which complies with a Protocol, that is : //! Same class (criterium IsInstance) //! This creation gets the Modules from the global set, those diff --git a/src/XSControl/XSControl_Controller.cxx b/src/XSControl/XSControl_Controller.cxx index e1dc727ba1..8b8fb5c8cc 100644 --- a/src/XSControl/XSControl_Controller.cxx +++ b/src/XSControl/XSControl_Controller.cxx @@ -131,6 +131,13 @@ void XSControl_Controller::Record (const Standard_CString theName) const listad.Bind(theName, this); } +void XSControl_Controller::Release(const Standard_CString theName) const +{ + if (listad.IsBound(theName)) { + listad.UnBind(theName); + } +} + //======================================================================= //function : Recorded //purpose : diff --git a/src/XSControl/XSControl_Controller.hxx b/src/XSControl/XSControl_Controller.hxx index 87b7a4b923..5e8454e429 100644 --- a/src/XSControl/XSControl_Controller.hxx +++ b/src/XSControl/XSControl_Controller.hxx @@ -78,11 +78,22 @@ class XSControl_Controller : public Standard_Transient Record (Name(Standard_True)); Record (Name(Standard_False)); } + + //! Removes from the general dictionary under Short and Long + //! Names (see method Name) + void AutoRelease() const + { + Release (Name(Standard_True)); + Release (Name(Standard_False)); + } //! Records in a general dictionary under a name //! Error if already used for another one Standard_EXPORT void Record (const Standard_CString name) const; + //! Removes from the general dictionary under a name + Standard_EXPORT void Release(const Standard_CString name) const; + //! Returns the Controller attached to a given name //! Returns a Null Handle if is unknown Standard_EXPORT static Handle(XSControl_Controller) Recorded (const Standard_CString name); -- 2.39.5