]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Restore registering CORBA objects, removed by previous wrong commit
authorrnv <rnv@opencascade.com>
Mon, 14 Nov 2016 15:57:55 +0000 (18:57 +0300)
committerrnv <rnv@opencascade.com>
Mon, 14 Nov 2016 15:57:55 +0000 (18:57 +0300)
src/SALOMEDS/SALOMEDS_Server.cxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDSImpl/SALOMEDSImpl_AttributeIOR.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Callback.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx
src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx

index a9893daa2e1f2cfd3cf266107822186ac1b73569..a1e9a1af18d3ce17c064f16416a0fd56f9cc8d42 100644 (file)
@@ -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_<SALOME_NamingService>::Instance() ;
-                        NS->init_orb( orb1 ) ;
+                        NS = *SINGLETON_<SALOME_NamingService>::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_<SALOME_NamingService>::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);
index d0eef1dd512d308974f3d46d82b0ecd03600c4ee..5c1337f1851906c3194881007a903f585a933227 100644 (file)
@@ -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; 
index bfa702ddd73f1d4bb47c7bff64e986d3db394780..20b3bd6d2cb1f6f46dca2daf53f32fd961bfccf0 100644 (file)
@@ -54,6 +54,7 @@ private:
   SALOMEDSImpl_Study*            _impl;  
   SALOMEDS_StudyBuilder_i*       _builder;    
   SALOMEDSImpl_AbstractCallback* _notifier;
+  SALOMEDSImpl_AbstractCallback* _genObjRegister;
   SALOMEDS_DriverFactory_i*      _factory;
   bool                           _closed;
 
index 8983f3d949dd03397a46faef21802ea2c18cdc2f..f5c8ec76464fdf2898f38a0164eb7d744b78b6af 100644 (file)
@@ -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());
 }
 
 //=======================================================================
index 0b935d0c2b6a081c1a1375052e66bda92a442659..8c5ae3c645fc85c307e6fed7a74bf11fb487c1e3 100644 (file)
@@ -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
index 7d838bc5d262159bd2071a4b47c4709d2777bd57..a9fae3dae14faf9dbeb30d0cc4950f6f98837b05 100644 (file)
@@ -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
 //#######################################################################################################
index ff30a54c1d72425d57d921425b48ffcc8585507e..bd8f55faf9b491937c06c28a5e69d892c6adf346 100644 (file)
@@ -72,6 +72,7 @@ private:
   SALOMEDSImpl_StudyBuilder*   _builder;
   SALOMEDSImpl_UseCaseBuilder* _useCaseBuilder;
   SALOMEDSImpl_AbstractCallback* _notifier;
+  SALOMEDSImpl_AbstractCallback* _genObjRegister;
 
   std::map<std::string, SALOMEDSImpl_SObject> _mapOfSO;
   std::map<std::string, SALOMEDSImpl_SComponent> _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;
 };
index bf0c5ea0adc76ba8dd0231ce668fcf18b976a1c6..f3e53011249236c44c56f3af48f99cefe94cbaf1 100644 (file)
@@ -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);
   }