Salome HOME
c68177b5c1d5e2ef03b21696a7026e4148e79143
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute_i.cxx
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 //  This library is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU Lesser General Public
8 //  License as published by the Free Software Foundation; either
9 //  version 2.1 of the License.
10 //
11 //  This library is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 //  Lesser General Public License for more details.
15 //
16 //  You should have received a copy of the GNU Lesser General Public
17 //  License along with this library; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22 //  File   : SALOMEDS_GenericAttribute_i.cxx
23 //  Author : Sergey RUIN
24 //  Module : SALOME
25 //
26 #include "utilities.h"
27 #include "SALOMEDS_GenericAttribute_i.hxx"
28 #include "SALOMEDS_Attributes.hxx"
29 #include "SALOMEDS.hxx"
30 #include "SALOMEDSImpl_SObject.hxx"
31 #include "SALOMEDSImpl_Study.hxx"
32 #include "Utils_ExceptHandlers.hxx"
33 #include "Basics_Utils.hxx"
34 #include <map>
35
36 #ifdef WIN32
37 #include <process.h>
38 #else
39 #include <sys/types.h>
40 #include <unistd.h>
41 #endif
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     string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl);
83     return CORBA::string_dup(type.c_str());
84   }    
85
86   return (char*)"";
87 }
88
89 char* SALOMEDS_GenericAttribute_i::GetClassType()
90 {
91   SALOMEDS::Locker lock;
92   if (_impl) {
93     string class_type = SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl);
94     return CORBA::string_dup(class_type.c_str());
95   }
96
97   return (char*)"";
98 }
99
100
101 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
102                                                          (DF_Attribute* theAttr,
103                                                           CORBA::ORB_ptr theOrb)
104 {
105   SALOMEDS::Locker lock;
106
107   string aClassType = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(theAttr)->GetClassType();
108   char* aTypeOfAttribute = (char*)aClassType.c_str();
109   SALOMEDS::GenericAttribute_var anAttribute;
110   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
111   __CreateGenericCORBAAttribute
112
113   return anAttribute._retn(); 
114 }
115
116 //===========================================================================
117 //   PRIVATE FUNCTIONS
118 //===========================================================================
119 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
120 {
121 #ifdef WIN32
122   long pid = (long)_getpid();
123 #else
124   long pid = (long)getpid();
125 #endif
126   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
127   return reinterpret_cast<CORBA::LongLong>(_impl);
128 }