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() ) ;
132 else if ( _DataFlowNode->IsOneOfInLineNodes() && !_DataFlowNode->IsLoopNode() ) {
133 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
140 _DataFlowEditor->UnValid() ;
144 _poa->deactivate_object(*_id) ;
145 CORBA::release(_poa) ;
147 _thisObj->_remove_ref();
149 endService( "Port_Impl::destroy" );
152 void Port_Impl::Remove() {
153 beginService( "Port_Impl::Remove" );
154 _poa->deactivate_object(*_id) ;
155 CORBA::release(_poa) ;
157 _thisObj->_remove_ref();
158 endService( "Port_Impl::Remove" );
161 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
162 return Input( aValue->ToAny() ) ;
165 bool Port_Impl::Input( const CORBA::Any * anAny ) {
166 beginService( "Port_Impl::Input" );
167 bool RetVal = false ;
168 if ( _DataFlowEditor->Graph()->GraphMacroLevel() == 0 ) {
169 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
171 Value_Impl::Input( anAny ) ;
172 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
173 _DataFlowPort->PortName() ,
176 else if ( _DataFlowEditor->IsExecuting() ) {
177 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
179 /* commenting out the lines below because it seems to be never executed
180 Editor::_Executing flag is set OFF in Executor::OutNode on execution finished
181 and in CNode_Impl class (also not called probably)
182 // asv: turn off Editor::_Executing flag
183 if ( _DataFlowExecutor->IsDone() ) {
184 _DataFlowEditor->Executing( false );
188 if ( !_DataFlowExecutor->IsDone() ) {
189 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
190 _DataFlowPort->PortName() ,
196 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
197 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
199 endService( "Port_Impl::Input" );
203 char * Port_Impl::Name() {
204 // beginService( "Port_Impl::Name" ) ;
205 const char * RetVal = _DataFlowPort->PortName() ;
206 // endService( "Port_Impl::Name" ) ;
207 return CORBA::string_dup( RetVal ) ;
210 char * Port_Impl::Type() {
211 // beginService( "Port_Impl::Type" ) ;
212 const char * RetVal = _DataFlowPort->PortType() ;
213 // endService( "Port_Impl::Type" ) ;
214 return CORBA::string_dup( RetVal ) ;
217 SUPERV::CNode_ptr Port_Impl::Node() {
219 SUPERV::CNode_var iobject ;
220 if ( _DataFlowNode ) {
221 // MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
222 iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
223 if ( CORBA::is_nil( iobject ) ) {
225 beginService( "Port_Impl::Node" ) ;
228 PortableServer::ObjectId * id ;
229 CORBA::Object_var obj ;
230 if ( _DataFlowNode->IsComputingNode() ) {
231 CNode_Impl * myNode = NULL ;
232 myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
233 instanceName() , interfaceName() ,
236 id = myNode->getId() ;
237 obj = _poa->id_to_reference(*id);
238 iobject = SUPERV::CNode::_narrow( obj ) ;
239 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
241 else if ( _DataFlowNode->IsFactoryNode() ) {
242 FNode_Impl * myNode = NULL ;
243 myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
244 instanceName() , interfaceName() ,
247 id = myNode->getId() ;
248 obj = _poa->id_to_reference(*id);
249 SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
250 iobject = SUPERV::CNode::_narrow( Fiobject ) ;
251 myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
253 else if ( _DataFlowNode->IsInLineNode() ) {
254 INode_Impl * myNode = NULL ;
255 myNode = new INode_Impl( _Orb , _Poa , _ContId ,
256 instanceName() , interfaceName() ,
259 id = myNode->getId() ;
260 obj = _poa->id_to_reference(*id);
261 SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
262 iobject = SUPERV::CNode::_narrow( Iiobject ) ;
263 myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
265 else if ( _DataFlowNode->IsGOTONode() ) {
266 GNode_Impl * myNode = NULL ;
267 myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
268 instanceName() , interfaceName() ,
271 id = myNode->getId() ;
272 obj = _poa->id_to_reference(*id);
273 SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
274 iobject = SUPERV::CNode::_narrow( Giobject ) ;
275 myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
277 else if ( _DataFlowNode->IsLoopNode() ) {
278 LNode_Impl * myNode = NULL ;
279 myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
280 instanceName() , interfaceName() ,
283 id = myNode->getId() ;
284 obj = _poa->id_to_reference(*id);
285 SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
286 iobject = SUPERV::CNode::_narrow( Liobject ) ;
287 myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
289 else if ( _DataFlowNode->IsEndLoopNode() ) {
290 ELNode_Impl * myNode = NULL ;
291 myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
292 instanceName() , interfaceName() ,
295 id = myNode->getId() ;
296 obj = _poa->id_to_reference(*id);
297 SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
298 iobject = SUPERV::CNode::_narrow( ELiobject ) ;
299 myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
301 else if ( _DataFlowNode->IsSwitchNode() ) {
302 SNode_Impl * myNode = NULL ;
303 myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
304 instanceName() , interfaceName() ,
307 id = myNode->getId() ;
308 obj = _poa->id_to_reference(*id);
309 SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
310 iobject = SUPERV::CNode::_narrow( Siobject ) ;
311 myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
313 else if ( _DataFlowNode->IsEndSwitchNode() ) {
314 ESNode_Impl * myNode = NULL ;
315 myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
316 instanceName() , interfaceName() ,
319 id = myNode->getId() ;
320 obj = _poa->id_to_reference(*id);
321 SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
322 iobject = SUPERV::CNode::_narrow( ESiobject ) ;
323 myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
327 // MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
331 MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
332 iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
333 if ( CORBA::is_nil( iobject ) ) {
334 MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
338 endService( "Port_Impl::Node" ) ;
340 return SUPERV::CNode::_duplicate( iobject ) ;
343 SUPERV::ListOfLinks * Port_Impl::Links() {
344 beginService( "Port_Impl::Links" ) ;
345 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
346 RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
347 _DataFlowPort->PortName()*/ ) ;
348 MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
349 << " and of Port " << _DataFlowPort->PortName()
350 << " _InputPort " << _InputPort ) ;
352 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
353 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
354 << RetVal[i]->OutPort()->Name() << ") --> "
355 << RetVal[i]->InPort()->Node()->Name() << "("
356 << RetVal[i]->InPort()->Name() << ")" ) ;
358 endService( "Port_Impl::Links" ) ;
359 return ( RetVal._retn() ) ;
362 SUPERV::Link_ptr Port_Impl::Link() {
364 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
365 if ( _DataFlowNode->IsEndSwitchNode() ) {
366 beginService( "Port_Impl::Link" ) ;
368 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
369 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
370 // << _DataFlowPort->PortName() << endl ;
371 Links = _DataFlowEditor->Graph()->ObjImpl()->Links( /*_DataFlowNode->ComputingNode() ,
372 _DataFlowPort->PortName()*/ ) ;
373 if ( Links->length() ) {
374 iobject = Links[ 0 ] ;
378 char * FromNodeName = NULL ;
379 char * FromServiceParameterName = NULL ;
380 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
381 _DataFlowPort->PortName() ,
383 & FromServiceParameterName ) ;
385 // cout << "Port_Impl::Link " << FromNodeName << "("
386 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
387 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
388 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
390 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
391 if ( anInPort->GetOutPort() ) {
392 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
393 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
394 anOutPort->NodeName() ) ) {
395 // MESSAGE( "Link " << anOutPort->NodeName() << "("
396 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
397 // << anInPort->PortName() << ")" << " ignored" ) ;
399 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
401 beginService( "Port_Impl::Link" ) ;
405 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
406 instanceName() , interfaceName() ,
409 _DataFlowPort->PortName() ,
410 (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
411 FromServiceParameterName ,
412 false , true , Success ) ;
414 PortableServer::ObjectId * id = myLink->getId() ;
415 CORBA::Object_var obj = _poa->id_to_reference(*id);
416 iobject = SUPERV::Link::_narrow(obj) ;
417 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
421 iobject = anOutPort->InPortObjRef( anInPort ) ;
427 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
428 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
429 endService( "Port_Impl::Link" ) ;
431 return SUPERV::Link::_duplicate( iobject ) ;
434 bool Port_Impl::IsInput() {
435 // beginService( "Port_Impl::IsInput" ) ;
436 bool RetVal = _InputPort ;
437 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
438 // endService( "Port_Impl::IsInput" ) ;
442 bool Port_Impl::IsLinked() {
443 // beginService( "Port_Impl::IsLinked" ) ;
444 bool RetVal = false ;
445 if ( _DataFlowNode ) {
446 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
447 GraphBase::OutPort * anOutPort = NULL ;
449 anOutPort = anInPort->GetOutPort() ;
451 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
452 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
453 // MESSAGE( "Link " << anOutPort->NodeName() << "("
454 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
455 // << anInPort->PortName() << ")" << " ignored" ) ;
458 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
461 // endService( "Port_Impl::IsLinked" ) ;
465 SUPERV::KindOfPort Port_Impl::Kind() {
466 // beginService( "Port_Impl::Kind" ) ;
467 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
468 // endService( "Port_Impl::Kind" ) ;
472 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
473 // beginService( "Port_Impl::SetKind" ) ;
474 _DataFlowPort->Kind( aKindOfPort ) ;
475 // endService( "Port_Impl::SetKind" ) ;
478 bool Port_Impl::IsParam() {
479 // beginService( "Port_Impl::IsParam" ) ;
480 bool RetVal = _DataFlowPort->IsParam() ;
481 // endService( "Port_Impl::IsParam" ) ;
485 bool Port_Impl::IsGate() {
486 // beginService( "Port_Impl::IsGate" ) ;
487 bool RetVal = _DataFlowPort->IsGate() ;
488 // endService( "Port_Impl::IsGate" ) ;
492 bool Port_Impl::IsInLine() {
493 // beginService( "Port_Impl::IsInLine" ) ;
494 // bool RetVal = _DataFlowPort->IsBus() ;
495 bool RetVal = _DataFlowPort->IsInLine() ;
496 // endService( "Port_Impl::IsInLine" ) ;
500 bool Port_Impl::IsLoop() {
501 // beginService( "Port_Impl::IsLoop" ) ;
502 bool RetVal = _DataFlowPort->IsLoop() ;
503 // endService( "Port_Impl::IsLoop" ) ;
507 bool Port_Impl::IsSwitch() {
508 // beginService( "Port_Impl::IsSwitch" ) ;
509 bool RetVal = _DataFlowPort->IsSwitch() ;
510 // endService( "Port_Impl::IsSwitch" ) ;
514 bool Port_Impl::IsEndSwitch() {
515 // beginService( "Port_Impl::IsEndSwitch" ) ;
516 bool RetVal = _DataFlowPort->IsEndSwitch() ;
517 // endService( "Port_Impl::IsEndSwitch" ) ;
521 bool Port_Impl::IsDataStream() {
522 // beginService( "Port_Impl::IsDataStream" ) ;
523 bool RetVal = _DataFlowPort->IsDataStream() ;
524 // endService( "Port_Impl::IsDataStream" ) ;
528 bool Port_Impl::HasInput() {
529 // beginService( "Port_Impl::" ) ;
530 bool RetVal = false ;
531 if ( _DataFlowNode ) {
532 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
533 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
534 // << _DataFlowPort->PortName() << endl ;
536 // endService( "Port_Impl::" ) ;
540 SUPERV::GraphState Port_Impl::State() {
541 // beginService( "Port_Impl::State" );
542 SUPERV::GraphState RetVal = SUPERV::EditingState ;
543 if ( _DataFlowEditor ) {
544 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
545 if ( _DataFlowExecutor ) {
546 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
547 _DataFlowPort->PortName() ) ;
550 // endService( "Port_Impl::State" );
554 bool Port_Impl::IsDone() {
555 // beginService( "Port_Impl::IsDone" );
556 bool RetVal = false ;
557 if ( _DataFlowEditor ) {
558 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
559 if ( _DataFlowExecutor ) {
560 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
561 _DataFlowPort->PortName() ) ;
564 // endService( "Port_Impl::IsDone" );