]> SALOME platform Git repositories - modules/superv.git/blob - src/Supervision/Port_Impl.cxx
Salome HOME
cd6b4dc84a838dfb72f08f4cc37dadeab61f1329
[modules/superv.git] / src / Supervision / Port_Impl.cxx
1 using namespace std;
2 //=============================================================================
3 // File      : Port_Impl.cxx
4 // Created   : Nov 2001
5 // Author    : Jean Rahuel
6 // Project   : SALOME
7 // $Header: 
8 //=============================================================================
9
10 #include <stdio.h>
11 #include <fstream>
12 #include <strstream>
13 #include <string>
14
15 #include "utilities.h"
16
17 #include "Graph_Impl.hxx"
18 #include "Port_Impl.hxx"
19
20 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
21                       PortableServer::POA_ptr poa ,
22                       PortableServer::ObjectId * contId , 
23                       const char *instanceName ,
24                       const char *interfaceName ,
25                       GraphEditor::DataFlow * DataFlowEditor ,
26                       GraphEditor::InNode * DataFlowNode ,
27 //                      const char *ParameterName ,
28                       GraphBase::Port * DataFlowPort ,
29                       bool InputPort ,
30                       const CORBA::Any * anAny ) :
31 //                      const SUPERV::Value_ptr aValue ) :
32   Value_Impl(orb, poa, contId, instanceName, interfaceName,
33 //             DataFlowEditor , DataFlowNode , ParameterName, aValue->ToAny() ,
34              DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
35              false ) {
36 //  MESSAGE("Value_Impl::Value_Impl activate object instanceName("
37 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
38 //          << hex << (void *) this << dec )
39   _Orb = CORBA::ORB::_duplicate(orb);
40   _Poa = poa ;
41   _ContId = contId ;
42   _thisObj = this ;
43   _id = _poa->activate_object(_thisObj);
44   _DataFlowEditor = DataFlowEditor ;
45   _DataFlowNode = DataFlowNode ;
46 //  _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
47   _DataFlowPort = DataFlowPort ;
48 //  _InputPort = true ;
49   _InputPort = InputPort ;
50 //  if ( _DataFlowPort == NULL ) {
51 //    _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
52 //    _InputPort = false ;
53 //  }
54   InPort( _InputPort ) ;
55 }
56
57 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
58                       PortableServer::POA_ptr poa ,
59                       PortableServer::ObjectId * contId , 
60                       const char *instanceName ,
61                       const char *interfaceName ,
62                       GraphEditor::DataFlow * DataFlowEditor ,
63                       GraphEditor::InNode * DataFlowNode ,
64 //                      const char *ParameterName ) :
65                       GraphBase::Port * DataFlowPort ,
66                       bool InputPort ) :
67   Value_Impl(orb, poa, contId, instanceName, interfaceName,
68              DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
69 //             DataFlowEditor , DataFlowNode , ParameterName , false ) {
70 //  MESSAGE("Value_Impl::Value_Impl activate object instanceName("
71 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
72 //          << hex << (void *) this << dec )
73   _Orb = CORBA::ORB::_duplicate(orb);
74   _Poa = poa ;
75   _ContId = contId ;
76   _thisObj = this ;
77   _id = _poa->activate_object(_thisObj);
78   _DataFlowEditor = DataFlowEditor ;
79   _DataFlowNode = DataFlowNode ;
80 //  _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
81   _DataFlowPort = DataFlowPort ;
82 //  _InputPort = true ;
83   _InputPort = InputPort ;
84 //  if ( _DataFlowPort == NULL ) {
85 //    _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
86 //    _InputPort = false ;
87 //  }
88   InPort( _InputPort ) ;
89 }
90
91 Port_Impl::Port_Impl() {
92 }
93
94 Port_Impl::~Port_Impl() {
95   beginService( "Port_Impl::~Port_Impl" );
96   endService( "Port_Impl::~Port_Impl" );
97 }
98
99 void Port_Impl::destroy() {
100   beginService( "Port_Impl::destroy" );
101   bool destroyed = false ;
102   if ( _DataFlowNode->IsOneOfInLineNodes() ) {
103     if ( _InputPort ) {
104       GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
105       if ( anInPort->GetOutPort() ) {
106         anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
107       }
108       _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
109       if ( _DataFlowNode->IsLoopNode() ) {
110         _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
111         _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
112         _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
113       }
114       destroyed = true ;
115     }
116     else if ( !_DataFlowNode->IsLoopNode() ) {
117       _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
118       destroyed = true ;
119     }
120     if ( destroyed ) {
121       _DataFlowEditor->UnValid() ;
122 //      _DataFlowEditor->IsValid() ;
123     }
124   }
125   if ( destroyed ) {
126     _poa->deactivate_object(*_id) ;
127     CORBA::release(_poa) ;
128     delete(_id) ;
129     _thisObj->_remove_ref();
130   }
131   endService( "Port_Impl::destroy" );
132 }
133
134 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
135   return Input( aValue->ToAny() ) ;
136 }
137
138 bool Port_Impl::Input( const CORBA::Any * anAny ) {
139   beginService( "Port_Impl::Input" );
140   bool RetVal = false ;
141   if ( _InputPort && _DataFlowEditor->IsEditing() ) {
142     RetVal = true ;
143     Value_Impl::Input( anAny ) ;
144     RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
145                                             _DataFlowPort->PortName() ,
146                                             *anAny ) ;
147   }
148   else if ( _DataFlowEditor->IsExecuting() ) {
149     GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
150 //    if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
151 //         _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
152     if ( _DataFlowExecutor ) {
153       RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
154                                                    _DataFlowPort->PortName() ,
155                                                    *anAny ) ;
156     }
157   }
158   endService( "Port_Impl::Input" );
159   return RetVal ;
160 }
161
162 char * Port_Impl::Name() {
163 //  beginService( "Port_Impl::Name" ) ;
164   const char * RetVal = _DataFlowPort->PortName() ;
165 //  endService( "Port_Impl::Name" ) ;
166   return CORBA::string_dup( RetVal ) ;
167 }
168
169 char * Port_Impl::Type() {
170 //  beginService( "Port_Impl::Type" ) ;
171   const char * RetVal = _DataFlowPort->PortType() ;
172 //  endService( "Port_Impl::Type" ) ;
173   return CORBA::string_dup( RetVal ) ;
174 }
175
176 SUPERV::CNode_ptr Port_Impl::Node() {
177   bool begin = true ;
178   SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
179   if ( CORBA::is_nil( _DataFlowNode->ObjRef() ) ) {
180     if ( begin ) {
181       beginService( "Port_Impl::Node" ) ;
182       begin = false ;
183     }
184     CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
185                                           instanceName() , interfaceName() ,
186                                           _DataFlowEditor ,
187                                           _DataFlowNode ) ;
188     PortableServer::ObjectId * id = myNode->getId() ;
189     CORBA::Object_var obj = _poa->id_to_reference(*id);
190     SUPERV::CNode_var iobject ;
191     iobject = SUPERV::CNode::_narrow(obj) ;
192     myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
193   }
194   else {
195     iobject = _DataFlowNode->ObjRef() ;
196   }
197   if ( !begin ) {
198     endService( "Port_Impl::Node" ) ;
199   }
200   return SUPERV::CNode::_duplicate( iobject ) ;
201 }
202
203 SUPERV::ListOfLinks * Port_Impl::Links() {
204   beginService( "Port_Impl::Links" ) ;
205   SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
206   RetVal = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
207                                               _DataFlowPort->PortName() ) ;
208   endService( "Port_Impl::Links" ) ;
209   return ( RetVal._retn() ) ;
210 }
211
212 SUPERV::Link_ptr Port_Impl::Link() {
213   bool begin = true ;
214   SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
215   if ( _DataFlowNode->IsEndSwitchNode() ) {
216     beginService( "Port_Impl::Link" ) ;
217     begin = false ;
218     SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
219     cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
220          << _DataFlowPort->PortName() << endl ;
221     Links = _DataFlowEditor->ObjImpl()->Links(
222                                         _DataFlowNode->ComputingNode() ,
223                                         _DataFlowPort->PortName() ) ;
224     if ( Links->length() ) {
225       iobject = Links[ 0 ] ;
226     }
227   }
228   else {
229     char * FromNodeName = NULL ;
230     char * FromServiceParameterName = NULL ;
231     bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
232                                             _DataFlowPort->PortName() ,
233                                             & FromNodeName ,
234                                             & FromServiceParameterName ) ;
235     if ( status ) {
236 //      cout << "Port_Impl::Link " << FromNodeName << "("
237 //           << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
238 //           << "(" << _DataFlowPort->PortName() << ")" << endl ;
239 //      SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
240
241       GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
242       if ( anInPort->GetOutPort() ) {
243         GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
244         if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
245           if ( begin ) {
246             beginService( "Port_Impl::Link" ) ;
247             begin = false ;
248           }
249           Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
250                                     instanceName() , interfaceName() ,
251                                     _DataFlowEditor ,
252                                     _DataFlowNode ,
253                                     _DataFlowPort->PortName() ,
254                                     (GraphEditor::InNode * ) _DataFlowEditor->GetChangeGraphNode( FromNodeName )->GetInNode() ,
255                                     FromServiceParameterName ,
256                                     false ) ;
257           PortableServer::ObjectId * id = myLink->getId() ;
258           CORBA::Object_var obj = _poa->id_to_reference(*id);
259           iobject = SUPERV::Link::_narrow(obj) ;
260           anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
261         }
262         else {
263           iobject = anOutPort->InPortObjRef( anInPort ) ;
264         }
265       }
266     }
267   }
268   if ( !begin ) {
269     endService( "Port_Impl::Link" ) ;
270   }
271   return SUPERV::Link::_duplicate( iobject ) ;
272 }
273
274 bool Port_Impl::IsInput() {
275 //  beginService( "Port_Impl::IsInput" ) ;
276   bool RetVal = _InputPort ;
277 //  endService( "Port_Impl::IsInput" ) ;
278   return RetVal ;
279 }
280
281 bool Port_Impl::IsLinked() {
282 //  beginService( "Port_Impl::IsLinked" ) ;
283   bool RetVal = true ;
284 #if 0
285   if ( _DataFlowNode->IsEndSwitchNode() && _DataFlowPort->IsBus() ) {
286   }
287   else {
288 #endif
289     RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
290 #if 0
291   }
292 #endif
293 //  endService( "Port_Impl::IsLinked" ) ;
294   return RetVal ;
295 }
296
297 SUPERV::KindOfPort Port_Impl::Kind() {
298 //  beginService( "Port_Impl::Kind" ) ;
299   SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
300 //  endService( "Port_Impl::Kind" ) ;
301   return RetVal ;
302 }
303
304 bool Port_Impl::IsParam() {
305 //  beginService( "Port_Impl::IsParam" ) ;
306   bool RetVal = _DataFlowPort->IsParam() ;
307 //  endService( "Port_Impl::IsParam" ) ;
308   return RetVal ;
309 }
310
311 bool Port_Impl::IsGate() {
312 //  beginService( "Port_Impl::IsGate" ) ;
313   bool RetVal = _DataFlowPort->IsGate() ;
314 //  endService( "Port_Impl::IsGate" ) ;
315   return RetVal ;
316 }
317
318 bool Port_Impl::IsInLine() {
319 //  beginService( "Port_Impl::IsInLine" ) ;
320 //  bool RetVal = _DataFlowPort->IsBus() ;
321   bool RetVal = _DataFlowPort->IsInLine() ;
322 //  endService( "Port_Impl::IsInLine" ) ;
323   return RetVal ;
324 }
325
326 bool Port_Impl::IsLoop() {
327 //  beginService( "Port_Impl::IsLoop" ) ;
328   bool RetVal = _DataFlowPort->IsLoop() ;
329 //  endService( "Port_Impl::IsLoop" ) ;
330   return RetVal ;
331 }
332
333 bool Port_Impl::IsSwitch() {
334 //  beginService( "Port_Impl::IsSwitch" ) ;
335   bool RetVal = _DataFlowPort->IsSwitch() ;
336 //  endService( "Port_Impl::IsSwitch" ) ;
337   return RetVal ;
338 }
339
340 bool Port_Impl::IsEndSwitch() {
341 //  beginService( "Port_Impl::IsEndSwitch" ) ;
342   bool RetVal = _DataFlowPort->IsEndSwitch() ;
343 //  endService( "Port_Impl::IsEndSwitch" ) ;
344   return RetVal ;
345 }
346
347 bool Port_Impl::HasInput() {
348 //  beginService( "Port_Impl::" ) ;
349   bool RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
350 //  endService( "Port_Impl::" ) ;
351   return RetVal ;
352 }
353
354 SUPERV::GraphState Port_Impl::State() {
355 //  beginService( "Port_Impl::State" );
356   SUPERV::GraphState RetVal = SUPERV::EditingState ;
357   if ( _DataFlowEditor ) {
358     GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
359     if ( _DataFlowExecutor ) {
360       RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
361                                          _DataFlowPort->PortName() ) ;
362     }
363   }
364 //  endService( "Port_Impl::State" );
365   return RetVal ;
366 }
367
368 bool Port_Impl::IsDone() {
369 //  beginService( "Port_Impl::IsDone" );
370   bool RetVal = false ;
371   if ( _DataFlowEditor ) {
372     GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
373     if ( _DataFlowExecutor ) {
374       RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
375                                           _DataFlowPort->PortName() ) ;
376     }
377   }
378 //  endService( "Port_Impl::IsDone" );
379   return RetVal ;
380 }