1 //To trace CORBA ref count, uncomment the following line
5 #include <omniORB4/CORBA.h>
8 #include "RuntimeSALOME.hxx"
9 #include "CORBAComponent.hxx"
10 #include "CORBANode.hxx"
16 #include "YacsTrace.hxx"
18 using namespace YACS::ENGINE;
21 const char CORBAComponent::KIND[]="CORBA";
23 //! CORBAComponent constructor
24 CORBAComponent::CORBAComponent(const std::string& name): ComponentInstance(name)
26 _objComponent=CORBA::Object::_nil();
29 //! CORBAComponent copy constructor
30 CORBAComponent::CORBAComponent(const CORBAComponent& other):ComponentInstance(other)
32 _objComponent=CORBA::Object::_nil();
35 CORBAComponent::~CORBAComponent()
38 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
39 if(_objComponent != CORBA::Object::_nil())
41 std::cerr << "CORBAComponent::destructor:refcount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
46 std::string CORBAComponent::getKind() const
51 //! Unload the component
52 void CORBAComponent::unload()
55 std::cerr << "CORBAComponent::unload : not implemented " << std::endl;
58 CORBA::Object_ptr CORBAComponent::getCompoPtr()
61 std::cerr << "CORBAComponent::getCompoPtr:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
63 return CORBA::Object::_duplicate(_objComponent);
66 //! Is the component instance already loaded ?
67 bool CORBAComponent::isLoaded()
69 if(CORBA::is_nil(_objComponent))
75 //! Load the component
76 void CORBAComponent::load()
78 DEBTRACE( "CORBAComponent::load" );
82 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
83 orb = getSALOMERuntime()->getOrb();
84 _objComponent= orb->string_to_object(getName().c_str());
86 std::cerr << "CORBAComponent::load:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
89 catch(CORBA::COMM_FAILURE& ex)
91 cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
93 throw Exception("Execution problem");
95 catch(CORBA::SystemException& ex)
97 cerr << "Caught a CORBA::SystemException." ;
100 CORBA::TypeCode_var tc = tmp.type();
101 const char *p = tc->name();
107 throw Exception("Execution problem");
109 catch(CORBA::Exception& ex)
111 cerr << "Caught CORBA::Exception. " ;
114 CORBA::TypeCode_var tc = tmp.type();
115 const char *p = tc->name();
121 throw Exception("Execution problem");
123 catch(omniORB::fatalException& fe)
125 cerr << "Caught omniORB::fatalException:" << endl;
126 cerr << " file: " << fe.file() << endl;
127 cerr << " line: " << fe.line() << endl;
128 cerr << " mesg: " << fe.errmsg() << endl;
129 throw Exception("Execution problem");
133 cerr << "Caught unknown exception." << endl;
134 throw Exception("Execution problem");
136 if( CORBA::is_nil(_objComponent) )
138 cerr << "Can't get reference to object (or it was nil)." << endl;
139 throw Exception("Execution problem");
141 //TODO: if IOR is valid but the component does not exist, it works (bad)
144 //! Create a ServiceNode with this component instance and no input or output port
146 * \param name : node name
147 * \return a new CORBANode node
149 ServiceNode* CORBAComponent::createNode(const std::string& name)
151 CORBANode* node= new CORBANode(name);
152 node->setComponent(this);
156 //! Clone the component instance
157 ComponentInstance* CORBAComponent::clone() const
159 //no real need to clone a CORBA Component : there is no component instance loading
161 return (ComponentInstance*)this;
162 //return new CORBAComponent(*this);
165 std::string CORBAComponent::getFileRepr() const
167 ostringstream stream;
168 stream << "<ref>" << getName() << "</ref>";