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