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_GenericAttribute_i.cxx
21 // Author : Sergey RUIN
25 #include "utilities.h"
26 #include "SALOMEDS_GenericAttribute_i.hxx"
27 #include "SALOMEDS_Attributes.hxx"
28 #include "SALOMEDS.hxx"
29 #include "SALOMEDSImpl_SObject.hxx"
30 #include "SALOMEDSImpl_Study.hxx"
31 #include "Utils_ExceptHandlers.hxx"
32 #include <TCollection_AsciiString.hxx>
38 #include <sys/types.h>
46 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
48 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(const Handle(TDF_Attribute)& theImpl, CORBA::ORB_ptr theOrb)
50 _orb = CORBA::ORB::_duplicate(theOrb);
54 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection)
56 SALOMEDS::Locker lock;
57 Unexpect aCatch(GALockProtection);
59 if (!_impl.IsNull() && _impl->IsValid() && !CORBA::is_nil(_orb)) {
61 SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
64 throw SALOMEDS::GenericAttribute::LockProtection();
69 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject()
71 SALOMEDS::Locker lock;
72 if (_impl.IsNull() || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
73 Handle(SALOMEDSImpl_SObject) so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
74 SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
79 char* SALOMEDS_GenericAttribute_i::Type()
81 SALOMEDS::Locker lock;
82 if (!_impl.IsNull()) {
83 return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl));
89 char* SALOMEDS_GenericAttribute_i::GetClassType()
91 SALOMEDS::Locker lock;
92 if (!_impl.IsNull()) {
93 return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl));
100 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
101 (const Handle(TDF_Attribute)& theAttr,
102 CORBA::ORB_ptr theOrb)
104 SALOMEDS::Locker lock;
107 static std::map<TDF_Attribute*, SALOMEDS_GenericAttribute_i*> _mapOfAttrib;
108 SALOMEDS::GenericAttribute_var anAttribute;
109 SALOMEDS_GenericAttribute_i* attr_servant = NULL;
111 if(_mapOfAttrib.find(theAttr.operator->()) != _mapOfAttrib.end()) {
112 attr_servant = _mapOfAttrib[theAttr.operator->()];
113 anAttribute = SALOMEDS::GenericAttribute::_narrow(attr_servant->_this());
116 char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr)->GetClassType().ToCString();
117 __CreateGenericCORBAAttribute
118 _mapOfAttrib[theAttr.operator->()] = attr_servant;
121 // mpv: now servants Destroyed by common algos of CORBA
122 TCollection_AsciiString aClassType = Handle(SALOMEDSImpl_GenericAttribute)::
123 DownCast(theAttr)->GetClassType();
124 char* aTypeOfAttribute = aClassType.ToCString();
125 SALOMEDS::GenericAttribute_var anAttribute;
126 SALOMEDS_GenericAttribute_i* attr_servant = NULL;
127 __CreateGenericCORBAAttribute
129 return anAttribute._retn();
132 //===========================================================================
134 //===========================================================================
135 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
138 long pid = (long)_getpid();
140 long pid = (long)getpid();
142 isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
143 TDF_Attribute* local_impl = _impl.operator->();
144 return ((CORBA::LongLong)local_impl);