1 // Copyright (C) 2007-2019 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_Study_i.hxx"
30 #include "SALOMEDS_SComponent_i.hxx"
31 #include "SALOMEDS_GenericAttribute_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_Study_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);
78 //============================================================================
79 /*! Function : destructor
82 //============================================================================
83 SALOMEDS_SObject_i::~SALOMEDS_SObject_i()
85 if(_impl) delete _impl;
88 //============================================================================
90 \brief Get default POA for the servant object.
92 This function is implicitly called from "_this()" function.
93 Default POA can be set via the constructor.
95 \return reference to the default POA for the servant
97 //============================================================================
98 PortableServer::POA_ptr SALOMEDS_SObject_i::_default_POA()
100 myPOA = PortableServer::POA::_duplicate(SALOMEDS_Study_i::GetThePOA());
101 //MESSAGE("SALOMEDS_SObject_i::_default_POA: " << myPOA);
102 return PortableServer::POA::_duplicate(myPOA);
105 //================================================================================
107 * \brief Returns true if the %SObject does not belong to any %Study
109 //================================================================================
111 CORBA::Boolean SALOMEDS_SObject_i::IsNull()
113 SALOMEDS::Locker lock;
114 return !_impl || _impl->IsNull();
117 //============================================================================
121 //============================================================================
122 char* SALOMEDS_SObject_i::GetID()
124 SALOMEDS::Locker lock;
125 return CORBA::string_dup(_impl->GetID().c_str());
128 //============================================================================
129 /*! Function : GetFatherComponent
132 //============================================================================
133 SALOMEDS::SComponent_ptr SALOMEDS_SObject_i::GetFatherComponent()
135 SALOMEDS::Locker lock;
136 SALOMEDS::SComponent_var sco = SALOMEDS_SComponent_i::New (_impl->GetFatherComponent(), _orb);
140 //============================================================================
141 /*! Function : GetFather
144 //============================================================================
145 SALOMEDS::SObject_ptr SALOMEDS_SObject_i::GetFather()
147 SALOMEDS::Locker lock;
148 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (_impl->GetFather(), _orb);
152 //============================================================================
153 /*! Function : FindAttribute
154 * Purpose : Find attribute of given type on this SObject
156 //============================================================================
157 CORBA::Boolean SALOMEDS_SObject_i::FindAttribute (SALOMEDS::GenericAttribute_out anAttribute,
158 const char* aTypeOfAttribute)
160 SALOMEDS::Locker lock;
161 DF_Attribute* anAttr = NULL;
162 if(_impl->FindAttribute(anAttr, (char*)aTypeOfAttribute)) {
163 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
170 //============================================================================
171 /*! Function : GetAllAttributes
172 * Purpose : Returns list of all attributes for this sobject
174 //============================================================================
176 SALOMEDS::ListOfAttributes* SALOMEDS_SObject_i::GetAllAttributes()
178 SALOMEDS::Locker lock;
179 std::vector<DF_Attribute*> aSeq = _impl->GetAllAttributes();
180 SALOMEDS::ListOfAttributes_var SeqOfAttr = new SALOMEDS::ListOfAttributes;
181 int length = aSeq.size();
183 SeqOfAttr->length(length);
186 for(int i = 0; i < length; i++) {
187 SALOMEDSImpl_GenericAttribute* anAttr = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(aSeq[i]);
188 SALOMEDS::GenericAttribute_var anAttribute;
189 anAttribute = SALOMEDS_GenericAttribute_i::CreateAttribute(anAttr, _orb);
190 if (!CORBA::is_nil(anAttribute)) {
191 SeqOfAttr[i] = anAttribute;
195 return SeqOfAttr._retn();
199 //============================================================================
200 /*! Function : ReferencedObject
203 //============================================================================
204 CORBA::Boolean SALOMEDS_SObject_i::ReferencedObject(SALOMEDS::SObject_out obj)
206 SALOMEDS::Locker lock;
207 SALOMEDSImpl_SObject aRefObj;
208 if(!_impl->ReferencedObject(aRefObj)) return false;
210 obj = SALOMEDS_SObject_i::New (aRefObj, _orb);
214 //============================================================================
215 /*! Function : FindSubObject
218 //============================================================================
219 CORBA::Boolean SALOMEDS_SObject_i::FindSubObject(CORBA::Long atag, SALOMEDS::SObject_out obj)
221 SALOMEDS::Locker lock;
222 SALOMEDSImpl_SObject aSubObj;
223 if(!_impl->FindSubObject(atag, aSubObj)) return false;
225 obj = SALOMEDS_SObject_i::New (aSubObj, _orb);
230 //============================================================================
232 * Purpose : gets a name
234 //============================================================================
235 char* SALOMEDS_SObject_i::Name()
237 SALOMEDS::Locker lock;
238 return CORBA::string_dup(_impl->Name().c_str());
241 //============================================================================
243 * Purpose : sets a name
245 //============================================================================
246 void SALOMEDS_SObject_i::Name(const char* name)
248 SALOMEDS::Locker lock;
249 std::string aName((char*)name);
253 //============================================================================
257 //============================================================================
258 CORBA::Short SALOMEDS_SObject_i::Tag()
260 SALOMEDS::Locker lock;
264 //============================================================================
265 /*! Function : GetLastChildTag
268 //============================================================================
269 CORBA::Short SALOMEDS_SObject_i::GetLastChildTag()
271 SALOMEDS::Locker lock;
272 return (CORBA::Short) _impl->GetLastChildTag();
275 //============================================================================
279 //============================================================================
280 CORBA::Short SALOMEDS_SObject_i::Depth()
282 SALOMEDS::Locker lock;
283 return _impl->Depth();
286 //============================================================================
287 /*! Function : GetObject
290 //============================================================================
291 CORBA::Object_ptr SALOMEDS_SObject_i::GetObject()
293 SALOMEDS::Locker lock;
294 CORBA::Object_ptr obj = CORBA::Object::_nil();
296 std::string IOR = _impl->GetIOR();
297 char* c_ior = CORBA::string_dup(IOR.c_str());
298 obj = _orb->string_to_object(c_ior);
299 CORBA::string_free(c_ior);
304 //============================================================================
305 /*! Function : GetName
308 //============================================================================
309 char* SALOMEDS_SObject_i::GetName()
311 SALOMEDS::Locker lock;
312 CORBA::String_var aStr = CORBA::string_dup(_impl->GetName().c_str());
316 //============================================================================
317 /*! Function : GetComment
320 //============================================================================
321 char* SALOMEDS_SObject_i::GetComment()
323 SALOMEDS::Locker lock;
324 CORBA::String_var aStr = CORBA::string_dup(_impl->GetComment().c_str());
328 //============================================================================
329 /*! Function : GetIOR
332 //============================================================================
333 char* SALOMEDS_SObject_i::GetIOR()
335 SALOMEDS::Locker lock;
336 CORBA::String_var aStr = CORBA::string_dup(_impl->GetIOR().c_str());
340 //============================================================================
341 /*! Function : SetAttrString
344 //============================================================================
345 void SALOMEDS_SObject_i::SetAttrString(const char* name, const char* value)
347 SALOMEDS::Locker lock;
348 _impl->SetAttrString(name,value);
351 //===========================================================================
353 //===========================================================================
354 CORBA::LongLong SALOMEDS_SObject_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
357 long pid = (long)_getpid();
359 long pid = (long)getpid();
361 isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
362 return reinterpret_cast<CORBA::LongLong>(_impl);