Salome HOME
Revert "Synchronize adm files"
[modules/kernel.git] / src / SALOMEDS / SALOMEDS_SimanStudy.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_SimanStudy.cxx
24 //  Author : Mikhail PONIKAROV
25 //  Module : SALOME
26 //
27 #include "utilities.h" 
28
29 #include "SALOMEDS_SimanStudy.hxx"
30
31 #include "SALOMEDS.hxx"
32 #include "SALOMEDS_Study.hxx"
33
34 #include "SALOMEDSImpl_Study.hxx"
35
36 #include "SALOMEDS_SimanStudy_i.hxx"
37
38 #include "Basics_Utils.hxx"
39
40 #include "Utils_ORB_INIT.hxx" 
41 #include "Utils_SINGLETON.hxx" 
42
43 /*
44 SALOMEDS_SimanStudy::SALOMEDS_SimanStudy(SALOMEDSImpl_SimanStudy* theStudy)
45 {
46   _isLocal = true;
47   _local_impl = theStudy;
48   _corba_impl = SALOMEDS::SimanStudy::_nil();
49   init_orb();
50 }*/
51
52 SALOMEDS_SimanStudy::SALOMEDS_SimanStudy(SALOMEDS::SimanStudy_ptr theStudy)
53 {
54   /*
55 #ifdef WIN32
56   long pid =  (long)_getpid();
57 #else
58   long pid =  (long)getpid();
59 #endif  
60
61   long addr = theStudy->GetLocalImpl(Kernel_Utils::GetHostname().c_str(), pid, _isLocal);
62   if(_isLocal) {
63     _local_impl = reinterpret_cast<SALOMEDSImpl_SimanStudy*>(addr);
64     _corba_impl = SALOMEDS::SimanStudy::_duplicate(theStudy);
65   }
66   else {
67     _local_impl = NULL;
68     _corba_impl = SALOMEDS::SimanStudy::_duplicate(theStudy);
69   }
70   */
71   _corba_impl = SALOMEDS::SimanStudy::_duplicate(theStudy);
72
73   init_orb();
74 }
75
76 SALOMEDS_SimanStudy::~SALOMEDS_SimanStudy()
77 {
78 }
79
80 void SALOMEDS_SimanStudy::CheckOut(const _PTR(Study) theTarget)
81 {
82   if (!theTarget) return;
83   SALOMEDS_Study* aStudy = dynamic_cast<SALOMEDS_Study*>(theTarget.get());
84   /*if (_isLocal) {
85     //SALOMEDS::Locker lock; mpv: this may cause dedlock when importData in module calls another SALOMEDS method with lock
86     _local_impl->CheckOut(aStudy->GetLocalImpl());
87   }
88   else*/ _corba_impl->CheckOut(aStudy->GetStudy());
89 }
90
91 void SALOMEDS_SimanStudy::CheckIn(const std::string theModuleName)
92 {
93   /*if (_isLocal) {
94     //SALOMEDS::Locker lock; mpv: this may cause dedlock when getModifiedData in module calls another SALOMEDS method with lock
95     _local_impl->CheckIn(theModuleName);
96   }
97   else*/ _corba_impl->CheckIn((char*)theModuleName.c_str());
98 }
99
100 _PTR(Study) SALOMEDS_SimanStudy::getReferencedStudy()
101 {
102   SALOMEDSClient_Study* aStudy = NULL;
103   /*if (_isLocal) {
104     SALOMEDS::Locker lock;
105
106     SALOMEDSImpl_Study* aStudy_impl = _local_impl->getReferencedStudy();
107     if (!aStudy_impl) return _PTR(Study)(aStudy);
108     aStudy = new SALOMEDS_Study(aStudy_impl);
109   }
110   else {
111     SALOMEDS::Study_var aStudy_impl = _corba_impl->getReferencedStudy();
112     if (CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
113     aStudy = new SALOMEDS_Study(aStudy_impl);
114   }*/
115   SALOMEDS::Study_var aStudy_impl = _corba_impl->getReferencedStudy();
116   if (CORBA::is_nil(aStudy_impl)) return _PTR(Study)(aStudy);
117   aStudy = new SALOMEDS_Study(aStudy_impl);
118   return _PTR(Study)(aStudy);
119 }
120
121 std::string SALOMEDS_SimanStudy::StudyId()
122 {
123   std::string anId;
124   /*if (_isLocal) {
125     SALOMEDS::Locker lock;
126     anId = _local_impl->StudyId();
127   }
128   else*/ anId = (CORBA::String_var)_corba_impl->StudyId();
129   return anId;
130 }
131
132 void SALOMEDS_SimanStudy::StudyId(const std::string theId)
133 {
134   /*if (_isLocal) {
135     SALOMEDS::Locker lock;
136     _local_impl->StudyId(theId);
137   }
138   else*/ _corba_impl->StudyId((char*)theId.c_str());
139 }
140
141 std::string SALOMEDS_SimanStudy::ScenarioId()
142 {
143   std::string anId;
144   /*if (_isLocal) {
145     SALOMEDS::Locker lock;
146     anId = _local_impl->ScenarioId();
147   }
148   else*/ anId = (CORBA::String_var)_corba_impl->ScenarioId();
149   return anId;
150 }
151
152 void SALOMEDS_SimanStudy::ScenarioId(const std::string theId)
153 {
154   /*if (_isLocal) {
155     SALOMEDS::Locker lock;
156     _local_impl->ScenarioId(theId);
157   }
158   else*/ _corba_impl->ScenarioId((char*)theId.c_str());
159 }
160
161 std::string SALOMEDS_SimanStudy::UserId()
162 {
163   std::string anId;
164   /*if (_isLocal) {
165     SALOMEDS::Locker lock;
166     anId = _local_impl->UserId();
167   }
168   else*/ anId = (CORBA::String_var)_corba_impl->UserId();
169   return anId;
170 }
171
172 void SALOMEDS_SimanStudy::UserId(const std::string theId)
173 {
174   /*if (_isLocal) {
175     SALOMEDS::Locker lock;
176     _local_impl->UserId(theId);
177   }
178   else*/ _corba_impl->UserId((char*)theId.c_str());
179 }
180
181 void SALOMEDS_SimanStudy::init_orb()
182 {
183   ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
184   ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
185   _orb = init(0, 0);
186 }