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 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
41 PortableServer::POA_ptr poa ,
42 PortableServer::ObjectId * contId ,
43 const char *instanceName ,
44 const char *interfaceName ,
45 GraphEditor::DataFlow * DataFlowEditor ,
46 GraphEditor::InNode * DataFlowNode ,
47 const char *ParameterName ,
48 const CORBA::Any * anAny ,
49 const bool activate ) :
50 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
52 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
53 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
54 // << hex << (void *) this << dec )
56 _id = _poa->activate_object(_thisObj);
58 _Orb = CORBA::ORB::_duplicate(orb);
61 _DataFlowEditor = DataFlowEditor ;
62 _DataFlowNode = DataFlowNode ;
63 if ( ParameterName != NULL ) {
64 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
65 strcpy( _ParameterName , ParameterName ) ;
68 _ParameterName = NULL ;
71 _Any = new CORBA::Any( *anAny ) ;
74 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
75 PortableServer::POA_ptr poa ,
76 PortableServer::ObjectId * contId ,
77 const char *instanceName ,
78 const char *interfaceName ,
79 GraphEditor::DataFlow * DataFlowEditor ,
80 GraphEditor::InNode * DataFlowNode ,
81 const char *ParameterName ,
82 const bool activate ) :
83 Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
85 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
86 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
87 // << hex << (void *) this << dec )
89 _id = _poa->activate_object(_thisObj);
91 _Orb = CORBA::ORB::_duplicate(orb);
94 _DataFlowEditor = DataFlowEditor ;
95 _DataFlowNode = DataFlowNode ;
96 if ( ParameterName != NULL ) {
97 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
98 strcpy( _ParameterName , ParameterName ) ;
101 _ParameterName = NULL ;
103 _InputValue = false ;
104 _Any = new CORBA::Any() ;
107 Value_Impl::Value_Impl() {
110 Value_Impl::~Value_Impl() {
111 beginService( "Value_Impl::~Value_Impl" );
112 endService( "Value_Impl::~Value_Impl" );
115 void Value_Impl::destroy() {
116 beginService( "Value_Impl::destroy" );
117 _poa->deactivate_object(*_id) ;
118 CORBA::release(_poa) ;
120 _thisObj->_remove_ref();
121 endService( "Value_Impl::destroy" );
124 void Value_Impl::InPort( bool anInput ) {
125 _InputPort = anInput ;
128 bool Value_Impl::Input( const CORBA::Any * anAny ) {
129 // _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
133 _Any = new CORBA::Any( *anAny ) ;
138 CORBA::Any * Value_Impl::ToAny() {
140 if ( _DataFlowEditor ) {
142 if ( _DataFlowNode ) {
143 name = _DataFlowNode->Name() ;
146 name = _DataFlowEditor->Name() ;
149 if ( _DataFlowNode ) {
150 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
153 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
155 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
156 anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
160 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
161 if ( _DataFlowExecutor ) {
162 anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
166 anAny = new CORBA::Any( *_Any ) ;
171 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
172 anAny = new CORBA::Any( * _DataFlowEditor->GetOutData( name ,
176 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
177 if ( _DataFlowExecutor ) {
178 anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
182 anAny = new CORBA::Any( *_Any ) ;
188 anAny = new CORBA::Any( *_Any ) ;
193 char * Value_Impl::ToString() {
194 // beginService( "Value_Impl::ToString" );
195 CORBA::Any anAny = *ToAny() ;
196 // cout << "Value_Impl::ToString " << _DataFlowNode->Name() << " "
197 // << _ParameterName << " " ;
198 if ( _DataFlowEditor ) {
200 if ( _DataFlowNode ) {
201 name = _DataFlowNode->Name() ;
204 name = _DataFlowEditor->Name() ;
207 if ( _DataFlowNode ) {
208 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
211 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
213 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
214 anAny = * _DataFlowEditor->GetInData( name ,
218 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
219 if ( _DataFlowExecutor ) {
220 anAny = * _DataFlowExecutor->GetInData( name ,
226 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
227 anAny = * _DataFlowEditor->GetOutData( name ,
231 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
232 if ( _DataFlowExecutor ) {
233 anAny = * _DataFlowExecutor->GetOutData( name ,
240 const char * retstr ;
242 switch (anAny.type()->kind()) {
243 case CORBA::tk_string: {
245 // MESSAGE( "ToString( string ) '" << retstr << "'" );
248 case CORBA::tk_long: {
252 retstr = astr.str().c_str() ;
253 // MESSAGE( "ToString( long ) '" << l << " " << retstr << "'" );
256 case CORBA::tk_double: {
259 astr << setw(25) << setprecision(18) << d << ends ;
260 retstr = astr.str().c_str() ;
262 while ( i < (int ) strlen( retstr ) && retstr[ i++ ] == ' ' ) {
265 // MESSAGE( "ToString( double ) '" << d << "' '" << retstr << "' '" << &retstr[ startstr ] << "'");
268 case CORBA::tk_objref: {
269 CORBA::Object_ptr obj ;
272 retstr = _Orb->object_to_string( obj );
273 // MESSAGE( "ToString( object ) '" << retstr << "'" );
276 retstr = "object_to_string catched " ;
281 retstr = "Unknown CORBA::Any Type" ;
282 // MESSAGE( retstr );
286 // endService( "Value_Impl::ToString" );
287 return CORBA::string_dup( &retstr[ startstr ] ) ;
290 bool Value_Impl::IsIOR() {
291 CORBA::Any anAny = *ToAny() ;
292 if ( _DataFlowEditor ) {
294 if ( _DataFlowNode ) {
295 name = _DataFlowNode->Name() ;
298 name = _DataFlowEditor->Name() ;
301 if ( _DataFlowNode ) {
302 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
305 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
307 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
308 anAny = * _DataFlowEditor->GetInData( name ,
312 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
313 if ( _DataFlowExecutor ) {
314 anAny = * _DataFlowExecutor->GetInData( name ,
320 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
321 anAny = * _DataFlowEditor->GetOutData( name ,
325 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
326 if ( _DataFlowExecutor ) {
327 anAny = * _DataFlowExecutor->GetOutData( name ,
333 return(anAny.type()->kind() == CORBA::tk_objref);
336 char* Value_Impl::ComponentDataType() {
337 GraphExecutor::DataFlow* _DataFlowExecutor = _DataFlowEditor->Executor();
338 const GraphBase::ComputingNode* node = _DataFlowExecutor->GetGraphNode(_DataFlowNode->Name());
339 if ( node->IsFactoryNode() ) {
340 Engines::Component_var compo = ((GraphBase::FactoryNode * ) node )->Component();
341 if ( CORBA::is_nil( compo ) ) {
342 return ( strdup( "UnknownComponent" ) ) ;
345 return ( strdup( compo->instanceName() ) ) ;
348 return ( strdup ( "UnknownComponent" ) ) ;