]> SALOME platform Git repositories - modules/kernel.git/blob - src/SALOMEDS/SALOMEDS_GenericAttribute_i.cxx
Salome HOME
Copyrights update
[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/
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 <TCollection_AsciiString.hxx>
33 #include <map>
34
35 #ifdef WIN32
36 #include <process.h>
37 #else
38 #include <sys/types.h>
39 #include <unistd.h>
40 #endif
41
42 #include "OpUtil.hxx"
43
44 using namespace std;
45
46 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
47
48 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(const Handle(TDF_Attribute)& theImpl, CORBA::ORB_ptr theOrb)
49 {
50   _orb = CORBA::ORB::_duplicate(theOrb);
51   _impl = theImpl;
52 }
53
54 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) 
55 {
56   SALOMEDS::Locker lock;
57   Unexpect aCatch(GALockProtection);
58
59   if (!_impl.IsNull() && _impl->IsValid() && !CORBA::is_nil(_orb)) {
60     try {
61       SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
62     }
63     catch (...) {
64       throw SALOMEDS::GenericAttribute::LockProtection();
65     }
66   }
67 }
68
69 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() 
70 {
71   SALOMEDS::Locker lock;
72   if (_impl.IsNull() || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
73   Handle(SALOMEDSImpl_SObject) so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
74   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
75   return so._retn();
76 }
77
78
79 char* SALOMEDS_GenericAttribute_i::Type() 
80 {
81   SALOMEDS::Locker lock;
82   if (!_impl.IsNull()) {
83     return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl));
84   }    
85
86   return "";
87 }
88
89 char* SALOMEDS_GenericAttribute_i::GetClassType()
90 {
91   SALOMEDS::Locker lock;
92   if (!_impl.IsNull()) {
93     return CORBA::string_dup(SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl));
94   }
95           
96   return "";
97 }  
98
99
100 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute(const Handle(TDF_Attribute)& theAttr,
101                                                                             CORBA::ORB_ptr theOrb) 
102 {
103 /*
104   SALOMEDS::Locker lock;
105   
106   static std::map<TDF_Attribute*, SALOMEDS_GenericAttribute_i*> _mapOfAttrib;
107   SALOMEDS::GenericAttribute_var anAttribute;
108   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
109
110   if(_mapOfAttrib.find(theAttr.operator->()) != _mapOfAttrib.end()) {
111     attr_servant = _mapOfAttrib[theAttr.operator->()];
112     anAttribute = SALOMEDS::GenericAttribute::_narrow(attr_servant->_this());
113   }
114   else {
115     char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr)->GetClassType().ToCString();
116     __CreateGenericCORBAAttribute
117     _mapOfAttrib[theAttr.operator->()] = attr_servant;
118   }
119 */
120   // mpv: now servants Destroyed by common algos of CORBA
121   char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr)->GetClassType().ToCString();
122   SALOMEDS::GenericAttribute_var anAttribute;
123   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
124   __CreateGenericCORBAAttribute
125
126   return anAttribute._retn(); 
127 }                                                                                                                    
128
129 //===========================================================================
130 //   PRIVATE FUNCTIONS
131 //===========================================================================
132 long SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
133 {
134 #ifdef WIN32
135   long pid = (long)_getpid();
136 #else
137   long pid = (long)getpid();
138 #endif  
139   isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
140   TDF_Attribute* local_impl = _impl.operator->();
141   return ((long)local_impl);
142 }