1 // Copyright (C) 2006-2008 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.
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
19 #include "RuntimeSALOME.hxx"
20 #include "SalomeComponent.hxx"
21 #include "SalomeContainer.hxx"
22 #include "CORBANode.hxx"
25 #include "SALOME_NamingService.hxx"
26 #include "SALOME_LifeCycleCORBA.hxx"
29 #include <omniORB4/CORBA.h>
33 using namespace YACS::ENGINE;
36 const char SalomeComponent::KIND[]="Salome";
38 //! SalomeComponent constructor
39 SalomeComponent::SalomeComponent(const std::string& name): ComponentInstance(name)
41 _objComponent=CORBA::Object::_nil();
44 //! SalomeComponent copy constructor
45 SalomeComponent::SalomeComponent(const SalomeComponent& other):ComponentInstance(other)
47 _objComponent=CORBA::Object::_nil();
50 SalomeComponent::~SalomeComponent()
54 std::string SalomeComponent::getKind() const
59 //! Unload the component
60 void SalomeComponent::unload()
63 std::cerr << "SalomeComponent::unload : not implemented " << std::endl;
66 //! Is the component instance already loaded ?
67 bool SalomeComponent::isLoaded()
69 if(CORBA::is_nil(_objComponent))
76 //! Load the component
77 void SalomeComponent::load()
81 SalomeContainer *containerC=(SalomeContainer *)_container;
82 containerC->lock();//To be sure
83 if(!_container->isAlreadyStarted())
96 containerC->lock();//To be sure
97 const char* componentName=_compoName.c_str();
98 //char *val2=CORBA::string_dup("");
99 // does not work with python components
100 // does not make a strict load but a find or load component
101 // _objComponent=containerC->_trueCont->load_impl(componentName,val2);
102 bool isLoadable = containerC->_trueCont->load_component_Library(componentName);
104 if (containerC->isAPaCOContainer()) {
105 std::string compo_paco_name(componentName);
106 compo_paco_name = compo_paco_name + "@PARALLEL@";
107 char * c_paco_name = CORBA::string_dup(compo_paco_name.c_str());
108 _objComponent=containerC->_trueCont->create_component_instance(c_paco_name, 0);
111 _objComponent=containerC->_trueCont->create_component_instance(componentName, 0);
113 if(CORBA::is_nil(_objComponent))
115 containerC->unLock();
116 std::string text="Error while trying to create a new component: component '"+ _compoName;
117 text=text+"' is not installed or it's a wrong name";
118 throw Exception(text);
120 containerC->unLock();
123 //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
124 //This component has no specified container : use default container policy
125 SALOME_NamingService ns(getSALOMERuntime()->getOrb());
126 SALOME_LifeCycleCORBA LCC(&ns);
127 Engines::MachineParameters params;
129 params.hostname="localhost";
130 params.container_name ="FactoryServer";
131 _objComponent=LCC.LoadComponent(params,_compoName.c_str());
134 void SalomeComponent::load()
136 throw Exception("YACS has been built without SALOME support");
140 //! Create a ServiceNode with this component instance and no input or output port
142 * \param name : node name
143 * \return a new SalomeNode node
145 ServiceNode* SalomeComponent::createNode(const std::string& name)
147 SalomeNode* node=new SalomeNode(name);
148 node->setComponent(this);
152 //! Clone the component instance
153 ComponentInstance* SalomeComponent::clone() const
155 if(_isAttachedOnCloning)
158 return (ComponentInstance*) (this);
161 return new SalomeComponent(*this);
164 std::string SalomeComponent::getFileRepr() const
166 ostringstream stream;
167 stream << "<component>" << getCompoName() << "</component>";
171 void SalomeComponent::setContainer(Container *cont)
173 if (cont == _container) return;
176 cont->checkCapabilityToDealWith(this);
179 _container->decrRef();
183 _container->incrRef();
184 ((SalomeContainer*)_container)->addComponentName(_compoName);