Salome HOME
70240c452f678585a5dab0ff5e18b56d5d8862f1
[modules/yacs.git] / src / runtime / SalomeHPComponent.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 "SalomeHPComponent.hxx"
21 #include "RuntimeSALOME.hxx"
22 #include "SalomeContainer.hxx"
23 #include "SalomeHPContainer.hxx"
24 #include "SalomeComponent.hxx" // for KIND
25 #include "SalomeContainerTmpForHP.hxx"
26 #include "CORBANode.hxx"
27
28 #ifdef SALOME_KERNEL
29 #include "SALOME_LifeCycleCORBA.hxx"
30 #endif
31
32 #include <omniORB4/CORBA.h>
33 #include <iostream>
34 #include <sstream>
35
36 //#define _DEVDEBUG_
37 #include "YacsTrace.hxx"
38
39 using namespace YACS::ENGINE;
40 using namespace std;
41
42 const char SalomeHPComponent::KIND[]="HPSalome";
43
44 SalomeHPComponent::SalomeHPComponent(const std::string& name): ComponentInstance(name)
45 {
46   _objComponent=CORBA::Object::_nil();
47 }
48
49 SalomeHPComponent::SalomeHPComponent(const SalomeHPComponent& other):ComponentInstance(other)
50 {
51   _objComponent=CORBA::Object::_nil();
52 }
53
54 SalomeHPComponent::~SalomeHPComponent()
55 {
56 }
57
58 std::string SalomeHPComponent::getKind() const
59 {
60   return KIND;
61 }
62
63 std::string SalomeHPComponent::getKindForNode() const
64 {
65   return SalomeComponent::KIND;
66 }
67
68 //! Unload the component 
69 void SalomeHPComponent::unload(Task *askingNode)
70 {
71   //Not implemented
72   std::cerr << "SalomeHPComponent::unload : not implemented " << std::endl;
73 }
74
75 //! Is the component instance already loaded ?
76 bool SalomeHPComponent::isLoaded(Task *askingNode) const
77 {
78   return false;
79 }
80
81 //#ifdef SALOME_KERNEL
82 //! Load the component 
83 void SalomeHPComponent::load(Task *askingNode)
84 {
85   if(_container)
86     {
87       SalomeHPContainer *salomeContainer(dynamic_cast<SalomeHPContainer *>(_container));
88       if(salomeContainer)
89         {
90           YACS::BASES::AutoCppPtr<SalomeContainerTmpForHP> tmpCont(SalomeContainerTmpForHP::BuildFrom(salomeContainer,askingNode));
91           _objComponent=tmpCont->loadComponent(askingNode);
92           return ;
93         }
94       throw Exception("Unrecognized type of Container ! Only Salome and HPSalome container are supported by the Salome components !");
95     }
96   else
97     throw Exception("No container on HP component ! Impossible to load !");
98 }
99 /*#else
100 void SalomeComponent::load(Task *askingNode)
101 {
102   throw Exception("YACS has been built without SALOME support");
103 }
104 #endif*/
105
106 //! Create a ServiceNode with this component instance and no input or output port
107 /*!
108  *   \param name : node name
109  *   \return       a new SalomeNode node
110  */
111 ServiceNode* SalomeHPComponent::createNode(const std::string& name)
112 {
113   SalomeNode* node(new SalomeNode(name));
114    node->setComponent(this);
115    return node;
116 }
117
118 //! Clone the component instance
119 ComponentInstance* SalomeHPComponent::clone() const
120 {
121   if(_isAttachedOnCloning)
122     {
123       incrRef();
124       return (ComponentInstance*) (this);
125     }
126   else
127     return new SalomeHPComponent(*this);
128 }
129
130 ComponentInstance *SalomeHPComponent::cloneAlways() const
131 {
132   return new SalomeHPComponent(*this);
133 }
134
135 std::string SalomeHPComponent::getFileRepr() const
136 {
137   ostringstream stream;
138   stream << "<component>" << getCompoName() << "</component>";
139   return stream.str();
140 }
141
142 bool SalomeHPComponent::setContainer(Container *cont)
143 {
144   if(!dynamic_cast<SalomeHPContainer *>(cont))
145     throw Exception("SalomeHPComponent::setContainer : a Salome HP component must be attached to a Salome HP container !");
146   if(ComponentInstance::setContainer(cont))
147     {
148       if(_container)
149         _container->addComponentName(_compoName);
150       return true;
151     }
152   else
153     return false;
154 }
155
156 void SalomeHPComponent::shutdown(int level)
157 {
158   DEBTRACE("SalomeHPComponent::shutdown " << level);
159   if(_container)
160     _container->shutdown(level);
161 }