Salome HOME
5a33219c3982482b6301a5c30d58a5ebbfc4a5ef
[modules/superv.git] / src / Supervision / Graph_Impl.cxx
1 //  SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
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. 
10 // 
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. 
15 // 
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 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : Graph_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30 #include <stdio.h>
31 #include <fstream>
32 //#include <sstream>
33 #include <string>
34
35 //#include "utilities.h"
36
37 #include "Graph_Impl.hxx"
38
39 #include "DataFlowEditor_DataFlow.hxx"
40
41 extern GraphExecutor::FiniteStateMachine * theAutomaton ;
42
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" );
54   _thisObj = this ;
55   _id = _poa->activate_object(_thisObj);
56   _Orb = CORBA::ORB::_duplicate(orb);
57   _Poa = poa ;
58   _ContId = contId ;
59
60   string dbgfile = "/tmp/" ;
61   dbgfile += instanceName ;
62   dbgfile += "_" ;
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' ;
70       int i ;
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' ;
75           break ;
76         }
77       }
78     }
79     else {
80       strcpy( theDataFlowName , &aDataFlowName[ 0 ] ) ;
81     }
82     dbgfile += theDataFlowName ;
83   }
84   dbgfile += ".log" ;
85   _DebugFileName = new char[ strlen( dbgfile.c_str() )+1 ] ;
86   strcpy( _DebugFileName , dbgfile.c_str() ) ;
87
88   _NamingService = new SALOME_NamingService( orb ) ;
89   GraphEditor::DataFlow *  aDataFlowEditor = new GraphEditor::DataFlow( _Orb , _NamingService ,
90                                                                         theDataFlowName ,
91                                                                         _DebugFileName ) ;
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" );
98 }
99
100 Graph_Impl::Graph_Impl() {
101 }
102
103 Graph_Impl::~Graph_Impl() {
104   beginService( "Graph_Impl::~Graph_Impl" );
105   endService( "Graph_Impl::~Graph_Impl" );
106 }
107
108 void Graph_Impl::destroy() {
109   beginService( "Graph_Impl::destroy" );
110   _poa->deactivate_object(*_id) ;
111   CORBA::release(_poa) ;
112   delete(_id) ;
113   _thisObj->_remove_ref();
114   endService( "Graph_Impl::destroy" );
115 }
116
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);
123   }
124   return(CORBA::string_dup(_Orb->object_to_string(myServant)));
125 }
126
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() ,
132                             Name() ) ;
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) ;
142 }
143
144 void Graph_Impl::ReadOnly() {
145   DataFlowEditor()->ReadOnly() ;
146 }
147
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) ;
156 }
157
158 GraphBase::SGraph * Graph_Impl::GetGraph() {
159   return DataFlowEditor()->GetDataFlow() ;
160 }
161
162 #if 0
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 ) ;
168 }
169
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 ) ;
175 }
176
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 ) ;
182 }
183 #endif
184
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 ) ;
190   }
191 //  endService( "Graph_Impl::LoadGraph" );
192   return RetVal ;
193 }
194
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 ) ;
200   }
201 //  endService( "Graph_Impl::Import" );
202   return RetVal ;
203 }
204
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" ) ) {
211   }
212   else if ( !strcmp( &aFile[ len - 3 ] , ".py" ) ) {
213     strcpy( &aFile[ len - 3 ] , ".xml" ) ;
214     len = strlen( aFile ) ;
215   }
216   else {
217     strcat( aFile , ".xml" ) ;
218     len = strlen( aFile ) ;
219   }
220   bool RetVal = DataFlowEditor()->SaveXml( aFile ) ;
221   if ( RetVal ) {
222     strcpy( &aFile[ len - 4 ] , ".py" ) ;
223     RetVal = DataFlowEditor()->SavePy( aFile ) ;
224   }
225   delete [] aFile ;
226 //  endService( "Graph_Impl::Export" );
227   return RetVal ;
228 }
229
230 #if 0
231 GraphBase::ListOfNodes * Graph_Impl::GetNodes() {
232 //  beginService( "Graph_Impl::GetNodes" );
233   GraphBase::ListOfNodes * RetVal = DataFlowEditor()->GetNodes() ;
234 //  endService( "Graph_Impl::GetNodes" );
235   return RetVal ;
236 }
237 GraphBase::ListOfLinks * Graph_Impl::GetLinks() {
238 //  beginService( "Graph_Impl::GetLinks" );
239   GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetLinks() ;
240 //  endService( "Graph_Impl::GetLinks" );
241   return RetVal ;
242 }
243 GraphBase::ListOfLinks * Graph_Impl::GetDatas() {
244 //  beginService( "Graph_Impl::GetDatas" );
245   GraphBase::ListOfLinks * RetVal = DataFlowEditor()->GetDatas() ;
246 //  endService( "Graph_Impl::GetDatas" );
247   return RetVal ;
248 }
249 #endif
250
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() ,
257                                           DataFlowEditor() ,
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 ) ) ;
265     }
266   }
267   endService( "Graph_Impl::CNode" );
268   return SUPERV::CNode::_duplicate( iobject ) ;
269 }
270
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() ,
279                                           DataFlowEditor() ,
280                                           NodeService ,
281                                           NodeComponentName ,
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 ) ) ;
288     }
289   }
290   endService( "Graph_Impl::FNode" );
291   return SUPERV::FNode::_duplicate( iobject ) ;
292 }
293
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() ,
301                                           DataFlowEditor() ,
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 ) ) ;
309     }
310   }
311   endService( "Graph_Impl::INode" );
312   return SUPERV::INode::_duplicate( iobject ) ;
313 }
314
315
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() ,
324                                           DataFlowEditor() ,
325                                           FuncName , PythonFuntion ,
326                                           SUPERV::GOTONode ) ;
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" ) ) ;
337         }
338       }
339     }
340   }
341   endService( "Graph_Impl::GNode" );
342   return SUPERV::GNode::_duplicate( iobject ) ;
343 }
344
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() ,
368                                           DataFlowEditor() ,
369                                           FuncNameList , PythonFunctionList ,
370 //                                          InitName , InitFunction ,
371 //                                          MoreName , MoreFunction ,
372 //                                          NextName , NextFunction ,
373                                           SUPERV::LoopNode ) ;
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 ) ) ;
379
380       SALOME_ModuleCatalog::Service aVoidService = SALOME_ModuleCatalog::Service() ;
381       char * anEndName ;
382       if ( strlen( InitName ) ) {
383         anEndName = new char( 3 + strlen( InitName ) + 1 ) ;
384         strcpy( anEndName , "End" ) ;
385         strcat( anEndName , InitName ) ;
386       }
387       else {
388         anEndName = new char( 3 + strlen( "Loop" ) + 1 ) ;
389         strcpy( anEndName , "EndLoop" ) ;
390       }
391       ELNode_Impl * myEndNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
392                                                  instanceName() , interfaceName() ,
393                                                  DataFlowEditor() ,
394                                                  anEndName ,
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" ) ) ;
404     }
405   }
406   anEndOfLoop = SUPERV::ELNode::_duplicate( iendobject ) ;
407   endService( "Graph_Impl::LNode" );
408   return SUPERV::LNode::_duplicate( iobject ) ;
409 }
410
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() ,
420                                           DataFlowEditor() ,
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 ) ) ;
428
429       string anEndName = "End" ;
430       if ( strlen( FuncName ) ) {
431         anEndName += FuncName ;
432       }
433       else {
434         anEndName += "Switch" ;
435       }
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() ,
441                                                DataFlowEditor() ,
442                                                anEndName.c_str() ,
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() ;
456       }
457     }
458   }
459   anEndOfSwitch = SUPERV::ESNode::_duplicate( iendobject ) ;
460   endService( "Graph_Impl::SNode" );
461   return SUPERV::SNode::_duplicate( iobject ) ;
462 }
463
464
465 SUPERV::CNode_ptr Graph_Impl::Node(char const * aNodeName ) {
466 //  beginService( "Graph_Impl::Node" );
467   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
468   /* JR : 13/06/03
469      if ( CORBA::is_nil( DataFlowEditor()->GetNode( aNodeName )->ObjRef() ) ) {
470      CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
471      instanceName() , interfaceName() ,
472      DataFlowEditor() ,
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 ) ) ;
478      }
479      else {
480      iobject = DataFlowEditor()->GetNode( aNodeName )->ObjRef() ;
481   */
482   GraphEditor::InNode * anInNode = DataFlowEditor()->GetNode( aNodeName ) ;
483   if ( anInNode ) {
484     if ( CORBA::is_nil( anInNode->ObjRef() ) ) {
485       SetNodeObjRef( anInNode ) ;
486     }
487     iobject = anInNode->ObjRef() ;
488   }
489 //  endService( "Graph_Impl::Node" );
490   return SUPERV::CNode::_duplicate( iobject ) ;
491 }
492
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() ,
506                                           DataFlowEditor() ,
507                                           DataFlowInNode ,
508                                           InPort->Name() ,
509                                           DataFlowOutNode ,
510                                           OutPort->Name() ,
511                                           true ) ;
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() ;
516     }
517   }
518   endService( "Graph_Impl::Link" );
519   return SUPERV::Link::_duplicate( iobject ) ;
520 }
521
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() ,
527                                           DataFlowEditor() ,
528                                           anInNode ) ;
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 ) ) ;
533   }
534   else if ( anInNode->IsFactoryNode() ) {
535     FNode_Impl * myNode = new FNode_Impl( _Orb , _Poa , _ContId ,
536                                           instanceName() , interfaceName() ,
537                                           DataFlowEditor() ,
538                                           anInNode ) ;
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 ) ) ;
543   }
544   else if ( anInNode->IsInLineNode() ) {
545     INode_Impl * myNode = new INode_Impl( _Orb , _Poa , _ContId ,
546                                           instanceName() , interfaceName() ,
547                                           DataFlowEditor() ,
548                                           anInNode ) ;
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 ) ) ;
553   }
554   else if ( anInNode->IsGOTONode() ) {
555     GNode_Impl * myNode = new GNode_Impl( _Orb , _Poa , _ContId ,
556                                           instanceName() , interfaceName() ,
557                                           DataFlowEditor() ,
558                                           anInNode ) ;
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 ) ) ;
563   }
564   else if ( anInNode->IsLoopNode() ) {
565     LNode_Impl * myNode = new LNode_Impl( _Orb , _Poa , _ContId ,
566                                           instanceName() , interfaceName() ,
567                                           DataFlowEditor() ,
568                                           anInNode ) ;
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 ) ) ;
573   }
574   else if ( anInNode->IsEndLoopNode() ) {
575     ELNode_Impl * myNode = new ELNode_Impl( _Orb , _Poa , _ContId ,
576                                             instanceName() , interfaceName() ,
577                                             DataFlowEditor() ,
578                                             anInNode ) ;
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 ) ) ;
583   }
584   else if ( anInNode->IsSwitchNode() ) {
585     SNode_Impl * myNode = new SNode_Impl( _Orb , _Poa , _ContId ,
586                                           instanceName() , interfaceName() ,
587                                           DataFlowEditor() ,
588                                           anInNode ) ;
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 ) ) ;
593   }
594   else if ( anInNode->IsEndSwitchNode() ) {
595     ESNode_Impl * myNode = new ESNode_Impl( _Orb , _Poa , _ContId ,
596                                             instanceName() , interfaceName() ,
597                                             DataFlowEditor() ,
598                                             anInNode ) ;
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 ) ) ;
603   }
604 }
605
606 SUPERV::ListOfNodes_var  Graph_Impl::SetNode( SUPERV::ListOfNodes_var RetVal ,
607                                               GraphBase::ComputingNode * aNode ) {
608   int index = 0 ;
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() ) ) ) ;
613 //  }
614 //  else {
615 //    MESSAGE("Graph_Impl::SetNode " << aNode->Name() << " " << aNode->Kind() ) ;
616 //  }
617   if ( aNode->IsComputingNode() ) {
618     index = RetVal->CNodes.length() ;
619     RetVal->CNodes.length( index+1 );
620   }
621   else if ( aNode->IsFactoryNode() ) {
622     index = RetVal->FNodes.length() ;
623     RetVal->FNodes.length( index+1 );
624   }
625   else if ( aNode->IsInLineNode() ) {
626     index = RetVal->INodes.length() ;
627     RetVal->INodes.length( index+1 );
628   }
629   else if ( aNode->IsGOTONode() ) {
630     index = RetVal->GNodes.length() ;
631     RetVal->GNodes.length( index+1 );
632   }
633   else if ( aNode->IsLoopNode() ) {
634     index = RetVal->LNodes.length() ;
635     RetVal->LNodes.length( index+1 );
636   }
637   else if ( aNode->IsEndLoopNode() ) {
638     index = RetVal->ELNodes.length() ;
639     RetVal->ELNodes.length( index+1 );
640   }
641   else if ( aNode->IsSwitchNode() ) {
642     index = RetVal->SNodes.length() ;
643     RetVal->SNodes.length( index+1 );
644   }
645   else if ( aNode->IsEndSwitchNode() ) {
646     index = RetVal->ESNodes.length() ;
647     RetVal->ESNodes.length( index+1 );
648   }
649   if ( CORBA::is_nil( aNode->ObjRef() ) ) {
650     SetNodeObjRef( (GraphEditor::InNode * ) aNode->GetInNode() ) ;
651   }
652   SUPERV::CNode_var aNodeObjRef = aNode->ObjRef() ;
653   if ( aNode->IsComputingNode() ) {
654     RetVal->CNodes[index] = SUPERV::CNode::_duplicate( aNodeObjRef ) ;
655   }
656   else if ( aNode->IsFactoryNode() ) {
657     RetVal->FNodes[index] = SUPERV::FNode::_duplicate( SUPERV::FNode::_narrow( aNodeObjRef ) ) ;
658   }
659   else if ( aNode->IsInLineNode() ) {
660     RetVal->INodes[index] = SUPERV::INode::_duplicate( SUPERV::INode::_narrow( aNodeObjRef ) ) ;
661   }
662   else if ( aNode->IsGOTONode() ) {
663     RetVal->GNodes[index] = SUPERV::GNode::_duplicate( SUPERV::GNode::_narrow( aNodeObjRef ) ) ;
664   }
665   else if ( aNode->IsLoopNode() ) {
666     RetVal->LNodes[index] = SUPERV::LNode::_duplicate( SUPERV::LNode::_narrow( aNodeObjRef ) ) ;
667   }
668   else if ( aNode->IsEndLoopNode() ) {
669     RetVal->ELNodes[index] = SUPERV::ELNode::_duplicate( SUPERV::ELNode::_narrow( aNodeObjRef ) ) ;
670   }
671   else if ( aNode->IsSwitchNode() ) {
672     RetVal->SNodes[index] = SUPERV::SNode::_duplicate( SUPERV::SNode::_narrow( aNodeObjRef ) ) ;
673   }
674    else if ( aNode->IsEndSwitchNode() ) {
675     RetVal->ESNodes[index] = SUPERV::ESNode::_duplicate( SUPERV::ESNode::_narrow( aNodeObjRef ) ) ;
676   }
677  return ( RetVal._retn() ) ;
678 }
679
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) ;
689   int i ;
690   for ( i = 0 ; i < DataFlowEditor()->GraphNodesSize() ; i++ ) {
691     GraphBase::ComputingNode * aNode = DataFlowEditor()->GraphNodes( i ) ;
692     RetVal = SetNode( RetVal , aNode ) ;
693   }
694   char * aStateG = "" ;
695   if ( _DataFlowExecutor ) {
696     aStateG = (char *) _DataFlowExecutor->StateName( _DataFlowExecutor->AutomatonState() ) ;
697   }
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() ;
709 //  }
710   endService( "Graph_Impl::Nodes" );
711   return ( RetVal._retn() ) ;
712 }
713
714 SUPERV::ListOfLinks * Graph_Impl::GLinks() {
715   return Links( NULL , NULL ) ;
716 }
717
718 SUPERV::ListOfLinks * Graph_Impl::Links( GraphBase::ComputingNode * theNode ,
719                                          const char * anInputParam ) {
720   bool begin = true ;
721   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
722   int i , j , countlink ;
723   countlink = 0 ;
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 ) {
729       ToProcess = true ;
730     }
731     else {
732       if ( !strcmp( theNode->Name() , aNode->Name() ) ) {
733         if ( !theNode->IsEndSwitchNode() ) {
734           ToProcess = true ;
735         }
736       }
737       else if ( theNode->IsEndSwitchNode() ) {
738         ToProcess = true ;
739       }
740     }
741     if ( ToProcess ) {
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" ) ;
763                 }
764                 else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
765                   if ( begin ) {
766                     beginService( "Graph_Impl::Links" );
767                     begin = false ;
768                   }
769                   GraphEditor::InNode * anOutNode = NULL ;
770                   anOutNode = (GraphEditor::InNode * ) DataFlowEditor()->GetChangeGraphNode( anOutPort->NodeName() )->GetInNode() ;
771                   if ( anOutNode ) {
772                     Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
773                                           instanceName() , interfaceName() ,
774                                           DataFlowEditor() ,
775                                           aNode ,
776                                           anInPort->PortName() ,
777                                           anOutNode ,
778                                           anOutPort->PortName() ,
779                                           false ) ;
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 ) ) ;
787                   }
788                 }
789                 else {
790                   RetVal->length( countlink + 1 ) ;
791                   RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
792                 }
793               }
794             }
795           }
796         }
797       }
798     }
799     for ( j = 0 ; j < aNode->GetNodeOutPortsSize() ; j++ ) {
800       GraphBase::OutPort * anOutPort = aNode->GetChangeNodeOutPort( j ) ;
801       int k ;
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" ) ;
817               }
818               else if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
819                 if ( begin ) {
820                   beginService( "Graph_Impl::Links" );
821                   begin = false ;
822                 }
823                 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
824                                         instanceName() , interfaceName() ,
825                                         DataFlowEditor() ,
826                                         toNode ,
827                                         anInPort->PortName() ,
828                                         aNode ,
829                                         anOutPort->PortName() ,
830                                         false ) ;
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 ) ) ;
838               }
839               else {
840                 RetVal->length( countlink + 1 ) ;
841                 RetVal[ countlink++ ] = SUPERV::Link::_duplicate( anOutPort->InPortObjRef( anInPort ) ) ;
842               }
843             }
844           }
845         }
846       }
847     }
848   }
849   if ( !begin ) {
850     endService( "Graph_Impl::Links" );
851   }
852   return ( RetVal._retn() ) ;
853 }
854
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() ) ;
861 }
862
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 ) ;
870 }
871
872 bool Graph_Impl::IsValid() {
873 //  beginService( "Graph_Impl::IsValid" );
874   bool RetVal = DataFlowEditor()->IsValid() ;
875 //  endService( "Graph_Impl::IsValid" );
876   return RetVal ;
877 }
878 bool Graph_Impl::IsExecutable() {
879 //  beginService( "Graph_Impl::IsExecutable" );
880   bool RetVal = DataFlowEditor()->IsExecutable() ;
881 //  endService( "Graph_Impl::IsExecutable" );
882   return RetVal ;
883 }
884 bool Graph_Impl::IsDataFlow() {
885 //  beginService( "Graph_Impl::IsDataFlow" );
886   bool RetVal = false ; // = DataFlowEditor()->IsDataFlow() ;
887 //  endService( "Graph_Impl::IsDataFlow" );
888   return RetVal ;
889 }
890
891 bool Graph_Impl::IsEditing() {
892 //  beginService( "Graph_Impl::IsEditing" );
893   bool RetVal = DataFlowEditor()->IsEditing() ;
894 //  endService( "Graph_Impl::IsEditing" );
895   return RetVal ;
896 }
897 bool Graph_Impl::IsExecuting() {
898 //  beginService( "Graph_Impl::IsExecuting" );
899   bool RetVal = !DataFlowEditor()->IsEditing() ;
900 //  endService( "Graph_Impl::IsExecuting" );
901   return RetVal ;
902 }
903
904 bool Graph_Impl::IsReadOnly() {
905 //  beginService( "Graph_Impl::IsExecuting" );
906   bool RetVal = DataFlowEditor()->IsReadOnly() ;
907 //  endService( "Graph_Impl::IsExecuting" );
908   return RetVal ;
909 }
910
911 long Graph_Impl::LevelMax() {
912 //  beginService( "Graph_Impl::LevelMax" );
913   long RetVal = DataFlowEditor()->LevelMax() ;
914 //  endService( "Graph_Impl::LevelMax" );
915   return RetVal ;
916 }
917 SUPERV::ListOfNodes * Graph_Impl::LevelNodes(long aLevel ) {
918 //  beginService( "Graph_Impl::LevelNodes" );
919   SUPERV::ListOfNodes_var RetVal = new SUPERV::ListOfNodes;
920   int i ;
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 ) ;
937   }
938 //  endService( "Graph_Impl::LevelNodes" );
939   return ( RetVal._retn() ) ;
940 }
941 long Graph_Impl::ThreadsMax() {
942 //  beginService( "Graph_Impl::ThreadsMax" );
943   long RetVal =  DataFlowEditor()->ThreadsMax() ;
944 //  endService( "Graph_Impl::ThreadsMax" );
945   return RetVal ;
946 }
947 long Graph_Impl::GraphsNumber() {
948 //  beginService( "Graph_Impl::GraphsNumber" );
949   long RetVal =  DataFlowEditor()->GraphsNumber() ;
950 //  endService( "Graph_Impl::GraphsNumber" );
951   return RetVal ;
952 }
953 long Graph_Impl::Threads() {
954 //  beginService( "Node_Impl::Threads" );
955   long RetVal = _DataFlowExecutor->Threads() ;
956 //  endService( "Node_Impl::Threads" );
957   return RetVal ;
958 }
959 long Graph_Impl::SuspendedThreads() {
960 //  beginService( "Node_Impl::SuspendedThreads" );
961   long RetVal = _DataFlowExecutor->SuspendedThreads() ;
962 //  endService( "Node_Impl::SuspendedThreads" );
963   return RetVal ;
964 }
965
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") ;
971       exit( 0 ) ;
972     }
973     if ( _DataFlowExecutor ) {
974       MESSAGE( "Graph_Impl::Begin " << _DataFlowExecutor->Threads() << " threads" )
975       if ( _DataFlowExecutor->Threads() ) {
976         _DataFlowExecutor->JoinedWait() ;
977       }
978       delete _DataFlowExecutor ;
979       _DataFlowExecutor = NULL ;
980       DataFlowEditor()->Executor( NULL ) ;
981     }
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() ,
995                                                      DebugFileName ) ;
996     MESSAGE( "Graph_Impl::Begin : DataFlowExecutor created" );
997     RetVal = _DataFlowExecutor->LoadDataFlow( *myGraph ) ;
998     if ( RetVal ) {
999       DataFlowEditor()->Executor( _DataFlowExecutor ) ;
1000     }
1001     if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1002       perror("pthread_mutex_unlock _MutexExecutorWait") ;
1003       exit( 0 ) ;
1004     }
1005   }
1006   return RetVal ;
1007 }
1008 bool Graph_Impl::Run() {
1009   beginService( "Graph_Impl::Run" );
1010   bool RetVal = false ;
1011   if ( DataFlowEditor()->IsEditing() ) {
1012     MESSAGE( "Graph_Impl::Run IsEditing" );
1013     RetVal = Begin() ;
1014     if ( RetVal ) {
1015       MESSAGE( "Graph_Impl::(Re)Run " );
1016       RetVal = CNode_Impl::Run() ;
1017     }
1018   }
1019   else {
1020     MESSAGE( "Graph_Impl::(Re)Run " );
1021     RetVal = CNode_Impl::ReRun() ;
1022   }
1023   endService( "Graph_Impl::Run" );
1024   return RetVal ;
1025 }
1026 bool Graph_Impl::Start() {
1027   beginService( "Graph_Impl::Start" );
1028   bool RetVal = false ;
1029   if ( DataFlowEditor()->IsEditing() ) {
1030     MESSAGE( "Graph_Impl::Start IsEditing" );
1031     RetVal = Begin() ;
1032   }
1033   else {
1034     RetVal = true ;
1035   }
1036   if ( RetVal ) {
1037     MESSAGE( "Graph_Impl::(Re)Start " );
1038     RetVal = ReStart() ;
1039   }
1040   endService( "Graph_Impl::Start" );
1041   return RetVal ;
1042 }
1043
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") ;
1053     exit( 0 ) ;
1054   }
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 ) ;
1062       }
1063       else {
1064         aNode = Node() ;
1065       }
1066     }
1067     else {
1068       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1069     }
1070 //    cout << "Graph_Impl::EventNoW " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1071   }
1072   else {
1073 //    cout << "Graph_Impl::EventNoW NO DataFlowExecutor or QSize=0 " << endl ;
1074   }
1075   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1076     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1077     exit( 0 ) ;
1078   }
1079   anEvent = theEvent ;
1080   aState = theState ;
1081   return RetVal ;
1082 }
1083
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") ;
1094     exit( 0 ) ;
1095   }
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 ) ;
1103       }
1104       else {
1105         aNode = Node() ;
1106       }
1107     }
1108     else {
1109       aNode = SUPERV::Graph::_duplicate( SUPERV::Graph::_nil() ) ;
1110     }
1111 //    cout << "Graph_Impl::Event " << aNode->Name() << " QSize " << _DataFlowExecutor->GetListSize() << endl ;
1112   }
1113   else {
1114 //    cout << "Graph_Impl::Event NO DataFlowExecutor or QSize=0 " << endl ;
1115   }
1116   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1117     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1118     exit( 0 ) ;
1119   }
1120   anEvent = theEvent ;
1121   aState = theState ;
1122   return RetVal ;
1123 }
1124
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") ;
1135     exit( 0 ) ;
1136   }
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 ) ;
1142     }
1143     else {
1144       aNode = Node() ;
1145     }
1146   }
1147   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1148     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1149     exit( 0 ) ;
1150   }
1151   anEvent = theEvent ;
1152   aState = theState ;
1153 //  endService( "Graph_Impl::EventW" );
1154   return RetVal ;
1155 }
1156
1157 long Graph_Impl::EventQSize() {
1158 //  beginService( "Graph_Impl::EventQSize" );
1159   long QSize = -1 ;
1160   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1161     perror("pthread_mutex_lock _MutexExecutorWait") ;
1162     exit( 0 ) ;
1163   }
1164   if ( _DataFlowExecutor ) {
1165     QSize = _DataFlowExecutor->EventQSize() ;
1166   }
1167   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1168     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1169     exit( 0 ) ;
1170   }
1171 //  endService( "Graph_Impl::EventQSize" );
1172   return QSize ;
1173 }
1174
1175 long Graph_Impl::LastLevelDone() {
1176 //  beginService( "Graph_Impl::LastLevelDone" );
1177   if ( pthread_mutex_lock( &_MutexExecutorWait ) ) {
1178     perror("pthread_mutex_lock _MutexExecutorWait") ;
1179     exit( 0 ) ;
1180   }
1181   long RetVal = 0 ;
1182   if ( _DataFlowExecutor ) {
1183     RetVal = _DataFlowExecutor->LastLevelDone() ;
1184   }
1185   if ( pthread_mutex_unlock( &_MutexExecutorWait ) ) {
1186     perror("pthread_mutex_unlock _MutexExecutorWait") ;
1187     exit( 0 ) ;
1188   }
1189 //  endService( "Graph_Impl::LastLevelDone" );
1190   return RetVal ;
1191 }
1192
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() ;
1198
1199     int i ;
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 ;
1212         RetVal = true ;
1213       }
1214       else {
1215         RetVal = false ;
1216         break ;
1217       }
1218     }
1219     if ( RetVal ) {
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 ;
1233           RetVal = true ;
1234         }
1235         else {
1236           RetVal = false ;
1237           break ;
1238         }
1239       }
1240     }
1241     if ( RetVal ) {
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()) ;
1254           int j ;
1255           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1256             if ( myPorts[ j ]->IsInput() ) {
1257               myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1258             }
1259             else {
1260               myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1261             }
1262           }
1263           RetVal = true ;
1264         }
1265         else {
1266           RetVal = false ;
1267           break ;
1268         }
1269       }
1270     }
1271     if ( RetVal ) {
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()) ;
1284           int j ;
1285           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1286             if ( myPorts[ j ]->IsInput() ) {
1287               myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1288             }
1289             else {
1290               myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1291             }
1292           }
1293           RetVal = true ;
1294         }
1295         else {
1296           RetVal = false ;
1297           break ;
1298         }
1299       }
1300     }
1301     if ( RetVal ) {
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()) ,
1311                                           anEndOfLoop ) ;
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()) ;
1321           int j ;
1322           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1323             if ( myPorts[ j ]->IsInput() ) {
1324               myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1325             }
1326           }
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 ;
1336           RetVal = true ;
1337         }
1338         else {
1339           RetVal = false ;
1340           break ;
1341         }
1342       }
1343     }
1344     if ( RetVal ) {
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()) ;
1358           int j ;
1359           for ( j = 0 ; j < (int ) myPorts.length() ; j++ ) {
1360             if ( myPorts[ j ]->IsInput() ) {
1361               myNode->InPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1362             }
1363             else {
1364               myNode->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1365             }
1366           }
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() ) ;
1380             }
1381             else {
1382               anEndOfSwitch->OutPort( myPorts[ j ]->Name() , myPorts[ j ]->Type() ) ;
1383             }
1384           }
1385           RetVal = true ;
1386         }
1387         else {
1388           RetVal = false ;
1389           break ;
1390         }
1391       }
1392     }
1393     if ( RetVal ) {
1394       SUPERV::ListOfLinks * aGraphLinks = aGraph->GLinks() ;
1395       SUPERV::ListOfPorts * aGraphPorts = aGraph->Ports() ;
1396 //      cout << "Graph_Impl::Merge " << aGraphLinks->length() << " links " << aGraphPorts->length() << " GraphPorts"
1397 //           << endl ;
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() ,
1405                                            OutPort->Name() ,
1406                                            DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1407                                            InPort->Name() ) ;
1408         if ( RetVal ) {
1409           int j ;
1410           for ( j = 1 ; j <= aLink->CoordsSize() ; j++ ) {
1411             long X , Y ;
1412             RetVal = aLink->Coords( j , X , Y ) ;
1413             if ( !RetVal )
1414               break ;
1415             RetVal = DataFlowEditor()->AddLinkCoord( DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkFromNodeName->c_str() ] )->Name() ,
1416                                                      OutPort->Name() ,
1417                                                      DataFlowEditor()->GetGraphNode( aMapOfNodes[ aLinkToNodeName->c_str() ] )->Name() ,
1418                                                      InPort->Name() ,
1419                                                      j , X , Y ) ;
1420             if ( !RetVal ) {
1421               break ;
1422             }
1423           }
1424         }
1425         delete aLinkFromNodeName ;
1426         delete aLinkToNodeName ;
1427         if ( !RetVal ) {
1428           break ;
1429         }
1430       }
1431       if ( RetVal ) {
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 ;
1442           if ( hasinput ) {
1443             RetVal = DataFlowEditor()->AddInputData( DataFlowEditor()->GetGraphNode( aMapOfNodes[ aNodeName ] )->Name() ,
1444                                                      thePortName + 1 ,
1445                                                      *(aPort->ToAny()) ) ;
1446           }
1447           delete [] aNodeName ;
1448           if ( !RetVal ) {
1449             break ;
1450           }
1451         }
1452       }
1453     }
1454   }
1455   endService( "Graph_Impl::Merge" );
1456   return RetVal ;
1457 }
1458