]> SALOME platform Git repositories - modules/yacs.git/blob - src/runtime/SalomePythonComponent.cxx
Salome HOME
merge from branch DEV tag mergeto_trunk_04apr08
[modules/yacs.git] / src / runtime / SalomePythonComponent.cxx
1 #include <Python.h>
2 #include "SalomePythonComponent.hxx"
3 #include "SalomeComponent.hxx"
4 #include "SalomePythonNode.hxx"
5 #include "Exception.hxx"
6 #include "Container.hxx"
7
8 #include <sstream>
9
10 using namespace YACS::ENGINE;
11
12 const char SalomePythonComponent::KIND[]="SalomePy";
13
14 unsigned SalomePythonComponent::_cntForReprS = 0;
15
16 SalomePythonComponent::SalomePythonComponent(const std::string &name):ComponentInstance(name),_cntForRepr(_cntForReprS++)
17 {
18 }
19
20 SalomePythonComponent::SalomePythonComponent(const SalomePythonComponent& other):ComponentInstance(other),_cntForRepr(_cntForReprS++)
21 {
22 }
23
24 SalomePythonComponent::~SalomePythonComponent()
25 {
26 }
27
28 void SalomePythonComponent::load()
29 {
30   if(_container)
31     {
32       _container->start();
33       return;
34     }
35   //This component has no specified container : use default container policy
36   //given by getStringValueToExportInInterp()
37   //throw Exception("SalomePythonComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
38 }
39
40 void SalomePythonComponent::unload()
41 {
42 }
43
44 bool SalomePythonComponent::isLoaded()
45 {
46   if(!_container)
47     return false;
48   else
49     return _container->isAlreadyStarted();
50 }
51
52 std::string SalomePythonComponent::getKind() const
53 {
54   //This is not a bug !!!! SalomeComponent NOT SalomePythonComponent. This is for Container assignation.
55   return SalomeComponent::KIND;
56 }
57
58 ComponentInstance* SalomePythonComponent::clone() const
59 {
60   if(_isAttachedOnCloning)
61     {
62       incrRef();
63       return (ComponentInstance*) (this);
64     }
65   else
66     return new SalomePythonComponent(*this);
67 }
68
69 ServiceNode *SalomePythonComponent::createNode(const std::string &name)
70 {
71   ServiceNode* node=new SalomePythonNode(name);
72   node->setComponent(this);
73   return node;
74 }
75
76 std::string SalomePythonComponent::getFileRepr() const
77 {
78   std::ostringstream stream;
79   stream << "<ref>" << "SalomePythonComponent #" << _cntForRepr << "</ref>";
80   return stream.str();
81 }
82
83 std::string SalomePythonComponent::getStringValueToExportInInterp() const
84 {
85   if(!_container)
86     return "localhost/FactoryServer";
87   else
88     return _container->getPlacementId();
89 }