1 // Copyright (C) 2006-2016 CEA/DEN, EDF R&D
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_NamingService.hxx"
36 #include "SALOME_LifeCycleCORBA.hxx"
37 #include "SALOME_ContainerManager.hxx"
38 #include "Basics_Utils.hxx"
46 #define getpid _getpid
50 #include "YacsTrace.hxx"
52 using namespace YACS::ENGINE;
55 const char SalomeContainer::KIND[]="Salome";
57 const char SalomeContainer::TYPE_PROPERTY_STR[]="type";
59 SalomeContainer::SalomeContainer():_launchModeType(new SalomeContainerMonoHelper),_shutdownLevel(999)
63 SalomeContainer::SalomeContainer(const SalomeContainer& other)
64 : Container(other),_componentNames(other._componentNames),
65 _launchModeType(other._launchModeType->deepCpyOnlyStaticInfo()),
66 _shutdownLevel(other._shutdownLevel),
71 SalomeContainer::SalomeContainer(const Container& other, const SalomeContainerTools& sct, const SalomeContainerHelper *lmt,
72 const std::vector<std::string>& componentNames, int shutdownLev):Container(other),_componentNames(componentNames),
73 _launchModeType(const_cast<SalomeContainerHelper *>(lmt)),_shutdownLevel(shutdownLev),_sct(sct)
79 SalomeContainer::~SalomeContainer()
81 _launchModeType->decrRef();
84 void SalomeContainer::lock()
89 void SalomeContainer::unLock()
94 std::string SalomeContainer::getKind() const
99 Container *SalomeContainer::clone() const
101 if(_isAttachedOnCloning)
104 return (Container*) (this);
107 return new SalomeContainer(*this);
110 Container *SalomeContainer::cloneAlways() const
112 return new SalomeContainer(*this);
115 void SalomeContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
117 if(inst->getKind()!=SalomeComponent::KIND)
118 throw Exception("SalomeContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
121 void SalomeContainer::setProperty(const std::string& name, const std::string& value)
123 if (name == AOC_ENTRY)
125 std::istringstream iss(value);
128 setAttachOnCloningStatus((bool)val);
130 else if (name == TYPE_PROPERTY_STR)
132 if (value == SalomeContainerMonoHelper::TYPE_NAME)
134 _launchModeType->decrRef();
135 _launchModeType=new SalomeContainerMonoHelper;
137 else if (value == SalomeContainerMultiHelper::TYPE_NAME)
139 _launchModeType->decrRef();
140 _launchModeType=new SalomeContainerMultiHelper;
143 throw Exception("SalomeContainer::setProperty : type value is not correct (mono or multi): " + value);
145 _sct.setProperty(name,value);
148 std::string SalomeContainer::getProperty(const std::string& name) const
150 if (name == TYPE_PROPERTY_STR)
151 return _launchModeType->getType();
154 int reti(_isAttachedOnCloning);
155 std::ostringstream oss; oss << reti;
158 return _sct.getProperty(name);
161 void SalomeContainer::clearProperties()
163 _sct.clearProperties();
166 void SalomeContainer::addComponentName(const std::string& name)
168 _componentNames.push_back(name);
171 void SalomeContainer::addToResourceList(const std::string& name)
173 _sct.addToResourceList(name);
176 //! Load a component instance in this container
178 * \param inst the component instance to load
180 CORBA::Object_ptr SalomeContainer::loadComponent(Task *askingNode)
182 return SalomeContainerTools::LoadComponent(_launchModeType,this,askingNode);
185 //! Get the container placement id for a component instance
187 * \param inst the component instance
188 * \return the placement id
190 std::string SalomeContainer::getPlacementId(const Task *askingNode) const
192 return SalomeContainerTools::GetPlacementId(_launchModeType,this,askingNode);
195 //! Get the container full path for a component instance
197 * \param inst the component instance
198 * \return the full placement id
200 std::string SalomeContainer::getFullPlacementId(const Task *askingNode) const
202 return SalomeContainerTools::GetFullPlacementId(_launchModeType,this,askingNode);
205 //! Check if the component instance container is already started
207 * \param inst the component instance
208 * \return true, if the container is already started, else false
210 bool SalomeContainer::isAlreadyStarted(const Task *askingNode) const
212 return _launchModeType->isAlreadyStarted(askingNode);
215 Engines::Container_ptr SalomeContainer::getContainerPtr(const Task *askingNode) const
217 return Engines::Container::_duplicate(_launchModeType->getContainer(askingNode));
220 //! Start a salome container (true salome container not yacs one) with given ContainerParameters (_params)
222 * \param inst the component instance
224 void SalomeContainer::start(const Task *askingNode) throw(YACS::Exception)
226 SalomeContainerTools::Start(_componentNames,_launchModeType,_sct,_shutdownLevel,this,askingNode);
229 void SalomeContainer::shutdown(int level)
231 DEBTRACE("SalomeContainer::shutdown: " << _name << "," << level << "," << _shutdownLevel);
232 if(level < _shutdownLevel)
236 //shutdown the SALOME containers
237 _launchModeType->shutdown();
240 std::map<std::string,std::string> SalomeContainer::getResourceProperties(const std::string& name) const
242 return _sct.getResourceProperties(name);
245 std::map<std::string,std::string> SalomeContainer::getProperties() const
247 return _sct.getProperties();