Salome HOME
[EDF29150] : Base mechanism to keep track of CPU and Mem info
[modules/kernel.git] / src / KernelHelpers / SALOME_KernelServices.cxx
index 3bb6b144bd2107d86e01ca35066e677b4bd06542..b0f8776601d45230afb5b56a0702af0688e61d0e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2020  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  CEA, EDF, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // Author: Guillaume Boulant (EDF/R&D) 
 
 #include "SALOME_KernelServices.hxx"
+#include "SALOME_Fake_NamingService.hxx"
+#include "Utils_SALOME_Exception.hxx"
+#include "KernelBasis.hxx"
+
+#include <map>
+#include <memory>
+
+std::map<std::string,CORBA::Object_var> _compo_map;
+
+std::unique_ptr<SALOME_NamingService_Abstract> _naming_service;
 
 namespace KERNEL {
   
-  /**
-   * This function returns a static reference to the orb. The orb can
-   * be used for example to initialize CORBA variables or to serialize
-   * and unserialize the CORBA objet to/from an IOR string.
-   */
-  CORBA::ORB_ptr getORB() {
-    static CORBA::ORB_ptr orb;
-    if(CORBA::is_nil(orb)){
-      int argc=0;
-      orb = CORBA::ORB_init(argc,0);
+  void assignNamingServiceSL()
+  {
+    if ( !_naming_service.get() )
+    {
+      _naming_service.reset( new SALOME_Fake_NamingService );
+    }
+    else
+    {
+      THROW_SALOME_EXCEPTION("assignNamingServiceSL : NS SALOME Wrapper is already set !");
     }
-    return orb;
   }
-  
+
   /**
    * This function returns a static reference to the SALOME naming service.
    */
-  SALOME_NamingService * getNamingService() {
-    static SALOME_NamingService * namingService;
-    if ( namingService == NULL ) {
-      namingService = new SALOME_NamingService(getORB());
+  SALOME_NamingService_Abstract *getNamingService()
+  {
+    if ( !_naming_service.get() )
+    {
+      if(getSSLMode())
+        _naming_service.reset( new SALOME_Fake_NamingService );
+      else
+        _naming_service.reset( new SALOME_NamingService(getORB()) );
     }
-    return namingService;
+    return _naming_service.get();
   }
   
   /**
@@ -54,7 +66,7 @@ namespace KERNEL {
   SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
     static SALOME_LifeCycleCORBA * lifeCycleCORBA;
     if ( lifeCycleCORBA == NULL ) {
-      SALOME_NamingService *aNamingService = getNamingService();
+      SALOME_NamingService_Abstract *aNamingService = getNamingService();
       lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
     }
     return lifeCycleCORBA;
@@ -64,11 +76,12 @@ namespace KERNEL {
   /**
    * This returns a static reference to the SALOME study. The
    * study can be used to get informations about it.
+   * \sa getStudyServantSA
    */
   SALOMEDS::Study_ptr getStudyServant() {
     static SALOMEDS::Study_ptr aStudy;
     if(CORBA::is_nil(aStudy)){
-      SALOME_NamingService *aNamingService = getNamingService();
+      SALOME_NamingService_Abstract *aNamingService = getNamingService();
       CORBA::Object_ptr anObject = aNamingService->Resolve("/Study");
       aStudy = SALOMEDS::Study::_narrow(anObject);
     }
@@ -83,7 +96,7 @@ namespace KERNEL {
   SALOME::Session_ptr getSalomeSession() {
     static SALOME::Session_ptr salomeSession;
     if(CORBA::is_nil(salomeSession)){
-      SALOME_NamingService *aNamingService = getNamingService();
+      SALOME_NamingService_Abstract *aNamingService = getNamingService();
       CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
       salomeSession = SALOME::Session::_narrow(obj);
     }
@@ -100,7 +113,7 @@ namespace KERNEL {
     static Engines::SalomeLauncher_ptr salomeLauncher;
     if(CORBA::is_nil(salomeLauncher)){
       //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
-      SALOME_NamingService *aNamingService = getNamingService();
+      SALOME_NamingService_Abstract *aNamingService = getNamingService();
       CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
       salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
     }
@@ -110,7 +123,7 @@ namespace KERNEL {
   Engines::ResourcesManager_ptr getResourcesManager() {
     static Engines::ResourcesManager_ptr resourcesManager;
     if(CORBA::is_nil(resourcesManager)){
-      SALOME_NamingService *aNamingService = getNamingService();
+      SALOME_NamingService_Abstract *aNamingService = getNamingService();
       CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
       resourcesManager = Engines::ResourcesManager::_narrow(obj);
     }
@@ -160,5 +173,26 @@ namespace KERNEL {
     es.text = CORBA::string_dup(text);
     return SALOME::SALOME_Exception(es);
   }
-
+  
+  void RegisterCompo(const std::string& compoName, CORBA::Object_var compoPtr)
+  {
+    _compo_map[compoName] = compoPtr;
+  }
+  
+  CORBA::Object_var RetrieveCompo(const std::string& compoName)
+  {
+    CORBA::Object_var ret;
+    auto it = _compo_map.find(compoName);
+    if( it != _compo_map.end() )
+    {
+      ret = (*it).second;
+    }
+    else
+    {
+      Engines::EngineComponent_var compo = getLifeCycleCORBA()->FindOrLoad_Component( "FactoryServer", compoName.c_str() );
+      ret = CORBA::Object::_narrow(compo);
+      _compo_map[compoName] = ret;
+    }
+    return ret._retn();
+  }
 }