1 // Copyright (C) 2007-2008 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.
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
22 // File : SALOMEDS_SObject.hxx
23 // Author : Sergey RUIN
28 #include "SALOMEDS_SObject.hxx"
30 #include "SALOMEDS.hxx"
31 #include "SALOMEDS_SComponent.hxx"
32 #include "SALOMEDS_GenericAttribute.hxx"
33 #include "SALOMEDS_Study.hxx"
34 #include "SALOMEDS_SObject_i.hxx"
36 #include "SALOMEDSImpl_SComponent.hxx"
37 #include "SALOMEDSImpl_GenericAttribute.hxx"
38 #include "SALOMEDSImpl_Study.hxx"
40 #include "Utils_ORB_INIT.hxx"
41 #include "Utils_SINGLETON.hxx"
43 #include "Basics_Utils.hxx"
45 #include "utilities.h"
51 #include <sys/types.h>
59 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
62 long pid = (long)_getpid();
64 long pid = (long)getpid();
67 CORBA::LongLong addr = // mpv: fix for IPAL13534: for 64-bit platforms use 8-bytes long for pointer storage
68 theSObject->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
71 _local_impl = reinterpret_cast<SALOMEDSImpl_SObject*>(addr);
72 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
76 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
82 SALOMEDS_SObject::SALOMEDS_SObject(const SALOMEDSImpl_SObject& theSObject)
85 _corba_impl = SALOMEDS::SObject::_nil();
87 if(theSObject.IsComponent()) {
88 SALOMEDSImpl_SComponent sco = theSObject;
89 _local_impl = sco.GetPersistentCopy();
92 _local_impl = theSObject.GetPersistentCopy();
98 SALOMEDS_SObject::~SALOMEDS_SObject()
101 _corba_impl->Destroy();
104 if(_local_impl) delete _local_impl;
108 std::string SALOMEDS_SObject::GetID()
112 SALOMEDS::Locker lock;
113 aValue = _local_impl->GetID();
115 else aValue = _corba_impl->GetID();
119 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
122 SALOMEDS::Locker lock;
123 return _PTR(SComponent)(new SALOMEDS_SComponent(_local_impl->GetFatherComponent()));
125 return _PTR(SComponent)(new SALOMEDS_SComponent(_corba_impl->GetFatherComponent()));
128 _PTR(SObject) SALOMEDS_SObject::GetFather()
131 SALOMEDS::Locker lock;
132 return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
134 return _PTR(SObject)(new SALOMEDS_SObject(_corba_impl->GetFather()));
137 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute,
138 const std::string& aTypeOfAttribute)
142 SALOMEDS::Locker lock;
143 DF_Attribute* anAttr = NULL;
144 ret = _local_impl->FindAttribute(anAttr, aTypeOfAttribute);
146 SALOMEDSImpl_GenericAttribute* ga = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(anAttr);
147 anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(ga));
151 SALOMEDS::GenericAttribute_var anAttr;
152 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
153 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
159 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
163 SALOMEDS::Locker lock;
164 SALOMEDSImpl_SObject aSO;
165 ret = _local_impl->ReferencedObject(aSO);
166 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
169 SALOMEDS::SObject_var aSO;
170 ret = _corba_impl->ReferencedObject(aSO.out());
171 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
178 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
182 SALOMEDS::Locker lock;
183 SALOMEDSImpl_SObject aSO;
184 ret = _local_impl->FindSubObject(theTag, aSO);
185 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
188 SALOMEDS::SObject_var aSO;
189 ret = _corba_impl->FindSubObject(theTag, aSO.out());
190 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
196 _PTR(Study) SALOMEDS_SObject::GetStudy()
199 SALOMEDS::Locker lock;
200 return _PTR(Study)(new SALOMEDS_Study(_local_impl->GetStudy()));
202 return _PTR(Study)(new SALOMEDS_Study(_corba_impl->GetStudy()));
205 std::string SALOMEDS_SObject::Name()
209 SALOMEDS::Locker lock;
210 aName = _local_impl->Name();
212 else aName = _corba_impl->Name();
217 void SALOMEDS_SObject::Name(const std::string& theName)
220 SALOMEDS::Locker lock;
221 _local_impl->Name(theName);
223 else _corba_impl->Name(theName.c_str());
226 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
228 vector<_PTR(GenericAttribute)> aVector;
230 SALOMEDSClient_GenericAttribute* anAttr;
233 SALOMEDS::Locker lock;
234 vector<DF_Attribute*> aSeq = _local_impl->GetAllAttributes();
235 aLength = aSeq.size();
236 for (int i = 0; i < aLength; i++) {
237 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]));
238 aVector.push_back(_PTR(GenericAttribute)(anAttr));
242 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
243 aLength = aSeq->length();
244 for (int i = 0; i < aLength; i++) {
245 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
246 aVector.push_back(_PTR(GenericAttribute)(anAttr));
253 std::string SALOMEDS_SObject::GetName()
257 SALOMEDS::Locker lock;
258 aName = _local_impl->GetName();
260 else aName = _corba_impl->GetName();
265 std::string SALOMEDS_SObject::GetComment()
267 std::string aComment;
269 SALOMEDS::Locker lock;
270 aComment = _local_impl->GetComment();
272 else aComment = _corba_impl->GetComment();
277 std::string SALOMEDS_SObject::GetIOR()
281 SALOMEDS::Locker lock;
282 anIOR = _local_impl->GetIOR();
284 else anIOR = _corba_impl->GetIOR();
289 int SALOMEDS_SObject::Tag()
292 SALOMEDS::Locker lock;
293 return _local_impl->Tag();
295 return _corba_impl->Tag();
298 int SALOMEDS_SObject::Depth()
301 SALOMEDS::Locker lock;
302 return _local_impl->Depth();
304 return _corba_impl->Depth();
307 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
309 CORBA::Object_var obj;
311 SALOMEDS::Locker lock;
312 std::string anIOR = GetIOR();
314 obj = _orb->string_to_object(anIOR.c_str());
318 obj = _corba_impl->GetObject();
322 return CORBA::Object::_nil();
325 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
328 if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SObject::_duplicate(_corba_impl);
329 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(*_local_impl, _orb);
330 _corba_impl = SALOMEDS::SObject::_duplicate(aSO);
334 return SALOMEDS::SObject::_duplicate(_corba_impl);
336 return SALOMEDS::SObject::_nil();
340 void SALOMEDS_SObject::init_orb()
342 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
343 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
344 _orb = init(0 , 0 ) ;