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() {
158 if ( _DataFlowEditor ) {
160 if ( _DataFlowNode ) {
161 name = _DataFlowNode->Name() ;
164 name = _DataFlowEditor->Graph()->Name() ;
167 if ( _DataFlowNode ) {
168 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
171 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
173 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
174 anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
178 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
179 if ( _DataFlowExecutor ) {
180 anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
184 anAny = new CORBA::Any( *_Any ) ;
189 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
190 anAny = new CORBA::Any( * _DataFlowEditor->GetOutData( name ,
194 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
195 if ( _DataFlowExecutor ) {
196 anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
200 anAny = new CORBA::Any( *_Any ) ;
206 anAny = new CORBA::Any( *_Any ) ;
211 char * Value_Impl::ToString() {
212 // beginService( "Value_Impl::ToString" );
213 CORBA::Any anAny = *ToAny() ;
214 // cout << "Value_Impl::ToString " << _DataFlowNode->Name() << " "
215 // << _ParameterName << " " ;
216 if ( _DataFlowEditor ) {
218 if ( _DataFlowNode ) {
219 name = _DataFlowNode->Name() ;
222 name = _DataFlowEditor->Graph()->Name() ;
225 if ( _DataFlowNode ) {
226 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
229 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
231 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
232 anAny = * _DataFlowEditor->GetInData( name ,
236 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
237 if ( _DataFlowExecutor ) {
238 anAny = * _DataFlowExecutor->GetInData( name ,
244 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
245 anAny = * _DataFlowEditor->GetOutData( name ,
249 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
250 if ( _DataFlowExecutor ) {
251 anAny = * _DataFlowExecutor->GetOutData( name ,
258 const char * retstr ;
260 switch (anAny.type()->kind()) {
261 case CORBA::tk_string: {
263 // MESSAGE( "ToString( string ) '" << retstr << "'" );
266 case CORBA::tk_long: {
270 retstr = astr.str().c_str() ;
271 // MESSAGE( "ToString( long ) '" << l << " " << retstr << "'" );
274 case CORBA::tk_double: {
277 astr << setw(25) << setprecision(18) << d << ends ;
278 retstr = astr.str().c_str() ;
280 while ( i < (int ) strlen( retstr ) && retstr[ i++ ] == ' ' ) {
283 // MESSAGE( "ToString( double ) '" << d << "' '" << retstr << "' '" << &retstr[ startstr ] << "'");
286 case CORBA::tk_objref: {
287 CORBA::Object_ptr obj ;
290 retstr = _Orb->object_to_string( obj );
291 // MESSAGE( "ToString( object ) '" << retstr << "'" );
294 retstr = "object_to_string catched " ;
299 retstr = "Unknown CORBA::Any Type" ;
300 // MESSAGE( retstr );
304 // endService( "Value_Impl::ToString" );
305 return CORBA::string_dup( &retstr[ startstr ] ) ;
308 bool Value_Impl::IsIOR() {
309 CORBA::Any anAny = *ToAny() ;
310 if ( _DataFlowEditor ) {
312 if ( _DataFlowNode ) {
313 name = _DataFlowNode->Name() ;
316 name = _DataFlowEditor->Graph()->Name() ;
319 if ( _DataFlowNode ) {
320 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
323 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
325 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
326 anAny = * _DataFlowEditor->GetInData( name ,
330 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
331 if ( _DataFlowExecutor ) {
332 anAny = * _DataFlowExecutor->GetInData( name ,
338 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
339 anAny = * _DataFlowEditor->GetOutData( name ,
343 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
344 if ( _DataFlowExecutor ) {
345 anAny = * _DataFlowExecutor->GetOutData( name ,
351 return(anAny.type()->kind() == CORBA::tk_objref);
354 char* Value_Impl::ComponentDataType() {
355 GraphExecutor::DataFlow* _DataFlowExecutor = _DataFlowEditor->Executor();
356 const GraphBase::ComputingNode* node = _DataFlowExecutor->Graph()->GetGraphNode(_DataFlowNode->Name());
357 if ( node->IsFactoryNode() ) {
358 Engines::Component_var compo = ((GraphBase::FactoryNode * ) node )->Component();
359 if ( CORBA::is_nil( compo ) ) {
360 return ( strdup( "UnknownComponent" ) ) ;
363 return ( strdup( compo->instanceName() ) ) ;
366 return ( strdup ( "UnknownComponent" ) ) ;