Back to index

salome-kernel  6.5.0
SALOMEDS_GenericAttribute.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.cxx
00024 //  Author : Sergey RUIN
00025 //  Module : SALOME
00026 //
00027 #include <string>
00028 
00029 #include "SALOMEDS_GenericAttribute.hxx"
00030 #include "SALOMEDSImpl_SObject.hxx"
00031 #include "SALOMEDS_SObject.hxx"
00032 #include "SALOMEDS_ClientAttributes.hxx"
00033 #include "SALOMEDS.hxx"
00034 
00035 #include "Basics_Utils.hxx"
00036 
00037 #ifdef WIN32
00038 #include <process.h>
00039 #else
00040 #include <sys/types.h>
00041 #include <unistd.h>
00042 #endif
00043 
00044 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDSImpl_GenericAttribute* theGA)
00045 {
00046   _isLocal = true;
00047   _local_impl = theGA;
00048   _corba_impl = SALOMEDS::GenericAttribute::_nil();
00049 }
00050 
00051 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDS::GenericAttribute_ptr theGA)
00052 {
00053 #ifdef WIN32
00054   long pid =  (long)_getpid();
00055 #else
00056   long pid =  (long)getpid();
00057 #endif  
00058 
00059   CORBA::LongLong addr = theGA->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
00060   if(_isLocal) {
00061     _local_impl = reinterpret_cast<SALOMEDSImpl_GenericAttribute*>(addr);
00062     _corba_impl = SALOMEDS::GenericAttribute::_nil();
00063   }
00064   else {
00065     _local_impl = NULL;
00066     _corba_impl = SALOMEDS::GenericAttribute::_duplicate(theGA);
00067   }
00068 }
00069 
00070 SALOMEDS_GenericAttribute::~SALOMEDS_GenericAttribute() 
00071 {
00072   if (!_isLocal) {
00073     _corba_impl->UnRegister();
00074   }
00075 }
00076 
00077 void SALOMEDS_GenericAttribute::CheckLocked() 
00078 {
00079   if (_isLocal) {
00080     SALOMEDS::Locker lock;
00081     try {
00082       _local_impl->CheckLocked();
00083     }
00084     catch(...) {
00085       throw SALOMEDS::GenericAttribute::LockProtection();
00086     }
00087   }
00088   else {
00089     _corba_impl->CheckLocked();
00090   }
00091 }
00092 
00093 std::string SALOMEDS_GenericAttribute::Type()
00094 {
00095   std::string aType;
00096   if (_isLocal) {
00097     SALOMEDS::Locker lock;
00098     aType = _local_impl->Type();
00099   }
00100   else {
00101     aType = (CORBA::String_var)_corba_impl->Type();
00102   }
00103   return aType;
00104 }
00105 
00106 std::string SALOMEDS_GenericAttribute::GetClassType()
00107 {
00108   std::string aType;
00109   if (_isLocal) {
00110     SALOMEDS::Locker lock;
00111     aType = _local_impl->GetClassType();
00112   }
00113   else {
00114     aType = (CORBA::String_var)_corba_impl->GetClassType();
00115   }
00116   return aType;
00117 }
00118 
00119 _PTR(SObject) SALOMEDS_GenericAttribute::GetSObject()
00120 {
00121   SALOMEDSClient_SObject* aSO = NULL;
00122   if (_isLocal) {
00123     SALOMEDS::Locker lock;
00124     aSO = new SALOMEDS_SObject(_local_impl->GetSObject());
00125   }
00126   else {
00127     aSO = new SALOMEDS_SObject((SALOMEDS::SObject_var)_corba_impl->GetSObject());
00128   }
00129 
00130   return _PTR(SObject)(aSO);
00131 }
00132 
00133 
00134 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDSImpl_GenericAttribute* theGA)
00135 {
00136   SALOMEDS::Locker lock;
00137 
00138   SALOMEDS_GenericAttribute* aGA = NULL;
00139   if(theGA) {
00140      std::string aTypeOfAttribute = theGA->GetClassType();
00141       __CreateGenericClientAttributeLocal
00142   }
00143   return aGA;
00144 }
00145 
00146 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDS::GenericAttribute_ptr theGA)
00147 {
00148   SALOMEDS_GenericAttribute* aGA = NULL;
00149   if(!CORBA::is_nil(theGA)) {
00150       CORBA::String_var astr=theGA->GetClassType();
00151       std::string aTypeOfAttribute = astr.in();
00152       __CreateGenericClientAttributeCORBA
00153   }
00154   return aGA;
00155 }