Salome HOME
Join modifications from BR_Dev_For_4_0 tag V4_1_1.
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute_i.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
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.
8 // 
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.
13 //
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
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //  File   : SALOMEDS_GenericAttribute_i.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
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 <map>
33
34 #ifdef WIN32
35 #include <process.h>
36 #else
37 #include <sys/types.h>
38 #include <unistd.h>
39 #endif
40
41 #include "OpUtil.hxx"
42
43 using namespace std;
44
45 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
46
47 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(DF_Attribute* theImpl, CORBA::ORB_ptr theOrb)
48 {
49   _orb = CORBA::ORB::_duplicate(theOrb);
50   _impl = theImpl;
51 }
52
53 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) 
54 {
55   SALOMEDS::Locker lock;
56   Unexpect aCatch(GALockProtection);
57
58   if (_impl  && !CORBA::is_nil(_orb)) {
59     try {
60       SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
61     }
62     catch (...) {
63       throw SALOMEDS::GenericAttribute::LockProtection();
64     }
65   }
66 }
67
68 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() 
69 {
70   SALOMEDS::Locker lock;
71   if (!_impl || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
72   SALOMEDSImpl_SObject so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
73   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
74   return so._retn();
75 }
76
77
78 char* SALOMEDS_GenericAttribute_i::Type() 
79 {
80   SALOMEDS::Locker lock;
81   if (_impl) {
82     return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl));
83   }    
84
85   return "";
86 }
87
88 char* SALOMEDS_GenericAttribute_i::GetClassType()
89 {
90   SALOMEDS::Locker lock;
91   if (_impl) {
92     return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl));
93   }
94
95   return "";
96 }
97
98
99 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
100                                                          (DF_Attribute* theAttr,
101                                                           CORBA::ORB_ptr theOrb)
102 {
103   SALOMEDS::Locker lock;
104
105   string aClassType = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(theAttr)->GetClassType();
106   char* aTypeOfAttribute = (char*)aClassType.c_str();
107   SALOMEDS::GenericAttribute_var anAttribute;
108   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
109   __CreateGenericCORBAAttribute
110
111   return anAttribute._retn(); 
112 }
113
114 //===========================================================================
115 //   PRIVATE FUNCTIONS
116 //===========================================================================
117 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
118 {
119 #ifdef WIN32
120   long pid = (long)_getpid();
121 #else
122   long pid = (long)getpid();
123 #endif
124   isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
125   return ((CORBA::LongLong)_impl);
126 }