1 // Copyright (C) 2007-2021 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, or (at your option) any later version.
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
23 // File : SALOMEDS_SObject.hxx
24 // Author : Sergey RUIN
29 #include "SALOMEDS_SObject.hxx"
31 #include "SALOMEDS.hxx"
32 #include "SALOMEDS_SComponent.hxx"
33 #include "SALOMEDS_GenericAttribute.hxx"
34 #include "SALOMEDS_Study.hxx"
35 #include "SALOMEDS_SObject_i.hxx"
37 #include "SALOMEDSImpl_SComponent.hxx"
38 #include "SALOMEDSImpl_GenericAttribute.hxx"
39 #include "SALOMEDSImpl_Study.hxx"
41 #include "Utils_ORB_INIT.hxx"
42 #include "Utils_SINGLETON.hxx"
44 #include "Basics_Utils.hxx"
46 #include "utilities.h"
52 #include <sys/types.h>
57 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
60 long pid = (long)_getpid();
62 long pid = (long)getpid();
65 CORBA::LongLong addr = // mpv: fix for IPAL13534: for 64-bit platforms use 8-bytes long for pointer storage
66 theSObject->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
69 _local_impl = reinterpret_cast<SALOMEDSImpl_SObject*>(addr);
70 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
74 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
80 SALOMEDS_SObject::SALOMEDS_SObject(const SALOMEDSImpl_SObject& theSObject)
83 _corba_impl = SALOMEDS::SObject::_nil();
85 if(theSObject.IsComponent()) {
86 SALOMEDSImpl_SComponent sco = theSObject;
87 _local_impl = sco.GetPersistentCopy();
90 _local_impl = theSObject.GetPersistentCopy();
96 SALOMEDS_SObject::~SALOMEDS_SObject()
99 _corba_impl->UnRegister();
102 if(_local_impl) delete _local_impl;
106 bool SALOMEDS_SObject::IsNull() const
108 return _isLocal ? ( !_local_impl || _local_impl->IsNull() ) : _corba_impl->IsNull();
111 std::string SALOMEDS_SObject::GetID()
115 SALOMEDS::Locker lock;
116 aValue = _local_impl->GetID();
118 else aValue = (CORBA::String_var)_corba_impl->GetID();
122 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
125 SALOMEDS::Locker lock;
126 return _PTR(SComponent)(new SALOMEDS_SComponent(_local_impl->GetFatherComponent()));
128 return _PTR(SComponent)(new SALOMEDS_SComponent((SALOMEDS::SComponent_var)_corba_impl->GetFatherComponent()));
131 _PTR(SObject) SALOMEDS_SObject::GetFather()
134 SALOMEDS::Locker lock;
135 return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
137 return _PTR(SObject)(new SALOMEDS_SObject((SALOMEDS::SObject_var)_corba_impl->GetFather()));
140 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute,
141 const std::string& aTypeOfAttribute)
145 SALOMEDS::Locker lock;
146 DF_Attribute* anAttr = NULL;
147 ret = _local_impl->FindAttribute(anAttr, aTypeOfAttribute);
149 SALOMEDSImpl_GenericAttribute* ga = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(anAttr);
150 anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(ga));
154 SALOMEDS::GenericAttribute_var anAttr;
155 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
156 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
162 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
166 SALOMEDS::Locker lock;
167 SALOMEDSImpl_SObject aSO;
168 ret = _local_impl->ReferencedObject(aSO);
169 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
172 SALOMEDS::SObject_var aSO;
173 ret = _corba_impl->ReferencedObject(aSO.out());
174 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
181 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
185 SALOMEDS::Locker lock;
186 SALOMEDSImpl_SObject aSO;
187 ret = _local_impl->FindSubObject(theTag, aSO);
188 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
191 SALOMEDS::SObject_var aSO;
192 ret = _corba_impl->FindSubObject(theTag, aSO.out());
193 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
199 std::string SALOMEDS_SObject::Name()
203 SALOMEDS::Locker lock;
204 aName = _local_impl->Name();
206 else aName = (CORBA::String_var)_corba_impl->Name();
211 void SALOMEDS_SObject::Name(const std::string& theName)
214 SALOMEDS::Locker lock;
215 _local_impl->Name(theName);
217 else _corba_impl->Name(theName.c_str());
220 std::vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
222 std::vector<_PTR(GenericAttribute)> aVector;
224 SALOMEDSClient_GenericAttribute* anAttr;
227 SALOMEDS::Locker lock;
228 std::vector<DF_Attribute*> aSeq = _local_impl->GetAllAttributes();
229 aLength = (int)aSeq.size(); //!< TODO: conversion from size_t to int
230 for (int i = 0; i < aLength; i++) {
231 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]));
232 aVector.push_back(_PTR(GenericAttribute)(anAttr));
236 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
237 aLength = aSeq->length();
238 for (int i = 0; i < aLength; i++) {
239 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
240 aVector.push_back(_PTR(GenericAttribute)(anAttr));
247 std::string SALOMEDS_SObject::GetName()
251 SALOMEDS::Locker lock;
252 aName = _local_impl->GetName();
254 else aName = (CORBA::String_var) _corba_impl->GetName();
259 std::string SALOMEDS_SObject::GetComment()
261 std::string aComment;
263 SALOMEDS::Locker lock;
264 aComment = _local_impl->GetComment();
266 else aComment = (CORBA::String_var) _corba_impl->GetComment();
271 std::string SALOMEDS_SObject::GetIOR()
275 SALOMEDS::Locker lock;
276 anIOR = _local_impl->GetIOR();
278 else anIOR = (CORBA::String_var) _corba_impl->GetIOR();
283 int SALOMEDS_SObject::Tag()
286 SALOMEDS::Locker lock;
287 return _local_impl->Tag();
289 return _corba_impl->Tag();
292 int SALOMEDS_SObject::GetLastChildTag()
295 SALOMEDS::Locker lock;
296 return _local_impl->GetLastChildTag();
298 return _corba_impl->GetLastChildTag();
301 int SALOMEDS_SObject::Depth()
304 SALOMEDS::Locker lock;
305 return _local_impl->Depth();
307 return _corba_impl->Depth();
310 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
312 CORBA::Object_var obj;
314 SALOMEDS::Locker lock;
315 std::string anIOR = GetIOR();
317 obj = _orb->string_to_object(anIOR.c_str());
321 obj = _corba_impl->GetObject();
325 return CORBA::Object::_nil();
328 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
331 if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SObject::_duplicate(_corba_impl);
332 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(*_local_impl, _orb);
333 _corba_impl = SALOMEDS::SObject::_duplicate(aSO);
337 return SALOMEDS::SObject::_duplicate(_corba_impl);
339 return SALOMEDS::SObject::_nil();
343 void SALOMEDS_SObject::init_orb()
345 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
346 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
347 _orb = init(0 , 0 ) ;
350 void SALOMEDS_SObject::SetAttrString(const std::string& name, const std::string& value)
354 SALOMEDS::Locker lock;
355 _local_impl->SetAttrString(name,value);
359 _corba_impl->SetAttrString(name.c_str(),value.c_str());