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
35 #include "utilities.h"
37 #include "Value_Impl.hxx"
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) {
51 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
52 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
53 // << hex << (void *) this << dec )
55 _id = _poa->activate_object(_thisObj);
57 _Orb = CORBA::ORB::_duplicate(orb);
60 _DataFlowEditor = DataFlowEditor ;
61 _DataFlowNode = DataFlowNode ;
62 if ( ParameterName != NULL ) {
63 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
64 strcpy( _ParameterName , ParameterName ) ;
67 _ParameterName = NULL ;
70 _Any = new CORBA::Any( *anAny ) ;
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) {
84 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
85 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
86 // << hex << (void *) this << dec )
88 _id = _poa->activate_object(_thisObj);
90 _Orb = CORBA::ORB::_duplicate(orb);
93 _DataFlowEditor = DataFlowEditor ;
94 _DataFlowNode = DataFlowNode ;
95 if ( ParameterName != NULL ) {
96 _ParameterName = new char[ strlen( ParameterName ) + 1 ] ;
97 strcpy( _ParameterName , ParameterName ) ;
100 _ParameterName = NULL ;
102 _InputValue = false ;
103 _Any = new CORBA::Any() ;
106 Value_Impl::Value_Impl() {
109 Value_Impl::~Value_Impl() {
110 beginService( "Value_Impl::~Value_Impl" );
111 endService( "Value_Impl::~Value_Impl" );
114 void Value_Impl::destroy() {
115 beginService( "Value_Impl::destroy" );
116 _poa->deactivate_object(*_id) ;
117 CORBA::release(_poa) ;
119 _thisObj->_remove_ref();
120 endService( "Value_Impl::destroy" );
123 void Value_Impl::InPort( bool anInput ) {
124 _InputPort = anInput ;
127 bool Value_Impl::Input( const CORBA::Any * anAny ) {
128 // _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
132 _Any = new CORBA::Any( *anAny ) ;
137 CORBA::Any * Value_Impl::ToAny() {
139 if ( _DataFlowEditor ) {
141 if ( _DataFlowNode ) {
142 name = _DataFlowNode->Name() ;
145 name = _DataFlowEditor->Name() ;
148 if ( _DataFlowNode ) {
149 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
152 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
154 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
155 anAny = new CORBA::Any( * _DataFlowEditor->GetInData( name ,
159 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
160 if ( _DataFlowExecutor ) {
161 anAny = new CORBA::Any( * _DataFlowExecutor->GetInData( name ,
165 anAny = new CORBA::Any( *_Any ) ;
170 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
171 anAny = new CORBA::Any( * _DataFlowEditor->GetOutData( name ,
175 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
176 if ( _DataFlowExecutor ) {
177 anAny = new CORBA::Any( * _DataFlowExecutor->GetOutData( name ,
181 anAny = new CORBA::Any( *_Any ) ;
187 anAny = new CORBA::Any( *_Any ) ;
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 ) {
199 if ( _DataFlowNode ) {
200 name = _DataFlowNode->Name() ;
203 name = _DataFlowEditor->Name() ;
206 if ( _DataFlowNode ) {
207 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
210 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
212 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
213 anAny = * _DataFlowEditor->GetInData( name ,
217 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
218 if ( _DataFlowExecutor ) {
219 anAny = * _DataFlowExecutor->GetInData( name ,
225 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
226 anAny = * _DataFlowEditor->GetOutData( name ,
230 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
231 if ( _DataFlowExecutor ) {
232 anAny = * _DataFlowExecutor->GetOutData( name ,
239 switch (anAny.type()->kind()) {
240 case CORBA::tk_string: {
242 // MESSAGE( "ToString( string ) " << retstr );
245 case CORBA::tk_double: {
248 retstr = new char[13];
249 snprintf(retstr, 13, "%lf", d);
250 // MESSAGE( "ToString( double ) " << retstr );
253 case CORBA::tk_long: {
256 retstr = new char[13];
257 snprintf(retstr, 13, "%ld", l);
258 // MESSAGE( "ToString( long ) " << retstr );
261 case CORBA::tk_objref: {
262 CORBA::Object_ptr obj ;
265 retstr = _Orb->object_to_string(obj );
266 // MESSAGE( "ToString( object ) " << retstr );
269 retstr = "Unknown CORBA::Any Type" ;
274 retstr = "Unknown CORBA::Any Type" ;
275 // MESSAGE( retstr );
279 // endService( "Value_Impl::ToString" );
280 return CORBA::string_dup( retstr ) ;
283 bool Value_Impl::IsIOR() {
284 CORBA::Any anAny = *ToAny() ;
285 if ( _DataFlowEditor ) {
287 if ( _DataFlowNode ) {
288 name = _DataFlowNode->Name() ;
291 name = _DataFlowEditor->Name() ;
294 if ( _DataFlowNode ) {
295 _InputValue = _DataFlowNode->HasInput( _ParameterName ) ;
298 _InputValue = _DataFlowEditor->HasInput( _ParameterName ) ;
300 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
301 anAny = * _DataFlowEditor->GetInData( name ,
305 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
306 if ( _DataFlowExecutor ) {
307 anAny = * _DataFlowExecutor->GetInData( name ,
313 if ( _InputValue && _DataFlowEditor->IsEditing() ) {
314 anAny = * _DataFlowEditor->GetOutData( name ,
318 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
319 if ( _DataFlowExecutor ) {
320 anAny = * _DataFlowExecutor->GetOutData( name ,
326 return(anAny.type()->kind() == CORBA::tk_objref);
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" ) ) ;
338 return ( strdup( compo->instanceName() ) ) ;
341 return ( strdup ( "UnknownComponent" ) ) ;