Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / SALOMEDS / SALOMEDS.cxx
1 // Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 //  SALOME SALOMEDS : data structure of SALOME and sources of Salome data server 
24 //  File   : SALOMEDS.cxx
25 //  Author : Sergey ANIKIN
26 //  Module : SALOME
27 //  $Header$
28 //
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDS_StudyManager.hxx"
31 #include "SALOMEDS_Study.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"
38 #include "SALOMEDS_StudyManager_i.hxx"
39
40 #include "SALOMEDS_Defines.hxx"
41
42 // IDL headers
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SALOMEDS)
45 #include <SALOME_NamingService.hxx>
46
47 // PAL8065: san -- Global recursive mutex for SALOMEDS methods
48 Utils_Mutex SALOMEDS::Locker::MutexDS;
49
50 // PAL8065: san -- Global SALOMEDS locker
51 SALOMEDS::Locker::Locker()
52 : Utils_Locker( &MutexDS )
53 {}
54
55 SALOMEDS::Locker::~Locker()
56 {}
57
58 void SALOMEDS::lock()
59 {
60   Locker::MutexDS.lock();
61 }
62
63 void SALOMEDS::unlock()
64 {
65         SALOMEDS::Locker::MutexDS.unlock();
66 }
67
68
69
70 // srn: Added new library methods that create basic SALOMEDS objects (StudyManager, Study, SComponent, SObject)
71
72 //=============================================================================
73 /*!
74  * C factory, accessible with dlsym, after dlopen
75  */
76 //=============================================================================
77
78
79 extern "C"
80 {
81 SALOMEDS_EXPORT
82   SALOMEDSClient_StudyManager* StudyManagerFactory()
83 {
84   return new SALOMEDS_StudyManager();
85 }
86 SALOMEDS_EXPORT
87   SALOMEDSClient_Study* StudyFactory(SALOMEDS::Study_ptr theStudy)
88 {
89   if(CORBA::is_nil(theStudy)) return NULL;
90   return new SALOMEDS_Study(theStudy);
91 }
92
93 SALOMEDS_EXPORT
94   SALOMEDSClient_SObject* SObjectFactory(SALOMEDS::SObject_ptr theSObject)
95 {
96   if(CORBA::is_nil(theSObject)) return NULL;
97   return new SALOMEDS_SObject(theSObject);
98 }
99
100 SALOMEDS_EXPORT
101   SALOMEDSClient_SComponent* SComponentFactory(SALOMEDS::SComponent_ptr theSComponent)
102 {
103   if(CORBA::is_nil(theSComponent)) return NULL;
104   return new SALOMEDS_SComponent(theSComponent);
105 }
106
107 SALOMEDS_EXPORT
108   SALOMEDSClient_StudyBuilder* BuilderFactory(SALOMEDS::StudyBuilder_ptr theBuilder)
109 {
110   if(CORBA::is_nil(theBuilder)) return NULL;
111   return new SALOMEDS_StudyBuilder(theBuilder);
112 }
113
114 SALOMEDS_EXPORT
115   SALOMEDSClient_StudyManager* CreateStudyManager(CORBA::ORB_ptr orb, PortableServer::POA_ptr root_poa)
116 {
117   SALOME_NamingService namingService(orb);
118   CORBA::Object_var obj = namingService.Resolve( "/myStudyManager" );
119   SALOMEDS::StudyManager_var theManager = SALOMEDS::StudyManager::_narrow( obj );
120   if( CORBA::is_nil(theManager) ) {
121     SALOMEDS_StudyManager_i * aStudyManager_i = new  SALOMEDS_StudyManager_i(orb, root_poa);
122     // Activate the objects.  This tells the POA that the objects are ready to accept requests.
123     PortableServer::ObjectId_var aStudyManager_iid =  root_poa->activate_object(aStudyManager_i);
124     //give ownership to the poa : the object will be deleted by the poa
125     aStudyManager_i->_remove_ref();
126     aStudyManager_i->register_name((char*)"/myStudyManager");
127   }
128   return new SALOMEDS_StudyManager();
129 }
130
131 SALOMEDS_EXPORT
132   SALOMEDSClient_IParameters* GetIParameters(const _PTR(AttributeParameter)& ap)
133 {
134   return new SALOMEDS_IParameters(ap);
135 }
136
137 SALOMEDS_EXPORT
138   SALOMEDS::SObject_ptr ConvertSObject(const _PTR(SObject)& theSObject)
139 {
140   
141   SALOMEDS_SObject* so = _CAST(SObject, theSObject);
142   if(!theSObject || !so) return SALOMEDS::SObject::_nil();
143   return so->GetSObject();
144 }
145
146 SALOMEDS_EXPORT
147   SALOMEDS::Study_ptr ConvertStudy(const _PTR(Study)& theStudy)
148 {
149   SALOMEDS_Study* study = _CAST(Study, theStudy);
150   if(!theStudy || !study) return SALOMEDS::Study::_nil();
151   return study->GetStudy();
152 }
153
154 SALOMEDS_EXPORT
155   SALOMEDS::StudyBuilder_ptr ConvertBuilder(const _PTR(StudyBuilder)& theBuilder)
156 {
157   SALOMEDS_StudyBuilder* builder = _CAST(StudyBuilder, theBuilder);
158   if(!theBuilder || !builder) return SALOMEDS::StudyBuilder::_nil(); 
159   return builder->GetBuilder();
160 }
161
162
163 }