Salome HOME
Copyright update 2022
[modules/gui.git] / src / Session / Session_Session_i.cxx
old mode 100755 (executable)
new mode 100644 (file)
index b6fe12d..36ae0cb
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2022  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <unistd.h>
 #endif
 
-/*!
-  constructor
-*/
-SALOME_Session_i::SALOME_Session_i(int argc,
-                                   char ** argv,
-                                   CORBA::ORB_ptr orb,
-                                   PortableServer::POA_ptr poa,
-                                   QMutex* GUIMutex,
-                                   QWaitCondition* GUILauncher)
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
+{
+  _NS.reset(new SALOME_NamingService(_orb));
+}
+
+SALOME_Session_i::SALOME_Session_i(int argc, char ** argv, CORBA::ORB_ptr orb, PortableServer::POA_ptr poa, QMutex* GUIMutex, QWaitCondition* GUILauncher, SALOME_NamingService_Abstract *NS):
+_argc(argc),_argv(argv),_isGUI(false),_GUIMutex(GUIMutex),_GUILauncher(GUILauncher),
+_orb(CORBA::ORB::_duplicate(orb)),_poa(PortableServer::POA::_duplicate(poa)),_isShuttingDown(false)
 {
-  _argc = argc ;
-  _argv = argv ;
-  _isGUI = FALSE ;
-  _runningStudies= 0 ;
-  _orb = CORBA::ORB::_duplicate(orb) ;
-  _poa = PortableServer::POA::_duplicate(poa) ;
-  _GUIMutex = GUIMutex;
-  _GUILauncher = GUILauncher;
-  _NS = new SALOME_NamingService(_orb);
-  _isShuttingDown = false;
-  //MESSAGE("constructor end");
+  _NS.reset(NS);
 }
 
 /*!
@@ -80,13 +71,14 @@ SALOME_Session_i::SALOME_Session_i(int argc,
 */
 Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibraryName)
 {
-  typedef Engines::EngineComponent_ptr TGetImpl(CORBA::ORB_ptr,
-                                                PortableServer::POA_ptr,
-                                                SALOME_NamingService*,QMutex*);
+  using TGetImpl = Engines::EngineComponent_ptr (*)(CORBA::ORB_ptr, PortableServer::POA_ptr, SALOME_NamingService*,QMutex*);
   OSD_SharedLibrary aSharedLibrary(const_cast<char*>(theLibraryName));
   if (aSharedLibrary.DlOpen(OSD_RTLD_LAZY)) {
     if (OSD_Function anOSDFun = aSharedLibrary.DlSymb("GetImpl"))
-      return ((TGetImpl (*)) anOSDFun)(_orb,_poa,_NS,_GUIMutex);
+    {
+      Engines::EngineComponent_ptr ret = ((TGetImpl) anOSDFun)(_orb,_poa,dynamic_cast<SALOME_NamingService*>(_NS.get()),_GUIMutex);
+      return ret;
+    }
   }
   CORBA::Object_var obj = SalomeApp_Engine_i::EngineForComponent(theLibraryName, true);
   if (!CORBA::is_nil(obj)){
@@ -101,7 +93,6 @@ Engines::EngineComponent_ptr SALOME_Session_i::GetComponent(const char* theLibra
 */
 SALOME_Session_i::~SALOME_Session_i()
 {
-  delete _NS;
   //MESSAGE("destructor end");
 }
 
@@ -137,6 +128,8 @@ void SALOME_Session_i::NSunregister()
   try
     {
       _NS->Destroy_Name("/Kernel/Session");
+      _NS->Destroy_Directory("/Kernel");
+      deleteContainersinNS();
     }
   catch (ServiceUnreachable&)
     {
@@ -206,7 +199,7 @@ void SALOME_Session_i::Shutdown()
 
 /*!
   Send a SALOME::StatSession structure (see idl) to the client
-  (number of running studies and presence of GUI)
+  (presence of GUI)
 */
 /*class QtLock
 {
@@ -220,24 +213,23 @@ SALOME::StatSession SALOME_Session_i::GetStatSession()
 {
   // update Session state
   _GUIMutex->lock();
+  int activeStudy = 0;
 
-  _runningStudies = 0;
   {
     //QtLock lock;
     _isGUI = SUIT_Session::session();
     if ( _isGUI && SUIT_Session::session()->activeApplication() )
-      _runningStudies = SUIT_Session::session()->activeApplication()->getNbStudies();
+      activeStudy = SUIT_Session::session()->activeApplication()->getNbStudies();
   }
 
   // getting stat info
-  SALOME::StatSession_var myStats = new SALOME::StatSession ;
-  if (_runningStudies)
+  SALOME::StatSession_var myStats = new SALOME::StatSession;
+  if (activeStudy)
     myStats->state = SALOME::running ;
   else if (_isShuttingDown)
     myStats->state = SALOME::shutdown ;
   else
     myStats->state = SALOME::asleep ;
-  myStats->runningStudies = _runningStudies ;
   myStats->activeGUI = _isGUI ;
 
   _GUIMutex->unlock();
@@ -245,16 +237,6 @@ SALOME::StatSession SALOME_Session_i::GetStatSession()
   return myStats._retn() ;
 }
 
-CORBA::Long SALOME_Session_i::GetActiveStudyId()
-{
-  long aStudyId=-1;
-  if ( SUIT_Session::session() && SUIT_Session::session()->activeApplication() ) {
-    if ( SUIT_Session::session()->activeApplication()->activeStudy() ) // mkr : IPAL12128
-      aStudyId = SUIT_Session::session()->activeApplication()->activeStudy()->id();
-  }
-  return aStudyId;
-}
-
 CORBA::Long SALOME_Session_i::getPID() {
   return (CORBA::Long)
 #ifndef WIN32
@@ -353,3 +335,30 @@ SALOME::StringSeq* SALOME_Session_i::getSelection()
   _GUIMutex->unlock();
   return selection._retn();
 }
+
+void SALOME_Session_i::deleteContainersinNS()
+{
+// destroy of all containers and modules
+  _NS->Change_Directory("/Containers");
+  std::vector<std::string> machines = _NS->list_subdirs();
+  for(int i=0;i<(int)machines.size();i++){
+    _NS->Change_Directory(machines[i].c_str());
+    std::vector<std::string> toto = _NS->list_directory();
+    for(int j=0;j<(int)toto.size();j++)
+      _NS->Destroy_Name(toto[j].c_str());
+    std::vector<std::string> containers = _NS->list_subdirs();
+    for(int j=0;j<(int)containers.size();j++){
+      _NS->Change_Directory(containers[j].c_str());
+      std::vector<std::string> modules = _NS->list_directory();
+      for(int k=0;k<(int)modules.size();k++)
+        _NS->Destroy_Name(modules[k].c_str());
+      _NS->Change_Directory("/Containers");
+      _NS->Change_Directory(machines[i].c_str());
+      _NS->Destroy_Directory(containers[j].c_str());
+    }
+    _NS->Change_Directory("/Containers");
+    _NS->Destroy_Directory(machines[i].c_str());
+  }
+  _NS->Change_Directory("/");
+  _NS->Destroy_Directory("/Containers");
+}