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 "CORBANode.hxx"
26 #include "SALOME_NamingService.hxx"
27 #include "SALOME_LifeCycleCORBA.hxx"
30 #include <omniORB4/CORBA.h>
35 #include "YacsTrace.hxx"
37 using namespace YACS::ENGINE;
40 const char SalomeComponent::KIND[]="Salome";
42 //! SalomeComponent constructor
43 SalomeComponent::SalomeComponent(const std::string& name): ComponentInstance(name)
45 _objComponent=CORBA::Object::_nil();
48 //! SalomeComponent copy constructor
49 SalomeComponent::SalomeComponent(const SalomeComponent& other):ComponentInstance(other)
51 _objComponent=CORBA::Object::_nil();
54 SalomeComponent::~SalomeComponent()
58 std::string SalomeComponent::getKind() const
63 //! Unload the component
64 void SalomeComponent::unload()
67 std::cerr << "SalomeComponent::unload : not implemented " << std::endl;
70 //! Is the component instance already loaded ?
71 bool SalomeComponent::isLoaded()
73 if(CORBA::is_nil(_objComponent))
80 //! Load the component
81 void SalomeComponent::load()
85 _objComponent=((SalomeContainer*)_container)->loadComponent(this);
88 //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
89 //This component has no specified container : use default container policy
90 SALOME_NamingService ns(getSALOMERuntime()->getOrb());
91 SALOME_LifeCycleCORBA LCC(&ns);
92 Engines::ContainerParameters params;
94 params.resource_params.name = "localhost";
95 params.container_name ="FactoryServer";
96 _objComponent=LCC.LoadComponent(params,_compoName.c_str());
99 void SalomeComponent::load()
101 throw Exception("YACS has been built without SALOME support");
105 //! Create a ServiceNode with this component instance and no input or output port
107 * \param name : node name
108 * \return a new SalomeNode node
110 ServiceNode* SalomeComponent::createNode(const std::string& name)
112 SalomeNode* node=new SalomeNode(name);
113 node->setComponent(this);
117 //! Clone the component instance
118 ComponentInstance* SalomeComponent::clone() const
120 if(_isAttachedOnCloning)
123 return (ComponentInstance*) (this);
126 return new SalomeComponent(*this);
129 std::string SalomeComponent::getFileRepr() const
131 ostringstream stream;
132 stream << "<component>" << getCompoName() << "</component>";
136 void SalomeComponent::setContainer(Container *cont)
138 if (cont == _container) return;
141 cont->checkCapabilityToDealWith(this);
144 _container->decrRef();
148 _container->incrRef();
149 ((SalomeContainer*)_container)->addComponentName(_compoName);
153 void SalomeComponent::shutdown(int level)
155 DEBTRACE("SalomeComponent::shutdown " << level);
157 _container->shutdown(level);