1 // Copyright (C) 2006-2014 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
20 #include "SalomeHPContainer.hxx"
21 #include "SalomeHPComponent.hxx"
22 #include "SalomeContainerTmpForHP.hxx"
23 #include "AutoLocker.hxx"
27 using namespace YACS::ENGINE;
29 const char SalomeHPContainer::KIND[]="HPSalome";
31 SalomeHPContainer::SalomeHPContainer():_shutdownLevel(999)
35 SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):_componentNames(other._componentNames),_shutdownLevel(999),_sct(other._sct),_initScript(other._initScript)
39 void SalomeHPContainer::setSizeOfPool(int sz)
41 _launchModeType.resize(sz);
44 int SalomeHPContainer::getSizeOfPool() const
46 return _launchModeType.size();
49 std::size_t SalomeHPContainer::getNumberOfFreePlace() const
51 return _launchModeType.getNumberOfFreePlace();
54 void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
56 _launchModeType.allocateFor(nodes);
59 void SalomeHPContainer::release(const Task *node)
61 _launchModeType.release(node);
64 SalomeHPContainer::~SalomeHPContainer()
68 void SalomeHPContainer::lock()
73 void SalomeHPContainer::unLock()
78 std::string SalomeHPContainer::getKind() const
83 std::string SalomeHPContainer::getDiscreminantStrOfThis(const Task *askingNode) const
85 YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(this,askingNode));
86 return tmpCont->getDiscreminantStrOfThis(askingNode);
89 bool SalomeHPContainer::isAlreadyStarted(const Task *askingNode) const
91 const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTaskThreadSafe(this,askingNode));
92 return helper->isAlreadyStarted(askingNode);
95 void SalomeHPContainer::start(const Task *askingNode) throw(Exception)
97 SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTaskThreadSafe(this,askingNode));
98 SalomeContainerTools::Start(_componentNames,helper,_sct,_shutdownLevel,this,askingNode);
101 void SalomeHPContainer::shutdown(int level)
103 if(level < _shutdownLevel)
106 for(std::size_t i=0;i<_launchModeType.size();i++)
108 SalomeContainerMonoHelper *helper(_launchModeType.at(i));
113 std::string SalomeHPContainer::getPlacementId(const Task *askingNode) const
115 const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
116 return SalomeContainerTools::GetPlacementId(helper,this,askingNode);
119 std::string SalomeHPContainer::getFullPlacementId(const Task *askingNode) const
121 const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
122 return SalomeContainerTools::GetFullPlacementId(helper,this,askingNode);
126 * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
128 Container *SalomeHPContainer::clone() const
131 return const_cast<SalomeHPContainer*>(this);
134 Container *SalomeHPContainer::cloneAlways() const
136 return new SalomeHPContainer(*this);
139 void SalomeHPContainer::setProperty(const std::string& name,const std::string& value)
141 if(name==AOC_ENTRY)//no sense to set it ! It is always true ! ignore it !
143 else if(name==SIZE_OF_POOL_KEY)
145 std::istringstream iss(value);
150 else if(name==INITIALIZE_SCRIPT_KEY)
155 _sct.setProperty(name,value);
158 std::string SalomeHPContainer::getProperty(const std::string& name) const
162 return std::string("1");
164 else if(name==SIZE_OF_POOL_KEY)
166 std::ostringstream oss; oss << getSizeOfPool();
169 else if(name==INITIALIZE_SCRIPT_KEY)
174 return _sct.getProperty(name);
177 void SalomeHPContainer::clearProperties()
180 _sct.clearProperties();
183 void SalomeHPContainer::addComponentName(const std::string& name)
185 _componentNames.push_back(name);
188 std::map<std::string,std::string> SalomeHPContainer::getProperties() const
190 std::map<std::string,std::string> ret(_sct.getProperties());
191 std::ostringstream oss; oss << getSizeOfPool();
192 ret[SIZE_OF_POOL_KEY]=oss.str();
193 if(!_initScript.empty())
194 ret[INITIALIZE_SCRIPT_KEY]=_initScript;
198 std::map<std::string,std::string> SalomeHPContainer::getResourceProperties(const std::string& name) const
200 return _sct.getResourceProperties(name);
203 void SalomeHPContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
205 if(inst->getKind()!=SalomeHPComponent::KIND)
206 throw Exception("SalomeHPContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");