Salome HOME
Updated copyright comment
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_GenericAttribute_i.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, 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_Study_i.hxx"
30 #include "SALOMEDS_Attributes.hxx"
31 #include "SALOMEDS.hxx"
32 #include "SALOMEDSImpl_SObject.hxx"
33 #include "SALOMEDSImpl_Study.hxx"
34 #include "Utils_ExceptHandlers.hxx"
35 #include "Basics_Utils.hxx"
36 #include <map>
37
38 #ifdef WIN32
39 #include <process.h>
40 #else
41 #include <sys/types.h>
42 #include <unistd.h>
43 #endif
44
45 UNEXPECT_CATCH(GALockProtection, SALOMEDS::GenericAttribute::LockProtection)
46
47 SALOMEDS_GenericAttribute_i::SALOMEDS_GenericAttribute_i(DF_Attribute* theImpl, CORBA::ORB_ptr theOrb) :
48   GenericObj_i(SALOMEDS_Study_i::GetThePOA())
49 {
50   _orb = CORBA::ORB::_duplicate(theOrb);
51   _impl = theImpl;
52 }
53
54 SALOMEDS_GenericAttribute_i::~SALOMEDS_GenericAttribute_i()
55 {
56 }
57
58 //============================================================================
59 /*!
60   \brief Get default POA for the servant object.
61
62   This function is implicitly called from "_this()" function.
63   Default POA can be set via the constructor.
64
65   \return reference to the default POA for the servant
66 */
67 //============================================================================
68 PortableServer::POA_ptr SALOMEDS_GenericAttribute_i::_default_POA()
69 {
70   myPOA = PortableServer::POA::_duplicate(SALOMEDS_Study_i::GetThePOA());
71   //MESSAGE("SALOMEDS_GenericAttribute_i::_default_POA: " << myPOA);
72   return PortableServer::POA::_duplicate(myPOA);
73 }
74
75 void SALOMEDS_GenericAttribute_i::CheckLocked()
76 {
77   SALOMEDS::Locker lock;
78   Unexpect aCatch(GALockProtection);
79
80   if (_impl  && !CORBA::is_nil(_orb)) {
81     try {
82       SALOMEDSImpl_GenericAttribute::Impl_CheckLocked(_impl);
83     }
84     catch (...) {
85       throw SALOMEDS::GenericAttribute::LockProtection();
86     }
87   }
88 }
89
90 SALOMEDS::SObject_ptr SALOMEDS_GenericAttribute_i::GetSObject() 
91 {
92   SALOMEDS::Locker lock;
93   if (!_impl || _impl->Label().IsNull()) return SALOMEDS::SObject::_nil();
94   SALOMEDSImpl_SObject so_impl = SALOMEDSImpl_Study::SObject(_impl->Label());
95   SALOMEDS::SObject_var so = SALOMEDS_SObject_i::New (so_impl, _orb);
96   return so._retn();
97 }
98
99
100 char* SALOMEDS_GenericAttribute_i::Type() 
101 {
102   SALOMEDS::Locker lock;
103   if (_impl) {
104     std::string type = SALOMEDSImpl_GenericAttribute::Impl_GetType(_impl);
105     return CORBA::string_dup(type.c_str());
106   }    
107
108   return CORBA::string_dup("");
109 }
110
111 char* SALOMEDS_GenericAttribute_i::GetClassType()
112 {
113   SALOMEDS::Locker lock;
114   if (_impl) {
115     std::string class_type = SALOMEDSImpl_GenericAttribute::Impl_GetClassType(_impl);
116     return CORBA::string_dup(class_type.c_str());
117   }
118
119   return CORBA::string_dup("");
120 }
121
122
123 SALOMEDS::GenericAttribute_ptr SALOMEDS_GenericAttribute_i::CreateAttribute
124                                                          (DF_Attribute* theAttr,
125                                                           CORBA::ORB_ptr theOrb)
126 {
127   SALOMEDS::Locker lock;
128
129   std::string aClassType = dynamic_cast<SALOMEDSImpl_GenericAttribute*>(theAttr)->GetClassType();
130   char* aTypeOfAttribute = (char*)aClassType.c_str();
131   SALOMEDS::GenericAttribute_var anAttribute;
132   SALOMEDS_GenericAttribute_i* attr_servant = NULL;
133   SALOME_UNUSED(attr_servant);
134   __CreateGenericCORBAAttribute
135
136   return anAttribute._retn(); 
137 }
138
139 //===========================================================================
140 //   PRIVATE FUNCTIONS
141 //===========================================================================
142 CORBA::LongLong SALOMEDS_GenericAttribute_i::GetLocalImpl(const char* theHostname, CORBA::Long thePID, CORBA::Boolean& isLocal)
143 {
144 #ifdef WIN32
145   long pid = (long)_getpid();
146 #else
147   long pid = (long)getpid();
148 #endif
149   isLocal = (strcmp(theHostname, Kernel_Utils::GetHostname().c_str()) == 0 && pid == thePID)?1:0;
150   return reinterpret_cast<CORBA::LongLong>(_impl);
151 }