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=_name.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 _objComponent=containerC->_trueCont->create_component_instance(componentName, 0);
88 if(CORBA::is_nil(_objComponent))
91 throw Exception("SalomeComponent::load : Error while trying to create a new component.");
96 //throw Exception("SalomeComponent::load : no container specified !!! To be implemented in executor to allocate default a Container in case of presenceOfDefaultContainer.");
97 //This component has no specified container : use default container policy
98 SALOME_NamingService ns(getSALOMERuntime()->getOrb());
99 SALOME_LifeCycleCORBA LCC(&ns);
100 Engines::MachineParameters params;
102 params.hostname="localhost";
103 params.container_name ="FactoryServer";
104 _objComponent=LCC.LoadComponent(params,_name.c_str());
107 void SalomeComponent::load()
109 throw Exception("YACS has been built without SALOME support");
113 //! Create a ServiceNode with this component instance and no input or output port
115 * \param name : node name
116 * \return a new SalomeNode node
118 ServiceNode* SalomeComponent::createNode(const std::string& name)
120 SalomeNode* node=new SalomeNode(name);
121 node->setComponent(this);
125 //! Clone the component instance
126 ComponentInstance* SalomeComponent::clone() const
128 if(_isAttachedOnCloning)
131 return (ComponentInstance*) (this);
134 return new SalomeComponent(*this);
137 std::string SalomeComponent::getFileRepr() const
139 ostringstream stream;
140 stream << "<component>" << getName() << "</component>";