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