Version: 8.3.0
SalomeContainer.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 
20 //#define REFCNT
21 //
22 #ifdef REFCNT
23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
27 #endif
28 
29 #include "RuntimeSALOME.hxx"
30 #include "SalomeContainer.hxx"
31 #include "SalomeComponent.hxx"
32 #include "ServiceNode.hxx"
33 #include "Proc.hxx"
34 
35 #include "SALOME_NamingService.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOME_ContainerManager.hxx"
38 #include "Basics_Utils.hxx"
39 #include "OpUtil.hxx"
40 
41 #include <sstream>
42 #include <iostream>
43 
44 #ifdef WIN32
45 #include <process.h>
46 #define getpid _getpid
47 #endif
48 
49 //#define _DEVDEBUG_
50 #include "YacsTrace.hxx"
51 
52 using namespace YACS::ENGINE;
53 using namespace std;
54 
55 const char SalomeContainer::KIND[]="Salome";
56 
57 const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
58 
59 SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
60 {
61 }
62 
64 : Container(other),_componentNames(other._componentNames),
65  _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()),
66  _shutdownLevel(other._shutdownLevel),
67  _sct(other._sct)
68 {
69 }
70 
72  const std::vector<std::string>& componentNames, int shutdownLev):Container(other),_componentNames(componentNames),
73  _launchModeType(const_cast<SalomeContainerHelper *>(lmt)),_shutdownLevel(shutdownLev),_sct(sct)
74 {
75  if(lmt)
76  lmt->incrRef();
77 }
78 
80 {
82 }
83 
85 {
86  _mutex.lock();
87 }
88 
90 {
91  _mutex.unLock();
92 }
93 
94 std::string SalomeContainer::getKind() const
95 {
96  return KIND;
97 }
98 
100 {
102  {
103  incrRef();
104  return (Container*) (this);
105  }
106  else
107  return new SalomeContainer(*this);
108 }
109 
111 {
112  return new SalomeContainer(*this);
113 }
114 
116 {
117  if(inst->getKind()!=SalomeComponent::KIND)
118  throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
119 }
120 
121 void SalomeContainer::setProperty(const std::string& name, const std::string& value)
122 {
123  if (name == AOC_ENTRY)
124  {
125  std::istringstream iss(value);
126  int val;
127  iss >> val;
128  setAttachOnCloningStatus((bool)val);
129  }
130  else if (name == TYPE_PROPERTY_STR)
131  {
133  {
136  }
137  else if (value == SalomeContainerMultiHelper::TYPE_NAME)
138  {
141  }
142  else
143  throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
144  }
145  _sct.setProperty(name,value);
146 }
147 
148 std::string SalomeContainer::getProperty(const std::string& name) const
149 {
150  if (name == TYPE_PROPERTY_STR)
151  return _launchModeType->getType();
152  if (name==AOC_ENTRY)
153  {
154  int reti(_isAttachedOnCloning);
155  std::ostringstream oss; oss << reti;
156  return oss.str();
157  }
158  return _sct.getProperty(name);
159 }
160 
162 {
164 }
165 
166 void SalomeContainer::addComponentName(const std::string& name)
167 {
168  _componentNames.push_back(name);
169 }
170 
171 void SalomeContainer::addToResourceList(const std::string& name)
172 {
173  _sct.addToResourceList(name);
174 }
175 
177 
180 CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode)
181 {
183 }
184 
186 
190 std::string SalomeContainer::getPlacementId(const Task *askingNode) const
191 {
193 }
194 
196 
200 std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const
201 {
203 }
204 
206 
210 bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const
211 {
212  return _launchModeType->isAlreadyStarted(askingNode);
213 }
214 
215 Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const
216 {
217  return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode));
218 }
219 
221 
224 void SalomeContainer::start(const Task *askingNode) throw(YACS::Exception)
225 {
226  SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,askingNode);
227 }
228 
230 {
231  DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);
232  if(level < _shutdownLevel)
233  return;
234 
235  _shutdownLevel=999;
236  //shutdown the SALOME containers
238 }
239 
240 std::map<std::string,std::string> SalomeContainer::getResourceProperties(const std::string& name) const
241 {
242  return _sct.getResourceProperties(name);
243 }
244 
245 std::map<std::string,std::string> SalomeContainer::getProperties() const
246 {
247  return _sct.getProperties();
248 }