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::String_var)_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((SALOMEDS::SComponent_var)_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((SALOMEDS::SObject_var)_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 SALOMEDS::Study_var study=_corba_impl->GetStudy();
203 return _PTR(Study)(new SALOMEDS_Study(study));
206 std::string SALOMEDS_SObject::Name()
210 SALOMEDS::Locker lock;
211 aName = _local_impl->Name();
213 else aName = (CORBA::String_var)_corba_impl->Name();
218 void SALOMEDS_SObject::Name(const std::string& theName)
221 SALOMEDS::Locker lock;
222 _local_impl->Name(theName);
224 else _corba_impl->Name(theName.c_str());
227 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
229 vector<_PTR(GenericAttribute)> aVector;
231 SALOMEDSClient_GenericAttribute* anAttr;
234 SALOMEDS::Locker lock;
235 vector<DF_Attribute*> aSeq = _local_impl->GetAllAttributes();
236 aLength = aSeq.size();
237 for (int i = 0; i < aLength; i++) {
238 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]));
239 aVector.push_back(_PTR(GenericAttribute)(anAttr));
243 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
244 aLength = aSeq->length();
245 for (int i = 0; i < aLength; i++) {
246 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
247 aVector.push_back(_PTR(GenericAttribute)(anAttr));
254 std::string SALOMEDS_SObject::GetName()
258 SALOMEDS::Locker lock;
259 aName = _local_impl->GetName();
261 else aName = (CORBA::String_var) _corba_impl->GetName();
266 std::string SALOMEDS_SObject::GetComment()
268 std::string aComment;
270 SALOMEDS::Locker lock;
271 aComment = _local_impl->GetComment();
273 else aComment = (CORBA::String_var) _corba_impl->GetComment();
278 std::string SALOMEDS_SObject::GetIOR()
282 SALOMEDS::Locker lock;
283 anIOR = _local_impl->GetIOR();
285 else anIOR = (CORBA::String_var) _corba_impl->GetIOR();
290 int SALOMEDS_SObject::Tag()
293 SALOMEDS::Locker lock;
294 return _local_impl->Tag();
296 return _corba_impl->Tag();
299 int SALOMEDS_SObject::Depth()
302 SALOMEDS::Locker lock;
303 return _local_impl->Depth();
305 return _corba_impl->Depth();
308 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
310 CORBA::Object_var obj;
312 SALOMEDS::Locker lock;
313 std::string anIOR = GetIOR();
315 obj = _orb->string_to_object(anIOR.c_str());
319 obj = _corba_impl->GetObject();
323 return CORBA::Object::_nil();
326 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
329 if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SObject::_duplicate(_corba_impl);
330 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(*_local_impl, _orb);
331 _corba_impl = SALOMEDS::SObject::_duplicate(aSO);
335 return SALOMEDS::SObject::_duplicate(_corba_impl);
337 return SALOMEDS::SObject::_nil();
341 void SALOMEDS_SObject::init_orb()
343 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
344 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
345 _orb = init(0 , 0 ) ;