1 // Copyright (C) 2006-2023 CEA, EDF
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #define private public
24 #define protected public
25 #include <omniORB4/CORBA.h>
26 #include <omniORB4/internal/typecode.h>
29 #include "RuntimeSALOME.hxx"
30 #include "SalomeContainer.hxx"
31 #include "SalomeComponent.hxx"
32 #include "ServiceNode.hxx"
35 #include "SALOME_LifeCycleCORBA.hxx"
36 #include "SALOME_ContainerManager.hxx"
37 #include "Basics_Utils.hxx"
45 #define getpid _getpid
49 #include "YacsTrace.hxx"
51 using namespace YACS::ENGINE;
54 const char SalomeContainer::KIND[]="Salome";
56 const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
58 SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
62 SalomeContainer::SalomeContainer(const SalomeContainer& other)
63 : Container(other),_componentNames(other._componentNames),
64 _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()),
65 _shutdownLevel(other._shutdownLevel),
70 SalomeContainer::SalomeContainer(const Container& other, const SalomeContainerTools& sct, const SalomeContainerHelper *lmt,
71 const std::vector<std::string>& componentNames, int shutdownLev):Container(other),_componentNames(componentNames),
72 _launchModeType(const_cast<SalomeContainerHelper *>(lmt)),_shutdownLevel(shutdownLev),_sct(sct)
78 SalomeContainer::~SalomeContainer()
80 _launchModeType->decrRef();
83 void SalomeContainer::lock()
88 void SalomeContainer::unLock()
93 std::string SalomeContainer::getKind() const
98 Container *SalomeContainer::clone() const
100 if(_isAttachedOnCloning)
103 return (Container*) (this);
106 return new SalomeContainer(*this);
109 Container *SalomeContainer::cloneAlways() const
111 return new SalomeContainer(*this);
114 void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const
116 if(inst->getKind()!=SalomeComponent::KIND)
117 throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
120 void SalomeContainer::setProperty(const std::string& name, const std::string& value)
122 if (name == AOC_ENTRY)
124 std::istringstream iss(value);
127 setAttachOnCloningStatus((bool)val);
129 else if (name == TYPE_PROPERTY_STR)
131 if (value == SalomeContainerMonoHelper::TYPE_NAME)
133 _launchModeType->decrRef();
134 _launchModeType=new SalomeContainerMonoHelper;
136 else if (value == SalomeContainerMultiHelper::TYPE_NAME)
138 _launchModeType->decrRef();
139 _launchModeType=new SalomeContainerMultiHelper;
142 throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
144 _sct.setProperty(name,value);
147 std::string SalomeContainer::getProperty(const std::string& name) const
149 if (name == TYPE_PROPERTY_STR)
150 return _launchModeType->getType();
153 int reti(_isAttachedOnCloning);
154 std::ostringstream oss; oss << reti;
157 return _sct.getProperty(name);
160 void SalomeContainer::clearProperties()
162 _sct.clearProperties();
165 void SalomeContainer::addComponentName(const std::string& name)
167 _componentNames.push_back(name);
170 void SalomeContainer::addToResourceList(const std::string& name)
172 _sct.addToResourceList(name);
175 //! Load a component instance in this container
177 * \param inst the component instance to load
179 CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode)
181 return SalomeContainerTools::LoadComponent(_launchModeType,this,askingNode);
184 //! Get the container placement id for a component instance
186 * \param inst the component instance
187 * \return the placement id
189 std::string SalomeContainer::getPlacementId(const Task *askingNode) const
191 return SalomeContainerTools::GetPlacementId(_launchModeType,this,askingNode);
194 //! Get the container full path for a component instance
196 * \param inst the component instance
197 * \return the full placement id
199 std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const
201 return SalomeContainerTools::GetFullPlacementId(_launchModeType,this,askingNode);
204 //! Check if the component instance container is already started
206 * \param inst the component instance
207 * \return true, if the container is already started, else false
209 bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const
211 return _launchModeType->isAlreadyStarted(askingNode);
214 Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const
216 return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode));
219 //! Start a salome container (true salome container not yacs one) with given ContainerParameters (_params)
221 * \param inst the component instance
223 void SalomeContainer::start(const Task *askingNode)
225 SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,askingNode);
228 void SalomeContainer::start(const Task *askingNode,
229 const std::string& resource_name,
230 const std::string& container_name)
232 if(canAcceptImposedResource()
233 && askingNode != nullptr
234 && askingNode->hasImposedResource())
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);
247 bool SalomeContainer::canAcceptImposedResource()
249 return _launchModeType->getType() == SalomeContainerMultiHelper::TYPE_NAME;
252 void SalomeContainer::shutdown(int level)
254 DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);
255 if(level < _shutdownLevel)
259 //shutdown the SALOME containers
260 _launchModeType->shutdown();
263 std::map<std::string,std::string> SalomeContainer::getResourceProperties(const std::string& name) const
265 return _sct.getResourceProperties(name);
268 std::map<std::string,std::string> SalomeContainer::getProperties() const
270 return _sct.getProperties();