Salome HOME
CCAR: some corrections in :
authorcaremoli <caremoli>
Fri, 6 Jun 2008 13:57:33 +0000 (13:57 +0000)
committercaremoli <caremoli>
Fri, 6 Jun 2008 13:57:33 +0000 (13:57 +0000)
- disconnection of CALCIUM ports
- shutdown of Python container
- shutdown of C++ container
- launching of standalone component

src/Container/Component_i.cxx
src/Container/Container_i.cxx
src/Container/SALOME_ContainerManager.cxx
src/Container/SALOME_ContainerPy.py
src/DSC/DSC_User/Datastream/Calcium/CalciumGenericProvidesPort.hxx
src/NamingService/SALOME_NamingServicePy.py

index 867411196bac4f20c75227798e473c4533e4217b..885750da9ed96f7101f1e2158805677b304a1541 100644 (file)
@@ -295,8 +295,8 @@ void Engines_Component_i::destroy()
 
   delete _myConnexionToRegistry;
   _myConnexionToRegistry = 0 ;
-  _poa->deactivate_object(*_id) ;
-  delete(_id) ;
+  if(_id)
+    delete(_id) ;
   //SCRUTE(pd_refCount);
   _thisObj->_remove_ref();
   //SCRUTE(pd_refCount);
index 0095b0bc579c69fdc082d273322ff3eb4f4137b0..d574fa95cc9515ef94910c860b14c88d9d07bf9d 100644 (file)
@@ -655,7 +655,7 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName,
     }
   else
     {
-      int count=10;
+      int count=20;
       CORBA::Object_var obj = CORBA::Object::_nil() ;
       while ( CORBA::is_nil(obj) && count )
         {
@@ -678,6 +678,7 @@ Engines_Container_i::create_component_instance(const char*genericRegisterName,
         {
           MESSAGE("SALOME_Container::create_component_instance successful");
           iobject=Engines::Component::_narrow(obj);
+          _listInstances_map[instanceName] = iobject;
           return iobject._retn();
         }
     }
index 20f46f6d7c48d28afa4a86b5cbc005c1c55600a1..b172832ed4a49440bf9ac0f0d18b9f80ae93ed14 100644 (file)
@@ -280,10 +280,19 @@ StartContainer(const Engines::MachineParameters& params,
   CORBA::Object_var obj = _NS->Resolve(containerNameInNS.c_str());
   if ( !CORBA::is_nil(obj) )
     {
-      // unregister the registered container if it exists
-      _NS->Destroy_Name(containerNameInNS.c_str());
-      // unregister component instances ???
-      //Engines::Container_var cont=Engines::Container::_narrow(obj);
+      // shutdown the registered container if it exists
+      Engines::Container_var cont=Engines::Container::_narrow(obj);
+      if(!CORBA::is_nil(cont))
+        {
+          try
+            {
+              cont->Shutdown();
+            }
+          catch(CORBA::Exception&)
+            {
+              INFOS("CORBA::Exception ignored.");
+            }
+        }
     }
 
   //redirect stdout and stderr in a file
index 4eac58a65fe1ec69c359b821e9d911f7b2ac8609..41cfcaeee9df9ad9b003044658ecb9045b6ec8d6 100755 (executable)
@@ -304,6 +304,8 @@ class SALOME_ContainerPy_i (Engines__POA.Container):
     #-------------------------------------------------------------------------
 
     def Shutdown(self):
+        self._naming_service.Destroy_Name(self._containerName);
+        self._naming_service.Destroy_FullDirectory(self._containerName);
         self._orb.shutdown(0)
         pass
 
@@ -316,32 +318,28 @@ class SALOME_ContainerPy_i (Engines__POA.Container):
 
 #=============================================================================
 
-#initialise the ORB and find the root POA
-print "Starting ",sys.argv[1]
-orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
-poa = orb.resolve_initial_references("RootPOA")
-if verbose(): print "ORB and POA initialized"
-
-#create an instance of SALOME_ContainerPy_i and a Container reference
-#containerName = "FactoryServerPy"
-MESSAGE( str(sys.argv) )
-containerName = sys.argv[1]
-cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
-if verbose(): print "SALOME_ContainerPy_i instance created ",cpy_i 
-cpy_o = cpy_i._this()
-if verbose(): print "SALOME_ContainerPy_i instance activated ",cpy_o
-sys.stdout.flush()
-sys.stderr.flush()
-
-#activate the POA
-poaManager = poa._get_the_POAManager()
-poaManager.activate()
-
-#Block for ever
-orb.run()
-
-
-        
-            
-
-
+if __name__ == "__main__":
+  #initialise the ORB and find the root POA
+  if verbose():print "Starting ",sys.argv[1]
+  orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
+  poa = orb.resolve_initial_references("RootPOA")
+  if verbose():print "ORB and POA initialized"
+
+  #create an instance of SALOME_ContainerPy_i and a Container reference
+  #containerName = "FactoryServerPy"
+  MESSAGE( str(sys.argv) )
+  containerName = sys.argv[1]
+  cpy_i = SALOME_ContainerPy_i(orb, poa, containerName)
+  if verbose():print "SALOME_ContainerPy_i instance created ",cpy_i 
+  cpy_o = cpy_i._this()
+  if verbose():print "SALOME_ContainerPy_i instance activated ",cpy_o
+  sys.stdout.flush()
+  sys.stderr.flush()
+
+  #activate the POA
+  poaManager = poa._get_the_POAManager()
+  poaManager.activate()
+
+  #Block for ever
+  orb.run()
+  if verbose():print "SALOME_ContainerPy_i shutdown"
index 6f8fd6d9769eebc9bee5ffe01c2d2b8732dfadf0..7adf70ce1e9c782a3071cc85e2683a7c50a4b2a2 100644 (file)
                             public virtual POA_Ports::PortProperties,  \
                             public GenericProvidesPort< __VA_ARGS__ , CalciumCouplingPolicy, calcium_provides_port > { \
   private :                                                            \
-    omni_semaphore _mustnotdisconnectyet;                              \
+    omni_mutex     _disconnect_mutex; \
+    int            _mustnotdisconnect; \
   public :                                                             \
     typedef  __VA_ARGS__               DataManipulator;                        \
     typedef  DataManipulator::Type     CorbaDataType;                  \
     typedef GenericPort< DataManipulator ,                             \
       CalciumCouplingPolicy >          Port;                           \
+      specificPortName () : _mustnotdisconnect(0) {}; \
                                                                        \
-    specificPortName () :_mustnotdisconnectyet(0) {};                  \
-                                                                       \
     virtual ~ specificPortName ();                                     \
                                                                        \
     inline void disconnect(bool provideLastGivenValue) {               \
-      if (! _mustnotdisconnectyet.trywait() ) {                                \
-       Port::disconnect(provideLastGivenValue);                        \
-      }                                                                        \
-    }                                                                          \
+      _disconnect_mutex.lock();                       \
+      if(_mustnotdisconnect > 1)                      \
+      {                                               \
+        _mustnotdisconnect--;                         \
+      }                                               \
+      else if(_mustnotdisconnect == 1)                \
+      {                                               \
+        _mustnotdisconnect--;                         \
+        Port::disconnect(provideLastGivenValue);      \
+      }                                               \
+      _disconnect_mutex.unlock();                     \
+    }                                                                                                        \
     inline void setDependencyType(CalciumTypes::DependencyType dependencyType) { \
       Port::setDependencyType(dependencyType);                         \
     }                                                                  \
     virtual void provides_port_changed(int connection_nbr,             \
                                       const Engines::DSC::Message message) { \
       if ( message == Engines::DSC::AddingConnection)                  \
-       _mustnotdisconnectyet.post();                                   \
+        {                                                 \
+          _disconnect_mutex.lock();                \
+          _mustnotdisconnect++;                           \
+          _disconnect_mutex.unlock();              \
+        }                                                 \
       else if ( message == Engines::DSC::RemovingConnection )          \
-       disconnect(false);                                              \
+        {                                                 \
+          disconnect(false);                              \
+        }                                                 \
     }                                                                  \
   };                                                                   \
 
index e4a44d309227ab9827f859aef0b8523b486193d2..81ad8d15a94b01799eeb1f900daa6fbb29f4fc10 100644 (file)
@@ -32,6 +32,7 @@ import sys
 import time
 from omniORB import CORBA
 import CosNaming
+import string
 from string import *
 
 from SALOME_utilities import *
@@ -88,7 +89,7 @@ class SALOME_NamingServicePy_i(object):
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         if len(result_resolve_path)>1:
             # A directory is treated (not only an object name)
             # We had to test if the directory where ObjRef should be recorded 
@@ -156,7 +157,7 @@ class SALOME_NamingServicePy_i(object):
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         _context_name=[]
         for i in range(len(result_resolve_path)-1):
             _context_name.append(CosNaming.NameComponent(result_resolve_path[i],"dir"))
@@ -189,7 +190,7 @@ class SALOME_NamingServicePy_i(object):
             #delete first '/' before split
             Path=Path[1:]
 
-        result_resolve_path = split(Path,'/')
+        result_resolve_path = string.split(Path,'/')
         _context_name = []
         for i in range(len(result_resolve_path)):
             _context_name[CosNaming.NameComponent(result_resolve_path[i],"dir")]            
@@ -204,7 +205,46 @@ class SALOME_NamingServicePy_i(object):
                 MESSAGE ( "Create_Directory : CosNaming.NamingContext.CannotProceed" )
             except (CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE):
                 MESSAGE ( "Create_Directory : CORBA.TRANSIENT,CORBA.OBJECT_NOT_EXIST,CORBA.COMM_FAILURE" )
-
  
-
-    
+    def Destroy_Name(self,Path):
+      resolve_path=string.split(Path,'/')
+      if resolve_path[0] == '': del resolve_path[0]
+      dir_path=resolve_path[:-1]
+      context_name=[]
+      for e in dir_path:
+         context_name.append(CosNaming.NameComponent(e,"dir"))
+      context_name.append(CosNaming.NameComponent(resolve_path[-1],"object"))
+      
+      try:
+        self._root_context.unbind(context_name)
+      except CosNaming.NamingContext.NotFound, ex:
+        return
+      except CORBA.Exception,ex:
+        return
+
+    def Destroy_FullDirectory(self,Path):
+      context_name=[]
+      for e in string.split(Path,'/'):
+        if e == '':continue
+        context_name.append(CosNaming.NameComponent(e,"dir"))
+
+      try:
+        context=self._root_context.resolve(context_name)
+      except CosNaming.NamingContext.NotFound, ex:
+        return
+      except CORBA.Exception,ex:
+        return
+
+      bl,bi=context.list(0)
+      if bi is not None:
+         ok,b=bi.next_one()
+         while(ok):
+            for s in b.binding_name :
+               if s.kind == "object":
+                  context.unbind([s])
+               elif s.kind == "dir":
+                  context.unbind([s])
+            ok,b=bi.next_one()
+
+      context.destroy()
+      self._root_context.unbind(context_name)