1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Value_Impl.cxx
25 // Author : Jean Rahuel
32 //#include <strstream>
36 //#include "utilities.h"
38 #include "Value_Impl.hxx"
40 #include "DataFlowExecutor_DataFlow.hxx"
42 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
43 PortableServer::POA_ptr poa ,
44 PortableServer::ObjectId * contId ,
45 const char *instanceName ,
46 const char *interfaceName ,
47 GraphEditor::DataFlow * DataFlowEditor ,
48 GraphEditor::InNode * DataFlowNode ,
49 const char *ParameterName ,
50 const CORBA::Any * anAny ,
51 const bool activate ) :
52 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
54 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
55 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
56 // << hex << (void *) this << dec )
58 _id = _poa->activate_object(_thisObj);
60 _Orb = CORBA::ORB::_duplicate(orb);
63 _DataFlowEditor = DataFlowEditor ;
64 _DataFlowNode = DataFlowNode ;
65 if ( ParameterName != NULL ) {
66 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
67 strcpy( _ParameterName , ParameterName ) ;
69 _NodeName = new char[ strlen( DataFlowNode->Name() ) + 1 ] ;
70 strcpy( _NodeName , DataFlowNode->Name() ) ;
77 _ParameterName = NULL ;
81 _Any = new CORBA::Any( *anAny ) ;
84 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
85 PortableServer::POA_ptr poa ,
86 PortableServer::ObjectId * contId ,
87 const char *instanceName ,
88 const char *interfaceName ,
89 GraphEditor::DataFlow * DataFlowEditor ,
90 GraphEditor::InNode * DataFlowNode ,
91 const char *ParameterName ,
92 const bool activate ) :
93 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
95 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
96 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
97 // << hex << (void *) this << dec )
99 _id = _poa->activate_object(_thisObj);
101 _Orb = CORBA::ORB::_duplicate(orb);
104 _DataFlowEditor = DataFlowEditor ;
105 _DataFlowNode = DataFlowNode ;
106 if ( ParameterName != NULL ) {
107 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
108 strcpy( _ParameterName , ParameterName ) ;
109 if ( DataFlowNode ) {
110 _NodeName = new char[ strlen( DataFlowNode->Name() ) + 1 ] ;
111 strcpy( _NodeName , DataFlowNode->Name() ) ;
118 _ParameterName = NULL ;
121 _InputValue = false ;
122 _Any = new CORBA::Any() ;
125 Value_Impl::Value_Impl() {
128 Value_Impl::~Value_Impl() {
129 beginService( "Value_Impl::~Value_Impl" );
130 endService( "Value_Impl::~Value_Impl" );
133 void Value_Impl::destroy() {
134 beginService( "Value_Impl::destroy" );
135 _poa->deactivate_object(*_id) ;
136 CORBA::release(_poa) ;
138 _thisObj->_remove_ref();
139 endService( "Value_Impl::destroy" );
142 void Value_Impl::InPort( bool anInput ) {
143 _InputPort = anInput ;
146 bool Value_Impl::Input( const CORBA::Any * anAny ) {
147 // _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
151 _Any = new CORBA::Any( *anAny ) ;
156 CORBA::Any * Value_Impl::ToAny() {
157 beginService( "Value_Impl::ToAny" );
159 if ( _DataFlowEditor ) {
161 if ( _DataFlowNode ) {
162 name = _DataFlowNode->Name() ;
165 name = _DataFlowEditor->Graph()->Name() ;
167 MESSAGE( "ToAny " << name<< "( " << _ParameterName << " )" ) ;
169 if ( _DataFlowNode ) {
170 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
173 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
175 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
176 if ( _DataFlowExecutor ) {
177 //JR 30.03.2005 anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
178 anAny = new CORBA::Any( _DataFlowExecutor->GetInData( name ,
181 else if ( _InputValue ) {
182 //JR 30.03.2005 anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
183 anAny = new CORBA::Any( _DataFlowEditor->GetInData( name ,
187 anAny = new CORBA::Any( *_Any ) ;
191 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
192 if ( _DataFlowExecutor ) {
193 //JR 30.03.2005 anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
194 anAny = new CORBA::Any( _DataFlowExecutor->GetOutData( name ,
198 anAny = new CORBA::Any( *_Any ) ;
203 anAny = new CORBA::Any( *_Any ) ;
205 endService( "Value_Impl::ToAny" );
209 char * Value_Impl::ToString() {
210 // beginService( "Value_Impl::ToString" );
211 //JR 22.03.2005 Memory Leak CORBA::Any anAny = *ToAny() ;
213 if ( _DataFlowEditor ) {
215 if ( _DataFlowNode ) {
216 name = _DataFlowNode->Name() ;
219 name = _DataFlowEditor->Graph()->Name() ;
221 // MESSAGE( "ToString " << name<< "( " << _ParameterName << " )" ) ;
223 if ( _DataFlowNode ) {
224 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
227 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
229 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
230 if ( _DataFlowExecutor ) {
231 // cout << "-->_DataFlowExecutor->GetInData " << name << " " << _ParameterName << endl ;
232 //JR 30.03.2005 const CORBA::Any * AnyPtr = _DataFlowExecutor->GetInData( name ,
233 const CORBA::Any AnyRef = _DataFlowExecutor->GetInData( name ,
235 //JR 30.03.2005 cout << "<--_DataFlowExecutor->GetInData " << AnyPtr << endl ;
236 //JR 30.03.2005 anAny = * AnyPtr ;
239 else if ( _InputValue ) {
240 // cout << "_DataFlowEditor->GetInData _DataFlowNode " << _DataFlowNode
241 // << " _InputValue " << _InputValue << endl ;
242 //JR 30.03.2005 anAny = * _DataFlowEditor->GetInData( name ,
243 anAny = _DataFlowEditor->GetInData( name ,
251 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
252 if ( _DataFlowExecutor ) {
253 // cout << "-->_DataFlowExecutor->GetOutData " << name << " " << _ParameterName << endl ;
254 //JR 30.03.2005 const CORBA::Any * AnyPtr = _DataFlowExecutor->GetOutData( name ,
255 const CORBA::Any AnyRef = _DataFlowExecutor->GetOutData( name ,
257 //JR 30.03.2005 cout << "<--_DataFlowExecutor->GetOutData " << AnyPtr << endl ;
258 //JR 30.03.2005 anAny = * AnyPtr ;
267 const char * retstr ;
269 switch (anAny.type()->kind()) {
270 case CORBA::tk_string: {
272 // MESSAGE( "ToString( string ) '" << retstr << "'" );
275 case CORBA::tk_long: {
279 retstr = astr.str().c_str() ;
280 // MESSAGE( "ToString( long ) '" << l << " " << retstr << "'" );
283 case CORBA::tk_double: {
286 astr << setw(25) << setprecision(18) << d << ends ;
287 retstr = astr.str().c_str() ;
289 while ( i < (int ) strlen( retstr ) && retstr[ i++ ] == ' ' ) {
292 // MESSAGE( "ToString( double ) '" << d << "' '" << retstr << "' '" << &retstr[ startstr ] << "'");
295 case CORBA::tk_objref: {
296 CORBA::Object_ptr obj ;
299 retstr = _Orb->object_to_string( obj );
300 // MESSAGE( "ToString( object ) '" << retstr << "'" );
303 retstr = "object_to_string catched " ;
308 retstr = "Unknown CORBA::Any Type" ;
309 // MESSAGE( retstr );
313 // endService( "Value_Impl::ToString" );
314 return CORBA::string_dup( &retstr[ startstr ] ) ;
317 bool Value_Impl::IsIOR() {
318 CORBA::Any anAny = *ToAny() ;
319 if ( _DataFlowEditor ) {
321 if ( _DataFlowNode ) {
322 name = _DataFlowNode->Name() ;
325 name = _DataFlowEditor->Graph()->Name() ;
328 if ( _DataFlowNode ) {
329 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
332 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
334 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
335 //JR 30.03.2005 anAny = * _DataFlowEditor->GetInData( name ,
336 anAny = _DataFlowEditor->GetInData( name ,
340 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
341 if ( _DataFlowExecutor ) {
342 //JR 30.03.2005 anAny = * _DataFlowExecutor->GetInData( name ,
343 anAny = _DataFlowExecutor->GetInData( name ,
349 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
350 //JR 30.03.2005 anAny = * _DataFlowEditor->GetOutData( name ,
351 anAny = _DataFlowEditor->GetOutData( name ,
355 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
356 if ( _DataFlowExecutor ) {
357 //JR 30.03.2005 anAny = * _DataFlowExecutor->GetOutData( name ,
358 anAny = _DataFlowExecutor->GetOutData( name ,
364 return(anAny.type()->kind() == CORBA::tk_objref);
367 char* Value_Impl::ComponentDataType() {
368 GraphExecutor::DataFlow* _DataFlowExecutor = _DataFlowEditor->Executor();
369 const GraphBase::ComputingNode* node = _DataFlowExecutor->Graph()->GetGraphNode(_DataFlowNode->Name());
370 if ( node->IsFactoryNode() ) {
371 Engines::Component_var compo = ((GraphBase::FactoryNode * ) node )->Component();
372 if ( CORBA::is_nil( compo ) ) {
373 return ( strdup( "UnknownComponent" ) ) ;
376 return ( strdup( compo->instanceName() ) ) ;
379 return ( strdup ( "UnknownComponent" ) ) ;