1 // Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SALOME SALOMEDS : data structure of SALOME and sources of Salome data server
24 // File : SALOMEDS.cxx
25 // Author : Sergey ANIKIN
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDS_Study.hxx"
31 #include "SALOMEDS_Study_i.hxx"
32 #include "SALOMEDS_StudyBuilder.hxx"
33 #include "SALOMEDS_SObject.hxx"
34 #include "SALOMEDS_SComponent.hxx"
35 #include "SALOMEDSClient.hxx"
36 #include "SALOMEDSClient_IParameters.hxx"
37 #include "SALOMEDS_IParameters.hxx"
39 #include "SALOMEDS_Defines.hxx"
42 #include <SALOMEconfig.h>
43 #include CORBA_SERVER_HEADER(SALOMEDS)
44 #include <SALOME_NamingService.hxx>
46 // PAL8065: san -- Global recursive mutex for SALOMEDS methods
47 Utils_Mutex SALOMEDS::Locker::MutexDS;
49 // PAL8065: san -- Global SALOMEDS locker
50 SALOMEDS::Locker::Locker()
51 : Utils_Locker( &MutexDS )
54 SALOMEDS::Locker::~Locker()
59 Locker::MutexDS.lock();
62 void SALOMEDS::unlock()
64 SALOMEDS::Locker::MutexDS.unlock();
67 // srn: Added new library methods that create basic SALOMEDS objects (Study, SComponent, SObject)
69 //=============================================================================
71 * C factory, accessible with dlsym, after dlopen
73 //=============================================================================
79 SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy)
81 if(CORBA::is_nil(theStudy)) return NULL;
82 return new SALOMEDS_Study(theStudy);
86 SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject)
88 if(CORBA::is_nil(theSObject)) return NULL;
89 return new SALOMEDS_SObject(theSObject);
93 SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent)
95 if(CORBA::is_nil(theSComponent)) return NULL;
96 return new SALOMEDS_SComponent(theSComponent);
100 SALOMEDSClient_StudyBuilder* BuilderFactory(SALOMEDS::StudyBuilder_ptr theBuilder)
102 if(CORBA::is_nil(theBuilder)) return NULL;
103 return new SALOMEDS_StudyBuilder(theBuilder);
107 SALOMEDSClient_Study* CreateStudy(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
109 SALOME_NamingService namingService(orb);
110 CORBA::Object_var obj = namingService.Resolve( "/Study" );
111 SALOMEDS::Study_var aStudy = SALOMEDS::Study::_narrow( obj );
112 SALOMEDS_Study_i* aStudy_i;
113 if( CORBA::is_nil(aStudy) ) {
114 aStudy_i = new SALOMEDS_Study_i(orb);
116 // Activate the objects. This tells the POA that the objects are ready to accept requests.
117 PortableServer::ObjectId_var aStudy_iid = root_poa->activate_object(aStudy_i);
118 aStudy = aStudy_i->_this();
119 namingService.Register(aStudy.in(), "/Study");
121 aStudy_i->_remove_ref();
126 SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
128 return new SALOMEDS_IParameters(ap);
132 SALOMEDS::SObject_ptr ConvertSObject(const _PTR(SObject)& theSObject)
134 SALOMEDS_SObject* so = _CAST(SObject, theSObject);
135 if ( !theSObject || !so )
136 return SALOMEDS::SObject::_nil();
137 return so->GetSObject();
141 SALOMEDS::Study_ptr ConvertStudy(const _PTR(Study)& theStudy)
143 SALOMEDS_Study* study = _CAST(Study, theStudy);
144 if ( !theStudy || !study )
145 return SALOMEDS::Study::_nil();
146 return study->GetStudy();
150 SALOMEDS::StudyBuilder_ptr ConvertBuilder(const _PTR(StudyBuilder)& theBuilder)
152 SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder);
153 if ( !theBuilder || !builder )
154 return SALOMEDS::StudyBuilder::_nil();
155 return builder->GetBuilder();