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