Back to index

salome-kernel  6.5.0
SALOME_KernelServices.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // This library is free software; you can redistribute it and/or
00004 // modify it under the terms of the GNU Lesser General Public
00005 // License as published by the Free Software Foundation; either
00006 // version 2.1 of the License.
00007 //
00008 // This library is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00011 // Lesser General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU Lesser General Public
00014 // License along with this library; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00016 //
00017 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00018 //
00019 // Author: Guillaume Boulant (EDF/R&D) 
00020 
00021 #include "SALOME_KernelServices.hxx"
00022 
00023 namespace KERNEL {
00024   
00030   CORBA::ORB_ptr getORB() {
00031     static CORBA::ORB_ptr orb;
00032     if(CORBA::is_nil(orb)){
00033       int argc=0;
00034       orb = CORBA::ORB_init(argc,0);
00035     }
00036     return orb;
00037   }
00038   
00042   SALOME_NamingService * getNamingService() {
00043     static SALOME_NamingService * namingService;
00044     if ( namingService == NULL ) {
00045       namingService = new SALOME_NamingService(getORB());
00046     }
00047     return namingService;
00048   }
00049   
00053   SALOME_LifeCycleCORBA * getLifeCycleCORBA() {
00054     static SALOME_LifeCycleCORBA * lifeCycleCORBA;
00055     if ( lifeCycleCORBA == NULL ) {
00056       SALOME_NamingService *aNamingService = getNamingService();
00057       lifeCycleCORBA = new SALOME_LifeCycleCORBA(aNamingService);
00058     }
00059     return lifeCycleCORBA;
00060   }
00061 
00062 
00068   SALOMEDS::StudyManager_ptr getStudyManager() {
00069     static SALOMEDS::StudyManager_ptr aStudyManager;
00070     if(CORBA::is_nil(aStudyManager)){
00071       SALOME_NamingService *aNamingService = getNamingService();
00072       CORBA::Object_ptr anObject = aNamingService->Resolve("/myStudyManager");
00073       aStudyManager = SALOMEDS::StudyManager::_narrow(anObject);
00074     }
00075     return aStudyManager;
00076   }
00077 
00083   SALOME::Session_ptr getSalomeSession() {
00084     static SALOME::Session_ptr salomeSession;
00085     if(CORBA::is_nil(salomeSession)){
00086       SALOME_NamingService *aNamingService = getNamingService();
00087       CORBA::Object_ptr obj = aNamingService->Resolve("/Kernel/Session");
00088       salomeSession = SALOME::Session::_narrow(obj);
00089     }
00090     return salomeSession;
00091   }
00092 
00098   Engines::SalomeLauncher_ptr getSalomeLauncher() {
00099     //LOG("KERNEL_services::getSalomeLauncher()");
00100     static Engines::SalomeLauncher_ptr salomeLauncher;
00101     if(CORBA::is_nil(salomeLauncher)){
00102       //LOG("KERNEL_services::getSalomeLauncher(): creating the static instance");
00103       SALOME_NamingService *aNamingService = getNamingService();
00104       CORBA::Object_ptr obj = aNamingService->Resolve("/SalomeLauncher");
00105       salomeLauncher = Engines::SalomeLauncher::_narrow(obj);
00106     }
00107     return salomeLauncher;
00108   }
00109 
00110   Engines::ResourcesManager_ptr getResourcesManager() {
00111     static Engines::ResourcesManager_ptr resourcesManager;
00112     if(CORBA::is_nil(resourcesManager)){
00113       SALOME_NamingService *aNamingService = getNamingService();
00114       CORBA::Object_ptr obj = aNamingService->Resolve("/ResourcesManager");
00115       resourcesManager = Engines::ResourcesManager::_narrow(obj);
00116     }
00117     return resourcesManager;
00118   }
00119 
00127   SALOMEDS::Study_ptr getStudyById(int aStudyId) {
00128     if ( aStudyId < 0 ) {
00129       INFOS("ERR: trying to get a study with ID<0");
00130       return SALOMEDS::Study::_nil();
00131     }
00132     return getStudyManager()->GetStudyByID(aStudyId);
00133   }
00134 
00135   int getStudyId(SALOMEDS::Study_ptr study) {
00136     if( CORBA::is_nil(study) ) return -1;
00137     return study->StudyId();
00138   }
00139 
00140 
00145   CORBA::Object_ptr SObjectToObject(SALOMEDS::SObject_ptr theSObject) {
00146 
00147     SALOMEDS::GenericAttribute_var anAttr;
00148     CORBA::Object_var anObject;
00149     if(CORBA::is_nil(theSObject))
00150       return anObject;
00151     try{
00152       if(theSObject->FindAttribute(anAttr, "AttributeIOR")){
00153        SALOMEDS::AttributeIOR_var anIOR  = SALOMEDS::AttributeIOR::_narrow(anAttr);
00154        CORBA::String_var aValue = anIOR->Value();
00155        CORBA::ORB_ptr anORB = getORB();
00156        if(strcmp(aValue,"") != 0)
00157          anObject = anORB->string_to_object(aValue);
00158       }
00159     }catch(...){
00160       INFOS("SObjectToObject - Unknown exception was occured!!!");
00161     }
00162     return anObject._retn();
00163   }
00164 
00169   CORBA::Object_ptr IORToObject(char * IOR) {
00170     return getORB()->string_to_object(IOR);
00171   }
00172 
00173   //
00174   // __GBO__ See the file ./src/SMESHGUI/SMESHGUI_Utils.h of SMESH_SRC
00175   // for other helper functions
00176   //
00177 
00178   SALOME::SALOME_Exception createSalomeException(const char * text) {
00179     SALOME::ExceptionStruct es;
00180     es.type = SALOME::INTERNAL_ERROR;
00181     es.text = CORBA::string_dup(text);
00182     return SALOME::SALOME_Exception(es);
00183   }
00184 
00185 }