Version: 9.16.0
SalomeComponent.cxx
Go to the documentation of this file.
1// Copyright (C) 2006-2026 CEA, EDF
2//
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.
7//
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.
12//
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
16//
17// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18//
19
20#include "RuntimeSALOME.hxx"
21#include "SalomeComponent.hxx"
22#include "SalomeContainer.hxx"
23#include "SalomeHPContainer.hxx"
24#include "CORBANode.hxx"
25#include "AutoLocker.hxx"
26
27#ifdef SALOME_KERNEL
29#include "SALOME_LifeCycleCORBA.hxx"
30#endif
31
32#include <omniORB4/CORBA.h>
33#include <iostream>
34#include <sstream>
35
36//#define _DEVDEBUG_
37#include "YacsTrace.hxx"
38
39using namespace YACS::ENGINE;
40using namespace std;
41
42const char SalomeComponent::KIND[]="Salome";
43
45SalomeComponent::SalomeComponent(const std::string& name): ComponentInstance(name)
46{
47 _objComponent=CORBA::Object::_nil();
48}
49
52{
53 _objComponent=CORBA::Object::_nil();
54}
55
57{
58}
59
60std::string SalomeComponent::getKind() const
61{
62 return KIND;
63}
64
66{
67 return KIND;
68}
69
72{
73 //Not implemented
74 std::cerr << "SalomeComponent::unload : not implemented " << std::endl;
75}
76
78bool SalomeComponent::isLoaded(Task *askingNode) const
79{
80 if(CORBA::is_nil(_objComponent))
81 return false;
82 else
83 return true;
84}
85
86//#ifdef SALOME_KERNEL
88void SalomeComponent::load(Task *askingNode)
89{
90 if(_container)
91 {
92 SalomeContainer *salomeContainer(dynamic_cast<SalomeContainer *>(_container));
93 if(salomeContainer)
94 {
95 _objComponent=salomeContainer->loadComponent(askingNode);
96 return ;
97 }
98 throw Exception("Unrecognized type of Container ! Only Salome are supported by the Salome components !");
99 }
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
103 SALOME_LifeCycleCORBA LCC(&ns);
104 Engines::ContainerParameters params;
105 LCC.preSet(params);
106 params.resource_params.name = "localhost";
107 params.container_name ="FactoryServer";
108 _objComponent=LCC.LoadComponent(params,_compoName.c_str());
109}
110/*#else
111void SalomeComponent::load(Task *askingNode)
112{
113 throw Exception("YACS has been built without SALOME support");
114}
115#endif*/
116
118
123{
124 SalomeNode* node=new SalomeNode(name);
125 node->setComponent(this);
126 return node;
127}
128
131{
133 {
134 incrRef();
135 return (ComponentInstance*) (this);
136 }
137 else
138 return new SalomeComponent(*this);
139}
140
142{
143 return new SalomeComponent(*this);
144}
145
147{
148 ostringstream stream;
149 stream << "<component>" << getCompoName() << "</component>";
150 return stream.str();
151}
152
154{
155 if(!dynamic_cast<SalomeContainer *>(cont))
156 throw Exception("SalomeComponent::setContainer : a Salome component must be attached to a Salome container !");
158 {
159 if(_container)
161 return true;
162 }
163 else
164 return false;
165}
166
168{
169 DEBTRACE("SalomeComponent::shutdown " << level);
170 if(_container)
171 _container->shutdown(level);
172}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Base class for all component instances.
virtual bool setContainer(Container *cont)
const std::string & getCompoName() const
std::string _compoName
WARNING : _compoName identify only the component type.
virtual void shutdown(int level)=0
virtual void addComponentName(const std::string &name)=0
Class for Salome component instance.
SalomeComponent(const std::string &name)
SalomeComponent constructor.
virtual bool setContainer(Container *cont)
virtual void unload(Task *askingNode)
Unload the component.
virtual ServiceNode * createNode(const std::string &name)
Create a ServiceNode with this component instance and no input or output port.
virtual void shutdown(int level)
virtual ComponentInstance * clone() const
Clone the component instance.
virtual std::string getFileRepr() const
For dump in file.
virtual std::string getKindForNode() const
virtual ComponentInstance * cloneAlways() const
virtual std::string getKind() const
Return the component kind.
virtual void load(Task *askingNode)
Load the component.
virtual bool isLoaded(Task *askingNode) const
Is the component instance already loaded ?
virtual CORBA::Object_ptr loadComponent(Task *inst)
Load a component instance in this container.
Class for Salome component Service Node.
Definition: CORBANode.hxx:68
Class for calculation node associated with a component service.
Definition: ServiceNode.hxx:35
virtual void setComponent(ComponentInstance *compo)
Associate an existing component instance to this service node AND check the consistency regarding the...
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()