From acde82d9a3d34c28032d80123aa654197f7c26a4 Mon Sep 17 00:00:00 2001 From: rnv Date: Mon, 14 Nov 2016 18:57:55 +0300 Subject: [PATCH] Restore registering CORBA objects, removed by previous wrong commit --- src/SALOMEDS/SALOMEDS_Server.cxx | 14 ++-- src/SALOMEDS/SALOMEDS_Study_i.cxx | 64 +++++++++++++++++++ src/SALOMEDS/SALOMEDS_Study_i.hxx | 1 + .../SALOMEDSImpl_AttributeIOR.cxx | 12 ++++ src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx | 2 + src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx | 44 +++++++++++++ src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx | 5 ++ .../SALOMEDSImpl_StudyBuilder.cxx | 5 +- 8 files changed, 136 insertions(+), 11 deletions(-) diff --git a/src/SALOMEDS/SALOMEDS_Server.cxx b/src/SALOMEDS/SALOMEDS_Server.cxx index a9893daa2..a1e9a1af1 100644 --- a/src/SALOMEDS/SALOMEDS_Server.cxx +++ b/src/SALOMEDS/SALOMEDS_Server.cxx @@ -59,7 +59,7 @@ int main(int argc, char** argv) #else CORBA::ORB_var orb = CORBA::ORB_init( argc, argv, "omniORB3" ); #endif - SALOME_NamingService* NS; + SALOME_NamingService NS; // Obtain a reference to the root POA. long TIMESleep = 500000000; int NumberOfTries = 40; @@ -109,8 +109,8 @@ int main(int argc, char** argv) if(EnvL==1) { CORBA::ORB_var orb1 = CORBA::ORB_init(argc,argv) ; - NS = SINGLETON_::Instance() ; - NS->init_orb( orb1 ) ; + NS = *SINGLETON_::Instance() ; + NS.init_orb( orb1 ) ; for(int j=1; j<=NumberOfTries; j++) { if (j!=1) @@ -161,13 +161,7 @@ int main(int argc, char** argv) // ready to accept requests. PortableServer::ObjectId_var myStudy_iid = poa->activate_object(myStudy_i); SALOMEDS::Study_var Study = myStudy_i->_this(); - - if (!NS) - { - NS = SINGLETON_::Instance(); - NS->init_orb( orb ); - } - NS->Register(Study.in(), "/Study"); + NS.Register(Study.in(), "/Study"); // Assign the value of the IOR in the study->root CORBA::String_var IORStudy = orb->object_to_string(Study); diff --git a/src/SALOMEDS/SALOMEDS_Study_i.cxx b/src/SALOMEDS/SALOMEDS_Study_i.cxx index d0eef1dd5..5c1337f18 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.cxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.cxx @@ -179,6 +179,50 @@ namespace SALOMEDS CORBA::ORB_var _orb; }; + class GenObjRegister: public SALOMEDSImpl_AbstractCallback + { + public: + GenObjRegister(CORBA::ORB_ptr orb) + { + _orb = CORBA::ORB::_duplicate(orb); + } + virtual void RegisterGenObj (const std::string& theIOR) + { + try + { + CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str()); + if ( obj->_non_existent() ) return; + SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->Register(); + } + } + catch(const CORBA::Exception& e) + { + } + } + virtual void UnRegisterGenObj(const std::string& theIOR) + { + try + { + CORBA::Object_var obj = _orb->string_to_object(theIOR.c_str()); + if ( obj->_non_existent() ) return; + SALOME::GenericObj_var gobj = SALOME::GenericObj::_narrow(obj); + if(! CORBA::is_nil(gobj) ) + { + gobj->UnRegister(); + } + } + catch(const CORBA::Exception& e) + { + } + } + + private: + CORBA::ORB_var _orb; + }; + } // namespace SALOMEDS //============================================================================ @@ -216,9 +260,11 @@ void SALOMEDS_Study_i::Init() { _builder = new SALOMEDS_StudyBuilder_i(_impl->NewBuilder(), _orb); _notifier = new SALOMEDS::Notifier(_orb); + _genObjRegister = new SALOMEDS::GenObjRegister(_orb); _closed = false; _impl->setNotifier(_notifier); + _impl->setGenObjRegister( _genObjRegister ); // Notify GUI that study was created SALOME_NamingService *aNamingService = KERNEL::getNamingService(); @@ -250,6 +296,7 @@ void SALOMEDS_Study_i::Clear() _impl->Clear(); _impl->setNotifier(0); delete _notifier; + delete _genObjRegister; SALOMEDS::Locker lock; @@ -1025,6 +1072,23 @@ void SALOMEDS_Study_i::UpdateIORLabelMap(const char* anIOR, const char* anEntry) _impl->UpdateIORLabelMap(std::string((char*)anIOR), std::string((char*)anEntry)); } +SALOMEDS::Study_ptr SALOMEDS_Study_i::GetStudy(const DF_Label& theLabel, CORBA::ORB_ptr orb) +{ + SALOMEDS::Locker lock; + + SALOMEDSImpl_AttributeIOR* Att = NULL; + if ((Att=(SALOMEDSImpl_AttributeIOR*)theLabel.Root().FindAttribute(SALOMEDSImpl_AttributeIOR::GetID()))){ + char* IOR = CORBA::string_dup(Att->Value().c_str()); + CORBA::Object_var obj = orb->string_to_object(IOR); + SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj) ; + ASSERT(!CORBA::is_nil(aStudy)); + return SALOMEDS::Study::_duplicate(aStudy); + } else { + MESSAGE("GetStudy: Problem to get study"); + } + return SALOMEDS::Study::_nil(); +} + void SALOMEDS_Study_i::IORUpdated(SALOMEDSImpl_AttributeIOR* theAttribute) { SALOMEDS::Locker lock; diff --git a/src/SALOMEDS/SALOMEDS_Study_i.hxx b/src/SALOMEDS/SALOMEDS_Study_i.hxx index bfa702ddd..20b3bd6d2 100644 --- a/src/SALOMEDS/SALOMEDS_Study_i.hxx +++ b/src/SALOMEDS/SALOMEDS_Study_i.hxx @@ -54,6 +54,7 @@ private: SALOMEDSImpl_Study* _impl; SALOMEDS_StudyBuilder_i* _builder; SALOMEDSImpl_AbstractCallback* _notifier; + SALOMEDSImpl_AbstractCallback* _genObjRegister; SALOMEDS_DriverFactory_i* _factory; bool _closed; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx index 8983f3d94..f5c8ec764 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx @@ -65,8 +65,19 @@ void SALOMEDSImpl_AttributeIOR::SetValue(const std::string& theValue) CheckLocked(); Backup(); + //remove IOR entry in study + if(theValue != myString) + { + SALOMEDSImpl_Study* study=SALOMEDSImpl_Study::GetStudy(Label()); + study->RegisterGenObj(theValue, Label()); + study->UnRegisterGenObj(myString, Label()); + study->DeleteIORLabelMapItem(myString); + } myString = theValue; + + //add IOR entry in study + SALOMEDSImpl_Study::IORUpdated(this); //Reason = 5 means that IOR attribute updated //Used in the gui module to detect that IOR attribure was assigned to the object @@ -93,6 +104,7 @@ SALOMEDSImpl_AttributeIOR::SALOMEDSImpl_AttributeIOR() SALOMEDSImpl_AttributeIOR::~SALOMEDSImpl_AttributeIOR() { + SALOMEDSImpl_Study::UnRegisterGenObj(myString, Label()); } //======================================================================= diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx index 0b935d0c2..8c5ae3c64 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx @@ -61,5 +61,7 @@ public: virtual bool removeSO_Notification(const SALOMEDSImpl_SObject& theSObject){return false;}; virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason ){return false;}; virtual bool modifyNB_Notification(const char* theVarName){return false;}; + virtual void RegisterGenObj (const std::string& theIOR) {} + virtual void UnRegisterGenObj(const std::string& theIOR) {} }; #endif diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx index 7d838bc5d..a9fae3dae 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx @@ -150,6 +150,7 @@ void SALOMEDSImpl_Study::Init() _builder = new SALOMEDSImpl_StudyBuilder(this); _cb = new SALOMEDSImpl_Callback(_useCaseBuilder); _notifier=0; + _genObjRegister=0; //Put on the root label a StudyHandle attribute to store the address of this object //It will be used to retrieve the study object by DF_Label that belongs to the study SALOMEDSImpl_StudyHandle::Set(_doc->Main().Root(), this); @@ -3200,6 +3201,49 @@ void SALOMEDSImpl_Study::setNotifier(SALOMEDSImpl_AbstractCallback* notifier) _notifier=notifier; } +static SALOMEDSImpl_AbstractCallback* & getGenObjRegister( DF_Document* doc ) +{ + static std::vector< SALOMEDSImpl_AbstractCallback* > _genObjRegVec; + if ( doc->GetDocumentID() >= (int)_genObjRegVec.size() ) + _genObjRegVec.resize( doc->GetDocumentID() + 1, 0 ); + return _genObjRegVec[ doc->GetDocumentID() ]; +} + +//================================================================================ +/*! + * \brief Stores theRegister + */ +//================================================================================ + +void SALOMEDSImpl_Study::setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister) +{ + getGenObjRegister( _doc ) = theRegister; +} + +//================================================================================ +/*! + * \brief Indirectly invokes GenericObj_i::Register() + */ +//================================================================================ + +void SALOMEDSImpl_Study::RegisterGenObj (const std::string& theIOR, DF_Label label) +{ + if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() )) + goRegister->RegisterGenObj( theIOR ); +} + +//================================================================================ +/*! + * \brief Indirectly invokes GenericObj_i::UnRegister() + */ +//================================================================================ + +void SALOMEDSImpl_Study::UnRegisterGenObj(const std::string& theIOR, DF_Label label) +{ + if ( SALOMEDSImpl_AbstractCallback* goRegister = getGenObjRegister( label.GetDocument() )) + goRegister->UnRegisterGenObj( theIOR ); +} + //####################################################################################################### //# STATIC PRIVATE FUNCTIONS //####################################################################################################### diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx index ff30a54c1..bd8f55faf 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx @@ -72,6 +72,7 @@ private: SALOMEDSImpl_StudyBuilder* _builder; SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder; SALOMEDSImpl_AbstractCallback* _notifier; + SALOMEDSImpl_AbstractCallback* _genObjRegister; std::map _mapOfSO; std::map _mapOfSCO; @@ -360,6 +361,10 @@ public: virtual bool modifySO_Notification(const SALOMEDSImpl_SObject& theSObject, int reason); virtual void setNotifier(SALOMEDSImpl_AbstractCallback* notifier); + static void RegisterGenObj (const std::string& theIOR, DF_Label label); + static void UnRegisterGenObj(const std::string& theIOR, DF_Label label); + void setGenObjRegister(SALOMEDSImpl_AbstractCallback* theRegister); + friend class SALOMEDSImpl_GenericAttribute; friend class SALOMEDSImpl_GenericVariable; }; diff --git a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx index bf0c5ea0a..f3e530112 100644 --- a/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx +++ b/src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx @@ -1014,7 +1014,10 @@ static void Translate_persistentID_to_IOR(DF_Label& Lab, SALOMEDSImpl_Driver* dr persist_ref, isMultiFile, isASCII); - SALOMEDSImpl_AttributeIOR::Set (current, ior_string); + SALOMEDSImpl_AttributeIOR* iorAttr = SALOMEDSImpl_AttributeIOR::Set (current, ior_string); + + // make myRefCounter of a loaded GenericObj == 1 + SALOMEDSImpl_Study::UnRegisterGenObj( ior_string, iorAttr->Label()); } Translate_persistentID_to_IOR (current, driver, isMultiFile, isASCII); } -- 2.39.2