1 // Copyright (C) 2006-2014 CEA/DEN, EDF R&D
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #include "SalomeHPComponent.hxx"
21 #include "RuntimeSALOME.hxx"
22 #include "SalomeContainer.hxx"
23 #include "SalomeHPContainer.hxx"
24 #include "SalomeComponent.hxx" // for KIND
25 #include "CORBANode.hxx"
26 #include "AutoLocker.hxx"
29 #include "SALOME_NamingService.hxx"
30 #include "SALOME_LifeCycleCORBA.hxx"
33 #include <omniORB4/CORBA.h>
38 #include "YacsTrace.hxx"
45 class SalomeContainerTmpForHP : public SalomeContainer
48 SalomeContainerTmpForHP(const Container& other, const SalomeContainerTools& sct, SalomeContainerHelper *lmt,
49 const std::vector<std::string>& componentNames, int shutdownLev,
50 const SalomeHPContainer *zeOriginCont, std::size_t pos):SalomeContainer(other,sct,lmt,componentNames,shutdownLev),_zeOriginCont(zeOriginCont),_pos(pos) { }
51 std::string getDiscreminantStrOfThis() const { std::ostringstream oss; oss << _zeOriginCont << "_" << _pos; return oss.str(); }
52 CORBA::Object_ptr loadComponent(Task *inst);
54 const SalomeHPContainer *_zeOriginCont;
60 using namespace YACS::ENGINE;
63 const char SalomeHPComponent::KIND[]="HPSalome";
65 CORBA::Object_ptr SalomeContainerTmpForHP::loadComponent(Task *askingNode)
67 const ComponentInstance *inst(askingNode?askingNode->getComponent():0);
69 throw Exception("SalomeContainerTmpForHP::loadComponent : asking to load a component on the given task whereas this task has no component !");
70 std::string compoName(inst->getCompoName());
72 YACS::BASES::AutoLocker<Container> alck(this);//To be sure
73 if(!this->isAlreadyStarted(askingNode))
74 this->start(askingNode);
76 CORBA::Object_ptr objComponent=CORBA::Object::_nil();
78 YACS::BASES::AutoLocker<Container> alck(this);//To be sure
79 std::string compoName(inst->getCompoName());
80 Engines::Container_var container(_launchModeType->getContainer(askingNode));
81 objComponent=container->find_component_instance(compoName.c_str(),0);
82 if(CORBA::is_nil(objComponent))
85 bool isLoadable(container->load_component_Library(compoName.c_str(), reason));
87 objComponent=SalomeContainerTools::CreateComponentInstance(this,container,inst);
93 SalomeHPComponent::SalomeHPComponent(const std::string& name): ComponentInstance(name)
95 _objComponent=CORBA::Object::_nil();
98 SalomeHPComponent::SalomeHPComponent(const SalomeHPComponent& other):ComponentInstance(other)
100 _objComponent=CORBA::Object::_nil();
103 SalomeHPComponent::~SalomeHPComponent()
107 std::string SalomeHPComponent::getKind() const
112 std::string SalomeHPComponent::getKindForNode() const
114 return SalomeComponent::KIND;
117 //! Unload the component
118 void SalomeHPComponent::unload(Task *askingNode)
121 std::cerr << "SalomeHPComponent::unload : not implemented " << std::endl;
124 //! Is the component instance already loaded ?
125 bool SalomeHPComponent::isLoaded(Task *askingNode) const
130 //#ifdef SALOME_KERNEL
131 //! Load the component
132 void SalomeHPComponent::load(Task *askingNode)
136 SalomeHPContainer *salomeContainer(dynamic_cast<SalomeHPContainer *>(_container));
139 SalomeContainerHelper *lmt(0);
140 std::size_t posIn(0);
142 YACS::BASES::AutoLocker<Container> altck(salomeContainer);
143 lmt=salomeContainer->getHelperOfTask(askingNode);
144 posIn=salomeContainer->locateTask(askingNode);
146 SalomeContainerTmpForHP tmpCont(*salomeContainer,salomeContainer->getContainerInfo(),lmt,
147 salomeContainer->getComponentNames(),salomeContainer->getShutdownLev(),salomeContainer,posIn);
148 _objComponent=tmpCont.loadComponent(askingNode);
151 throw Exception("Unrecognized type of Container ! Only Salome and HPSalome container are supported by the Salome components !");
154 throw Exception("No container on HP component ! Impossible to load !");
157 void SalomeComponent::load(Task *askingNode)
159 throw Exception("YACS has been built without SALOME support");
163 //! Create a ServiceNode with this component instance and no input or output port
165 * \param name : node name
166 * \return a new SalomeNode node
168 ServiceNode* SalomeHPComponent::createNode(const std::string& name)
170 SalomeNode* node(new SalomeNode(name));
171 node->setComponent(this);
175 //! Clone the component instance
176 ComponentInstance* SalomeHPComponent::clone() const
178 if(_isAttachedOnCloning)
181 return (ComponentInstance*) (this);
184 return new SalomeHPComponent(*this);
187 std::string SalomeHPComponent::getFileRepr() const
189 ostringstream stream;
190 stream << "<component>" << getCompoName() << "</component>";
194 bool SalomeHPComponent::setContainer(Container *cont)
196 if(!dynamic_cast<SalomeHPContainer *>(cont))
197 throw Exception("SalomeHPComponent::setContainer : a Salome HP component must be attached to a Salome HP container !");
198 if(ComponentInstance::setContainer(cont))
201 _container->addComponentName(_compoName);
208 void SalomeHPComponent::shutdown(int level)
210 DEBTRACE("SalomeHPComponent::shutdown " << level);
212 _container->shutdown(level);