Salome HOME
Join modifications from branch BR_DEBUG_3_2_0b1
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute.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.cxx
21 //  Author : Sergey RUIN
22 //  Module : SALOME
23
24
25
26 #include <string>
27 #include <TCollection_AsciiString.hxx> 
28
29 #include "SALOMEDS_GenericAttribute.hxx"
30 #include "SALOMEDSImpl_SObject.hxx"
31 #include "SALOMEDS_SObject.hxx"
32 #include "SALOMEDS_ClientAttributes.hxx"
33 #include "SALOMEDS.hxx"
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 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(const Handle(SALOMEDSImpl_GenericAttribute)& theGA)
47 {
48   _isLocal = true;
49   _local_impl = theGA;
50   _corba_impl = SALOMEDS::GenericAttribute::_nil();
51 }
52
53 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDS::GenericAttribute_ptr theGA)
54 {
55 #ifdef WIN32
56   long pid =  (long)_getpid();
57 #else
58   long pid =  (long)getpid();
59 #endif  
60
61   long addr = theGA->GetLocalImpl(GetHostname().c_str(), pid, _isLocal);
62   if(_isLocal) {
63     _local_impl = ((SALOMEDSImpl_GenericAttribute*)(addr));
64     _corba_impl = SALOMEDS::GenericAttribute::_nil();
65   }
66   else {
67     _local_impl = NULL;
68     _corba_impl = SALOMEDS::GenericAttribute::_duplicate(theGA);
69   }
70 }
71
72 SALOMEDS_GenericAttribute::~SALOMEDS_GenericAttribute() 
73 {
74   if (!_isLocal) {
75     _corba_impl->Destroy();
76   }
77 }
78
79 void SALOMEDS_GenericAttribute::CheckLocked() 
80 {
81   if (_isLocal) {
82     SALOMEDS::Locker lock;
83     try {
84       _local_impl->CheckLocked();
85     }
86     catch(...) {
87       throw SALOMEDS::GenericAttribute::LockProtection();
88     }
89   }
90   else {
91     _corba_impl->CheckLocked();
92   }
93 }
94
95 std::string SALOMEDS_GenericAttribute::Type()
96 {
97   std::string aType;
98   if (_isLocal) {
99     SALOMEDS::Locker lock;
100     aType = _local_impl->Type().ToCString();
101   }
102   else {
103     aType = _corba_impl->Type();
104   }
105   return aType;
106 }
107
108 std::string SALOMEDS_GenericAttribute::GetClassType()
109 {
110   std::string aType;
111   if (_isLocal) {
112     SALOMEDS::Locker lock;
113     aType = _local_impl->GetClassType().ToCString();
114   }
115   else {
116     aType = _corba_impl->GetClassType();
117   }
118   return aType;
119 }
120
121 _PTR(SObject) SALOMEDS_GenericAttribute::GetSObject()
122 {
123   SALOMEDSClient_SObject* aSO = NULL;
124   if (_isLocal) {
125     SALOMEDS::Locker lock;
126     aSO = new SALOMEDS_SObject(_local_impl->GetSObject());
127   }
128   else {
129     aSO = new SALOMEDS_SObject(_corba_impl->GetSObject());
130   }
131
132   return _PTR(SObject)(aSO);
133 }
134
135
136 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute
137                            (const Handle(SALOMEDSImpl_GenericAttribute)& theGA)
138 {
139   SALOMEDS::Locker lock;
140
141   SALOMEDS_GenericAttribute* aGA = NULL;
142   std::string aTypeOfAttribute = theGA->GetClassType().ToCString();
143   __CreateGenericClientAttributeLocal
144   return aGA;
145 }
146
147 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDS::GenericAttribute_ptr theGA)
148 {
149   SALOMEDS_GenericAttribute* aGA = NULL;
150   std::string aTypeOfAttribute = theGA->GetClassType();
151   __CreateGenericClientAttributeCORBA
152   return aGA;
153 }