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 : Graph_Impl.cxx
25 // Author : Jean Rahuel
35 //#include "utilities.h"
37 #include "Graph_Impl.hxx"
39 #include "DataFlowEditor_DataFlow.hxx"
41 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
43 Graph_Impl::Graph_Impl( CORBA::ORB_ptr orb ,
44 PortableServer::POA_ptr poa ,
45 PortableServer::ObjectId * contId ,
46 const char *instanceName ,
47 const char *interfaceName ,
48 const char *aDataFlowName ) :
49 INode_Impl(orb, poa, contId, instanceName, interfaceName, aDataFlowName) {
50 // MESSAGE("Graph_Impl::Graph_Impl activate object instanceName("
51 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
52 // << hex << (void *) this << dec )
53 beginService( "Graph_Impl::Graph_Impl" );
55 _id = _poa->activate_object(_thisObj);
56 _Orb = CORBA::ORB::_duplicate(orb);
60 string dbgfile = "/tmp/" ;
61 dbgfile += instanceName ;
63 int lenname = strlen( aDataFlowName ) ;
64 char * theDataFlowName = new char [ lenname+1 ] ;
65 strcpy( theDataFlowName , aDataFlowName ) ;
66 if ( aDataFlowName ) {
67 if ( lenname > 4 && !strcmp( &aDataFlowName[ lenname - 4 ] , ".xml" ) ) {
68 strncpy( theDataFlowName , &aDataFlowName[ 0 ] , lenname-4 ) ;
69 theDataFlowName[ lenname-4 ] = '\0' ;
71 for ( i = lenname - 5 ; i >= 0 ; i-- ) {
72 if ( aDataFlowName[ i ] == '/' ) {
73 strncpy( theDataFlowName , &aDataFlowName[ i + 1 ] , lenname-5-i ) ;
74 theDataFlowName[ lenname-5-i ] = '\0' ;
80 strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
82 dbgfile += theDataFlowName ;
85 _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
86 strcpy( _DebugFileName , dbgfile.c_str() ) ;
88 _NamingService = new SALOME_NamingService( orb ) ;
89 GraphEditor::DataFlow * aDataFlowEditor = new GraphEditor::DataFlow( _Orb , _NamingService ,
92 DataFlowEditor( aDataFlowEditor ) ;
93 DataFlowEditor()->SetObjImpl( this ) ;
94 pthread_mutex_init( &_MutexExecutorWait , NULL ) ;
95 _DataFlowExecutor = NULL ;
96 delete [] theDataFlowName ;
97 endService( "Graph_Impl::Graph_Impl" );
100 Graph_Impl::Graph_Impl() {
103 Graph_Impl::~Graph_Impl() {
104 beginService( "Graph_Impl::~Graph_Impl" );
105 endService( "Graph_Impl::~Graph_Impl" );
108 void Graph_Impl::destroy() {
109 beginService( "Graph_Impl::destroy" );
110 _poa->deactivate_object(*_id) ;
111 CORBA::release(_poa) ;
113 _thisObj->_remove_ref();
114 endService( "Graph_Impl::destroy" );
117 char* Graph_Impl::getIOR() {
118 if (CORBA::is_nil(myServant)) {
119 PortableServer::ObjectId* id = getId();
120 CORBA::Object_var obj;
121 obj = _poa->id_to_reference(*id);
122 myServant = SUPERV::Graph::_narrow(obj);
124 return(CORBA::string_dup(_Orb->object_to_string(myServant)));
127 SUPERV::Graph_ptr Graph_Impl::Copy() {
128 beginService( "Graph_Impl::Copy" );
129 Graph_Impl * myGraph ;
130 myGraph = new Graph_Impl( _Orb , _Poa, _ContId,
131 instanceName() , interfaceName() ,
133 PortableServer::ObjectId * id = myGraph->getId() ;
134 CORBA::Object_var obj = _poa->id_to_reference(*id);
135 SUPERV::Graph_var iobject ;
136 iobject = SUPERV::Graph::_narrow(obj) ;
137 // GraphBase::SGraph * aSGraph = aGraph->GetGraph() ;
138 GraphBase::SGraph * aSGraph = GetGraph() ;
139 myGraph->LoadGraph( aSGraph ) ;
140 endService( "Graph_Impl::Copy" );
141 return SUPERV::Graph::_duplicate(iobject) ;
144 void Graph_Impl::ReadOnly() {
145 DataFlowEditor()->ReadOnly() ;
148 SUPERV::INode_ptr Graph_Impl::Node() {
149 // beginService( "Graph_Impl::Node" );
150 PortableServer::ObjectId * id = getId() ;
151 CORBA::Object_var obj = _poa->id_to_reference(*id);
152 SUPERV::Graph_var iobject ;
153 iobject = SUPERV::Graph::_narrow(obj) ;
154 // endService( "Graph_Impl::Node" );
155 return SUPERV::Graph::_duplicate(iobject) ;
158 GraphBase::SGraph * Graph_Impl::GetGraph() {
159 return DataFlowEditor()->GetDataFlow() ;
163 char * Graph_Impl::DataFlowInfo() {
164 beginService( "Graph_Impl::DataFlowInfo" );
165 char * RetVal = DataFlowEditor()->DataFlowInfo() ;
166 endService( "Graph_Impl::DataFlowInfo" );
167 return CORBA::string_dup( RetVal ) ;
170 char * Graph_Impl::DataNodeInfo() {
171 beginService( "Graph_Impl::DataNodeInfo" );
172 char * RetVal = DataFlowEditor()->DataNodeInfo() ;
173 endService( "Graph_Impl::DataNodeInfo" );
174 return CORBA::string_dup( RetVal ) ;
177 char * Graph_Impl::NodeInfo( const char * aNodeName ) {
178 beginService( "Graph_Impl::NodeInfo" );
179 char * RetVal = DataFlowEditor()->NodeInfo( aNodeName ) ;
180 endService( "Graph_Impl::NodeInfo" );
181 return CORBA::string_dup( RetVal ) ;
185 bool Graph_Impl::LoadGraph(const GraphBase::SGraph * aDataFlow ) {
186 // beginService( "Graph_Impl::LoadGraph" );
187 bool RetVal = false ;
188 if ( DataFlowEditor()->IsEditing() ) {
189 RetVal = DataFlowEditor()->LoadDataFlow( aDataFlow ) ;
191 // endService( "Graph_Impl::LoadGraph" );
195 bool Graph_Impl::Import(const char * aXmlFile ) {
196 // beginService( "Graph_Impl::Import" );
197 bool RetVal = false ;
198 if ( DataFlowEditor()->IsEditing() ) {
199 RetVal = DataFlowEditor()->LoadXml( aXmlFile ) ;
201 // endService( "Graph_Impl::Import" );
205 bool Graph_Impl::Export(const char * anXmlFile ) {
206 // beginService( "Graph_Impl::Export" );
207 char * aFile = new char [ strlen( anXmlFile ) + 5 ] ;
208 strcpy( aFile , anXmlFile ) ;
209 int len = strlen( aFile ) ;
210 if ( !strcmp( &aFile[ len - 4 ] , ".xml" ) ) {
212 else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
213 strcpy( &aFile[ len - 3 ] , ".xml" ) ;
214 len = strlen( aFile ) ;
217 strcat( aFile , ".xml" ) ;
218 len = strlen( aFile ) ;
220 bool RetVal = DataFlowEditor()->SaveXml( aFile ) ;
222 strcpy( &aFile[ len - 4 ] , ".py" ) ;
223 RetVal = DataFlowEditor()->SavePy( aFile ) ;
226 // endService( "Graph_Impl::Export" );
231 GraphBase::ListOfNodes * Graph_Impl::GetNodes() {
232 // beginService( "Graph_Impl::GetNodes" );
233 GraphBase::ListOfNodes * RetVal = DataFlowEditor()->GetNodes() ;
234 // endService( "Graph_Impl::GetNodes" );
237 GraphBase::ListOfLinks * Graph_Impl::GetLinks() {
238 // beginService( "Graph_Impl::GetLinks" );
239 GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetLinks() ;
240 // endService( "Graph_Impl::GetLinks" );
243 GraphBase::ListOfLinks * Graph_Impl::GetDatas() {
244 // beginService( "Graph_Impl::GetDatas" );
245 GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetDatas() ;
246 // endService( "Graph_Impl::GetDatas" );
251 SUPERV::CNode_ptr Graph_Impl::CNode( const SALOME_ModuleCatalog::Service &NodeService ) {
252 beginService( "Graph_Impl::CNode" );
253 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
254 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
255 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
256 instanceName() , interfaceName() ,
258 NodeService , NULLSTRING ,
259 SUPERV::ComputingNode , NULLSTRING ) ;
260 if ( myNode->DataFlowNode() ) {
261 PortableServer::ObjectId * id = myNode->getId() ;
262 CORBA::Object_var obj = _poa->id_to_reference(*id);
263 iobject = SUPERV::CNode::_narrow(obj) ;
264 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
267 endService( "Graph_Impl::CNode" );
268 return SUPERV::CNode::_duplicate( iobject ) ;
271 SUPERV::FNode_ptr Graph_Impl::FNode( const char * NodeComponentName ,
272 const char * NodeInterfaceName ,
273 const SALOME_ModuleCatalog::Service &NodeService ) {
274 beginService( "Graph_Impl::FNode" );
275 SUPERV::FNode_var iobject = SUPERV::FNode::_nil() ;
276 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
277 FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
278 instanceName() , interfaceName() ,
282 NodeInterfaceName ) ;
283 if ( myNode->DataFlowNode() ) {
284 PortableServer::ObjectId * id = myNode->getId() ;
285 CORBA::Object_var obj = _poa->id_to_reference(*id);
286 iobject = SUPERV::FNode::_narrow(obj) ;
287 myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
290 endService( "Graph_Impl::FNode" );
291 return SUPERV::FNode::_duplicate( iobject ) ;
294 SUPERV::INode_ptr Graph_Impl::INode( const char * FuncName ,
295 const SUPERV::ListOfStrings & PythonFuntion ) {
296 beginService( "Graph_Impl::INode" );
297 SUPERV::INode_var iobject = SUPERV::INode::_nil() ;
298 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
299 INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
300 instanceName() , interfaceName() ,
302 FuncName , PythonFuntion ,
303 SUPERV::InLineNode ) ;
304 if ( myNode->DataFlowNode() ) {
305 PortableServer::ObjectId * id = myNode->getId() ;
306 CORBA::Object_var obj = _poa->id_to_reference(*id);
307 iobject = SUPERV::INode::_narrow(obj) ;
308 myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
311 endService( "Graph_Impl::INode" );
312 return SUPERV::INode::_duplicate( iobject ) ;
316 SUPERV::GNode_ptr Graph_Impl::GNode( const char * FuncName ,
317 const SUPERV::ListOfStrings & PythonFuntion ,
318 const char * anInLineNode ) {
319 beginService( "Graph_Impl::GNode" );
320 SUPERV::GNode_var iobject = SUPERV::GNode::_nil() ;
321 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
322 GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
323 instanceName() , interfaceName() ,
325 FuncName , PythonFuntion ,
327 if ( myNode->DataFlowNode() ) {
328 PortableServer::ObjectId * id = myNode->getId() ;
329 CORBA::Object_var obj = _poa->id_to_reference(*id);
330 iobject = SUPERV::GNode::_narrow(obj) ;
331 myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
332 if ( strlen( anInLineNode ) ) {
333 GraphBase::InLineNode * CoupledINode = (GraphBase::InLineNode * ) DataFlowEditor()->GetGraphNode( anInLineNode ) ;
334 if ( anInLineNode ) {
335 myNode->SetCoupled( anInLineNode ) ;
336 Link( myNode->Port( "OutGate" ) , CoupledINode->ObjRef()->Port( "InGate" ) ) ;
341 endService( "Graph_Impl::GNode" );
342 return SUPERV::GNode::_duplicate( iobject ) ;
345 SUPERV::LNode_ptr Graph_Impl::LNode( const char * InitName ,
346 const SUPERV::ListOfStrings & InitFunction ,
347 const char * MoreName ,
348 const SUPERV::ListOfStrings & MoreFunction ,
349 const char * NextName ,
350 const SUPERV::ListOfStrings & NextFunction ,
351 SUPERV::INode_out anEndOfLoop ) {
352 beginService( "Graph_Impl::LNode" );
353 SUPERV::LNode_var iobject = SUPERV::LNode::_nil() ;
354 SUPERV::ELNode_var iendobject = SUPERV::ELNode::_nil() ;
355 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
356 GraphBase::ListOfFuncName FuncNameList ;
357 FuncNameList.resize(3) ;
358 FuncNameList[0] = InitName ;
359 FuncNameList[1] = MoreName ;
360 FuncNameList[2] = NextName ;
361 GraphBase::ListOfPythonFunctions PythonFunctionList ;
362 PythonFunctionList.resize(3) ;
363 PythonFunctionList[0] = &InitFunction ;
364 PythonFunctionList[1] = &MoreFunction ;
365 PythonFunctionList[2] = &NextFunction ;
366 LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
367 instanceName() , interfaceName() ,
369 FuncNameList , PythonFunctionList ,
370 // InitName , InitFunction ,
371 // MoreName , MoreFunction ,
372 // NextName , NextFunction ,
374 if ( myNode->DataFlowNode() ) {
375 PortableServer::ObjectId * id = myNode->getId() ;
376 CORBA::Object_var obj = _poa->id_to_reference(*id);
377 iobject = SUPERV::LNode::_narrow(obj) ;
378 myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
380 SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
382 if ( strlen( InitName ) ) {
383 anEndName = new char( 3 + strlen( InitName ) + 1 ) ;
384 strcpy( anEndName , "End" ) ;
385 strcat( anEndName , InitName ) ;
388 anEndName = new char( 3 + strlen( "Loop" ) + 1 ) ;
389 strcpy( anEndName , "EndLoop" ) ;
391 ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
392 instanceName() , interfaceName() ,
395 SUPERV::EndLoopNode ) ;
396 PortableServer::ObjectId * endid = myEndNode->getId() ;
397 CORBA::Object_var endobj = _poa->id_to_reference(*endid);
398 iendobject = SUPERV::ELNode::_narrow(endobj) ;
399 myEndNode->SetObjRef( SUPERV::ELNode::_duplicate( iendobject ) ) ;
400 myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
401 myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
402 Link( myNode->Port( "DoLoop" ) , myEndNode->Port( "DoLoop" ) ) ;
403 Link( myEndNode->Port( "DoLoop" ) , myNode->Port( "InitLoop" ) ) ;
406 anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
407 endService( "Graph_Impl::LNode" );
408 return SUPERV::LNode::_duplicate( iobject ) ;
411 SUPERV::SNode_ptr Graph_Impl::SNode( const char * FuncName ,
412 const SUPERV::ListOfStrings & PythonFunction ,
413 SUPERV::INode_out anEndOfSwitch ) {
414 beginService( "Graph_Impl::SNode" );
415 SUPERV::SNode_var iobject = SUPERV::SNode::_nil() ;
416 SUPERV::ESNode_var iendobject = SUPERV::ESNode::_nil() ;
417 if ( DataFlowEditor()->IsEditing() && !DataFlowEditor()->IsReadOnly() ) {
418 SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
419 instanceName() , interfaceName() ,
421 FuncName , PythonFunction ,
422 SUPERV::SwitchNode ) ;
423 if ( myNode->DataFlowNode() ) {
424 PortableServer::ObjectId * id = myNode->getId() ;
425 CORBA::Object_var obj = _poa->id_to_reference(*id);
426 iobject = SUPERV::SNode::_narrow(obj) ;
427 myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
429 string anEndName = "End" ;
430 if ( strlen( FuncName ) ) {
431 anEndName += FuncName ;
434 anEndName += "Switch" ;
436 // cout << "Graph_Impl::SNode anEndName " << (void *) FuncName << " " << FuncName
437 // << " " << strlen(FuncName) << " " << (void *) anEndName.c_str() << " "
438 // << anEndName.c_str() << endl ;
439 ESNode_Impl * myEndNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
440 instanceName() , interfaceName() ,
443 SUPERV::EndSwitchNode ) ;
444 // cout << "Graph_Impl::SNode returned anEndName " << (void *) FuncName << " "
445 // << FuncName << " " << strlen(FuncName) << " " << (void *) anEndName.c_str()
446 // << " " << anEndName.c_str() << endl ;
447 PortableServer::ObjectId * endid = myEndNode->getId() ;
448 CORBA::Object_var endobj = _poa->id_to_reference(*endid);
449 iendobject = SUPERV::ESNode::_narrow(endobj) ;
450 myEndNode->SetObjRef( SUPERV::ESNode::_duplicate( iendobject ) ) ;
451 myNode->SetCoupled( myEndNode->BaseNode()->Name() ) ;
452 myEndNode->SetCoupled( myNode->BaseNode()->Name() ) ;
453 if ( !Link( myNode->Port( "Default" ) , myEndNode->Port( "Default" ) ) ) {
454 iobject = SUPERV::SNode::_nil() ;
455 iendobject = SUPERV::ESNode::_nil() ;
459 anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
460 endService( "Graph_Impl::SNode" );
461 return SUPERV::SNode::_duplicate( iobject ) ;
465 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
466 // beginService( "Graph_Impl::Node" );
467 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
469 if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
470 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
471 instanceName() , interfaceName() ,
473 DataFlowEditor()->GetNode( aNodeName ) ) ;
474 PortableServer::ObjectId * id = myNode->getId() ;
475 CORBA::Object_var obj = _poa->id_to_reference(*id);
476 iobject = SUPERV::CNode::_narrow(obj) ;
477 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
480 iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
482 GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
484 if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
485 SetNodeObjRef( anInNode ) ;
487 iobject = anInNode->ObjRef() ;
489 // endService( "Graph_Impl::Node" );
490 return SUPERV::CNode::_duplicate( iobject ) ;
493 SUPERV::Link_ptr Graph_Impl::Link( SUPERV::Port_ptr OutPort ,
494 SUPERV::Port_ptr InPort ) {
495 beginService( "Graph_Impl::Link" );
496 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
497 if ( DataFlowEditor()->IsEditing() &&
498 !DataFlowEditor()->IsReadOnly() ) {
499 const char * DataFlowOutNodeName = OutPort->Node()->Name() ;
500 GraphEditor::InNode * DataFlowOutNode = DataFlowEditor()->GetNode( DataFlowOutNodeName ) ;
501 const char * DataFlowInNodeName = InPort->Node()->Name() ;
502 GraphEditor::InNode * DataFlowInNode = DataFlowEditor()->GetNode( DataFlowInNodeName ) ;
503 if ( DataFlowOutNode && DataFlowInNode ) {
504 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
505 instanceName() , interfaceName() ,
512 PortableServer::ObjectId * id = myLink->getId() ;
513 CORBA::Object_var obj = _poa->id_to_reference(*id);
514 iobject = SUPERV::Link::_narrow(obj) ;
515 // iobject = InPort->Link() ;
518 endService( "Graph_Impl::Link" );
519 return SUPERV::Link::_duplicate( iobject ) ;
522 void Graph_Impl::SetNodeObjRef( GraphEditor::InNode * anInNode ) {
523 CORBA::Object_var obj ;
524 if ( anInNode->IsComputingNode() ) {
525 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
526 instanceName() , interfaceName() ,
529 PortableServer::ObjectId * id = myNode->getId() ;
530 obj = _poa->id_to_reference(*id);
531 SUPERV::CNode_var iobject = SUPERV::CNode::_narrow(obj) ;
532 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
534 else if ( anInNode->IsFactoryNode() ) {
535 FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
536 instanceName() , interfaceName() ,
539 PortableServer::ObjectId * id = myNode->getId() ;
540 obj = _poa->id_to_reference(*id);
541 SUPERV::FNode_var iobject = SUPERV::FNode::_narrow(obj) ;
542 myNode->SetObjRef( SUPERV::FNode::_duplicate( iobject ) ) ;
544 else if ( anInNode->IsInLineNode() ) {
545 INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
546 instanceName() , interfaceName() ,
549 PortableServer::ObjectId * id = myNode->getId() ;
550 obj = _poa->id_to_reference(*id);
551 SUPERV::INode_var iobject = SUPERV::INode::_narrow(obj) ;
552 myNode->SetObjRef( SUPERV::INode::_duplicate( iobject ) ) ;
554 else if ( anInNode->IsGOTONode() ) {
555 GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
556 instanceName() , interfaceName() ,
559 PortableServer::ObjectId * id = myNode->getId() ;
560 obj = _poa->id_to_reference(*id);
561 SUPERV::GNode_var iobject = SUPERV::GNode::_narrow(obj) ;
562 myNode->SetObjRef( SUPERV::GNode::_duplicate( iobject ) ) ;
564 else if ( anInNode->IsLoopNode() ) {
565 LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
566 instanceName() , interfaceName() ,
569 PortableServer::ObjectId * id = myNode->getId() ;
570 obj = _poa->id_to_reference(*id);
571 SUPERV::LNode_var iobject = SUPERV::LNode::_narrow(obj) ;
572 myNode->SetObjRef( SUPERV::LNode::_duplicate( iobject ) ) ;
574 else if ( anInNode->IsEndLoopNode() ) {
575 ELNode_Impl * myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
576 instanceName() , interfaceName() ,
579 PortableServer::ObjectId * id = myNode->getId() ;
580 obj = _poa->id_to_reference(*id);
581 SUPERV::ELNode_var iobject = SUPERV::ELNode::_narrow(obj) ;
582 myNode->SetObjRef( SUPERV::ELNode::_duplicate( iobject ) ) ;
584 else if ( anInNode->IsSwitchNode() ) {
585 SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
586 instanceName() , interfaceName() ,
589 PortableServer::ObjectId * id = myNode->getId() ;
590 obj = _poa->id_to_reference(*id);
591 SUPERV::SNode_var iobject = SUPERV::SNode::_narrow(obj) ;
592 myNode->SetObjRef( SUPERV::SNode::_duplicate( iobject ) ) ;
594 else if ( anInNode->IsEndSwitchNode() ) {
595 ESNode_Impl * myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
596 instanceName() , interfaceName() ,
599 PortableServer::ObjectId * id = myNode->getId() ;
600 obj = _poa->id_to_reference(*id);
601 SUPERV::ESNode_var iobject = SUPERV::ESNode::_narrow(obj) ;
602 myNode->SetObjRef( SUPERV::ESNode::_duplicate( iobject ) ) ;
606 SUPERV::ListOfNodes_var Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
607 GraphBase::ComputingNode * aNode ) {
609 // MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
610 // if ( _DataFlowExecutor ) {
611 // MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() << " "
612 // << _DataFlowExecutor->StateName( _DataFlowExecutor->AutomatonState( aNode->Name() ) ) ) ;
615 // MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
617 if ( aNode->IsComputingNode() ) {
618 index = RetVal->CNodes.length() ;
619 RetVal->CNodes.length( index+1 );
621 else if ( aNode->IsFactoryNode() ) {
622 index = RetVal->FNodes.length() ;
623 RetVal->FNodes.length( index+1 );
625 else if ( aNode->IsInLineNode() ) {
626 index = RetVal->INodes.length() ;
627 RetVal->INodes.length( index+1 );
629 else if ( aNode->IsGOTONode() ) {
630 index = RetVal->GNodes.length() ;
631 RetVal->GNodes.length( index+1 );
633 else if ( aNode->IsLoopNode() ) {
634 index = RetVal->LNodes.length() ;
635 RetVal->LNodes.length( index+1 );
637 else if ( aNode->IsEndLoopNode() ) {
638 index = RetVal->ELNodes.length() ;
639 RetVal->ELNodes.length( index+1 );
641 else if ( aNode->IsSwitchNode() ) {
642 index = RetVal->SNodes.length() ;
643 RetVal->SNodes.length( index+1 );
645 else if ( aNode->IsEndSwitchNode() ) {
646 index = RetVal->ESNodes.length() ;
647 RetVal->ESNodes.length( index+1 );
649 if ( CORBA::is_nil( aNode->ObjRef() ) ) {
650 SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
652 SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
653 if ( aNode->IsComputingNode() ) {
654 RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
656 else if ( aNode->IsFactoryNode() ) {
657 RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
659 else if ( aNode->IsInLineNode() ) {
660 RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
662 else if ( aNode->IsGOTONode() ) {
663 RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
665 else if ( aNode->IsLoopNode() ) {
666 RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
668 else if ( aNode->IsEndLoopNode() ) {
669 RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
671 else if ( aNode->IsSwitchNode() ) {
672 RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
674 else if ( aNode->IsEndSwitchNode() ) {
675 RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
677 return ( RetVal._retn() ) ;
680 SUPERV::ListOfNodes * Graph_Impl::Nodes() {
681 SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
682 beginService( "Graph_Impl::Nodes" );
683 RetVal->CNodes.length(0) ;
684 RetVal->FNodes.length(0) ;
685 RetVal->INodes.length(0) ;
686 RetVal->LNodes.length(0) ;
687 RetVal->SNodes.length(0) ;
688 RetVal->GNodes.length(0) ;
690 for ( i = 0 ; i < DataFlowEditor()->GraphNodesSize() ; i++ ) {
691 GraphBase::ComputingNode * aNode = DataFlowEditor()->GraphNodes( i ) ;
692 RetVal = SetNode( RetVal , aNode ) ;
694 char * aStateG = "" ;
695 if ( _DataFlowExecutor ) {
696 aStateG = (char *) _DataFlowExecutor->StateName( _DataFlowExecutor->AutomatonState() ) ;
698 // MESSAGE("Graph_Impl::Nodes GraphState " << aStateG
699 // << " CNodes " << RetVal->CNodes.length()
700 // << " FNodes " << RetVal->FNodes.length()
701 // << " INodes " << RetVal->INodes.length()
702 // << " GNodes " << RetVal->GNodes.length()
703 // << " LNodes " << RetVal->LNodes.length()
704 // << " ELNodes " << RetVal->ELNodes.length()
705 // << " SNodes " << RetVal->SNodes.length()
706 // << " ESNodes " << RetVal->ESNodes.length() ) ;
707 // if ( _DataFlowExecutor ) {
708 // _DataFlowExecutor->EventList() ;
710 endService( "Graph_Impl::Nodes" );
711 return ( RetVal._retn() ) ;
714 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
715 return Links( NULL , NULL ) ;
718 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
719 const char * anInputParam ) {
721 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
722 int i , j , countlink ;
724 for ( i = 0 ; i < DataFlowEditor()->GraphNodesSize() ; i++ ) {
725 GraphEditor::InNode * aNode = NULL ;
726 aNode = (GraphEditor::InNode * ) DataFlowEditor()->GraphNodes( i )->GetInNode() ;
727 bool ToProcess = false ;
728 if ( theNode == NULL ) {
732 if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
733 if ( !theNode->IsEndSwitchNode() ) {
737 else if ( theNode->IsEndSwitchNode() ) {
742 for ( j = 0 ; j < aNode->GetNodeInPortsSize() ; j++ ) {
743 GraphBase::InPort * anInPort = NULL ;
744 anInPort = aNode->GetChangeNodeInPort( j ) ;
745 if ( anInputParam == NULL ||
746 !strcmp( anInPort->PortName() , anInputParam ) ) {
747 if ( anInPort->GetOutPort() ) {
748 GraphBase::OutPort * anOutPort = NULL ;
749 anOutPort = anInPort->GetOutPort() ;
750 if ( strcmp( anOutPort->NodeName() , Name() ) ) {
751 // MESSAGE("Graph_Impl::Links " << anOutPort->NodeName() << "("
752 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
753 // << anInPort->PortName() << ")" ) ;
754 if ( theNode == NULL ||
755 ( theNode != NULL && theNode->IsEndSwitchNode() &&
756 !strcmp( theNode->Name() , aNode->Name() ) ) ) {
757 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
758 ( aNode->IsEndLoopNode() && !strcmp( aNode->CoupledNode()->Name() ,
759 anOutPort->NodeName() ) ) ) {
760 // MESSAGE( "Link " << anOutPort->NodeName() << "("
761 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
762 // << anInPort->PortName() << ")" << " ignored" ) ;
764 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
766 beginService( "Graph_Impl::Links" );
769 GraphEditor::InNode * anOutNode = NULL ;
770 anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
772 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
773 instanceName() , interfaceName() ,
776 anInPort->PortName() ,
778 anOutPort->PortName() ,
780 PortableServer::ObjectId * id = myLink->getId() ;
781 CORBA::Object_var obj = _poa->id_to_reference(*id);
782 SUPERV::Link_var iobject ;
783 iobject = SUPERV::Link::_narrow(obj) ;
784 RetVal->length( countlink + 1 ) ;
785 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
786 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
790 RetVal->length( countlink + 1 ) ;
791 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
799 for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
800 GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
802 for ( k = 0 ; k < anOutPort->InPortsSize() ; k++ ) {
803 GraphBase::InPort * anInPort = anOutPort->ChangeInPorts( k ) ;
804 GraphEditor::InNode * toNode = (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( anInPort->NodeName() )->GetInNode() ;
805 if ( theNode == NULL ||
806 !strcmp( theNode->Name() , toNode->Name() ) ||
807 !strcmp( theNode->Name() , aNode->Name() ) ) {
808 if ( theNode || ( toNode->IsEndSwitchNode() && !aNode->IsSwitchNode() ) ) {
809 if ( anInputParam == NULL ||
810 !strcmp( anInPort->PortName() , anInputParam ) ) {
811 if ( anInPort->IsLoop() || anOutPort->IsLoop() ||
812 ( toNode->IsEndLoopNode() && !strcmp( toNode->CoupledNode()->Name() ,
813 anOutPort->NodeName() ) ) ) {
814 // MESSAGE( "Link " << anOutPort->NodeName() << "("
815 // << anOutPort->PortName() << ") --> " << aNode->Name() << "("
816 // << anInPort->PortName() << ")" << " ignored" ) ;
818 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
820 beginService( "Graph_Impl::Links" );
823 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
824 instanceName() , interfaceName() ,
827 anInPort->PortName() ,
829 anOutPort->PortName() ,
831 PortableServer::ObjectId * id = myLink->getId() ;
832 CORBA::Object_var obj = _poa->id_to_reference(*id);
833 SUPERV::Link_var iobject ;
834 iobject = SUPERV::Link::_narrow(obj) ;
835 RetVal->length( countlink + 1 ) ;
836 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( iobject ) ;
837 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
840 RetVal->length( countlink + 1 ) ;
841 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
850 endService( "Graph_Impl::Links" );
852 return ( RetVal._retn() ) ;
855 SUPERV::ListOfGraphs * Graph_Impl::Graphs() {
856 // beginService( "Graph_Impl::ListOfGraphs" );
857 SUPERV::ListOfGraphs_var RetVal = new SUPERV::ListOfGraphs ;
858 MESSAGE( "Graph_Impl::Graphs not yet implemented" );
859 // endService( "Graph_Impl::ListOfGraphs" );
860 return ( RetVal._retn() ) ;
863 Engines::Component_ptr Graph_Impl::ComponentRef( const char * aComputerContainer ,
864 const char * aComponentName ) {
865 Engines::Container_var myContainer ;
866 Engines::Component_var objComponent ;
867 DataFlowEditor()->StartComponent( 0 , aComputerContainer , aComponentName ,
868 myContainer , objComponent ) ;
869 return Engines::Component::_duplicate( objComponent ) ;
872 bool Graph_Impl::IsValid() {
873 // beginService( "Graph_Impl::IsValid" );
874 bool RetVal = DataFlowEditor()->IsValid() ;
875 // endService( "Graph_Impl::IsValid" );
878 bool Graph_Impl::IsExecutable() {
879 // beginService( "Graph_Impl::IsExecutable" );
880 bool RetVal = DataFlowEditor()->IsExecutable() ;
881 // endService( "Graph_Impl::IsExecutable" );
884 bool Graph_Impl::IsDataFlow() {
885 // beginService( "Graph_Impl::IsDataFlow" );
886 bool RetVal = false ; // = DataFlowEditor()->IsDataFlow() ;
887 // endService( "Graph_Impl::IsDataFlow" );
891 bool Graph_Impl::IsEditing() {
892 // beginService( "Graph_Impl::IsEditing" );
893 bool RetVal = DataFlowEditor()->IsEditing() ;
894 // endService( "Graph_Impl::IsEditing" );
897 bool Graph_Impl::IsExecuting() {
898 // beginService( "Graph_Impl::IsExecuting" );
899 bool RetVal = !DataFlowEditor()->IsEditing() ;
900 // endService( "Graph_Impl::IsExecuting" );
904 bool Graph_Impl::IsReadOnly() {
905 // beginService( "Graph_Impl::IsExecuting" );
906 bool RetVal = DataFlowEditor()->IsReadOnly() ;
907 // endService( "Graph_Impl::IsExecuting" );
911 long Graph_Impl::LevelMax() {
912 // beginService( "Graph_Impl::LevelMax" );
913 long RetVal = DataFlowEditor()->LevelMax() ;
914 // endService( "Graph_Impl::LevelMax" );
917 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
918 // beginService( "Graph_Impl::LevelNodes" );
919 SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
921 SUPERV::ListOfStrings_var Nodes = DataFlowEditor()->LevelNodes( aLevel ) ;
922 // RetVal->length( Nodes->length() );
923 for ( i = 0 ; i < (int ) Nodes->length() ; i++ ) {
924 // char * aNode = Nodes[ i ] ;
925 GraphBase::ComputingNode * aNode = DataFlowEditor()->GetChangeGraphNode( Nodes[ i ] ) ;
926 RetVal = SetNode( RetVal , aNode ) ;
927 // cout << "Graph_Impl::LevelNodes( " << aLevel << " ) " << aNode->Name() << endl ;
928 // CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
929 // instanceName() , interfaceName() ,
930 // DataFlowEditor() ,
931 // (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( aNode )->GetInNode() ) ;
932 // PortableServer::ObjectId * id = myNode->getId() ;
933 // CORBA::Object_var obj = _poa->id_to_reference(*id);
934 // SUPERV::CNode_var iobject ;
935 // iobject = SUPERV::CNode::_narrow(obj) ;
936 // RetVal[i] = SUPERV::CNode::_duplicate( iobject ) ;
938 // endService( "Graph_Impl::LevelNodes" );
939 return ( RetVal._retn() ) ;
941 long Graph_Impl::ThreadsMax() {
942 // beginService( "Graph_Impl::ThreadsMax" );
943 long RetVal = DataFlowEditor()->ThreadsMax() ;
944 // endService( "Graph_Impl::ThreadsMax" );
947 long Graph_Impl::GraphsNumber() {
948 // beginService( "Graph_Impl::GraphsNumber" );
949 long RetVal = DataFlowEditor()->GraphsNumber() ;
950 // endService( "Graph_Impl::GraphsNumber" );
953 long Graph_Impl::Threads() {
954 // beginService( "Node_Impl::Threads" );
955 long RetVal = _DataFlowExecutor->Threads() ;
956 // endService( "Node_Impl::Threads" );
959 long Graph_Impl::SuspendedThreads() {
960 // beginService( "Node_Impl::SuspendedThreads" );
961 long RetVal = _DataFlowExecutor->SuspendedThreads() ;
962 // endService( "Node_Impl::SuspendedThreads" );
966 bool Graph_Impl::Begin() {
967 bool RetVal = false ;
968 if ( DataFlowEditor()->IsEditing() ) {
969 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
970 perror("pthread_mutex_lock _MutexExecutorWait") ;
973 if ( _DataFlowExecutor ) {
974 MESSAGE( "Graph_Impl::Begin " << _DataFlowExecutor->Threads() << " threads" )
975 if ( _DataFlowExecutor->Threads() ) {
976 _DataFlowExecutor->JoinedWait() ;
978 delete _DataFlowExecutor ;
979 _DataFlowExecutor = NULL ;
980 DataFlowEditor()->Executor( NULL ) ;
982 DataFlowEditor()->EditedAfterExecution( false ) ;
983 int _ExecNumber = theAutomaton->ExecNumber() ;
984 char ExecNumber[30] ;
985 sprintf( ExecNumber , "_%d" , _ExecNumber ) ;
986 int len = strlen( _DebugFileName ) ;
987 char * DebugFileName = new char [ len + strlen( ExecNumber ) + 6 ] ;
988 strncpy( DebugFileName , _DebugFileName , len - 4 ) ;
989 DebugFileName[ len - 4 ] = '\0' ;
990 strcat( DebugFileName , ExecNumber ) ;
991 strcat( DebugFileName , "_Exec.log" ) ;
992 GraphBase::SGraph * myGraph = DataFlowEditor()->GetDataFlow() ;
993 _DataFlowExecutor = new GraphExecutor::DataFlow( _Orb , _NamingService ,
994 myGraph->Info.theName.c_str() ,
996 MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
997 RetVal = _DataFlowExecutor->LoadDataFlow( *myGraph ) ;
999 DataFlowEditor()->Executor( _DataFlowExecutor ) ;
1001 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1002 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1008 bool Graph_Impl::Run() {
1009 beginService( "Graph_Impl::Run" );
1010 bool RetVal = false ;
1011 if ( DataFlowEditor()->IsEditing() ) {
1012 MESSAGE( "Graph_Impl::Run IsEditing" );
1015 MESSAGE( "Graph_Impl::(Re)Run " );
1016 RetVal = CNode_Impl::Run() ;
1020 MESSAGE( "Graph_Impl::(Re)Run " );
1021 RetVal = CNode_Impl::ReRun() ;
1023 endService( "Graph_Impl::Run" );
1026 bool Graph_Impl::Start() {
1027 beginService( "Graph_Impl::Start" );
1028 bool RetVal = false ;
1029 if ( DataFlowEditor()->IsEditing() ) {
1030 MESSAGE( "Graph_Impl::Start IsEditing" );
1037 MESSAGE( "Graph_Impl::(Re)Start " );
1038 RetVal = ReStart() ;
1040 endService( "Graph_Impl::Start" );
1044 bool Graph_Impl::EventNoW( SUPERV::CNode_out aNode ,
1045 SUPERV::GraphEvent & anEvent ,
1046 SUPERV::GraphState & aState ) {
1047 bool RetVal = false ;
1048 char * aNodeName = NULL ;
1049 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1050 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1051 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1052 perror("pthread_mutex_lock _MutexExecutorWait") ;
1055 if ( _DataFlowExecutor &&
1056 ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1057 RetVal = _DataFlowExecutor->Event( & aNodeName , theEvent , theState , false ) ;
1058 // endService( "Graph_Impl::Event" );
1059 if ( strlen( aNodeName ) ) {
1060 if ( strcmp( aNodeName , Name() ) ) {
1061 aNode = Node( aNodeName ) ;
1068 aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1070 // cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1073 // cout << "Graph_Impl::EventNoW NO DataFlowExecutor or QSize=0 " << endl ;
1075 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1076 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1079 anEvent = theEvent ;
1084 bool Graph_Impl::Event( SUPERV::CNode_out aNode ,
1085 SUPERV::GraphEvent & anEvent ,
1086 SUPERV::GraphState & aState ) {
1087 // beginService( "Graph_Impl::Event" );
1088 bool RetVal = false ;
1089 char * aNodeName = NULL ;
1090 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1091 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1092 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1093 perror("pthread_mutex_lock _MutexExecutorWait") ;
1096 if ( _DataFlowExecutor &&
1097 ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ){
1098 RetVal = _DataFlowExecutor->Event( & aNodeName , theEvent , theState ) ;
1099 // endService( "Graph_Impl::Event" );
1100 if ( strlen( aNodeName ) ) {
1101 if ( strcmp( aNodeName , Name() ) ) {
1102 aNode = Node( aNodeName ) ;
1109 aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1111 // cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1114 // cout << "Graph_Impl::Event NO DataFlowExecutor or QSize=0 " << endl ;
1116 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1117 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1120 anEvent = theEvent ;
1125 bool Graph_Impl::EventW( SUPERV::CNode_out aNode ,
1126 SUPERV::GraphEvent & anEvent ,
1127 SUPERV::GraphState & aState ) {
1128 // beginService( "Graph_Impl::EventW" );
1129 bool RetVal = false ;
1130 char * aNodeName = NULL ;
1131 SUPERV::GraphEvent theEvent = SUPERV::UndefinedEvent ;
1132 SUPERV::GraphState theState = SUPERV::UndefinedState ;
1133 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1134 perror("pthread_mutex_lock _MutexExecutorWait") ;
1137 if ( _DataFlowExecutor &&
1138 ( _DataFlowExecutor->GetListSize() || !DataFlowEditor()->IsEditing() ) ) {
1139 RetVal = _DataFlowExecutor->EventW( & aNodeName , theEvent , theState ) ;
1140 if ( RetVal && strcmp( aNodeName , Name() ) ) {
1141 aNode = Node( aNodeName ) ;
1147 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1148 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1151 anEvent = theEvent ;
1153 // endService( "Graph_Impl::EventW" );
1157 long Graph_Impl::EventQSize() {
1158 // beginService( "Graph_Impl::EventQSize" );
1160 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1161 perror("pthread_mutex_lock _MutexExecutorWait") ;
1164 if ( _DataFlowExecutor ) {
1165 QSize = _DataFlowExecutor->EventQSize() ;
1167 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1168 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1171 // endService( "Graph_Impl::EventQSize" );
1175 long Graph_Impl::LastLevelDone() {
1176 // beginService( "Graph_Impl::LastLevelDone" );
1177 if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1178 perror("pthread_mutex_lock _MutexExecutorWait") ;
1182 if ( _DataFlowExecutor ) {
1183 RetVal = _DataFlowExecutor->LastLevelDone() ;
1185 if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1186 perror("pthread_mutex_unlock _MutexExecutorWait") ;
1189 // endService( "Graph_Impl::LastLevelDone" );
1193 bool Graph_Impl::Merge(const SUPERV::Graph_ptr aGraph ) {
1194 beginService( "Graph_Impl::Merge" );
1195 bool RetVal = true ;
1196 if ( DataFlowEditor()->IsEditing() ) {
1197 SUPERV::ListOfNodes * aGraphNodes = aGraph->Nodes() ;
1200 map< string , int > aMapOfNodes ;
1201 for ( i = 0 ; i < (int ) aGraphNodes->CNodes.length() ; i++ ) {
1202 SUPERV::CNode_var aNode = (aGraphNodes->CNodes)[ i ] ;
1203 SUPERV::CNode_ptr myNode = CNode( *(aNode->Service()) ) ;
1204 if ( !CORBA::is_nil( myNode ) ) {
1205 myNode->SetName( aNode->Name() ) ;
1206 myNode->SetAuthor( aNode->Author() ) ;
1207 myNode->SetComment( aNode->Comment() ) ;
1208 myNode->Coords( aNode->X() , aNode->Y() ) ;
1209 string * aNodetheName = new string( aNode->Name() ) ;
1210 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1211 delete aNodetheName ;
1220 for ( i = 0 ; i < (int ) aGraphNodes->FNodes.length() ; i++ ) {
1221 SUPERV::FNode_var aNode = (aGraphNodes->FNodes)[ i ] ;
1222 SUPERV::FNode_ptr myNode = FNode( aNode->GetComponentName() ,
1223 aNode->GetInterfaceName() ,
1224 *(aNode->Service()) ) ;
1225 if ( !CORBA::is_nil( myNode ) ) {
1226 myNode->SetName( aNode->Name() ) ;
1227 myNode->SetAuthor( aNode->Author() ) ;
1228 myNode->SetComment( aNode->Comment() ) ;
1229 myNode->Coords( aNode->X() , aNode->Y() ) ;
1230 string * aNodetheName = new string( aNode->Name() ) ;
1231 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1232 delete aNodetheName ;
1242 for ( i = 0 ; i < (int ) aGraphNodes->INodes.length() ; i++ ) {
1243 SUPERV::INode_var aNode = (aGraphNodes->INodes)[ i ] ;
1244 SUPERV::INode_ptr myNode = INode( aNode->PyFuncName() , *(aNode->PyFunction()) ) ;
1245 if ( !CORBA::is_nil( myNode ) ) {
1246 myNode->SetName( aNode->Name() ) ;
1247 myNode->SetAuthor( aNode->Author() ) ;
1248 myNode->SetComment( aNode->Comment() ) ;
1249 myNode->Coords( aNode->X() , aNode->Y() ) ;
1250 string * aNodetheName = new string( aNode->Name() ) ;
1251 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1252 delete aNodetheName ;
1253 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1255 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1256 if ( myPorts[ j ]->IsInput() ) {
1257 myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1260 myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1272 for ( i = 0 ; i < (int ) aGraphNodes->GNodes.length() ; i++ ) {
1273 SUPERV::GNode_var aNode = (aGraphNodes->GNodes)[ i ] ;
1274 SUPERV::GNode_ptr myNode = GNode( aNode->PyFuncName() , *(aNode->PyFunction()) , aNode->Coupled()->Name() ) ;
1275 if ( !CORBA::is_nil( myNode ) ) {
1276 myNode->SetName( aNode->Name() ) ;
1277 myNode->SetAuthor( aNode->Author() ) ;
1278 myNode->SetComment( aNode->Comment() ) ;
1279 myNode->Coords( aNode->X() , aNode->Y() ) ;
1280 string * aNodetheName = new string( aNode->Name() ) ;
1281 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1282 delete aNodetheName ;
1283 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1285 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1286 if ( myPorts[ j ]->IsInput() ) {
1287 myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1290 myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1302 for ( i = 0 ; i < (int ) aGraphNodes->LNodes.length() ; i++ ) {
1303 SUPERV::LNode_var aNode = (aGraphNodes->LNodes)[ i ] ;
1304 SUPERV::INode_ptr anEndOfLoop ;
1305 SUPERV::LNode_ptr myNode = LNode( aNode->PyInitName() ,
1306 *(aNode->PyInit()) ,
1307 aNode->PyMoreName() ,
1308 *(aNode->PyMore()) ,
1309 aNode->PyNextName() ,
1310 *(aNode->PyNext()) ,
1312 if ( !CORBA::is_nil( myNode ) ) {
1313 myNode->SetName( aNode->Name() ) ;
1314 myNode->SetAuthor( aNode->Author() ) ;
1315 myNode->SetComment( aNode->Comment() ) ;
1316 myNode->Coords( aNode->X() , aNode->Y() ) ;
1317 string * aNodetheName = new string( aNode->Name() ) ;
1318 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1319 delete aNodetheName ;
1320 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1322 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1323 if ( myPorts[ j ]->IsInput() ) {
1324 myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1327 SUPERV::INode_ptr myEndOfLoop = aNode->Coupled() ;
1328 anEndOfLoop->SetName( myEndOfLoop->Name() ) ;
1329 anEndOfLoop->SetAuthor( myEndOfLoop->Author() ) ;
1330 anEndOfLoop->SetComment( myEndOfLoop->Comment() ) ;
1331 anEndOfLoop->Coords( myEndOfLoop->X() , myEndOfLoop->Y() ) ;
1332 anEndOfLoop->SetPyFunction( myEndOfLoop->PyFuncName() , *(myEndOfLoop->PyFunction()) ) ;
1333 aNodetheName = new string( myEndOfLoop->Name() ) ;
1334 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( anEndOfLoop->Name() ) ;
1335 delete aNodetheName ;
1345 for ( i = 0 ; i < (int ) aGraphNodes->SNodes.length() ; i++ ) {
1346 SUPERV::SNode_var aNode = (aGraphNodes->SNodes)[ i ] ;
1347 SUPERV::INode_ptr anEndOfSwitch ;
1348 SUPERV::SNode_ptr myNode = SNode( aNode->PyFuncName() , *(aNode->PyFunction()) , anEndOfSwitch ) ;
1349 if ( !CORBA::is_nil( myNode ) ) {
1350 myNode->SetName( aNode->Name() ) ;
1351 myNode->SetAuthor( aNode->Author() ) ;
1352 myNode->SetComment( aNode->Comment() ) ;
1353 myNode->Coords( aNode->X() , aNode->Y() ) ;
1354 string * aNodetheName = new string( aNode->Name() ) ;
1355 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( myNode->Name() ) ;
1356 delete aNodetheName ;
1357 SUPERV::ListOfPorts myPorts = *(aNode->Ports()) ;
1359 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1360 if ( myPorts[ j ]->IsInput() ) {
1361 myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1364 myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1367 SUPERV::INode_ptr myEndOfSwitch = aNode->Coupled() ;
1368 anEndOfSwitch->SetName( myEndOfSwitch->Name() ) ;
1369 anEndOfSwitch->SetAuthor( myEndOfSwitch->Author() ) ;
1370 anEndOfSwitch->SetComment( myEndOfSwitch->Comment() ) ;
1371 anEndOfSwitch->Coords( myEndOfSwitch->X() , myEndOfSwitch->Y() ) ;
1372 anEndOfSwitch->SetPyFunction( myEndOfSwitch->PyFuncName() , *(myEndOfSwitch->PyFunction()) ) ;
1373 aNodetheName = new string( myEndOfSwitch->Name() ) ;
1374 aMapOfNodes[ *aNodetheName ] = DataFlowEditor()->GetGraphNodeIndex( anEndOfSwitch->Name() ) ;
1375 delete aNodetheName ;
1376 myPorts = *(myEndOfSwitch->Ports()) ;
1377 for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1378 if ( myPorts[ j ]->IsInput() ) {
1379 anEndOfSwitch->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1382 anEndOfSwitch->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1394 SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
1395 SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
1396 // cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
1398 for ( i = 0 ; i < (int ) aGraphLinks->length() ; i++ ) {
1399 SUPERV::Link_var aLink = (*aGraphLinks)[ i ] ;
1400 SUPERV::Port_var OutPort = aLink->OutPort() ;
1401 SUPERV::Port_var InPort = aLink->InPort() ;
1402 string * aLinkFromNodeName = new string( OutPort->Node()->Name() ) ;
1403 string * aLinkToNodeName = new string( InPort->Node()->Name() ) ;
1404 RetVal = DataFlowEditor()->AddLink( DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
1406 DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1410 for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
1412 RetVal = aLink->Coords( j , X , Y ) ;
1415 RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
1417 DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1425 delete aLinkFromNodeName ;
1426 delete aLinkToNodeName ;
1432 for ( i = 0 ; i < (int ) aGraphPorts->length() ; i++ ) {
1433 SUPERV::Port_var aPort = (*aGraphPorts)[ i ] ;
1434 char * aPortName = aPort->Name() ;
1435 char * aNodeName = new char[ strlen( aPortName ) + 1 ] ;
1436 strcpy( aNodeName , aPortName ) ;
1437 char * thePortName = strchr( aNodeName , '\\' ) ;
1438 thePortName[ 0 ] = '\0' ;
1439 bool hasinput = aGraph->Node( aNodeName )->Port( thePortName + 1 )->HasInput() ;
1440 // cout << "Graph_Impl::Merge " << " aNodeName " << aNodeName << " aPort " << thePortName + 1
1441 // << " HasInput " << hasinput << endl ;
1443 RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
1445 *(aPort->ToAny()) ) ;
1447 delete [] aNodeName ;
1455 endService( "Graph_Impl::Merge" );