]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/SalomeHPContainer.cxx
Salome HOME
Fix memory corruption and refactor some points.
[modules/yacs.git] / src / runtime / SalomeHPContainer.cxx
1 // Copyright (C) 2006-2014  CEA/DEN, EDF R&D
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 #include "SalomeHPContainer.hxx"
21 #include "SalomeComponent.hxx"
22
23 #include <algorithm>
24
25 using namespace YACS::ENGINE;
26
27 const char SalomeHPContainer::KIND[]="HPSalome";
28
29 SalomeHPContainer::SalomeHPContainer():_shutdownLevel(999)
30 {
31 }
32
33 SalomeHPContainer::SalomeHPContainer(const SalomeHPContainer& other):_componentNames(other._componentNames),_shutdownLevel(999),_sct(other._sct)
34 {
35 }
36
37 void SalomeHPContainer::setSizeOfPool(int sz)
38 {
39   _launchModeType.resize(sz);
40 }
41
42 std::size_t SalomeHPContainer::getNumberOfFreePlace() const
43 {
44   return _launchModeType.getNumberOfFreePlace();
45 }
46
47 void SalomeHPContainer::allocateFor(const std::vector<const Task *>& nodes)
48 {
49   _launchModeType.allocateFor(nodes);
50 }
51
52 void SalomeHPContainer::release(Task *node)
53 {
54   _launchModeType.release(node);
55 }
56
57 SalomeHPContainer::~SalomeHPContainer()
58 {
59 }
60
61 void SalomeHPContainer::lock()
62 {
63   _mutex.lock();
64 }
65
66 void SalomeHPContainer::unLock()
67 {
68   _mutex.unlock();
69 }
70
71 bool SalomeHPContainer::isAlreadyStarted(const Task *askingNode) const
72 {
73   const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
74   return helper->isAlreadyStarted(askingNode);
75 }
76
77 void SalomeHPContainer::start(const Task *askingNode) throw(Exception)
78 {
79   SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
80   SalomeContainerTools::Start(_componentNames,helper,_sct,_shutdownLevel,this,askingNode);
81 }
82
83 void SalomeHPContainer::shutdown(int level)
84 {
85   if(level < _shutdownLevel)
86       return;
87   _shutdownLevel=999;
88   for(std::size_t i=0;_launchModeType.size();i++)
89     {
90       SalomeContainerMonoHelper *helper(_launchModeType.at(i));
91       helper->shutdown();
92     }
93 }
94
95 std::string SalomeHPContainer::getPlacementId(const Task *askingNode) const
96 {
97   const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
98   return SalomeContainerTools::GetPlacementId(helper,this,askingNode);
99 }
100
101 std::string SalomeHPContainer::getFullPlacementId(const Task *askingNode) const
102 {
103   const SalomeContainerMonoHelper *helper(_launchModeType.getHelperOfTask(askingNode));
104   return SalomeContainerTools::GetFullPlacementId(helper,this,askingNode);
105 }
106
107 /*!
108  * It is not a bug here ! clone for homogeneous container is not supposed to be copied !
109  */
110 Container *SalomeHPContainer::clone() const
111 {
112   incrRef();
113   return const_cast<SalomeHPContainer*>(this);
114 }
115
116 Container *SalomeHPContainer::cloneAlways() const
117 {
118   return new SalomeHPContainer(*this);
119 }
120
121 void SalomeHPContainer::setProperty(const std::string& name,const std::string& value)
122 {
123   _sct.setProperty(name,value);
124 }
125
126 std::string SalomeHPContainer::getProperty(const std::string& name) const
127 {
128   return _sct.getProperty(name);
129 }
130
131 void SalomeHPContainer::clearProperties()
132 {
133   _sct.clearProperties();
134 }
135
136 void SalomeHPContainer::addComponentName(const std::string& name)
137 {
138   _componentNames.push_back(name);
139 }
140
141 std::map<std::string,std::string> SalomeHPContainer::getProperties() const
142 {
143   return _sct.getProperties();
144 }
145
146 std::map<std::string,std::string> SalomeHPContainer::getResourceProperties(const std::string& name) const
147 {
148   return _sct.getResourceProperties(name);
149 }
150
151 void SalomeHPContainer::checkCapabilityToDealWith(const ComponentInstance *inst) const throw(YACS::Exception)
152 {
153   if(inst->getKind()!=SalomeComponent::KIND)
154     throw Exception("SalomeHPContainer::checkCapabilityToDealWith : SalomeContainer is not able to deal with this type of ComponentInstance.");
155 }