Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute.cxx
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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
23 //  File   : SALOMEDS_GenericAttribute.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include <string>
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 #include "Basics_Utils.hxx"
36
37 #ifdef WIN32
38 #include <process.h>
39 #else
40 #include <sys/types.h>
41 #include <unistd.h>
42 #endif
43
44 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDSImpl_GenericAttribute* theGA)
45 {
46   _isLocal = true;
47   _local_impl = theGA;
48   _corba_impl = SALOMEDS::GenericAttribute::_nil();
49 }
50
51 SALOMEDS_GenericAttribute::SALOMEDS_GenericAttribute(SALOMEDS::GenericAttribute_ptr theGA)
52 {
53 #ifdef WIN32
54   long pid =  (long)_getpid();
55 #else
56   long pid =  (long)getpid();
57 #endif  
58
59   CORBA::LongLong addr = theGA->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
60   if(_isLocal) {
61     _local_impl = reinterpret_cast<SALOMEDSImpl_GenericAttribute*>(addr);
62     _corba_impl = SALOMEDS::GenericAttribute::_nil();
63   }
64   else {
65     _local_impl = NULL;
66     _corba_impl = SALOMEDS::GenericAttribute::_duplicate(theGA);
67   }
68 }
69
70 SALOMEDS_GenericAttribute::~SALOMEDS_GenericAttribute() 
71 {
72   if (!_isLocal) {
73     _corba_impl->UnRegister();
74   }
75 }
76
77 void SALOMEDS_GenericAttribute::CheckLocked() 
78 {
79   if (_isLocal) {
80     SALOMEDS::Locker lock;
81     try {
82       _local_impl->CheckLocked();
83     }
84     catch(...) {
85       throw SALOMEDS::GenericAttribute::LockProtection();
86     }
87   }
88   else {
89     _corba_impl->CheckLocked();
90   }
91 }
92
93 std::string SALOMEDS_GenericAttribute::Type()
94 {
95   std::string aType;
96   if (_isLocal) {
97     SALOMEDS::Locker lock;
98     aType = _local_impl->Type();
99   }
100   else {
101     aType = (CORBA::String_var)_corba_impl->Type();
102   }
103   return aType;
104 }
105
106 std::string SALOMEDS_GenericAttribute::GetClassType()
107 {
108   std::string aType;
109   if (_isLocal) {
110     SALOMEDS::Locker lock;
111     aType = _local_impl->GetClassType();
112   }
113   else {
114     aType = (CORBA::String_var)_corba_impl->GetClassType();
115   }
116   return aType;
117 }
118
119 _PTR(SObject) SALOMEDS_GenericAttribute::GetSObject()
120 {
121   SALOMEDSClient_SObject* aSO = NULL;
122   if (_isLocal) {
123     SALOMEDS::Locker lock;
124     aSO = new SALOMEDS_SObject(_local_impl->GetSObject());
125   }
126   else {
127     aSO = new SALOMEDS_SObject((SALOMEDS::SObject_var)_corba_impl->GetSObject());
128   }
129
130   return _PTR(SObject)(aSO);
131 }
132
133
134 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDSImpl_GenericAttribute* theGA)
135 {
136   SALOMEDS::Locker lock;
137
138   SALOMEDS_GenericAttribute* aGA = NULL;
139   if(theGA) {
140      std::string aTypeOfAttribute = theGA->GetClassType();
141       __CreateGenericClientAttributeLocal
142   }
143   return aGA;
144 }
145
146 SALOMEDS_GenericAttribute* SALOMEDS_GenericAttribute::CreateAttribute(SALOMEDS::GenericAttribute_ptr theGA)
147 {
148   SALOMEDS_GenericAttribute* aGA = NULL;
149   if(!CORBA::is_nil(theGA)) {
150       CORBA::String_var astr=theGA->GetClassType();
151       std::string aTypeOfAttribute = astr.in();
152       __CreateGenericClientAttributeCORBA
153   }
154   return aGA;
155 }