Salome HOME
Implemented method Modified() for SALOMEDS_Study that marks the Study as being modified.
[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 <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
101                                         (const Handle(TDF_Attribute)& theAttr,
102                                          CORBA::ORB_ptr theOrb)
103 {
104   SALOMEDS::Locker lock;
105
106 /*
107   static std::map<TDF_Attribute*, SALOMEDS_GenericAttribute_i*> _mapOfAttrib;
108   SALOMEDS::GenericAttribute_var anAttribute;
109   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
110
111   if(_mapOfAttrib.find(theAttr.operator->()) != _mapOfAttrib.end()) {
112     attr_servant = _mapOfAttrib[theAttr.operator->()];
113     anAttribute = SALOMEDS::GenericAttribute::_narrow(attr_servant->_this());
114   }
115   else {
116     char* aTypeOfAttribute = Handle(SALOMEDSImpl_GenericAttribute)::DownCast(theAttr)->GetClassType().ToCString();
117     __CreateGenericCORBAAttribute
118     _mapOfAttrib[theAttr.operator->()] = attr_servant;
119   }
120 */
121   // mpv: now servants Destroyed by common algos of CORBA
122   TCollection_AsciiString aClassType = Handle(SALOMEDSImpl_GenericAttribute)::
123     DownCast(theAttr)->GetClassType();
124   char* aTypeOfAttribute = aClassType.ToCString();
125   SALOMEDS::GenericAttribute_var anAttribute;
126   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
127   __CreateGenericCORBAAttribute
128
129   return anAttribute._retn(); 
130 }
131
132 //===========================================================================
133 //   PRIVATE FUNCTIONS
134 //===========================================================================
135 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
136 {
137 #ifdef WIN32
138   long pid = (long)_getpid();
139 #else
140   long pid = (long)getpid();
141 #endif
142   isLocal = (strcmp(theHostname, GetHostname().c_str()) == 0 && pid == thePID)?1:0;
143   TDF_Attribute* local_impl = _impl.operator->();
144   return ((CORBA::LongLong)local_impl);
145 }