Version: 9.15.0
SalomeContainer.cxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2025 CEA, EDF
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_LifeCycleCORBA.hxx"
36 #include "SALOME_ContainerManager.hxx"
37 #include "Basics_Utils.hxx"
38 #include "OpUtil.hxx"
39 
40 #include <sstream>
41 #include <iostream>
42 
43 #ifdef WIN32
44 #include <process.h>
45 #define getpid _getpid
46 #endif
47 
48 //#define _DEVDEBUG_
49 #include "YacsTrace.hxx"
50 
51 using namespace YACS::ENGINE;
52 using namespace std;
53 
54 const char SalomeContainer::KIND[]="Salome";
55 
56 const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
57 
58 SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
59 {
60 }
61 
63 : Container(other),_componentNames(other._componentNames),
64  _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()),
65  _shutdownLevel(other._shutdownLevel),
66  _sct(other._sct)
67 {
68 }
69 
71  const std::vector<std::string>& componentNames, int shutdownLev):Container(other),_componentNames(componentNames),
72  _launchModeType(const_cast<SalomeContainerHelper *>(lmt)),_shutdownLevel(shutdownLev),_sct(sct)
73 {
74  if(lmt)
75  lmt->incrRef();
76 }
77 
79 {
81 }
82 
84 {
85  _mutex.lock();
86 }
87 
89 {
90  _mutex.unLock();
91 }
92 
93 std::string SalomeContainer::getKind() const
94 {
95  return KIND;
96 }
97 
99 {
101  {
102  incrRef();
103  return (Container*) (this);
104  }
105  else
106  return new SalomeContainer(*this);
107 }
108 
110 {
111  return new SalomeContainer(*this);
112 }
113 
115 {
116  if(inst->getKind()!=SalomeComponent::KIND)
117  throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
118 }
119 
120 void SalomeContainer::setProperty(const std::string& name, const std::string& value)
121 {
122  if (name == AOC_ENTRY)
123  {
124  std::istringstream iss(value);
125  int val;
126  iss >> val;
127  setAttachOnCloningStatus((bool)val);
128  }
129  else if (name == TYPE_PROPERTY_STR)
130  {
132  {
135  }
136  else if (value == SalomeContainerMultiHelper::TYPE_NAME)
137  {
140  }
141  else
142  throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
143  }
144  _sct.setProperty(name,value);
145 }
146 
147 std::string SalomeContainer::getProperty(const std::string& name) const
148 {
149  if (name == TYPE_PROPERTY_STR)
150  return _launchModeType->getType();
151  if (name==AOC_ENTRY)
152  {
153  int reti(_isAttachedOnCloning);
154  std::ostringstream oss; oss << reti;
155  return oss.str();
156  }
157  return _sct.getProperty(name);
158 }
159 
161 {
163 }
164 
165 void SalomeContainer::addComponentName(const std::string& name)
166 {
167  _componentNames.push_back(name);
168 }
169 
170 void SalomeContainer::addToResourceList(const std::string& name)
171 {
172  _sct.addToResourceList(name);
173 }
174 
176 
179 CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode)
180 {
182 }
183 
185 
189 std::string SalomeContainer::getPlacementId(const Task *askingNode) const
190 {
192 }
193 
195 
199 std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const
200 {
202 }
203 
205 
209 bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const
210 {
211  return _launchModeType->isAlreadyStarted(askingNode);
212 }
213 
214 Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const
215 {
216  return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode));
217 }
218 
220 
223 void SalomeContainer::start(const Task *askingNode)
224 {
226 }
227 
228 void SalomeContainer::start(const Task *askingNode,
229  const std::string& resource_name,
230  const std::string& container_name)
231 {
233  && askingNode != nullptr
234  && askingNode->hasImposedResource())
235  {
236  SalomeContainerTools tempSct = _sct;
237  tempSct.setProperty("name", resource_name);
238  tempSct.setProperty("container_name", container_name);
239  // components are not supported yet on this kind of start
240  std::vector<std::string> noComponentNames;
241  SalomeContainerTools::Start(noComponentNames,_launchModeType,tempSct,_shutdownLevel,this,askingNode);
242  }
243  else
244  start(askingNode);
245 }
246 
248 {
250 }
251 
253 {
254  DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);
255  if(level < _shutdownLevel)
256  return;
257 
258  _shutdownLevel=999;
259  //shutdown the SALOME containers
261 }
262 
263 std::map<std::string,std::string> SalomeContainer::getResourceProperties(const std::string& name) const
264 {
265  return _sct.getResourceProperties(name);
266 }
267 
268 std::map<std::string,std::string> SalomeContainer::getProperties() const
269 {
270  return _sct.getProperties();
271 }
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Base class for all component instances.
virtual std::string getKind() const
Return the component kind.
static const char AOC_ENTRY[]
Definition: Container.hxx:88
virtual void setAttachOnCloningStatus(bool val) const
Definition: Container.cxx:68
virtual Engines::Container_var getContainer(const Task *askingNode) const =0
virtual std::string getType() const =0
virtual bool isAlreadyStarted(const Task *askingNode) const =0
static std::string GetPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
static void Start(const std::vector< std::string > &compoNames, SalomeContainerHelper *schelp, SalomeContainerToolsBase &sct, int &shutdownLevel, const Container *cont, const Task *askingNode)
static CORBA::Object_ptr LoadComponent(SalomeContainerHelper *launchModeType, Container *cont, Task *askingNode)
static std::string GetFullPlacementId(const SalomeContainerHelper *launchModeType, const Container *cont, const Task *askingNode)
std::map< std::string, std::string > getResourceProperties(const std::string &name) const override
std::string getProperty(const std::string &name) const override
const std::map< std::string, std::string > & getProperties() const override
void setProperty(const std::string &name, const std::string &value) override
void addToResourceList(const std::string &name) override
std::string getFullPlacementId(const Task *askingNode) const
Get the container full path for a component instance.
bool isAlreadyStarted(const Task *askingNode) const
Check if the component instance container is already started.
void start(const Task *askingNode) override
Start a salome container (true salome container not yacs one) with given ContainerParameters (_params...
std::string getPlacementId(const Task *askingNode) const
Get the container placement id for a component instance.
void setProperty(const std::string &name, const std::string &value)
std::map< std::string, std::string > getResourceProperties(const std::string &name) const
void checkCapabilityToDealWith(const ComponentInstance *inst) const
void unLock()
For thread safety for concurrent load operation on same Container.
void lock()
For thread safety for concurrent load operation on same Container.
std::vector< std::string > _componentNames
virtual CORBA::Object_ptr loadComponent(Task *inst)
Load a component instance in this container.
std::string getProperty(const std::string &name) const
void addComponentName(const std::string &name)
SalomeContainerHelper * _launchModeType
bool canAcceptImposedResource() override
Engines::Container_ptr getContainerPtr(const Task *askingNode) const
void addToResourceList(const std::string &name)
YACS::BASES::Mutex _mutex
thread safety in Salome ???
Container * clone() const
WARNING ! clone behaviour MUST be in coherence with what is returned by isAttachedOnCloning() method
std::map< std::string, std::string > getProperties() const
static const char TYPE_PROPERTY_STR[]
virtual bool hasImposedResource() const
Definition: Task.hxx:58