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.hxx"
32 #include "SALOMEDSImpl_GenericAttribute.hxx"
33 #include "SALOMEDSImpl_SComponent.hxx"
34 #include "SALOMEDSImpl_Study.hxx"
35 #include "SALOMEDSImpl_AttributeIOR.hxx"
36 #include "Basics_Utils.hxx"
43 #include <sys/types.h>
47 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::New(const SALOMEDSImpl_SObject& theImpl, CORBA::ORB_ptr theORB)
49 SALOMEDS_SObject_i* so_servant = new SALOMEDS_SObject_i(theImpl, theORB);
51 return so_servant->_this();
55 //============================================================================
56 /*! Function : constructor
59 //============================================================================
60 SALOMEDS_SObject_i::SALOMEDS_SObject_i(const SALOMEDSImpl_SObject& impl, CORBA::ORB_ptr orb)
64 if(impl.IsComponent()) {
65 SALOMEDSImpl_SComponent sco = impl;
66 _impl = sco.GetPersistentCopy();
69 _impl = impl.GetPersistentCopy();
72 _orb = CORBA::ORB::_duplicate(orb);
76 //============================================================================
77 /*! Function : destructor
80 //============================================================================
81 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
83 if(_impl) delete _impl;
86 //================================================================================
88 * \brief Returns true if the %SObject does not belong to any %Study
90 //================================================================================
92 CORBA::Boolean SALOMEDS_SObject_i::IsNull()
94 SALOMEDS::Locker lock;
95 return !_impl || _impl->IsNull();
98 //============================================================================
102 //============================================================================
103 char* SALOMEDS_SObject_i::GetID()
105 SALOMEDS::Locker lock;
106 return CORBA::string_dup(_impl->GetID().c_str());
109 //============================================================================
110 /*! Function : GetFatherComponent
113 //============================================================================
114 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
116 SALOMEDS::Locker lock;
117 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
121 //============================================================================
122 /*! Function : GetFather
125 //============================================================================
126 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
128 SALOMEDS::Locker lock;
129 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
133 //============================================================================
134 /*! Function : FindAttribute
135 * Purpose : Find attribute of given type on this SObject
137 //============================================================================
138 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
139 const char* aTypeOfAttribute)
141 SALOMEDS::Locker lock;
142 DF_Attribute* anAttr = NULL;
143 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
144 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
151 //============================================================================
152 /*! Function : GetAllAttributes
153 * Purpose : Returns list of all attributes for this sobject
155 //============================================================================
157 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
159 SALOMEDS::Locker lock;
160 std::vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
161 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
162 int length = aSeq.size();
164 SeqOfAttr->length(length);
167 for(int i = 0; i < length; i++) {
168 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
169 SALOMEDS::GenericAttribute_var anAttribute;
170 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
171 if (!CORBA::is_nil(anAttribute)) {
172 SeqOfAttr[i] = anAttribute;
176 return SeqOfAttr._retn();
180 //============================================================================
181 /*! Function : ReferencedObject
184 //============================================================================
185 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
187 SALOMEDS::Locker lock;
188 SALOMEDSImpl_SObject aRefObj;
189 if(!_impl->ReferencedObject(aRefObj)) return false;
191 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
195 //============================================================================
196 /*! Function : FindSubObject
199 //============================================================================
200 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
202 SALOMEDS::Locker lock;
203 SALOMEDSImpl_SObject aSubObj;
204 if(!_impl->FindSubObject(atag, aSubObj)) return false;
206 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
211 //============================================================================
213 * Purpose : gets a name
215 //============================================================================
216 char* SALOMEDS_SObject_i::Name()
218 SALOMEDS::Locker lock;
219 return CORBA::string_dup(_impl->Name().c_str());
222 //============================================================================
224 * Purpose : sets a name
226 //============================================================================
227 void SALOMEDS_SObject_i::Name(const char* name)
229 SALOMEDS::Locker lock;
230 std::string aName((char*)name);
234 //============================================================================
238 //============================================================================
239 CORBA::Short SALOMEDS_SObject_i::Tag()
241 SALOMEDS::Locker lock;
245 //============================================================================
246 /*! Function : GetLastChildTag
249 //============================================================================
250 CORBA::Short SALOMEDS_SObject_i::GetLastChildTag()
252 SALOMEDS::Locker lock;
253 return (CORBA::Short) _impl->GetLastChildTag();
256 //============================================================================
260 //============================================================================
261 CORBA::Short SALOMEDS_SObject_i::Depth()
263 SALOMEDS::Locker lock;
264 return _impl->Depth();
267 //============================================================================
268 /*! Function : GetObject
271 //============================================================================
272 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
274 SALOMEDS::Locker lock;
275 CORBA::Object_ptr obj = CORBA::Object::_nil();
277 std::string IOR = _impl->GetIOR();
278 char* c_ior = CORBA::string_dup(IOR.c_str());
279 obj = _orb->string_to_object(c_ior);
280 CORBA::string_free(c_ior);
285 //============================================================================
286 /*! Function : GetName
289 //============================================================================
290 char* SALOMEDS_SObject_i::GetName()
292 SALOMEDS::Locker lock;
293 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
297 //============================================================================
298 /*! Function : GetComment
301 //============================================================================
302 char* SALOMEDS_SObject_i::GetComment()
304 SALOMEDS::Locker lock;
305 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
309 //============================================================================
310 /*! Function : GetIOR
313 //============================================================================
314 char* SALOMEDS_SObject_i::GetIOR()
316 SALOMEDS::Locker lock;
317 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
321 //============================================================================
322 /*! Function : SetAttrString
325 //============================================================================
326 void SALOMEDS_SObject_i::SetAttrString(const char* name, const char* value)
328 SALOMEDS::Locker lock;
329 _impl->SetAttrString(name,value);
332 //===========================================================================
334 //===========================================================================
335 CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
338 long pid = (long)_getpid();
340 long pid = (long)getpid();
342 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
343 return reinterpret_cast<CORBA::LongLong>(_impl);