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 "SalomeHPContainerTools.hxx"
21 #include "Exception.hxx"
25 using namespace YACS::ENGINE;
27 void SalomeHPContainerVectOfHelper::resize(std::size_t sz)
30 _whichOccupied.resize(sz); std::fill(_whichOccupied.begin(),_whichOccupied.end(),false);
31 _launchModeType.clear(); _launchModeType.resize(sz);
32 _currentlyWorking.clear();
35 std::size_t SalomeHPContainerVectOfHelper::getNumberOfFreePlace() const
37 return std::count(_whichOccupied.begin(),_whichOccupied.end(),false);
40 void SalomeHPContainerVectOfHelper::allocateFor(const std::vector<const Task *>& nodes)
42 for(std::vector<const Task *>::const_iterator it=nodes.begin();it!=nodes.end();it++)
46 if(_currentlyWorking.find(*it)!=_currentlyWorking.end())
47 throw Exception("Searching to allocate for a ServiceNode instance already declared as allocated !");
48 std::vector<bool>::iterator it2(std::find(_whichOccupied.begin(),_whichOccupied.end(),false));
49 if(it2==_whichOccupied.end())
50 throw Exception("All ressources are already occupied ! You are expected to wait for released resources !");
51 std::size_t pos(std::distance(_whichOccupied.begin(),it2));
52 _currentlyWorking[*it]=pos; _whichOccupied[pos]=true;
56 void SalomeHPContainerVectOfHelper::release(const Task *node)
60 std::map< const Task *,std::size_t >::iterator it(_currentlyWorking.find(node));
61 if(it==_currentlyWorking.end())
62 throw Exception("Request to release a resource not declared as working !");
63 _whichOccupied[(*it).second]=false;
64 _currentlyWorking.erase(it);
67 const SalomeContainerMonoHelper& SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node) const
69 return _launchModeType[locateTask(node)];
72 SalomeContainerMonoHelper& SalomeHPContainerVectOfHelper::getHelperOfTask(const Task *node)
74 return _launchModeType[locateTask(node)];
77 std::size_t SalomeHPContainerVectOfHelper::locateTask(const Task *node) const
79 std::map< const Task *,std::size_t >::const_iterator it(_currentlyWorking.find(node));
80 if(it==_currentlyWorking.end())
81 throw Exception("current Node to be located is not marked as launched !");
82 std::size_t ret((*it).second);
87 void SalomeHPContainerVectOfHelper::checkNoCurrentWork() const
89 for(std::map<const Task *,std::size_t >::const_iterator it=_currentlyWorking.begin();it!=_currentlyWorking.end();it++)
91 throw Exception("Something wrong a node is still declared to be using the ressource !");
92 for(std::vector<SalomeContainerMonoHelper>::const_iterator it=_launchModeType.begin();it!=_launchModeType.end();it++)
93 if((*it).isAlreadyStarted(0))
94 throw Exception("Some of the containers have be started ! Please shutdown them before !");
97 void SalomeHPContainerVectOfHelper::checkPosInVec(std::size_t pos) const
99 if(pos<0 || pos>=_launchModeType.size())
100 throw Exception("The task has been found, but its id is not in the correct range ! resize of of container size during run ?");