1 // Copyright (C) 2007-2016 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_i.cxx
24 // Author : Sergey RUIN
27 #include "utilities.h"
28 #include "SALOMEDS_SObject_i.hxx"
29 #include "SALOMEDS_SComponent_i.hxx"
30 #include "SALOMEDS_GenericAttribute_i.hxx"
31 #include "SALOMEDS_StudyManager_i.hxx"
32 #include "SALOMEDS.hxx"
33 #include "SALOMEDSImpl_GenericAttribute.hxx"
34 #include "SALOMEDSImpl_SComponent.hxx"
35 #include "SALOMEDSImpl_Study.hxx"
36 #include "SALOMEDSImpl_AttributeIOR.hxx"
37 #include "Basics_Utils.hxx"
44 #include <sys/types.h>
48 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const SALOMEDSImpl_SObject& theImpl, CORBA::ORB_ptr theORB)
50 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
52 return so_servant->_this();
56 //============================================================================
57 /*! Function : constructor
60 //============================================================================
61 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb) :
62 GenericObj_i(SALOMEDS_StudyManager_i::GetThePOA())
66 if(impl.IsComponent()) {
67 SALOMEDSImpl_SComponent sco = impl;
68 _impl = sco.GetPersistentCopy();
71 _impl = impl.GetPersistentCopy();
74 _orb = CORBA::ORB::_duplicate(orb);
75 //SALOME::GenericObj_i::myPOA = SALOMEDS_StudyManager_i::GetPOA(GetStudy());
79 //============================================================================
80 /*! Function : destructor
83 //============================================================================
84 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
86 if(_impl) delete _impl;
89 //============================================================================
91 \brief Get default POA for the servant object.
93 This function is implicitly called from "_this()" function.
94 Default POA can be set via the constructor.
96 \return reference to the default POA for the servant
98 //============================================================================
99 PortableServer::POA_ptr SALOMEDS_SObject_i::_default_POA()
101 myPOA = PortableServer::POA::_duplicate(SALOMEDS_StudyManager_i::GetThePOA());
102 //MESSAGE("SALOMEDS_SObject_i::_default_POA: " << myPOA);
103 return PortableServer::POA::_duplicate(myPOA);
106 //================================================================================
108 * \brief Returns true if the %SObject does not belong to any %Study
110 //================================================================================
112 CORBA::Boolean SALOMEDS_SObject_i::IsNull()
114 SALOMEDS::Locker lock;
115 return !_impl || _impl->IsNull();
118 //============================================================================
122 //============================================================================
123 char* SALOMEDS_SObject_i::GetID()
125 SALOMEDS::Locker lock;
126 return CORBA::string_dup(_impl->GetID().c_str());
129 //============================================================================
130 /*! Function : GetFatherComponent
133 //============================================================================
134 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
136 SALOMEDS::Locker lock;
137 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
141 //============================================================================
142 /*! Function : GetFather
145 //============================================================================
146 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
148 SALOMEDS::Locker lock;
149 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
153 //============================================================================
157 //============================================================================
158 SALOMEDS::Study_ptr SALOMEDS_SObject_i::GetStudy()
160 SALOMEDS::Locker lock;
161 SALOMEDSImpl_Study* aStudy = _impl->GetStudy();
163 MESSAGE("Problem GetStudy");
164 return SALOMEDS::Study::_nil();
167 std::string IOR = aStudy->GetTransientReference();
168 CORBA::Object_var obj = _orb->string_to_object(IOR.c_str());
169 SALOMEDS::Study_var Study = SALOMEDS::Study::_narrow(obj) ;
170 ASSERT(!CORBA::is_nil(Study));
171 return SALOMEDS::Study::_duplicate(Study);
174 //============================================================================
175 /*! Function : FindAttribute
176 * Purpose : Find attribute of given type on this SObject
178 //============================================================================
179 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
180 const char* aTypeOfAttribute)
182 SALOMEDS::Locker lock;
183 DF_Attribute* anAttr = NULL;
184 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
185 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
192 //============================================================================
193 /*! Function : GetAllAttributes
194 * Purpose : Returns list of all attributes for this sobject
196 //============================================================================
198 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
200 SALOMEDS::Locker lock;
201 std::vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
202 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
203 int length = aSeq.size();
205 SeqOfAttr->length(length);
208 for(int i = 0; i < length; i++) {
209 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
210 SALOMEDS::GenericAttribute_var anAttribute;
211 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
212 if (!CORBA::is_nil(anAttribute)) {
213 SeqOfAttr[i] = anAttribute;
217 return SeqOfAttr._retn();
221 //============================================================================
222 /*! Function : ReferencedObject
225 //============================================================================
226 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
228 SALOMEDS::Locker lock;
229 SALOMEDSImpl_SObject aRefObj;
230 if(!_impl->ReferencedObject(aRefObj)) return false;
232 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
236 //============================================================================
237 /*! Function : FindSubObject
240 //============================================================================
241 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
243 SALOMEDS::Locker lock;
244 SALOMEDSImpl_SObject aSubObj;
245 if(!_impl->FindSubObject(atag, aSubObj)) return false;
247 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
252 //============================================================================
254 * Purpose : gets a name
256 //============================================================================
257 char* SALOMEDS_SObject_i::Name()
259 SALOMEDS::Locker lock;
260 return CORBA::string_dup(_impl->Name().c_str());
263 //============================================================================
265 * Purpose : sets a name
267 //============================================================================
268 void SALOMEDS_SObject_i::Name(const char* name)
270 SALOMEDS::Locker lock;
271 std::string aName((char*)name);
275 //============================================================================
279 //============================================================================
280 CORBA::Short SALOMEDS_SObject_i::Tag()
282 SALOMEDS::Locker lock;
286 //============================================================================
287 /*! Function : GetLastChildTag
290 //============================================================================
291 CORBA::Short SALOMEDS_SObject_i::GetLastChildTag()
293 SALOMEDS::Locker lock;
294 return (CORBA::Short) _impl->GetLastChildTag();
297 //============================================================================
301 //============================================================================
302 CORBA::Short SALOMEDS_SObject_i::Depth()
304 SALOMEDS::Locker lock;
305 return _impl->Depth();
308 //============================================================================
309 /*! Function : GetObject
312 //============================================================================
313 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
315 SALOMEDS::Locker lock;
316 CORBA::Object_ptr obj = CORBA::Object::_nil();
318 std::string IOR = _impl->GetIOR();
319 char* c_ior = CORBA::string_dup(IOR.c_str());
320 obj = _orb->string_to_object(c_ior);
321 CORBA::string_free(c_ior);
326 //============================================================================
327 /*! Function : GetName
330 //============================================================================
331 char* SALOMEDS_SObject_i::GetName()
333 SALOMEDS::Locker lock;
334 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
338 //============================================================================
339 /*! Function : GetComment
342 //============================================================================
343 char* SALOMEDS_SObject_i::GetComment()
345 SALOMEDS::Locker lock;
346 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
350 //============================================================================
351 /*! Function : GetIOR
354 //============================================================================
355 char* SALOMEDS_SObject_i::GetIOR()
357 SALOMEDS::Locker lock;
358 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
362 //============================================================================
363 /*! Function : SetAttrString
366 //============================================================================
367 void SALOMEDS_SObject_i::SetAttrString(const char* name, const char* value)
369 SALOMEDS::Locker lock;
370 _impl->SetAttrString(name,value);
373 //===========================================================================
375 //===========================================================================
376 CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
379 long pid = (long)_getpid();
381 long pid = (long)getpid();
383 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
384 return reinterpret_cast<CORBA::LongLong>(_impl);