Version: 9.16.0
CORBAComponent.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//To trace CORBA ref count, uncomment the following line
21//#define REFCNT
22//
23#ifdef REFCNT
24#define private public
25#include <omniORB4/CORBA.h>
26#endif
27
28#include "RuntimeSALOME.hxx"
29#include "CORBAComponent.hxx"
30#include "CORBANode.hxx"
31
32#include <sstream>
33#include <iostream>
34
35//#define _DEVDEBUG_
36#include "YacsTrace.hxx"
37
38using namespace YACS::ENGINE;
39using namespace std;
40
41const char CORBAComponent::KIND[]="CORBA";
42
44CORBAComponent::CORBAComponent(const std::string& name): ComponentInstance(name)
45{
46 _objComponent=CORBA::Object::_nil();
47}
48
51{
52 _objComponent=CORBA::Object::_nil();
53}
54
56{
57#ifdef REFCNT
58 DEBTRACE( "+++++++++++++++++" << getName() << " +++++++++++++++++" );
59 if(_objComponent != CORBA::Object::_nil())
60 {
61 std::cerr << "CORBAComponent::destructor:refcount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
62 }
63#endif
64}
65
66std::string CORBAComponent::getKind() const
67{
68 return KIND;
69}
70
72{
73 return KIND;
74}
75
78{
79 //Not implemented
80 std::cerr << "CORBAComponent::unload : not implemented " << std::endl;
81}
82
83CORBA::Object_ptr CORBAComponent::getCompoPtr()
84{
85#ifdef REFCNT
86 std::cerr << "CORBAComponent::getCompoPtr:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
87#endif
88 return CORBA::Object::_duplicate(_objComponent);
89}
90
92bool CORBAComponent::isLoaded(Task *askingNode) const
93{
94 if(CORBA::is_nil(_objComponent))
95 return false;
96 else
97 return true;
98}
99
101void CORBAComponent::load(Task *askingNode)
102{
103 DEBTRACE( "CORBAComponent::load" );
104 try
105 {
106 DEBTRACE( "+++++++++++++++++" << getCompoName() << " +++++++++++++++++" );
108#ifdef REFCNT
109 std::cerr << "CORBAComponent::load:refCount: " <<_objComponent->_PR_getobj()->pd_refCount << std::endl;
110#endif
111 }
112 catch(CORBA::COMM_FAILURE& ex)
113 {
114 cerr << "Caught system exception COMM_FAILURE -- unable to contact the "
115 << "object." << endl;
116 throw Exception("Execution problem");
117 }
118 catch(CORBA::SystemException& ex)
119 {
120 cerr << "Caught a CORBA::SystemException." ;
121 CORBA::Any tmp;
122 tmp <<= ex;
123 CORBA::TypeCode_var tc = tmp.type();
124 const char *p = tc->name();
125 if ( *p != '\0' )
126 cerr <<p;
127 else
128 cerr << tc->id();
129 cerr << endl;
130 throw Exception("Execution problem");
131 }
132 catch(CORBA::Exception& ex)
133 {
134 cerr << "Caught CORBA::Exception. " ;
135 CORBA::Any tmp;
136 tmp <<= ex;
137 CORBA::TypeCode_var tc = tmp.type();
138 const char *p = tc->name();
139 if ( *p != '\0' )
140 cerr <<p;
141 else
142 cerr << tc->id();
143 cerr << endl;
144 throw Exception("Execution problem");
145 }
146 catch(omniORB::fatalException& fe)
147 {
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");
153 }
154 catch(...)
155 {
156 cerr << "Caught unknown exception." << endl;
157 throw Exception("Execution problem");
158 }
159 if( CORBA::is_nil(_objComponent) )
160 {
161 cerr << "Can't get reference to object (or it was nil)." << endl;
162 throw Exception("Execution problem");
163 }
164 //TODO: if IOR is valid but the component does not exist, it works (bad)
165}
166
168
173{
174 CORBANode* node= new CORBANode(name);
175 node->setComponent(this);
176 return node;
177}
178
181{
182 //no real need to clone a CORBA Component : there is no component instance loading
183 incrRef();
184 return (ComponentInstance*)this;
185 //return new CORBAComponent(*this);
186}
187
189{
190 return new CORBAComponent(*this);
191}
192
194{
195 ostringstream stream;
196 stream << "<ref>" << getCompoName() << "</ref>";
197 return stream.str();
198}
#define DEBTRACE(msg)
Definition: YacsTrace.hxx:31
Class for CORBA component instance.
virtual std::string getKind() const
Return the component kind.
virtual ComponentInstance * clone() const
Clone the component instance.
virtual void load(Task *askingNode)
Load the component.
virtual CORBA::Object_ptr getCompoPtr()
CORBAComponent(const std::string &name)
CORBAComponent constructor.
CORBA::Object_var _objComponent
virtual ComponentInstance * cloneAlways() const
virtual std::string getKindForNode() const
virtual void unload(Task *askingNode)
Unload the component.
virtual std::string getFileRepr() const
For dump in file.
virtual bool isLoaded(Task *askingNode) const
Is the component instance already loaded ?
virtual ServiceNode * createNode(const std::string &name)
Create a ServiceNode with this component instance and no input or output port.
Class for CORBA Service Node.
Definition: CORBANode.hxx:45
Base class for all component instances.
const std::string & getCompoName() const
CORBA::Object_var getFromNS(const char *entry) const
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...
Proc * p
Definition: driver.cxx:216
YACSRUNTIMESALOME_EXPORT RuntimeSALOME * getSALOMERuntime()