Salome HOME
Merge branch 'master' of https://codev-tuleap.cea.fr/plugins/git/salome/yacs
[modules/yacs.git] / src / engine / InlineNode.cxx
1 // Copyright (C) 2006-2019  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 "InlineNode.hxx"
21 #include "Visitor.hxx"
22 #include "Container.hxx"
23 #include "HomogeneousPoolContainer.hxx"
24 #include <iostream>
25
26 #define _DEVDEBUG_
27 #include "YacsTrace.hxx"
28
29 using namespace YACS::ENGINE;
30 using namespace std;
31
32 const char InlineNode::LOCAL_STR[]="local";
33
34 const char InlineNode::REMOTE_STR[]="remote";
35
36 InlineNode::~InlineNode()
37 {
38   if(_container)
39     _container->decrRef();
40 }
41
42 void InlineNode::accept(Visitor *visitor)
43 {
44   visitor->visitInlineNode(this);
45 }
46
47 //! Set the script (as a string) to execute
48 /*!
49  * \param script: script to execute
50  */
51 void InlineNode::setScript(const std::string& script) 
52
53   _script=script; 
54   modified();
55 }
56
57
58 InlineFuncNode::~InlineFuncNode()
59 {
60 }
61
62 void InlineFuncNode::accept(Visitor *visitor)
63 {
64   visitor->visitInlineFuncNode(this);
65 }
66
67 /*!
68  * \param fname: name of the function contained in the script to execute
69  */
70 void InlineFuncNode::setFname(const std::string& fname)
71 {
72   _fname=fname;
73   modified();
74 }
75
76 void InlineFuncNode::checkBasicConsistency() const throw(YACS::Exception)
77 {
78   InlineNode::checkBasicConsistency();
79   if(_fname.empty() )
80      {
81        string mess = "Function name is not defined";
82        throw Exception(mess);
83      }
84 }
85
86 void InlineNode::setExecutionMode(const std::string& mode)
87 {
88   if(mode == _mode)return;
89   if(mode == LOCAL_STR || mode == REMOTE_STR)
90     {
91       _mode=mode;
92       modified();
93     }
94 }
95
96 std::string InlineNode::getExecutionMode()
97 {
98   return _mode;
99 }
100
101 Container* InlineNode::getContainer()
102 {
103   return _container;
104 }
105
106 void InlineNode::setContainer(Container* cont)
107 {
108   if (cont == _container) return;
109   if(_container)
110     _container->decrRef();
111   _container=cont;
112   if(_container)
113     _container->incrRef();
114 }
115
116 void InlineNode::performDuplicationOfPlacement(const Node& other)
117 {
118   const InlineNode &otherC=*(dynamic_cast<const InlineNode *>(&other));
119   //if other has no container don't clone: this will not have one
120   if(otherC._container)
121     _container=otherC._container->clone();
122 }
123
124 void InlineNode::performShallowDuplicationOfPlacement(const Node& other)
125 {
126   const InlineNode &otherC=*(dynamic_cast<const InlineNode *>(&other));
127   //if other has no container don't clone: this will not have one
128   if(otherC._container)
129     {
130       _container=otherC._container;
131       _container->incrRef();
132     }
133 }
134
135 bool InlineNode::isDeployable() const
136 {
137   if(_mode==REMOTE_STR)
138     return true;
139   else
140     return false;
141 }
142
143 int InlineNode::getMaxLevelOfParallelism() const
144 {
145   if(!isDeployable())
146     return 1;
147   if(!_container)
148     return 1;
149   std::map<std::string,std::string> props(_container->getProperties());
150   std::map<std::string,std::string>::iterator it(props.find(std::string("nb_proc_per_node")));
151   if(it==props.end())
152     return 1;
153   if((*it).second.empty())
154     return 1;
155   std::istringstream iss((*it).second);
156   int ret(1); iss >> ret;
157   return ret;
158 }
159
160 void InlineNode::partitionRegardingDPL(const PartDefinition *pd, std::map<ComposedNode *, YACS::BASES::AutoRefCnt<PartDefinition> >& zeMap)
161 {
162   if(!isDeployable())
163     return ;
164   if(!_container)
165     return ;
166   HomogeneousPoolContainer *contC(dynamic_cast<HomogeneousPoolContainer *>(_container));
167   if(!contC)
168     return ;
169   YACS::BASES::AutoConstRefCnt<PartDefinition> zePd;
170   zePd.takeRef(pd);
171   YACS::BASES::AutoRefCnt<HomogeneousPoolContainer> zeCont(contC->decorate(zePd));
172   setContainer(zeCont);
173 }