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 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
121 if ( _DataFlowNode->IsLoopNode() ) {
122 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
123 _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
124 _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
128 else if ( !_DataFlowNode->IsLoopNode() ) {
129 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
133 _DataFlowEditor->UnValid() ;
134 // _DataFlowEditor->IsValid() ;
138 _poa->deactivate_object(*_id) ;
139 CORBA::release(_poa) ;
141 _thisObj->_remove_ref();
143 endService( "Port_Impl::destroy" );
146 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
147 return Input( aValue->ToAny() ) ;
150 bool Port_Impl::Input( const CORBA::Any * anAny ) {
151 beginService( "Port_Impl::Input" );
152 bool RetVal = false ;
153 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
155 Value_Impl::Input( anAny ) ;
156 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
157 _DataFlowPort->PortName() ,
160 else if ( _DataFlowEditor->IsExecuting() ) {
161 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
162 // if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
163 // _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
164 if ( _DataFlowExecutor ) {
165 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
166 _DataFlowPort->PortName() ,
171 MESSAGE( "Port_Impl::Input returns false _InputPort " << _InputPort << " IsEditing "
172 << _DataFlowEditor->IsEditing() << " Executor " << _DataFlowEditor->Executor() ) ;
174 endService( "Port_Impl::Input" );
178 char * Port_Impl::Name() {
179 // beginService( "Port_Impl::Name" ) ;
180 const char * RetVal = _DataFlowPort->PortName() ;
181 // endService( "Port_Impl::Name" ) ;
182 return CORBA::string_dup( RetVal ) ;
185 char * Port_Impl::Type() {
186 // beginService( "Port_Impl::Type" ) ;
187 const char * RetVal = _DataFlowPort->PortType() ;
188 // endService( "Port_Impl::Type" ) ;
189 return CORBA::string_dup( RetVal ) ;
192 SUPERV::CNode_ptr Port_Impl::Node() {
194 SUPERV::CNode_var iobject ;
195 if ( _DataFlowNode ) {
196 MESSAGE( "Port_Impl::Node " << _DataFlowNode->Name() ) ;
197 iobject = SUPERV::CNode::_narrow( _DataFlowNode->ObjRef() ) ;
198 if ( CORBA::is_nil( iobject ) ) {
200 beginService( "Port_Impl::Node" ) ;
203 PortableServer::ObjectId * id ;
204 CORBA::Object_var obj ;
205 if ( _DataFlowNode->IsComputingNode() ) {
206 CNode_Impl * myNode = NULL ;
207 myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
208 instanceName() , interfaceName() ,
211 id = myNode->getId() ;
212 obj = _poa->id_to_reference(*id);
213 iobject = SUPERV::CNode::_narrow( obj ) ;
214 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
216 else if ( _DataFlowNode->IsFactoryNode() ) {
217 FNode_Impl * myNode = NULL ;
218 myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
219 instanceName() , interfaceName() ,
222 id = myNode->getId() ;
223 obj = _poa->id_to_reference(*id);
224 SUPERV::FNode_var Fiobject = SUPERV::FNode::_narrow( obj ) ;
225 iobject = SUPERV::CNode::_narrow( Fiobject ) ;
226 myNode->SetObjRef( SUPERV::FNode::_duplicate( Fiobject ) ) ;
228 else if ( _DataFlowNode->IsInLineNode() ) {
229 INode_Impl * myNode = NULL ;
230 myNode = new INode_Impl( _Orb , _Poa , _ContId ,
231 instanceName() , interfaceName() ,
234 id = myNode->getId() ;
235 obj = _poa->id_to_reference(*id);
236 SUPERV::INode_var Iiobject = SUPERV::INode::_narrow( obj ) ;
237 iobject = SUPERV::CNode::_narrow( Iiobject ) ;
238 myNode->SetObjRef( SUPERV::INode::_duplicate( Iiobject ) ) ;
240 else if ( _DataFlowNode->IsGOTONode() ) {
241 GNode_Impl * myNode = NULL ;
242 myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
243 instanceName() , interfaceName() ,
246 id = myNode->getId() ;
247 obj = _poa->id_to_reference(*id);
248 SUPERV::GNode_var Giobject = SUPERV::GNode::_narrow( obj ) ;
249 iobject = SUPERV::CNode::_narrow( Giobject ) ;
250 myNode->SetObjRef( SUPERV::GNode::_duplicate( Giobject ) ) ;
252 else if ( _DataFlowNode->IsLoopNode() ) {
253 LNode_Impl * myNode = NULL ;
254 myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
255 instanceName() , interfaceName() ,
258 id = myNode->getId() ;
259 obj = _poa->id_to_reference(*id);
260 SUPERV::LNode_var Liobject = SUPERV::LNode::_narrow( obj ) ;
261 iobject = SUPERV::CNode::_narrow( Liobject ) ;
262 myNode->SetObjRef( SUPERV::LNode::_duplicate( Liobject ) ) ;
264 else if ( _DataFlowNode->IsEndLoopNode() ) {
265 ELNode_Impl * myNode = NULL ;
266 myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
267 instanceName() , interfaceName() ,
270 id = myNode->getId() ;
271 obj = _poa->id_to_reference(*id);
272 SUPERV::ELNode_var ELiobject = SUPERV::ELNode::_narrow( obj ) ;
273 iobject = SUPERV::CNode::_narrow( ELiobject ) ;
274 myNode->SetObjRef( SUPERV::ELNode::_duplicate( ELiobject ) ) ;
276 else if ( _DataFlowNode->IsSwitchNode() ) {
277 SNode_Impl * myNode = NULL ;
278 myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
279 instanceName() , interfaceName() ,
282 id = myNode->getId() ;
283 obj = _poa->id_to_reference(*id);
284 SUPERV::SNode_var Siobject = SUPERV::SNode::_narrow( obj ) ;
285 iobject = SUPERV::CNode::_narrow( Siobject ) ;
286 myNode->SetObjRef( SUPERV::SNode::_duplicate( Siobject ) ) ;
288 else if ( _DataFlowNode->IsEndSwitchNode() ) {
289 ESNode_Impl * myNode = NULL ;
290 myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
291 instanceName() , interfaceName() ,
294 id = myNode->getId() ;
295 obj = _poa->id_to_reference(*id);
296 SUPERV::ESNode_var ESiobject = SUPERV::ESNode::_narrow( obj ) ;
297 iobject = SUPERV::CNode::_narrow( ESiobject ) ;
298 myNode->SetObjRef( SUPERV::ESNode::_duplicate( ESiobject ) ) ;
302 // MESSAGE( "Port_Impl::Node known objref " << iobject->Name() ) ;
306 MESSAGE( "Port_Impl::GraphNode " << _DataFlowEditor->Graph()->Name() ) ;
307 iobject = SUPERV::CNode::_narrow( _DataFlowEditor->Graph()->ObjRef() ) ;
308 if ( CORBA::is_nil( iobject ) ) {
309 MESSAGE( "Port_Impl::GraphNode NilRef" ) ;
313 endService( "Port_Impl::Node" ) ;
315 return SUPERV::CNode::_duplicate( iobject ) ;
318 SUPERV::ListOfLinks * Port_Impl::Links() {
319 beginService( "Port_Impl::Links" ) ;
320 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
321 RetVal = _DataFlowEditor->Graph()->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
322 _DataFlowPort->PortName() ) ;
323 MESSAGE( "Links of Node " << _DataFlowNode->ComputingNode()->Name()
324 << " and of Port " << _DataFlowPort->PortName()
325 << " _InputPort " << _InputPort ) ;
327 for ( i = 0 ; i < (int ) RetVal->length() ; i++ ) {
328 MESSAGE( "Link " << RetVal[i]->OutPort()->Node()->Name() << "("
329 << RetVal[i]->OutPort()->Name() << ") --> "
330 << RetVal[i]->InPort()->Node()->Name() << "("
331 << RetVal[i]->InPort()->Name() << ")" ) ;
333 endService( "Port_Impl::Links" ) ;
334 return ( RetVal._retn() ) ;
337 SUPERV::Link_ptr Port_Impl::Link() {
339 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
340 if ( _DataFlowNode->IsEndSwitchNode() ) {
341 beginService( "Port_Impl::Link" ) ;
343 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
344 // cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
345 // << _DataFlowPort->PortName() << endl ;
346 Links = _DataFlowEditor->Graph()->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
347 _DataFlowPort->PortName() ) ;
348 if ( Links->length() ) {
349 iobject = Links[ 0 ] ;
353 char * FromNodeName = NULL ;
354 char * FromServiceParameterName = NULL ;
355 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
356 _DataFlowPort->PortName() ,
358 & FromServiceParameterName ) ;
360 // cout << "Port_Impl::Link " << FromNodeName << "("
361 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
362 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
363 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
365 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
366 if ( anInPort->GetOutPort() ) {
367 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
368 if ( _DataFlowNode->IsEndLoopNode() && !strcmp( _DataFlowNode->CoupledNode()->Name() ,
369 anOutPort->NodeName() ) ) {
370 // MESSAGE( "Link " << anOutPort->NodeName() << "("
371 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
372 // << anInPort->PortName() << ")" << " ignored" ) ;
374 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
376 beginService( "Port_Impl::Link" ) ;
380 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
381 instanceName() , interfaceName() ,
384 _DataFlowPort->PortName() ,
385 (GraphEditor::InNode * ) _DataFlowEditor->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
386 FromServiceParameterName ,
387 false , true , Success ) ;
389 PortableServer::ObjectId * id = myLink->getId() ;
390 CORBA::Object_var obj = _poa->id_to_reference(*id);
391 iobject = SUPERV::Link::_narrow(obj) ;
392 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
396 iobject = anOutPort->InPortObjRef( anInPort ) ;
402 MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
403 << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
404 endService( "Port_Impl::Link" ) ;
406 return SUPERV::Link::_duplicate( iobject ) ;
409 bool Port_Impl::IsInput() {
410 // beginService( "Port_Impl::IsInput" ) ;
411 bool RetVal = _InputPort ;
412 // MESSAGE( Name() << "IsInput() " << _InputPort ) ;
413 // endService( "Port_Impl::IsInput" ) ;
417 bool Port_Impl::IsLinked() {
418 // beginService( "Port_Impl::IsLinked" ) ;
419 bool RetVal = false ;
420 if ( _DataFlowNode ) {
421 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
422 GraphBase::OutPort * anOutPort = NULL ;
424 anOutPort = anInPort->GetOutPort() ;
426 if ( _DataFlowNode->IsEndLoopNode() && anOutPort &&
427 !strcmp( _DataFlowNode->CoupledNode()->Name() , anOutPort->NodeName() ) ) {
428 // MESSAGE( "Link " << anOutPort->NodeName() << "("
429 // << anOutPort->PortName() << ") --> " << _DataFlowNode->Name() << "("
430 // << anInPort->PortName() << ")" << " ignored" ) ;
433 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
436 // endService( "Port_Impl::IsLinked" ) ;
440 SUPERV::KindOfPort Port_Impl::Kind() {
441 // beginService( "Port_Impl::Kind" ) ;
442 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
443 // endService( "Port_Impl::Kind" ) ;
447 void Port_Impl::SetKind( SUPERV::KindOfPort aKindOfPort ) {
448 // beginService( "Port_Impl::SetKind" ) ;
449 _DataFlowPort->Kind( aKindOfPort ) ;
450 // endService( "Port_Impl::SetKind" ) ;
453 bool Port_Impl::IsParam() {
454 // beginService( "Port_Impl::IsParam" ) ;
455 bool RetVal = _DataFlowPort->IsParam() ;
456 // endService( "Port_Impl::IsParam" ) ;
460 bool Port_Impl::IsGate() {
461 // beginService( "Port_Impl::IsGate" ) ;
462 bool RetVal = _DataFlowPort->IsGate() ;
463 // endService( "Port_Impl::IsGate" ) ;
467 bool Port_Impl::IsInLine() {
468 // beginService( "Port_Impl::IsInLine" ) ;
469 // bool RetVal = _DataFlowPort->IsBus() ;
470 bool RetVal = _DataFlowPort->IsInLine() ;
471 // endService( "Port_Impl::IsInLine" ) ;
475 bool Port_Impl::IsLoop() {
476 // beginService( "Port_Impl::IsLoop" ) ;
477 bool RetVal = _DataFlowPort->IsLoop() ;
478 // endService( "Port_Impl::IsLoop" ) ;
482 bool Port_Impl::IsSwitch() {
483 // beginService( "Port_Impl::IsSwitch" ) ;
484 bool RetVal = _DataFlowPort->IsSwitch() ;
485 // endService( "Port_Impl::IsSwitch" ) ;
489 bool Port_Impl::IsEndSwitch() {
490 // beginService( "Port_Impl::IsEndSwitch" ) ;
491 bool RetVal = _DataFlowPort->IsEndSwitch() ;
492 // endService( "Port_Impl::IsEndSwitch" ) ;
496 bool Port_Impl::IsDataStream() {
497 // beginService( "Port_Impl::IsDataStream" ) ;
498 bool RetVal = _DataFlowPort->IsDataStream() ;
499 // endService( "Port_Impl::IsDataStream" ) ;
503 bool Port_Impl::HasInput() {
504 // beginService( "Port_Impl::" ) ;
505 bool RetVal = false ;
506 if ( _DataFlowNode ) {
507 RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
508 // cout << "Port_Impl::HasInput " << RetVal << " NodeName " << _DataFlowPort->NodeName() << " PortName "
509 // << _DataFlowPort->PortName() << endl ;
511 // endService( "Port_Impl::" ) ;
515 SUPERV::GraphState Port_Impl::State() {
516 // beginService( "Port_Impl::State" );
517 SUPERV::GraphState RetVal = SUPERV::EditingState ;
518 if ( _DataFlowEditor ) {
519 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
520 if ( _DataFlowExecutor ) {
521 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
522 _DataFlowPort->PortName() ) ;
525 // endService( "Port_Impl::State" );
529 bool Port_Impl::IsDone() {
530 // beginService( "Port_Impl::IsDone" );
531 bool RetVal = false ;
532 if ( _DataFlowEditor ) {
533 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
534 if ( _DataFlowExecutor ) {
535 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
536 _DataFlowPort->PortName() ) ;
539 // endService( "Port_Impl::IsDone" );