Salome HOME
Merge branch V7_3_1_BR
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute_i.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_i.cxx
24 //  Author : Sergey RUIN
25 //  Module : SALOME
26 //
27 #include "utilities.h"
28 #include "SALOMEDS_GenericAttribute_i.hxx"
29 #include "SALOMEDS_Attributes.hxx"
30 #include "SALOMEDS.hxx"
31 #include "SALOMEDSImpl_SObject.hxx"
32 #include "SALOMEDSImpl_Study.hxx"
33 #include "Utils_ExceptHandlers.hxx"
34 #include "Basics_Utils.hxx"
35 #include <map>
36
37 #ifdef WIN32
38 #include <process.h>
39 #else
40 #include <sys/types.h>
41 #include <unistd.h>
42 #endif
43
44 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection);
45
46 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(DF_Attribute* theImpl, CORBA::ORB_ptr theOrb)
47 {
48   _orb = CORBA::ORB::_duplicate(theOrb);
49   _impl = theImpl;
50 }
51
52 SALOMEDS_GenericAttribute_i::~SALOMEDS_GenericAttribute_i()
53 {
54 }
55
56 void SALOMEDS_GenericAttribute_i::CheckLocked() throw (SALOMEDS::GenericAttribute::LockProtection) 
57 {
58   SALOMEDS::Locker lock;
59   Unexpect aCatch(GALockProtection);
60
61   if (_impl  && !CORBA::is_nil(_orb)) {
62     try {
63       SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
64     }
65     catch (...) {
66       throw SALOMEDS::GenericAttribute::LockProtection();
67     }
68   }
69 }
70
71 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() 
72 {
73   SALOMEDS::Locker lock;
74   if (!_impl || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
75   SALOMEDSImpl_SObject so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
76   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
77   return so._retn();
78 }
79
80
81 char* SALOMEDS_GenericAttribute_i::Type() 
82 {
83   SALOMEDS::Locker lock;
84   if (_impl) {
85     std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl);
86     return CORBA::string_dup(type.c_str());
87   }    
88
89   return CORBA::string_dup("");
90 }
91
92 char* SALOMEDS_GenericAttribute_i::GetClassType()
93 {
94   SALOMEDS::Locker lock;
95   if (_impl) {
96     std::string class_type = SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl);
97     return CORBA::string_dup(class_type.c_str());
98   }
99
100   return CORBA::string_dup("");
101 }
102
103
104 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
105                                                          (DF_Attribute* theAttr,
106                                                           CORBA::ORB_ptr theOrb)
107 {
108   SALOMEDS::Locker lock;
109
110   std::string aClassType = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(theAttr)->GetClassType();
111   char* aTypeOfAttribute = (char*)aClassType.c_str();
112   SALOMEDS::GenericAttribute_var anAttribute;
113   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
114   __CreateGenericCORBAAttribute
115
116   return anAttribute._retn(); 
117 }
118
119 //===========================================================================
120 //   PRIVATE FUNCTIONS
121 //===========================================================================
122 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
123 {
124 #ifdef WIN32
125   long pid = (long)_getpid();
126 #else
127   long pid = (long)getpid();
128 #endif
129   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
130   return reinterpret_cast<CORBA::LongLong>(_impl);
131 }