]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/Value_Impl.cxx
Salome HOME
bd87bcb3841c99a988aff340868661aa155c4de4
[modules/superv.git] / src / Supervision / Value_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Value_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 #include <strstream>
33 #include <string>
34
35 #include "utilities.h"
36
37 #include "Value_Impl.hxx"
38
39 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
40                         PortableServer::POA_ptr poa ,
41                         PortableServer::ObjectId * contId , 
42                         const char *instanceName ,
43                         const char *interfaceName ,
44                         GraphEditor::DataFlow * DataFlowEditor ,
45                         GraphEditor::InNode * DataFlowNode ,
46                         const char *ParameterName ,
47                         const CORBA::Any * anAny ,
48                         const bool activate ) :
49   Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
50   if ( activate ) {
51 //    MESSAGE("Value_Impl::Value_Impl activate object instanceName("
52 //            << instanceName << ") interfaceName(" << interfaceName << ") --> "
53 //            << hex << (void *) this << dec )
54     _thisObj = this ;
55     _id = _poa->activate_object(_thisObj);
56   }
57   _Orb = CORBA::ORB::_duplicate(orb);
58   _Poa = poa ;
59   _ContId = contId ;
60   _DataFlowEditor = DataFlowEditor ;
61   _DataFlowNode = DataFlowNode ;
62   if ( ParameterName != NULL ) {
63     _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
64     strcpy( _ParameterName , ParameterName ) ;
65   }
66   else {
67     _ParameterName = NULL ;
68   }
69   _InputValue = false ;
70   _Any = new CORBA::Any( *anAny ) ;
71 }
72
73 Value_Impl::Value_Impl( CORBA::ORB_ptr orb ,
74                         PortableServer::POA_ptr poa ,
75                         PortableServer::ObjectId * contId , 
76                         const char *instanceName ,
77                         const char *interfaceName ,
78                         GraphEditor::DataFlow * DataFlowEditor ,
79                         GraphEditor::InNode * DataFlowNode ,
80                         const char *ParameterName ,
81                         const bool activate ) :
82   Engines_Component_i(orb, poa, contId, instanceName, interfaceName, false, false) {
83   if ( activate ) {
84 //    MESSAGE("Value_Impl::Value_Impl activate object instanceName("
85 //            << instanceName << ") interfaceName(" << interfaceName << ") --> "
86 //            << hex << (void *) this << dec )
87     _thisObj = this ;
88     _id = _poa->activate_object(_thisObj);
89   }
90   _Orb = CORBA::ORB::_duplicate(orb);
91   _Poa = poa ;
92   _ContId = contId ;
93   _DataFlowEditor = DataFlowEditor ;
94   _DataFlowNode = DataFlowNode ;
95   if ( ParameterName != NULL ) {
96     _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
97     strcpy( _ParameterName , ParameterName ) ;
98   }
99   else {
100     _ParameterName = NULL ;
101   }
102   _InputValue = false ;
103   _Any = new CORBA::Any() ;
104 }
105
106 Value_Impl::Value_Impl() {
107 }
108
109 Value_Impl::~Value_Impl() {
110   beginService( "Value_Impl::~Value_Impl" );
111   endService( "Value_Impl::~Value_Impl" );
112 }
113
114 void Value_Impl::destroy() {
115   beginService( "Value_Impl::destroy" );
116   _poa->deactivate_object(*_id) ;
117   CORBA::release(_poa) ;
118   delete(_id) ;
119   _thisObj->_remove_ref();
120   endService( "Value_Impl::destroy" );
121 }
122
123 void Value_Impl::InPort( bool anInput ) {
124   _InputPort = anInput ;
125 }
126
127 bool Value_Impl::Input( const CORBA::Any * anAny ) {
128 //  _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
129 //                                 _ParameterName ,
130 //                                 *anAny ) ;
131   delete _Any ;
132   _Any = new CORBA::Any( *anAny ) ;
133   _InputValue = true ;
134   return true ;
135 }
136
137 CORBA::Any * Value_Impl::ToAny() {
138   CORBA::Any * anAny ;
139   if ( _DataFlowEditor ) {
140     char * name ;
141     if ( _DataFlowNode ) {
142       name = _DataFlowNode->Name() ;
143     }
144     else {
145       name = _DataFlowEditor->Name() ;
146     }
147     if ( _InputPort ) {
148       if ( _DataFlowNode ) {
149         _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
150       }
151       else {
152         _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
153       }
154       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
155         anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
156                                                               _ParameterName ) ) ;
157       }
158       else {
159         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
160         if ( _DataFlowExecutor ) {
161           anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
162                                                                   _ParameterName ) ) ;
163         }
164         else {
165           anAny = new CORBA::Any( *_Any ) ;
166         }
167       }
168     }
169     else {
170       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
171         anAny = new CORBA::Any( * _DataFlowEditor->GetOutData( name ,
172                                                               _ParameterName ) ) ;
173       }
174       else {
175         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
176         if ( _DataFlowExecutor ) {
177           anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
178                                                                   _ParameterName ) ) ;
179         }
180         else {
181           anAny = new CORBA::Any( *_Any ) ;
182         }
183       }
184     }
185   }
186   else {
187     anAny = new CORBA::Any( *_Any ) ;
188   }
189   return anAny ;
190 }
191
192 char * Value_Impl::ToString() {
193 //  beginService( "Value_Impl::ToString" );
194   CORBA::Any anAny = *ToAny() ;
195 //  cout << "Value_Impl::ToString " << _DataFlowNode->Name() << " "
196 //       << _ParameterName << " " ;
197   if ( _DataFlowEditor ) {
198     char * name ;
199     if ( _DataFlowNode ) {
200       name = _DataFlowNode->Name() ;
201     }
202     else {
203       name = _DataFlowEditor->Name() ;
204     }
205     if ( _InputPort ) {
206       if ( _DataFlowNode ) {
207         _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
208       }
209       else {
210         _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
211       }
212       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
213         anAny = * _DataFlowEditor->GetInData( name ,
214                                               _ParameterName ) ;
215       }
216       else {
217         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
218         if ( _DataFlowExecutor ) {
219           anAny = * _DataFlowExecutor->GetInData( name ,
220                                                   _ParameterName ) ;
221         }
222       }
223     }
224     else {
225       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
226         anAny = * _DataFlowEditor->GetOutData( name ,
227                                                _ParameterName ) ;
228       }
229       else {
230         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
231         if ( _DataFlowExecutor ) {
232           anAny = * _DataFlowExecutor->GetOutData( name ,
233                                                    _ParameterName ) ;
234         }
235       }
236     }
237   }
238   char* retstr ;
239   switch (anAny.type()->kind()) {
240     case CORBA::tk_string: {
241       anAny >>= retstr;
242 //      MESSAGE( "ToString( string ) " << retstr );
243       break ;
244     }
245     case CORBA::tk_double: {
246       double d;
247       anAny >>= d;
248       retstr = new char[13];
249       snprintf(retstr, 13, "%lf", d);
250 //      MESSAGE( "ToString( double ) " << retstr );
251       break ;
252     }
253     case CORBA::tk_long: {
254       long l;
255       anAny >>= l;
256       retstr = new char[13];
257       snprintf(retstr, 13, "%ld", l);
258 //      MESSAGE( "ToString( long ) " << retstr );
259       break ;
260     }
261     case CORBA::tk_objref: {
262       CORBA::Object_ptr obj ;
263       try {
264         anAny >>= obj ;
265         retstr = _Orb->object_to_string(obj );
266 //        MESSAGE( "ToString( object ) " << retstr );
267       }
268       catch ( ... ) {
269         retstr = "Unknown CORBA::Any Type" ;
270       }
271       break ;
272     }
273     default: {
274       retstr = "Unknown CORBA::Any Type" ;
275 //      MESSAGE( retstr );
276       break ;
277     }
278   }
279 //  endService( "Value_Impl::ToString" );
280   return CORBA::string_dup( retstr ) ;
281 }
282
283 bool Value_Impl::IsIOR() {
284   CORBA::Any anAny = *ToAny() ;
285   if ( _DataFlowEditor ) {
286     char * name ;
287     if ( _DataFlowNode ) {
288       name = _DataFlowNode->Name() ;
289     }
290     else {
291       name = _DataFlowEditor->Name() ;
292     }
293     if ( _InputPort ) {
294       if ( _DataFlowNode ) {
295         _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
296       }
297       else {
298         _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
299       }
300       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
301         anAny = * _DataFlowEditor->GetInData( name ,
302                                               _ParameterName ) ;
303       }
304       else {
305         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
306         if ( _DataFlowExecutor ) {
307           anAny = * _DataFlowExecutor->GetInData( name ,
308                                                   _ParameterName ) ;
309         }
310       }
311     }
312     else {
313       if ( _InputValue && _DataFlowEditor->IsEditing() ) {
314         anAny = * _DataFlowEditor->GetOutData( name ,
315                                                _ParameterName ) ;
316       }
317       else {
318         GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
319         if ( _DataFlowExecutor ) {
320           anAny = * _DataFlowExecutor->GetOutData( name ,
321                                                    _ParameterName ) ;
322         }
323       }
324     }
325   }
326   return(anAny.type()->kind() == CORBA::tk_objref);
327 }
328
329 char* Value_Impl::ComponentDataType() {
330   GraphExecutor::DataFlow* _DataFlowExecutor = _DataFlowEditor->Executor();
331   const GraphBase::ComputingNode* node = _DataFlowExecutor->GetGraphNode(_DataFlowNode->Name());
332   if ( node->IsFactoryNode() ) {
333     Engines::Component_var compo = ((GraphBase::FactoryNode * ) node )->Component();
334     if ( CORBA::is_nil( compo ) ) {
335       return ( strdup( "UnknownComponent" ) ) ;
336     }
337     else {
338       return ( strdup( compo->instanceName() ) ) ;
339     }
340   }
341   return ( strdup ( "UnknownComponent" ) ) ;
342 }