Salome HOME
Copyright update 2021
[modules/yacs.git] / src / runtime / SalomePythonComponent.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 <Python.h>
21 #include "SalomePythonComponent.hxx"
22 #include "SalomeComponent.hxx"
23 #include "SalomePythonNode.hxx"
24 #include "Exception.hxx"
25 #include "Container.hxx"
26
27 #include <sstream>
28
29 using namespace YACS::ENGINE;
30
31 const char SalomePythonComponent::KIND[]="SalomePy";
32
33 unsigned SalomePythonComponent::_cntForReprS = 0;
34
35 SalomePythonComponent::SalomePythonComponent(const std::string &name):ComponentInstance(name),_cntForRepr(_cntForReprS++)
36 {
37 }
38
39 SalomePythonComponent::SalomePythonComponent(const SalomePythonComponent& other):ComponentInstance(other),_cntForRepr(_cntForReprS++)
40 {
41 }
42
43 SalomePythonComponent::~SalomePythonComponent()
44 {
45 }
46
47 void SalomePythonComponent::load(Task *askingNode)
48 {
49   if(_container)
50     {
51       _container->start(askingNode);
52       return;
53     }
54   //This component has no specified container : use default container policy
55   //given by getStringValueToExportInInterp()
56   //throw Exception("SalomePythonComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
57 }
58
59 void SalomePythonComponent::unload(Task *askingNode)
60 {
61 }
62
63 bool SalomePythonComponent::isLoaded(Task *askingNode) const
64 {
65   if(!_container)
66     return false;
67   else
68     return _container->isAlreadyStarted(askingNode);
69 }
70
71 std::string SalomePythonComponent::getKind() const
72 {
73   //This is not a bug !!!! SalomeComponent NOT SalomePythonComponent. This is for Container assignation.
74   return SalomeComponent::KIND;
75 }
76
77 ComponentInstance* SalomePythonComponent::clone() const
78 {
79   if(_isAttachedOnCloning)
80     {
81       incrRef();
82       return (ComponentInstance*) (this);
83     }
84   else
85     return new SalomePythonComponent(*this);
86 }
87
88 ComponentInstance *SalomePythonComponent::cloneAlways() const
89 {
90   return new SalomePythonComponent(*this);
91 }
92
93 ServiceNode *SalomePythonComponent::createNode(const std::string &name)
94 {
95   ServiceNode* node=new SalomePythonNode(name);
96   node->setComponent(this);
97   return node;
98 }
99
100 std::string SalomePythonComponent::getFileRepr() const
101 {
102   std::ostringstream stream;
103   stream << "<ref>" << "SalomePythonComponent #" << _cntForRepr << "</ref>";
104   return stream.str();
105 }
106
107 std::string SalomePythonComponent::getStringValueToExportInInterp(const Task *askingNode) const
108 {
109   if(!_container)
110     return "localhost/FactoryServer";
111   else
112     return _container->getPlacementId(askingNode);
113 }