Back to index

salome-kernel  6.5.0
SALOMEDS.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
00024 //  File   : SALOMEDS.cxx
00025 //  Author : Sergey ANIKIN
00026 //  Module : SALOME
00027 //  $Header: /home/server/cvs/KERNEL/KERNEL_SRC/src/SALOMEDS/SALOMEDS.cxx,v 1.7.30.2.12.1 2012-04-12 14:05:20 vsr Exp $
00028 //
00029 #include "SALOMEDS.hxx"
00030 #include "SALOMEDS_StudyManager.hxx"
00031 #include "SALOMEDS_Study.hxx"
00032 #include "SALOMEDS_StudyBuilder.hxx"
00033 #include "SALOMEDS_SObject.hxx"
00034 #include "SALOMEDS_SComponent.hxx"
00035 #include "SALOMEDSClient.hxx"
00036 #include "SALOMEDSClient_IParameters.hxx"
00037 #include "SALOMEDS_IParameters.hxx"
00038 #include "SALOMEDS_StudyManager_i.hxx"
00039 
00040 #include "SALOMEDS_Defines.hxx"
00041 
00042 // IDL headers
00043 #include <SALOMEconfig.h>
00044 #include CORBA_SERVER_HEADER(SALOMEDS)
00045 #include <SALOME_NamingService.hxx>
00046 
00047 // PAL8065: san -- Global recursive mutex for SALOMEDS methods
00048 Utils_Mutex SALOMEDS::Locker::MutexDS;
00049 
00050 // PAL8065: san -- Global SALOMEDS locker
00051 SALOMEDS::Locker::Locker()
00052 : Utils_Locker( &MutexDS )
00053 {}
00054 
00055 SALOMEDS::Locker::~Locker()
00056 {}
00057 
00058 void SALOMEDS::lock()
00059 {
00060   Locker::MutexDS.lock();
00061 }
00062 
00063 void SALOMEDS::unlock()
00064 {
00065        SALOMEDS::Locker::MutexDS.unlock();
00066 }
00067 
00068 
00069 
00070 // srn: Added new library methods that create basic SALOMEDS objects (StudyManager, Study, SComponent, SObject)
00071 
00072 //=============================================================================
00076 //=============================================================================
00077 
00078 
00079 extern "C"
00080 {
00081 SALOMEDS_EXPORT
00082   SALOMEDSClient_StudyManager* StudyManagerFactory()
00083 {
00084   return new SALOMEDS_StudyManager();
00085 }
00086 SALOMEDS_EXPORT
00087   SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy)
00088 {
00089   if(CORBA::is_nil(theStudy)) return NULL;
00090   return new SALOMEDS_Study(theStudy);
00091 }
00092 
00093 SALOMEDS_EXPORT
00094   SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject)
00095 {
00096   if(CORBA::is_nil(theSObject)) return NULL;
00097   return new SALOMEDS_SObject(theSObject);
00098 }
00099 
00100 SALOMEDS_EXPORT
00101   SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent)
00102 {
00103   if(CORBA::is_nil(theSComponent)) return NULL;
00104   return new SALOMEDS_SComponent(theSComponent);
00105 }
00106 
00107 SALOMEDS_EXPORT
00108   SALOMEDSClient_StudyBuilder* BuilderFactory(SALOMEDS::StudyBuilder_ptr theBuilder)
00109 {
00110   if(CORBA::is_nil(theBuilder)) return NULL;
00111   return new SALOMEDS_StudyBuilder(theBuilder);
00112 }
00113 
00114 SALOMEDS_EXPORT
00115   SALOMEDSClient_StudyManager* CreateStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
00116 {
00117   SALOME_NamingService namingService(orb);
00118   CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" );
00119   SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj );
00120   if( CORBA::is_nil(theManager) ) {
00121     SALOMEDS_StudyManager_i * aStudyManager_i = new  SALOMEDS_StudyManager_i(orb, root_poa);
00122     // Activate the objects.  This tells the POA that the objects are ready to accept requests.
00123     PortableServer::ObjectId_var aStudyManager_iid =  root_poa->activate_object(aStudyManager_i);
00124     //give ownership to the poa : the object will be deleted by the poa
00125     aStudyManager_i->_remove_ref();
00126     aStudyManager_i->register_name((char*)"/myStudyManager");
00127   }
00128   return new SALOMEDS_StudyManager();
00129 }
00130 
00131 SALOMEDS_EXPORT
00132   SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
00133 {
00134   return new SALOMEDS_IParameters(ap);
00135 }
00136 
00137 SALOMEDS_EXPORT
00138   SALOMEDS::SObject_ptr ConvertSObject(const _PTR(SObject)& theSObject)
00139 {
00140   
00141   SALOMEDS_SObject* so = _CAST(SObject, theSObject);
00142   if(!theSObject || !so) return SALOMEDS::SObject::_nil();
00143   return so->GetSObject();
00144 }
00145 
00146 SALOMEDS_EXPORT
00147   SALOMEDS::Study_ptr ConvertStudy(const _PTR(Study)& theStudy)
00148 {
00149   SALOMEDS_Study* study = _CAST(Study, theStudy);
00150   if(!theStudy || !study) return SALOMEDS::Study::_nil();
00151   return study->GetStudy();
00152 }
00153 
00154 SALOMEDS_EXPORT
00155   SALOMEDS::StudyBuilder_ptr ConvertBuilder(const _PTR(StudyBuilder)& theBuilder)
00156 {
00157   SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder);
00158   if(!theBuilder || !builder) return SALOMEDS::StudyBuilder::_nil(); 
00159   return builder->GetBuilder();
00160 }
00161 
00162 
00163 }