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 "RuntimeSALOME.hxx"
21 #include "SalomeComponent.hxx"
22 #include "SalomeContainer.hxx"
23 #include "SalomeHPContainer.hxx"
24 #include "CORBANode.hxx"
25 #include "AutoLocker.hxx"
28 #include "SALOME_NamingService.hxx"
29 #include "SALOME_LifeCycleCORBA.hxx"
32 #include <omniORB4/CORBA.h>
37 #include "YacsTrace.hxx"
39 using namespace YACS::ENGINE;
42 const char SalomeComponent::KIND[]="Salome";
44 //! SalomeComponent constructor
45 SalomeComponent::SalomeComponent(const std::string& name): ComponentInstance(name)
47 _objComponent=CORBA::Object::_nil();
50 //! SalomeComponent copy constructor
51 SalomeComponent::SalomeComponent(const SalomeComponent& other):ComponentInstance(other)
53 _objComponent=CORBA::Object::_nil();
56 SalomeComponent::~SalomeComponent()
60 std::string SalomeComponent::getKind() const
65 std::string SalomeComponent::getKindForNode() const
70 //! Unload the component
71 void SalomeComponent::unload(Task *askingNode)
74 std::cerr << "SalomeComponent::unload : not implemented " << std::endl;
77 //! Is the component instance already loaded ?
78 bool SalomeComponent::isLoaded(Task *askingNode) const
80 if(CORBA::is_nil(_objComponent))
86 //#ifdef SALOME_KERNEL
87 //! Load the component
88 void SalomeComponent::load(Task *askingNode)
92 SalomeContainer *salomeContainer(dynamic_cast<SalomeContainer *>(_container));
95 _objComponent=salomeContainer->loadComponent(askingNode);
98 throw Exception("Unrecognized type of Container ! Only Salome are supported by the Salome components !");
100 //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
101 //This component has no specified container : use default container policy
102 SALOME_NamingService ns(getSALOMERuntime()->getOrb());
103 SALOME_LifeCycleCORBA LCC(&ns);
104 Engines::ContainerParameters params;
106 params.resource_params.name = "localhost";
107 params.container_name ="FactoryServer";
108 _objComponent=LCC.LoadComponent(params,_compoName.c_str());
111 void SalomeComponent::load(Task *askingNode)
113 throw Exception("YACS has been built without SALOME support");
117 //! Create a ServiceNode with this component instance and no input or output port
119 * \param name : node name
120 * \return a new SalomeNode node
122 ServiceNode* SalomeComponent::createNode(const std::string& name)
124 SalomeNode* node=new SalomeNode(name);
125 node->setComponent(this);
129 //! Clone the component instance
130 ComponentInstance* SalomeComponent::clone() const
132 if(_isAttachedOnCloning)
135 return (ComponentInstance*) (this);
138 return new SalomeComponent(*this);
141 std::string SalomeComponent::getFileRepr() const
143 ostringstream stream;
144 stream << "<component>" << getCompoName() << "</component>";
148 bool SalomeComponent::setContainer(Container *cont)
150 if(!dynamic_cast<SalomeContainer *>(cont))
151 throw Exception("SalomeComponent::setContainer : a Salome component must be attached to a Salome container !");
152 if(ComponentInstance::setContainer(cont))
155 _container->addComponentName(_compoName);
162 void SalomeComponent::shutdown(int level)
164 DEBTRACE("SalomeComponent::shutdown " << level);
166 _container->shutdown(level);