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 : Port_Impl.cxx
25 // Author : Jean Rahuel
35 //#include "utilities.h"
37 #include "Graph_Impl.hxx"
38 #include "Port_Impl.hxx"
40 Port_Impl::Port_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 GraphBase::Port * DataFlowPort ,
49 const CORBA::Any * anAny ) :
50 Value_Impl(orb, poa, contId, instanceName, interfaceName,
51 DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
53 // MESSAGE("Port_Impl::Port_Impl activate object instanceName("
54 // << instanceName << ") interfaceName(" << interfaceName
55 // << ") IsDataStream " << DataFlowPort->IsDataStream() )
56 _Orb = CORBA::ORB::_duplicate(orb);
59 if ( !DataFlowPort->IsDataStream() ) {
61 _id = _poa->activate_object(_thisObj) ;
63 _DataFlowEditor = DataFlowEditor ;
64 _DataFlowNode = DataFlowNode ;
65 _DataFlowPort = DataFlowPort ;
66 _InputPort = InputPort ;
67 InPort( _InputPort ) ;
70 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
71 PortableServer::POA_ptr poa ,
72 PortableServer::ObjectId * contId ,
73 const char *instanceName ,
74 const char *interfaceName ,
75 GraphEditor::DataFlow * DataFlowEditor ,
76 GraphEditor::InNode * DataFlowNode ,
77 GraphBase::Port * DataFlowPort ,
79 Value_Impl(orb, poa, contId, instanceName, interfaceName,
80 DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
81 char * nodename = DataFlowEditor->Graph()->Name() ;
83 nodename = DataFlowNode->Name() ;
85 // MESSAGE("Port_Impl::Port_Impl activate object instanceName("
86 // << instanceName << ") interfaceName(" << interfaceName
87 // << ") " << nodename << "(" << DataFlowPort->PortName()
88 // << ") IsDataStream " << DataFlowPort->IsDataStream() ) ;
89 _Orb = CORBA::ORB::_duplicate(orb);
92 if ( !DataFlowPort->IsDataStream() ) {
94 _id = _poa->activate_object(_thisObj) ;
96 _DataFlowEditor = DataFlowEditor ;
97 _DataFlowNode = DataFlowNode ;
98 _DataFlowPort = DataFlowPort ;
99 _InputPort = InputPort ;
100 InPort( _InputPort ) ;
103 Port_Impl::Port_Impl() {
106 Port_Impl::~Port_Impl() {
107 beginService( "Port_Impl::~Port_Impl" );
108 endService( "Port_Impl::~Port_Impl" );
111 void Port_Impl::destroy() {
112 beginService( "Port_Impl::destroy" );
113 bool destroyed = false ;
114 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
116 // GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
117 // if ( anInPort->GetOutPort() ) {
118 // anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
120 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
121 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
122 if ( _DataFlowNode->IsLoopNode() ) {
123 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
124 _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
125 _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
130 else if ( _DataFlowNode->IsOneOfInLineNodes() && !_DataFlowNode->IsLoopNode() ) {
131 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
138 _DataFlowEditor->UnValid() ;
142 _poa->deactivate_object(*_id) ;
143 // CORBA::release(_poa) ;
145 // _thisObj->_remove_ref();
147 endService( "Port_Impl::destroy" );
150 // Only during delete of an InLineNode (because of Loop/EndLoop and Switch/EndSwitch
151 // CoupledNodes) ; look at destroy above ...
152 void Port_Impl::Remove() {
153 beginService( "Port_Impl::Remove" );
154 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
156 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
159 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
161 _poa->deactivate_object(*_id) ;
162 // CORBA::release(_poa) ;
164 // _thisObj->_remove_ref();
166 endService( "Port_Impl::Remove" );
169 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
170 return Input( aValue->ToAny() ) ;
173 bool Port_Impl::Input( const CORBA::Any * anAny ) {
174 beginService( "Port_Impl::Input" );
175 bool RetVal = false ;
176 MESSAGE( "Port_Impl::Input(CORBA::Any *) : " << _DataFlowNode->Name() << "( "
177 << _DataFlowPort->PortName() << " ) " ) ;
178 if ( _DataFlowEditor->Graph()->GraphMacroLevel() == 0 ) {
179 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
181 Value_Impl::Input( anAny ) ;
182 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
183 _DataFlowPort->PortName() ,
186 else if ( _DataFlowEditor->IsExecuting() ) {
187 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
189 /* commenting out the lines below because it seems to be never executed
190 Editor::_Executing flag is set OFF in Executor::OutNode on execution finished
191 and in CNode_Impl class (also not called probably)
192 // asv: turn off Editor::_Executing flag
193 if ( _DataFlowExecutor->IsDone() ) {
194 _DataFlowEditor->Executing( false );
198 if ( !_DataFlowExecutor->IsDone() ) {
199 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
200 _DataFlowPort->PortName() ,
206 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
207 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
209 endService( "Port_Impl::Input" );
213 char * Port_Impl::Name() {
214 // beginService( "Port_Impl::Name" ) ;
215 const char * RetVal = _DataFlowPort->PortName() ;
216 // endService( "Port_Impl::Name" ) ;
217 return CORBA::string_dup( RetVal ) ;
220 char * Port_Impl::Type() {
221 // beginService( "Port_Impl::Type" ) ;
222 const char * RetVal = _DataFlowPort->PortType() ;
223 // endService( "Port_Impl::Type" ) ;
224 return CORBA::string_dup( RetVal ) ;
227 SUPERV::CNode_ptr Port_Impl::Node() {
229 SUPERV::CNode_var iobject ;
230 if ( _DataFlowNode ) {
231 // MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
232 iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
233 if ( CORBA::is_nil( iobject ) ) {
235 beginService( "Port_Impl::Node" ) ;
238 PortableServer::ObjectId * id ;
239 CORBA::Object_var obj ;
240 if ( _DataFlowNode->IsComputingNode() ) {
241 CNode_Impl * myNode = NULL ;
242 myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
243 instanceName() , interfaceName() ,
246 id = myNode->getId() ;
247 obj = _poa->id_to_reference(*id);
248 iobject = SUPERV::CNode::_narrow( obj ) ;
249 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
251 else if ( _DataFlowNode->IsFactoryNode() ) {
252 FNode_Impl * myNode = NULL ;
253 myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
254 instanceName() , interfaceName() ,
257 id = myNode->getId() ;
258 obj = _poa->id_to_reference(*id);
259 SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
260 iobject = SUPERV::CNode::_narrow( Fiobject ) ;
261 myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
263 else if ( _DataFlowNode->IsInLineNode() ) {
264 INode_Impl * myNode = NULL ;
265 myNode = new INode_Impl( _Orb , _Poa , _ContId ,
266 instanceName() , interfaceName() ,
269 id = myNode->getId() ;
270 obj = _poa->id_to_reference(*id);
271 SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
272 iobject = SUPERV::CNode::_narrow( Iiobject ) ;
273 myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
275 else if ( _DataFlowNode->IsGOTONode() ) {
276 GNode_Impl * myNode = NULL ;
277 myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
278 instanceName() , interfaceName() ,
281 id = myNode->getId() ;
282 obj = _poa->id_to_reference(*id);
283 SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
284 iobject = SUPERV::CNode::_narrow( Giobject ) ;
285 myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
287 else if ( _DataFlowNode->IsLoopNode() ) {
288 LNode_Impl * myNode = NULL ;
289 myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
290 instanceName() , interfaceName() ,
293 id = myNode->getId() ;
294 obj = _poa->id_to_reference(*id);
295 SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
296 iobject = SUPERV::CNode::_narrow( Liobject ) ;
297 myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
299 else if ( _DataFlowNode->IsEndLoopNode() ) {
300 ELNode_Impl * myNode = NULL ;
301 myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
302 instanceName() , interfaceName() ,
305 id = myNode->getId() ;
306 obj = _poa->id_to_reference(*id);
307 SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
308 iobject = SUPERV::CNode::_narrow( ELiobject ) ;
309 myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
311 else if ( _DataFlowNode->IsSwitchNode() ) {
312 SNode_Impl * myNode = NULL ;
313 myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
314 instanceName() , interfaceName() ,
317 id = myNode->getId() ;
318 obj = _poa->id_to_reference(*id);
319 SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
320 iobject = SUPERV::CNode::_narrow( Siobject ) ;
321 myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
323 else if ( _DataFlowNode->IsEndSwitchNode() ) {
324 ESNode_Impl * myNode = NULL ;
325 myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
326 instanceName() , interfaceName() ,
329 id = myNode->getId() ;
330 obj = _poa->id_to_reference(*id);
331 SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
332 iobject = SUPERV::CNode::_narrow( ESiobject ) ;
333 myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
337 // MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
341 MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
342 iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
343 if ( CORBA::is_nil( iobject ) ) {
344 MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
348 endService( "Port_Impl::Node" ) ;
350 return SUPERV::CNode::_duplicate( iobject ) ;
353 SUPERV::ListOfLinks * Port_Impl::Links() {
354 beginService( "Port_Impl::Links" ) ;
355 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
356 RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
357 _DataFlowPort->PortName()*/ ) ;
358 MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
359 << " and of Port " << _DataFlowPort->PortName()
360 << " _InputPort " << _InputPort ) ;
362 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
363 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
364 << RetVal[i]->OutPort()->Name() << ") --> "
365 << RetVal[i]->InPort()->Node()->Name() << "("
366 << RetVal[i]->InPort()->Name() << ")" ) ;
368 endService( "Port_Impl::Links" ) ;
369 return ( RetVal._retn() ) ;
372 SUPERV::Link_ptr Port_Impl::Link() {
374 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
375 if ( _DataFlowNode->IsEndSwitchNode() ) {
376 beginService( "Port_Impl::Link" ) ;
378 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
379 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
380 // << _DataFlowPort->PortName() << endl ;
381 Links = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
382 _DataFlowPort->PortName()*/ ) ;
383 if ( Links->length() ) {
384 iobject = Links[ 0 ] ;
388 char * FromNodeName = NULL ;
389 char * FromServiceParameterName = NULL ;
390 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
391 _DataFlowPort->PortName() ,
393 & FromServiceParameterName ) ;
395 // cout << "Port_Impl::Link " << FromNodeName << "("
396 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
397 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
398 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
400 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
401 if ( anInPort->GetOutPort() ) {
402 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
403 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
404 anOutPort->NodeName() ) ) {
405 // MESSAGE( "Link " << anOutPort->NodeName() << "("
406 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
407 // << anInPort->PortName() << ")" << " ignored" ) ;
409 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
411 beginService( "Port_Impl::Link" ) ;
415 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
416 instanceName() , interfaceName() ,
419 _DataFlowPort->PortName() ,
420 (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
421 FromServiceParameterName ,
422 false , true , Success ) ;
424 PortableServer::ObjectId * id = myLink->getId() ;
425 CORBA::Object_var obj = _poa->id_to_reference(*id);
426 iobject = SUPERV::Link::_narrow(obj) ;
427 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
431 iobject = anOutPort->InPortObjRef( anInPort ) ;
437 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
438 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
439 endService( "Port_Impl::Link" ) ;
441 return SUPERV::Link::_duplicate( iobject ) ;
444 bool Port_Impl::IsInput() {
445 // beginService( "Port_Impl::IsInput" ) ;
446 bool RetVal = _InputPort ;
447 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
448 // endService( "Port_Impl::IsInput" ) ;
452 bool Port_Impl::IsLinked() {
453 // beginService( "Port_Impl::IsLinked" ) ;
454 bool RetVal = false ;
455 if ( _DataFlowNode ) {
456 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
457 GraphBase::OutPort * anOutPort = NULL ;
459 anOutPort = anInPort->GetOutPort() ;
461 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
462 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
463 // MESSAGE( "Link " << anOutPort->NodeName() << "("
464 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
465 // << anInPort->PortName() << ")" << " ignored" ) ;
468 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
471 // endService( "Port_Impl::IsLinked" ) ;
475 SUPERV::KindOfPort Port_Impl::Kind() {
476 // beginService( "Port_Impl::Kind" ) ;
477 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
478 // endService( "Port_Impl::Kind" ) ;
482 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
483 // beginService( "Port_Impl::SetKind" ) ;
484 _DataFlowPort->Kind( aKindOfPort ) ;
485 // endService( "Port_Impl::SetKind" ) ;
488 bool Port_Impl::IsParam() {
489 // beginService( "Port_Impl::IsParam" ) ;
490 bool RetVal = _DataFlowPort->IsParam() ;
491 // endService( "Port_Impl::IsParam" ) ;
495 bool Port_Impl::IsGate() {
496 // beginService( "Port_Impl::IsGate" ) ;
497 bool RetVal = _DataFlowPort->IsGate() ;
498 // endService( "Port_Impl::IsGate" ) ;
502 bool Port_Impl::IsInLine() {
503 // beginService( "Port_Impl::IsInLine" ) ;
504 // bool RetVal = _DataFlowPort->IsBus() ;
505 bool RetVal = _DataFlowPort->IsInLine() ;
506 // endService( "Port_Impl::IsInLine" ) ;
510 bool Port_Impl::IsLoop() {
511 // beginService( "Port_Impl::IsLoop" ) ;
512 bool RetVal = _DataFlowPort->IsLoop() ;
513 // endService( "Port_Impl::IsLoop" ) ;
517 bool Port_Impl::IsSwitch() {
518 // beginService( "Port_Impl::IsSwitch" ) ;
519 bool RetVal = _DataFlowPort->IsSwitch() ;
520 // endService( "Port_Impl::IsSwitch" ) ;
524 bool Port_Impl::IsEndSwitch() {
525 // beginService( "Port_Impl::IsEndSwitch" ) ;
526 bool RetVal = _DataFlowPort->IsEndSwitch() ;
527 // endService( "Port_Impl::IsEndSwitch" ) ;
531 bool Port_Impl::IsDataStream() {
532 // beginService( "Port_Impl::IsDataStream" ) ;
533 bool RetVal = _DataFlowPort->IsDataStream() ;
534 // endService( "Port_Impl::IsDataStream" ) ;
538 bool Port_Impl::HasInput() {
539 // beginService( "Port_Impl::" ) ;
540 bool RetVal = false ;
541 if ( _DataFlowNode ) {
542 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
543 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
544 // << _DataFlowPort->PortName() << endl ;
546 // endService( "Port_Impl::" ) ;
550 SUPERV::GraphState Port_Impl::State() {
551 // beginService( "Port_Impl::State" );
552 SUPERV::GraphState RetVal = SUPERV::EditingState ;
553 if ( _DataFlowEditor ) {
554 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
555 if ( _DataFlowExecutor ) {
556 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
557 _DataFlowPort->PortName() ) ;
560 // endService( "Port_Impl::State" );
564 bool Port_Impl::IsDone() {
565 // beginService( "Port_Impl::IsDone" );
566 bool RetVal = false ;
567 if ( _DataFlowEditor ) {
568 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
569 if ( _DataFlowExecutor ) {
570 RetVal = _DataFlowExecutor->PortDone( _DataFlowPort->NodeName() ,
571 _DataFlowPort->PortName() ) ;
574 // endService( "Port_Impl::IsDone" );