Back to index

salome-kernel  6.5.0
SALOME_KernelServices.hxx
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 #ifndef __KERNEL_SERVICES_H__
00022 #define __KERNEL_SERVICES_H__
00023 
00024 #include "KernelHelpers.hxx"
00025 
00026 #include "SALOMEconfig.h"
00027 #include CORBA_SERVER_HEADER(SALOMEDS)
00028 #include CORBA_SERVER_HEADER(SALOMEDS_Attributes)
00029 #include CORBA_SERVER_HEADER(SALOME_ContainerManager)
00030 #include CORBA_CLIENT_HEADER(SALOME_Session)
00031 #include CORBA_SERVER_HEADER(SALOME_Exception)
00032 
00033 #include "SALOME_NamingService.hxx"
00034 #include "SALOME_LifeCycleCORBA.hxx"
00035 
00036 namespace KERNEL {
00037 
00038   // ---------------------------------------------
00039   // SALOME KERNEL main services
00040   KERNELHELPERS_EXPORT CORBA::ORB_ptr                getORB();
00041   KERNELHELPERS_EXPORT SALOME_NamingService *        getNamingService();
00042   KERNELHELPERS_EXPORT SALOME_LifeCycleCORBA *       getLifeCycleCORBA();
00043   KERNELHELPERS_EXPORT SALOME::Session_ptr           getSalomeSession();
00044   KERNELHELPERS_EXPORT SALOMEDS::StudyManager_ptr    getStudyManager();
00045   KERNELHELPERS_EXPORT Engines::SalomeLauncher_ptr   getSalomeLauncher();
00046   KERNELHELPERS_EXPORT Engines::ResourcesManager_ptr getResourcesManager();
00047 
00048   // ---------------------------------------------
00049   // SALOME KERNEL services to deal with a SALOME study, SObject and
00050   // SComponent.
00051   //
00052   KERNELHELPERS_EXPORT SALOMEDS::Study_ptr getStudyById(int aStudyId);
00053   KERNELHELPERS_EXPORT int                 getStudyId(SALOMEDS::Study_ptr study);
00054   KERNELHELPERS_EXPORT CORBA::Object_ptr   IORToObject(char * IOR);
00055   KERNELHELPERS_EXPORT CORBA::Object_ptr   SObjectToObject(SALOMEDS::SObject_ptr);
00056   
00057 
00058 
00064   template<class TInterface> typename TInterface::_var_type
00065   ObjectToInterface(CORBA::Object_ptr object) {
00066     if(!CORBA::is_nil(object))
00067       return TInterface::_narrow(object);
00068     return TInterface::_nil();
00069   }
00070 
00071   template<class TInterface> typename TInterface::_var_type
00072   SObjectToInterface(SALOMEDS::SObject_ptr sobject) {
00073     CORBA::Object_ptr object = SObjectToObject(sobject);
00074     return ObjectToInterface<TInterface>(object);
00075   }
00076 
00077   // _MEM_: note that template functions have to be declared AND
00078   // implemented in the header because they are not compiled in this
00079   // library but in every client library that includes this header
00080   // file. The effective compilation depends on the particular class
00081   // used for TInterface.
00082 
00083   // ---------------------------------------------
00084   // To create a standard SALOME exception embedding a simple text
00085   KERNELHELPERS_EXPORT SALOME::SALOME_Exception createSalomeException(const char * text);
00086 }
00087 
00088 
00089 //
00090 // =============================================================
00091 // SALOME Logger macros
00092 // =============================================================
00093 //
00094 // We can use the macros defined by SALOMELocalTrace/utilities.h
00095 #include "utilities.h"
00096 #define SALOMELOG(msg) {MESS_BEGIN("[XSALOME]") << msg << MESS_END}
00097 #define LOG SALOMELOG
00098 
00099 // This can help to LOG (or use in stream) the CORBA exceptions
00100 // Ex: LOG("An exception occurs: "<<e) will log the data of the exception e
00101 #include <CORBA.h>
00102 #include <ostream>
00103 static std::ostream &
00104 operator<<(std::ostream & os, const CORBA::Exception & e)
00105 {
00106   CORBA::Any tmp;
00107   tmp <<=e ;
00108   CORBA::TypeCode_var tc = tmp.type();
00109   const char * p = tc->name ();
00110   if (*p != '\0')
00111     os << p;
00112   else
00113     os << tc->id();
00114   return os;
00115 }
00116 
00117 
00118 #endif // KERNEL_SERVICES