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