Back to index

salome-kernel  6.5.0
SALOMEDS_GenericAttribute_i.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 //  File   : SALOMEDS_GenericAttribute_i.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include "utilities.h"
00028 #include "SALOMEDS_GenericAttribute_i.hxx"
00029 #include "SALOMEDS_Attributes.hxx"
00030 #include "SALOMEDS.hxx"
00031 #include "SALOMEDSImpl_SObject.hxx"
00032 #include "SALOMEDSImpl_Study.hxx"
00033 #include "Utils_ExceptHandlers.hxx"
00034 #include "Basics_Utils.hxx"
00035 #include <map>
00036 
00037 #ifdef WIN32
00038 #include <process.h>
00039 #else
00040 #include <sys/types.h>
00041 #include <unistd.h>
00042 #endif
00043 
00044 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
00045 
00046 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(DF_Attribute* theImpl, CORBA::ORB_ptr theOrb)
00047 {
00048   _orb = CORBA::ORB::_duplicate(theOrb);
00049   _impl = theImpl;
00050 }
00051 
00052 SALOMEDS_GenericAttribute_i::~SALOMEDS_GenericAttribute_i()
00053 {
00054 }
00055 
00056 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) 
00057 {
00058   SALOMEDS::Locker lock;
00059   Unexpect aCatch(GALockProtection);
00060 
00061   if (_impl  && !CORBA::is_nil(_orb)) {
00062     try {
00063       SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
00064     }
00065     catch (...) {
00066       throw SALOMEDS::GenericAttribute::LockProtection();
00067     }
00068   }
00069 }
00070 
00071 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() 
00072 {
00073   SALOMEDS::Locker lock;
00074   if (!_impl || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
00075   SALOMEDSImpl_SObject so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
00076   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
00077   return so._retn();
00078 }
00079 
00080 
00081 char* SALOMEDS_GenericAttribute_i::Type() 
00082 {
00083   SALOMEDS::Locker lock;
00084   if (_impl) {
00085     std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl);
00086     return CORBA::string_dup(type.c_str());
00087   }    
00088 
00089   return CORBA::string_dup("");
00090 }
00091 
00092 char* SALOMEDS_GenericAttribute_i::GetClassType()
00093 {
00094   SALOMEDS::Locker lock;
00095   if (_impl) {
00096     std::string class_type = SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl);
00097     return CORBA::string_dup(class_type.c_str());
00098   }
00099 
00100   return CORBA::string_dup("");
00101 }
00102 
00103 
00104 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
00105                                                          (DF_Attribute* theAttr,
00106                                                           CORBA::ORB_ptr theOrb)
00107 {
00108   SALOMEDS::Locker lock;
00109 
00110   std::string aClassType = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(theAttr)->GetClassType();
00111   char* aTypeOfAttribute = (char*)aClassType.c_str();
00112   SALOMEDS::GenericAttribute_var anAttribute;
00113   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
00114   __CreateGenericCORBAAttribute
00115 
00116   return anAttribute._retn(); 
00117 }
00118 
00119 //===========================================================================
00120 //   PRIVATE FUNCTIONS
00121 //===========================================================================
00122 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
00123 {
00124 #ifdef WIN32
00125   long pid = (long)_getpid();
00126 #else
00127   long pid = (long)getpid();
00128 #endif
00129   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
00130   return reinterpret_cast<CORBA::LongLong>(_impl);
00131 }