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 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
174 if ( _DataFlowExecutor ) {
175 anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
178 else if ( _InputValue ) {
179 anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
183 anAny = new CORBA::Any( *_Any ) ;
187 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
188 if ( _DataFlowExecutor ) {
189 anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
193 anAny = new CORBA::Any( *_Any ) ;
198 anAny = new CORBA::Any( *_Any ) ;
203 char * Value_Impl::ToString() {
204 // beginService( "Value_Impl::ToString" );
205 CORBA::Any anAny = *ToAny() ;
206 if ( _DataFlowEditor ) {
208 if ( _DataFlowNode ) {
209 name = _DataFlowNode->Name() ;
212 name = _DataFlowEditor->Graph()->Name() ;
214 // cout << "Value_Impl::ToString " << name << " " << _ParameterName << " " ;
216 if ( _DataFlowNode ) {
217 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
220 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
222 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
223 if ( _DataFlowExecutor ) {
224 // cout << "_DataFlowExecutor->GetInData" << endl ;
225 anAny = * _DataFlowExecutor->GetInData( name ,
228 else if ( _InputValue ) {
229 // cout << "_DataFlowEditor->GetInData _DataFlowNode " << _DataFlowNode
230 // << " _InputValue " << _InputValue << endl ;
231 anAny = * _DataFlowEditor->GetInData( name ,
239 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
240 if ( _DataFlowExecutor ) {
241 anAny = * _DataFlowExecutor->GetOutData( name ,
250 const char * retstr ;
252 switch (anAny.type()->kind()) {
253 case CORBA::tk_string: {
255 // MESSAGE( "ToString( string ) '" << retstr << "'" );
258 case CORBA::tk_long: {
262 retstr = astr.str().c_str() ;
263 // MESSAGE( "ToString( long ) '" << l << " " << retstr << "'" );
266 case CORBA::tk_double: {
269 astr << setw(25) << setprecision(18) << d << ends ;
270 retstr = astr.str().c_str() ;
272 while ( i < (int ) strlen( retstr ) && retstr[ i++ ] == ' ' ) {
275 // MESSAGE( "ToString( double ) '" << d << "' '" << retstr << "' '" << &retstr[ startstr ] << "'");
278 case CORBA::tk_objref: {
279 CORBA::Object_ptr obj ;
282 retstr = _Orb->object_to_string( obj );
283 // MESSAGE( "ToString( object ) '" << retstr << "'" );
286 retstr = "object_to_string catched " ;
291 retstr = "Unknown CORBA::Any Type" ;
292 // MESSAGE( retstr );
296 // endService( "Value_Impl::ToString" );
297 return CORBA::string_dup( &retstr[ startstr ] ) ;
300 bool Value_Impl::IsIOR() {
301 CORBA::Any anAny = *ToAny() ;
302 if ( _DataFlowEditor ) {
304 if ( _DataFlowNode ) {
305 name = _DataFlowNode->Name() ;
308 name = _DataFlowEditor->Graph()->Name() ;
311 if ( _DataFlowNode ) {
312 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
315 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
317 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
318 anAny = * _DataFlowEditor->GetInData( name ,
322 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
323 if ( _DataFlowExecutor ) {
324 anAny = * _DataFlowExecutor->GetInData( name ,
330 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
331 anAny = * _DataFlowEditor->GetOutData( name ,
335 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
336 if ( _DataFlowExecutor ) {
337 anAny = * _DataFlowExecutor->GetOutData( name ,
343 return(anAny.type()->kind() == CORBA::tk_objref);
346 char* Value_Impl::ComponentDataType() {
347 GraphExecutor::DataFlow* _DataFlowExecutor = _DataFlowEditor->Executor();
348 const GraphBase::ComputingNode* node = _DataFlowExecutor->Graph()->GetGraphNode(_DataFlowNode->Name());
349 if ( node->IsFactoryNode() ) {
350 Engines::Component_var compo = ((GraphBase::FactoryNode * ) node )->Component();
351 if ( CORBA::is_nil( compo ) ) {
352 return ( strdup( "UnknownComponent" ) ) ;
355 return ( strdup( compo->instanceName() ) ) ;
358 return ( strdup ( "UnknownComponent" ) ) ;