X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOMEDS%2FSALOMEDS_GenericAttribute_i.cxx;h=dcfc754948b8c23c9f4c4d8da241e7da7e719709;hb=ec64825655b99b08182ef682868ccb732edb3c2a;hp=bbd790db6fa78f2d83f77b9500c04acc00e5a820;hpb=61d4fc88c862e718985aa6e9b1bf72f055553eee;p=modules%2Fkernel.git diff --git a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx index bbd790db6..dcfc75494 100644 --- a/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx +++ b/src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx @@ -1,29 +1,144 @@ +// Copyright (C) 2005 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ +// +// File : SALOMEDS_GenericAttribute_i.cxx +// Author : Sergey RUIN +// Module : SALOME + + +#include "utilities.h" +#include "SALOMEDS_GenericAttribute_i.hxx" +#include "SALOMEDS_Attributes.hxx" +#include "SALOMEDS.hxx" +#include "SALOMEDSImpl_SObject.hxx" +#include "SALOMEDSImpl_Study.hxx" +#include "Utils_ExceptHandlers.hxx" +#include +#include + +#ifdef WIN32 +#include +#else +#include +#include +#endif + +#include "OpUtil.hxx" + using namespace std; -// File : SALOMEDS_GenericAttribute_i.cxx -// Created : Fri Jul 05 15:49:37 2002 -// Author : Mikhail PONIKAROV - -// Project : SALOME -// Module : SALOMEDS -// Copyright : Open CASCADE 2002 -// $Header$ - -#include "SALOMEDS_StudyBuilder_i.hxx" - -void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) { - if (!_myAttr.IsNull() && _myAttr->IsValid() && !CORBA::is_nil(_myOrb)) { - Handle(SALOMEDS_IORAttribute) Att; - if (_myAttr->Label().Root().FindAttribute(SALOMEDS_IORAttribute::GetID(),Att)){ - TCollection_AsciiString ch(Att->Get()); - char* IOR = CORBA::string_dup(ch.ToCString()); - CORBA::Object_var obj = _myOrb->string_to_object(IOR); - SALOMEDS::Study_ptr aStudy = SALOMEDS::Study::_narrow(obj); - // ASSERT(!CORBA::is_nil(aStudy)); - if (aStudy->NewBuilder()->HasOpenCommand()) return; - if (aStudy->GetProperties()->IsLocked()) { - // INFOS("Locked document modification !!!"); - throw SALOMEDS::GenericAttribute::LockProtection(); - } + +UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection); + +SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(const Handle(TDF_Attribute)& theImpl, CORBA::ORB_ptr theOrb) +{ + _orb = CORBA::ORB::_duplicate(theOrb); + _impl = theImpl; +} + +void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) +{ + SALOMEDS::Locker lock; + Unexpect aCatch(GALockProtection); + + if (!_impl.IsNull() && _impl->IsValid() && !CORBA::is_nil(_orb)) { + try { + SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl); + } + catch (...) { + throw SALOMEDS::GenericAttribute::LockProtection(); } } } + +SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() +{ + SALOMEDS::Locker lock; + if (_impl.IsNull() || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil(); + Handle(SALOMEDSImpl_SObject) so_impl = SALOMEDSImpl_Study::SObject(_impl->Label()); + SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb); + return so._retn(); +} + + +char* SALOMEDS_GenericAttribute_i::Type() +{ + SALOMEDS::Locker lock; + if (!_impl.IsNull()) { + return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl)); + } + + return ""; +} + +char* SALOMEDS_GenericAttribute_i::GetClassType() +{ + SALOMEDS::Locker lock; + if (!_impl.IsNull()) { + return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl)); + } + + return ""; +} + + +SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute + (const Handle(TDF_Attribute)& theAttr, + CORBA::ORB_ptr theOrb) +{ + SALOMEDS::Locker lock; + +/* + static std::map _mapOfAttrib; + SALOMEDS::GenericAttribute_var anAttribute; + SALOMEDS_GenericAttribute_i* attr_servant = NULL; + + if(_mapOfAttrib.find(theAttr.operator->()) != _mapOfAttrib.end()) { + attr_servant = _mapOfAttrib[theAttr.operator->()]; + anAttribute = SALOMEDS::GenericAttribute::_narrow(attr_servant->_this()); + } + else { + char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr)->GetClassType().ToCString(); + __CreateGenericCORBAAttribute + _mapOfAttrib[theAttr.operator->()] = attr_servant; + } +*/ + // mpv: now servants Destroyed by common algos of CORBA + char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute):: + DownCast(theAttr)->GetClassType().ToCString(); + SALOMEDS::GenericAttribute_var anAttribute; + SALOMEDS_GenericAttribute_i* attr_servant = NULL; + __CreateGenericCORBAAttribute + + return anAttribute._retn(); +} + +//=========================================================================== +// PRIVATE FUNCTIONS +//=========================================================================== +long SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal) +{ +#ifdef WIN32 + long pid = (long)_getpid(); +#else + long pid = (long)getpid(); +#endif + isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0; + TDF_Attribute* local_impl = _impl.operator->(); + return ((long)local_impl); +}