1 #include "RuntimeSALOME.hxx"
2 #include "SalomeComponent.hxx"
3 #include "SalomeContainer.hxx"
4 #include "CORBANode.hxx"
7 #include "SALOME_NamingService.hxx"
8 #include "SALOME_LifeCycleCORBA.hxx"
11 #include <omniORB4/CORBA.h>
15 using namespace YACS::ENGINE;
18 const char SalomeComponent::KIND[]="Salome";
20 //! SalomeComponent constructor
21 SalomeComponent::SalomeComponent(const std::string& name): ComponentInstance(name)
23 _objComponent=CORBA::Object::_nil();
26 //! SalomeComponent copy constructor
27 SalomeComponent::SalomeComponent(const SalomeComponent& other):ComponentInstance(other)
29 _objComponent=CORBA::Object::_nil();
32 SalomeComponent::~SalomeComponent()
36 std::string SalomeComponent::getKind() const
41 //! Unload the component
42 void SalomeComponent::unload()
45 std::cerr << "SalomeComponent::unload : not implemented " << std::endl;
48 //! Is the component instance already loaded ?
49 bool SalomeComponent::isLoaded()
51 if(CORBA::is_nil(_objComponent))
58 //! Load the component
59 void SalomeComponent::load()
63 SalomeContainer *containerC=(SalomeContainer *)_container;
64 containerC->lock();//To be sure
65 if(!_container->isAlreadyStarted())
78 containerC->lock();//To be sure
79 const char* componentName=_compoName.c_str();
80 //char *val2=CORBA::string_dup("");
81 // does not work with python components
82 // does not make a strict load but a find or load component
83 // _objComponent=containerC->_trueCont->load_impl(componentName,val2);
84 bool isLoadable = containerC->_trueCont->load_component_Library(componentName);
86 if (containerC->isAPaCOContainer()) {
87 std::string compo_paco_name(componentName);
88 compo_paco_name = compo_paco_name + "@PARALLEL@";
89 char * c_paco_name = CORBA::string_dup(compo_paco_name.c_str());
90 _objComponent=containerC->_trueCont->create_component_instance(c_paco_name, 0);
93 _objComponent=containerC->_trueCont->create_component_instance(componentName, 0);
95 if(CORBA::is_nil(_objComponent))
98 std::string text="Error while trying to create a new component: component '"+ _compoName;
99 text=text+"' is not installed or it's a wrong name";
100 throw Exception(text);
102 containerC->unLock();
105 //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
106 //This component has no specified container : use default container policy
107 SALOME_NamingService ns(getSALOMERuntime()->getOrb());
108 SALOME_LifeCycleCORBA LCC(&ns);
109 Engines::MachineParameters params;
111 params.hostname="localhost";
112 params.container_name ="FactoryServer";
113 _objComponent=LCC.LoadComponent(params,_compoName.c_str());
116 void SalomeComponent::load()
118 throw Exception("YACS has been built without SALOME support");
122 //! Create a ServiceNode with this component instance and no input or output port
124 * \param name : node name
125 * \return a new SalomeNode node
127 ServiceNode* SalomeComponent::createNode(const std::string& name)
129 SalomeNode* node=new SalomeNode(name);
130 node->setComponent(this);
134 //! Clone the component instance
135 ComponentInstance* SalomeComponent::clone() const
137 if(_isAttachedOnCloning)
140 return (ComponentInstance*) (this);
143 return new SalomeComponent(*this);
146 std::string SalomeComponent::getFileRepr() const
148 ostringstream stream;
149 stream << "<component>" << getCompoName() << "</component>";
153 void SalomeComponent::setContainer(Container *cont)
155 if (cont == _container) return;
158 cont->checkCapabilityToDealWith(this);
161 _container->decrRef();
165 _container->incrRef();
166 ((SalomeContainer*)_container)->addComponentName(_compoName);