1 // Copyright (C) 2006-2023 CEA, EDF
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 //To trace CORBA ref count, uncomment the following line
24 #define private public
25 #include <omniORB4/CORBA.h>
28 #include "RuntimeSALOME.hxx"
29 #include "CORBAComponent.hxx"
30 #include "CORBANode.hxx"
36 #include "YacsTrace.hxx"
38 using namespace YACS::ENGINE;
41 const char CORBAComponent::KIND[]="CORBA";
43 //! CORBAComponent constructor
44 CORBAComponent::CORBAComponent(const std::string& name): ComponentInstance(name)
46 _objComponent=CORBA::Object::_nil();
49 //! CORBAComponent copy constructor
50 CORBAComponent::CORBAComponent(const CORBAComponent& other):ComponentInstance(other)
52 _objComponent=CORBA::Object::_nil();
55 CORBAComponent::~CORBAComponent()
58 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
59 if(_objComponent != CORBA::Object::_nil())
61 std::cerr << "CORBAComponent::destructor:refcount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
66 std::string CORBAComponent::getKind() const
71 std::string CORBAComponent::getKindForNode() const
76 //! Unload the component
77 void CORBAComponent::unload(Task *askingNode)
80 std::cerr << "CORBAComponent::unload : not implemented " << std::endl;
83 CORBA::Object_ptr CORBAComponent::getCompoPtr()
86 std::cerr << "CORBAComponent::getCompoPtr:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
88 return CORBA::Object::_duplicate(_objComponent);
91 //! Is the component instance already loaded ?
92 bool CORBAComponent::isLoaded(Task *askingNode) const
94 if(CORBA::is_nil(_objComponent))
100 //! Load the component
101 void CORBAComponent::load(Task *askingNode)
103 DEBTRACE( "CORBAComponent::load" );
106 DEBTRACE( "+++++++++++++++++" << getCompoName() << " +++++++++++++++++" );
107 _objComponent= getSALOMERuntime()->getFromNS(getCompoName().c_str());
109 std::cerr << "CORBAComponent::load:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
112 catch(CORBA::COMM_FAILURE& ex)
114 cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
115 << "object." << endl;
116 throw Exception("Execution problem");
118 catch(CORBA::SystemException& ex)
120 cerr << "Caught a CORBA::SystemException." ;
123 CORBA::TypeCode_var tc = tmp.type();
124 const char *p = tc->name();
130 throw Exception("Execution problem");
132 catch(CORBA::Exception& ex)
134 cerr << "Caught CORBA::Exception. " ;
137 CORBA::TypeCode_var tc = tmp.type();
138 const char *p = tc->name();
144 throw Exception("Execution problem");
146 catch(omniORB::fatalException& fe)
148 cerr << "Caught omniORB::fatalException:" << endl;
149 cerr << " file: " << fe.file() << endl;
150 cerr << " line: " << fe.line() << endl;
151 cerr << " mesg: " << fe.errmsg() << endl;
152 throw Exception("Execution problem");
156 cerr << "Caught unknown exception." << endl;
157 throw Exception("Execution problem");
159 if( CORBA::is_nil(_objComponent) )
161 cerr << "Can't get reference to object (or it was nil)." << endl;
162 throw Exception("Execution problem");
164 //TODO: if IOR is valid but the component does not exist, it works (bad)
167 //! Create a ServiceNode with this component instance and no input or output port
169 * \param name : node name
170 * \return a new CORBANode node
172 ServiceNode* CORBAComponent::createNode(const std::string& name)
174 CORBANode* node= new CORBANode(name);
175 node->setComponent(this);
179 //! Clone the component instance
180 ComponentInstance* CORBAComponent::clone() const
182 //no real need to clone a CORBA Component : there is no component instance loading
184 return (ComponentInstance*)this;
185 //return new CORBAComponent(*this);
188 ComponentInstance* CORBAComponent::cloneAlways() const
190 return new CORBAComponent(*this);
193 std::string CORBAComponent::getFileRepr() const
195 ostringstream stream;
196 stream << "<ref>" << getCompoName() << "</ref>";