]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_Driver_i.cxx
Salome HOME
add check on mpi implementation
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_Driver_i.cxx
1 // Copyright (C) 2007-2011  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
23 #include "SALOMEDS_Driver_i.hxx"
24 #include "SALOMEDS_TMPFile_i.hxx"
25 #include "utilities.h"
26 #include "SALOMEDS_SObject_i.hxx"
27 #include "SALOMEDS_SComponent_i.hxx"
28 #include "SALOMEDS_Study_i.hxx"
29 #include "SALOMEDS.hxx"
30 #include <stdlib.h>
31
32 SALOMEDS_Driver_i::~SALOMEDS_Driver_i()
33 {
34 }
35
36 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::Save(const SALOMEDSImpl_SComponent& theComponent,
37                                       const std::string& theURL,
38                                       long& theStreamLength,
39                                       bool isMultiFile)
40 {  
41   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
42   CORBA::String_var url = CORBA::string_dup(theURL.c_str());
43
44   SALOMEDS::unlock();
45   SALOMEDS::TMPFile_var aStream = _driver->Save(sco.in(), url, isMultiFile);
46   SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
47   theStreamLength = aTMPFile->Size();
48   SALOMEDS::lock();
49
50   return aTMPFile;
51 }
52
53 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::SaveASCII(const SALOMEDSImpl_SComponent& theComponent,
54                                                    const std::string& theURL,
55                                                    long& theStreamLength,
56                                                    bool isMultiFile)
57 {
58   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
59   CORBA::String_var url = CORBA::string_dup(theURL.c_str());
60
61   SALOMEDS::unlock();
62   SALOMEDS::TMPFile_var aStream = _driver->SaveASCII(sco.in(), url, isMultiFile);
63   SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
64   theStreamLength = aTMPFile->Size();
65   SALOMEDS::lock();
66
67   return aTMPFile;
68 }
69   
70 bool SALOMEDS_Driver_i::Load(const SALOMEDSImpl_SComponent& theComponent,
71                              const unsigned char* theStream,
72                              const long theStreamLength,
73                              const std::string& theURL,
74                              bool isMultiFile)
75 {
76   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
77   CORBA::String_var url = CORBA::string_dup(theURL.c_str());
78   CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
79
80   SALOMEDS::TMPFile_var aStream;
81   if (theStreamLength > 0) 
82     aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);  
83   else 
84     aStream = new SALOMEDS::TMPFile(0);
85
86   SALOMEDS::unlock();
87   bool isOk = _driver->Load(sco.in(), aStream.in(), url, isMultiFile);
88   SALOMEDS::lock();
89
90   return isOk;
91 }
92
93 bool SALOMEDS_Driver_i::LoadASCII(const SALOMEDSImpl_SComponent& theComponent,
94                                   const unsigned char* theStream,
95                                   const long theStreamLength,
96                                   const std::string& theURL,
97                                   bool isMultiFile)
98 {
99   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
100   CORBA::String_var url = CORBA::string_dup(theURL.c_str());
101   CORBA::Octet* anOctetBuf = (CORBA::Octet*)theStream;
102
103   SALOMEDS::TMPFile_var aStream;
104   if(theStreamLength > 0) 
105     aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);  
106   else 
107     aStream = new SALOMEDS::TMPFile(0);
108
109   SALOMEDS::unlock();
110   bool isOk = _driver->LoadASCII(sco.in(), aStream.in(), url, isMultiFile);
111   SALOMEDS::lock();
112
113   return isOk;
114 }
115
116 void SALOMEDS_Driver_i::Close(const SALOMEDSImpl_SComponent& theComponent)
117 {
118   SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (theComponent, _orb);
119
120   SALOMEDS::unlock();
121   _driver->Close(sco.in());
122   SALOMEDS::lock();
123 }
124
125
126
127 std::string SALOMEDS_Driver_i::IORToLocalPersistentID(const SALOMEDSImpl_SObject& theSObject,
128                                                  const std::string& IORString,
129                                                  bool isMultiFile,
130                                                  bool isASCII)
131 {
132   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theSObject, _orb);
133   CORBA::String_var ior = CORBA::string_dup(IORString.c_str());
134
135   SALOMEDS::unlock();
136   CORBA::String_var pers_string =_driver->IORToLocalPersistentID(so.in(), ior.in(), isMultiFile, isASCII);
137   SALOMEDS::lock();
138
139   return std::string(pers_string);
140 }
141
142
143 std::string SALOMEDS_Driver_i::LocalPersistentIDToIOR(const SALOMEDSImpl_SObject& theObject,
144                                                  const std::string& aLocalPersistentID,
145                                                  bool isMultiFile,
146                                                  bool isASCII)
147 {
148   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
149   CORBA::String_var pers_string = CORBA::string_dup(aLocalPersistentID.c_str());
150   SALOMEDS::unlock();
151   CORBA::String_var IOR = _driver->LocalPersistentIDToIOR(so.in(), pers_string.in(), isMultiFile, isASCII);
152   SALOMEDS::lock();
153   return std::string(IOR);
154 }
155
156 bool SALOMEDS_Driver_i::CanCopy(const SALOMEDSImpl_SObject& theObject)
157 {
158   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
159
160   SALOMEDS::unlock();
161   bool isOk = _driver->CanCopy(so.in());
162   so->UnRegister();
163   SALOMEDS::lock();
164
165   return isOk;
166 }
167
168
169 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::CopyFrom(const SALOMEDSImpl_SObject& theObject, 
170                                                   int& theObjectID,
171                                                   long& theStreamLength)
172 {
173   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
174
175   SALOMEDS::unlock();
176   CORBA::Long anObjectID;
177   SALOMEDS::TMPFile_var aStream = _driver->CopyFrom(so.in(), anObjectID);
178   SALOMEDSImpl_TMPFile* aTMPFile = new SALOMEDS_TMPFile_i(aStream._retn());
179   theStreamLength = aTMPFile->Size();
180   theObjectID = anObjectID;
181   SALOMEDS::lock();
182
183   return aTMPFile;
184 }
185
186 bool SALOMEDS_Driver_i::CanPaste(const std::string& theComponentName, int theObjectID)
187 {
188   SALOMEDS::unlock();
189   bool canPaste = _driver->CanPaste(theComponentName.c_str(), theObjectID);
190   SALOMEDS::lock();
191   return canPaste;
192 }
193
194 std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
195                                     const long theStreamLength,
196                                     int theObjectID,
197                                     const SALOMEDSImpl_SObject& theObject)
198 {
199   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (theObject, _orb);
200   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)theStream;
201
202   SALOMEDS::TMPFile_var aStream;
203   if(theStreamLength > 0) 
204     aStream = new SALOMEDS::TMPFile(theStreamLength, theStreamLength, anOctetBuf, 0);  
205   else 
206     aStream = new SALOMEDS::TMPFile(0);
207
208   SALOMEDS::unlock();
209   SALOMEDS::SObject_var ret_so = _driver->PasteInto(aStream.in(), theObjectID, so.in());
210   SALOMEDS::lock();
211
212   return std::string(ret_so->GetID());
213 }
214
215 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy, 
216                                                     bool isPublished, 
217                                                     bool isMultiFile,
218                                                     bool& isValidScript,
219                                                     long& theStreamLength)
220 {
221   SALOMEDS_Study_i *  st_servant = SALOMEDS_Study_i::GetStudyServant(theStudy, _orb);//new SALOMEDS_Study_i (theStudy, _orb);
222   SALOMEDS::Study_var st  = SALOMEDS::Study::_narrow(st_servant->_this());
223   Engines::EngineComponent_ptr aComponent = Engines::EngineComponent::_narrow(_driver);
224
225   SALOMEDS::unlock();
226   CORBA::Boolean aValidScript, aPublished = isPublished;
227   Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, isMultiFile, aValidScript);
228   SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
229   theStreamLength = aTMPFile->Size();
230   isValidScript = aValidScript;
231   SALOMEDS::lock();
232
233   return aTMPFile;
234 }
235
236 //###############################################################################################################
237 //                                          SALOMEDS_DriverFactory
238 //###############################################################################################################
239
240 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByType(const std::string& theComponentType)
241 {
242   CORBA::Object_var obj;
243
244   std::string aFactoryType;
245   if (theComponentType == "SUPERV") aFactoryType = "SuperVisionContainer";
246   else aFactoryType = "FactoryServer";
247
248   SALOMEDS::unlock();
249   obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component(aFactoryType.c_str(), theComponentType.c_str());
250   SALOMEDS::lock();
251
252   if (CORBA::is_nil(obj)) {
253     obj = SALOME_LifeCycleCORBA(_name_service).FindOrLoad_Component("FactoryServerPy", theComponentType.c_str());
254   }
255
256   if (!CORBA::is_nil(obj)) {
257     SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
258     return new SALOMEDS_Driver_i(aDriver, _orb);
259   }
260
261   return NULL;
262 }
263
264 SALOMEDSImpl_Driver* SALOMEDS_DriverFactory_i::GetDriverByIOR(const std::string& theIOR)
265 {
266   CORBA::Object_var obj;
267   obj = _orb->string_to_object(theIOR.c_str());
268  
269   if (!CORBA::is_nil(obj)) {
270     SALOMEDS::Driver_var aDriver = SALOMEDS::Driver::_narrow(obj);
271     return new SALOMEDS_Driver_i(aDriver, _orb);
272   }
273
274   return NULL;
275 }