1 // Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SALOMEDS_SObject.hxx
21 // Author : Sergey RUIN
26 #include "SALOMEDS_SObject.hxx"
28 #include "SALOMEDS.hxx"
29 #include "SALOMEDS_SComponent.hxx"
30 #include "SALOMEDS_GenericAttribute.hxx"
31 #include "SALOMEDS_Study.hxx"
32 #include "SALOMEDS_SObject_i.hxx"
34 #include "SALOMEDSImpl_SComponent.hxx"
35 #include "SALOMEDSImpl_GenericAttribute.hxx"
36 #include "SALOMEDSImpl_Study.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
45 #include <sys/types.h>
50 #include "utilities.h"
54 SALOMEDS_SObject::SALOMEDS_SObject(SALOMEDS::SObject_ptr theSObject)
57 long pid = (long)_getpid();
59 long pid = (long)getpid();
62 CORBA::LongLong addr = // mpv: fix for IPAL13534: for 64-bit platforms use 8-bytes long for pointer storage
63 theSObject->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
66 _local_impl = ((SALOMEDSImpl_SObject*)(addr));
67 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
71 _corba_impl = SALOMEDS::SObject::_duplicate(theSObject);
77 SALOMEDS_SObject::SALOMEDS_SObject(const SALOMEDSImpl_SObject& theSObject)
80 _corba_impl = SALOMEDS::SObject::_nil();
82 if(theSObject.IsComponent()) {
83 SALOMEDSImpl_SComponent sco = theSObject;
84 _local_impl = sco.GetPersistentCopy();
87 _local_impl = theSObject.GetPersistentCopy();
93 SALOMEDS_SObject::~SALOMEDS_SObject()
96 _corba_impl->Destroy();
99 if(_local_impl) delete _local_impl;
103 std::string SALOMEDS_SObject::GetID()
107 SALOMEDS::Locker lock;
108 aValue = _local_impl->GetID();
110 else aValue = _corba_impl->GetID();
114 _PTR(SComponent) SALOMEDS_SObject::GetFatherComponent()
117 SALOMEDS::Locker lock;
118 return _PTR(SComponent)(new SALOMEDS_SComponent(_local_impl->GetFatherComponent()));
120 return _PTR(SComponent)(new SALOMEDS_SComponent(_corba_impl->GetFatherComponent()));
123 _PTR(SObject) SALOMEDS_SObject::GetFather()
126 SALOMEDS::Locker lock;
127 return _PTR(SObject)(new SALOMEDS_SObject(_local_impl->GetFather()));
129 return _PTR(SObject)(new SALOMEDS_SObject(_corba_impl->GetFather()));
132 bool SALOMEDS_SObject::FindAttribute(_PTR(GenericAttribute)& anAttribute,
133 const std::string& aTypeOfAttribute)
137 SALOMEDS::Locker lock;
138 DF_Attribute* anAttr = NULL;
139 ret = _local_impl->FindAttribute(anAttr, aTypeOfAttribute);
141 SALOMEDSImpl_GenericAttribute* ga = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(anAttr);
142 anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(ga));
146 SALOMEDS::GenericAttribute_var anAttr;
147 ret = _corba_impl->FindAttribute(anAttr.out(), aTypeOfAttribute.c_str());
148 if(ret) anAttribute = _PTR(GenericAttribute)(SALOMEDS_GenericAttribute::CreateAttribute(anAttr));
154 bool SALOMEDS_SObject::ReferencedObject(_PTR(SObject)& theObject)
158 SALOMEDS::Locker lock;
159 SALOMEDSImpl_SObject aSO;
160 ret = _local_impl->ReferencedObject(aSO);
161 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
164 SALOMEDS::SObject_var aSO;
165 ret = _corba_impl->ReferencedObject(aSO.out());
166 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
173 bool SALOMEDS_SObject::FindSubObject(int theTag, _PTR(SObject)& theObject)
177 SALOMEDS::Locker lock;
178 SALOMEDSImpl_SObject aSO;
179 ret = _local_impl->FindSubObject(theTag, aSO);
180 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
183 SALOMEDS::SObject_var aSO;
184 ret = _corba_impl->FindSubObject(theTag, aSO.out());
185 if(ret) theObject = _PTR(SObject)(new SALOMEDS_SObject(aSO));
191 _PTR(Study) SALOMEDS_SObject::GetStudy()
194 SALOMEDS::Locker lock;
195 return _PTR(Study)(new SALOMEDS_Study(_local_impl->GetStudy()));
197 return _PTR(Study)(new SALOMEDS_Study(_corba_impl->GetStudy()));
200 std::string SALOMEDS_SObject::Name()
204 SALOMEDS::Locker lock;
205 aName = _local_impl->Name();
207 else aName = _corba_impl->Name();
212 void SALOMEDS_SObject::Name(const std::string& theName)
215 SALOMEDS::Locker lock;
216 _local_impl->Name(theName);
218 else _corba_impl->Name(theName.c_str());
221 vector<_PTR(GenericAttribute)> SALOMEDS_SObject::GetAllAttributes()
223 vector<_PTR(GenericAttribute)> aVector;
225 SALOMEDSClient_GenericAttribute* anAttr;
228 SALOMEDS::Locker lock;
229 vector<DF_Attribute*> aSeq = _local_impl->GetAllAttributes();
230 aLength = aSeq.size();
231 for (int i = 0; i < aLength; i++) {
232 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]));
233 aVector.push_back(_PTR(GenericAttribute)(anAttr));
237 SALOMEDS::ListOfAttributes_var aSeq = _corba_impl->GetAllAttributes();
238 aLength = aSeq->length();
239 for (int i = 0; i < aLength; i++) {
240 anAttr = SALOMEDS_GenericAttribute::CreateAttribute(aSeq[i]);
241 aVector.push_back(_PTR(GenericAttribute)(anAttr));
248 std::string SALOMEDS_SObject::GetName()
252 SALOMEDS::Locker lock;
253 aName = _local_impl->GetName();
255 else aName = _corba_impl->GetName();
260 std::string SALOMEDS_SObject::GetComment()
262 std::string aComment;
264 SALOMEDS::Locker lock;
265 aComment = _local_impl->GetComment();
267 else aComment = _corba_impl->GetComment();
272 std::string SALOMEDS_SObject::GetIOR()
276 SALOMEDS::Locker lock;
277 anIOR = _local_impl->GetIOR();
279 else anIOR = _corba_impl->GetIOR();
284 int SALOMEDS_SObject::Tag()
287 SALOMEDS::Locker lock;
288 return _local_impl->Tag();
290 return _corba_impl->Tag();
293 int SALOMEDS_SObject::Depth()
296 SALOMEDS::Locker lock;
297 return _local_impl->Depth();
299 return _corba_impl->Depth();
302 CORBA::Object_ptr SALOMEDS_SObject::GetObject()
304 CORBA::Object_var obj;
306 SALOMEDS::Locker lock;
307 std::string anIOR = GetIOR();
309 obj = _orb->string_to_object(anIOR.c_str());
313 obj = _corba_impl->GetObject();
317 return CORBA::Object::_nil();
320 SALOMEDS::SObject_ptr SALOMEDS_SObject::GetSObject()
323 if(!CORBA::is_nil(_corba_impl)) return SALOMEDS::SObject::_duplicate(_corba_impl);
324 SALOMEDS::SObject_var aSO = SALOMEDS_SObject_i::New(*_local_impl, _orb);
325 _corba_impl = SALOMEDS::SObject::_duplicate(aSO);
329 return SALOMEDS::SObject::_duplicate(_corba_impl);
331 return SALOMEDS::SObject::_nil();
335 void SALOMEDS_SObject::init_orb()
337 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
338 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
339 _orb = init(0 , 0 ) ;