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 //To trace CORBA ref count, uncomment the following line
23 #define private public
24 #include <omniORB4/CORBA.h>
27 #include "RuntimeSALOME.hxx"
28 #include "CORBAComponent.hxx"
29 #include "CORBANode.hxx"
35 #include "YacsTrace.hxx"
37 using namespace YACS::ENGINE;
40 const char CORBAComponent::KIND[]="CORBA";
42 //! CORBAComponent constructor
43 CORBAComponent::CORBAComponent(const std::string& name): ComponentInstance(name)
45 _objComponent=CORBA::Object::_nil();
48 //! CORBAComponent copy constructor
49 CORBAComponent::CORBAComponent(const CORBAComponent& other):ComponentInstance(other)
51 _objComponent=CORBA::Object::_nil();
54 CORBAComponent::~CORBAComponent()
57 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
58 if(_objComponent != CORBA::Object::_nil())
60 std::cerr << "CORBAComponent::destructor:refcount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
65 std::string CORBAComponent::getKind() const
70 //! Unload the component
71 void CORBAComponent::unload()
74 std::cerr << "CORBAComponent::unload : not implemented " << std::endl;
77 CORBA::Object_ptr CORBAComponent::getCompoPtr()
80 std::cerr << "CORBAComponent::getCompoPtr:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
82 return CORBA::Object::_duplicate(_objComponent);
85 //! Is the component instance already loaded ?
86 bool CORBAComponent::isLoaded()
88 if(CORBA::is_nil(_objComponent))
94 //! Load the component
95 void CORBAComponent::load()
97 DEBTRACE( "CORBAComponent::load" );
101 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
102 orb = getSALOMERuntime()->getOrb();
103 _objComponent= orb->string_to_object(getCompoName().c_str());
105 std::cerr << "CORBAComponent::load:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
108 catch(CORBA::COMM_FAILURE& ex)
110 cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
111 << "object." << endl;
112 throw Exception("Execution problem");
114 catch(CORBA::SystemException& ex)
116 cerr << "Caught a CORBA::SystemException." ;
119 CORBA::TypeCode_var tc = tmp.type();
120 const char *p = tc->name();
126 throw Exception("Execution problem");
128 catch(CORBA::Exception& ex)
130 cerr << "Caught CORBA::Exception. " ;
133 CORBA::TypeCode_var tc = tmp.type();
134 const char *p = tc->name();
140 throw Exception("Execution problem");
142 catch(omniORB::fatalException& fe)
144 cerr << "Caught omniORB::fatalException:" << endl;
145 cerr << " file: " << fe.file() << endl;
146 cerr << " line: " << fe.line() << endl;
147 cerr << " mesg: " << fe.errmsg() << endl;
148 throw Exception("Execution problem");
152 cerr << "Caught unknown exception." << endl;
153 throw Exception("Execution problem");
155 if( CORBA::is_nil(_objComponent) )
157 cerr << "Can't get reference to object (or it was nil)." << endl;
158 throw Exception("Execution problem");
160 //TODO: if IOR is valid but the component does not exist, it works (bad)
163 //! Create a ServiceNode with this component instance and no input or output port
165 * \param name : node name
166 * \return a new CORBANode node
168 ServiceNode* CORBAComponent::createNode(const std::string& name)
170 CORBANode* node= new CORBANode(name);
171 node->setComponent(this);
175 //! Clone the component instance
176 ComponentInstance* CORBAComponent::clone() const
178 //no real need to clone a CORBA Component : there is no component instance loading
180 return (ComponentInstance*)this;
181 //return new CORBAComponent(*this);
184 std::string CORBAComponent::getFileRepr() const
186 ostringstream stream;
187 stream << "<ref>" << getCompoName() << "</ref>";