2 //=============================================================================
3 // File : Port_Impl.cxx
5 // Author : Jean Rahuel
8 //=============================================================================
15 #include "utilities.h"
17 #include "Graph_Impl.hxx"
18 #include "Port_Impl.hxx"
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 ,
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 ,
36 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
37 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
38 // << hex << (void *) this << dec )
39 _Orb = CORBA::ORB::_duplicate(orb);
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 ;
54 InPort( _InputPort ) ;
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 ,
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);
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 ;
88 InPort( _InputPort ) ;
91 Port_Impl::Port_Impl() {
94 Port_Impl::~Port_Impl() {
95 beginService( "Port_Impl::~Port_Impl" );
96 endService( "Port_Impl::~Port_Impl" );
99 void Port_Impl::destroy() {
100 beginService( "Port_Impl::destroy" );
101 bool destroyed = false ;
102 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
104 GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
105 if ( anInPort->GetOutPort() ) {
106 anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
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() ) ;
116 else if ( !_DataFlowNode->IsLoopNode() ) {
117 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
121 _DataFlowEditor->UnValid() ;
122 // _DataFlowEditor->IsValid() ;
126 _poa->deactivate_object(*_id) ;
127 CORBA::release(_poa) ;
129 _thisObj->_remove_ref();
131 endService( "Port_Impl::destroy" );
134 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
135 return Input( aValue->ToAny() ) ;
138 bool Port_Impl::Input( const CORBA::Any * anAny ) {
139 beginService( "Port_Impl::Input" );
140 bool RetVal = false ;
141 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
143 Value_Impl::Input( anAny ) ;
144 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
145 _DataFlowPort->PortName() ,
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() ,
158 endService( "Port_Impl::Input" );
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 ) ;
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 ) ;
176 SUPERV::CNode_ptr Port_Impl::Node() {
178 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
179 if ( CORBA::is_nil( _DataFlowNode->ObjRef() ) ) {
181 beginService( "Port_Impl::Node" ) ;
184 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
185 instanceName() , interfaceName() ,
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 ) ) ;
195 iobject = _DataFlowNode->ObjRef() ;
198 endService( "Port_Impl::Node" ) ;
200 return SUPERV::CNode::_duplicate( iobject ) ;
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() ) ;
212 SUPERV::Link_ptr Port_Impl::Link() {
214 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
215 if ( _DataFlowNode->IsEndSwitchNode() ) {
216 beginService( "Port_Impl::Link" ) ;
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 ] ;
229 char * FromNodeName = NULL ;
230 char * FromServiceParameterName = NULL ;
231 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
232 _DataFlowPort->PortName() ,
234 & FromServiceParameterName ) ;
236 // cout << "Port_Impl::Link " << FromNodeName << "("
237 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
238 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
239 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
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 ) ) ) {
246 beginService( "Port_Impl::Link" ) ;
249 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
250 instanceName() , interfaceName() ,
253 _DataFlowPort->PortName() ,
254 (GraphEditor::InNode * ) _DataFlowEditor->GetChangeGraphNode( FromNodeName )->GetInNode() ,
255 FromServiceParameterName ,
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 ) ) ;
263 iobject = anOutPort->InPortObjRef( anInPort ) ;
269 endService( "Port_Impl::Link" ) ;
271 return SUPERV::Link::_duplicate( iobject ) ;
274 bool Port_Impl::IsInput() {
275 // beginService( "Port_Impl::IsInput" ) ;
276 bool RetVal = _InputPort ;
277 // endService( "Port_Impl::IsInput" ) ;
281 bool Port_Impl::IsLinked() {
282 // beginService( "Port_Impl::IsLinked" ) ;
285 if ( _DataFlowNode->IsEndSwitchNode() && _DataFlowPort->IsBus() ) {
289 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
293 // endService( "Port_Impl::IsLinked" ) ;
297 SUPERV::KindOfPort Port_Impl::Kind() {
298 // beginService( "Port_Impl::Kind" ) ;
299 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
300 // endService( "Port_Impl::Kind" ) ;
304 bool Port_Impl::IsParam() {
305 // beginService( "Port_Impl::IsParam" ) ;
306 bool RetVal = _DataFlowPort->IsParam() ;
307 // endService( "Port_Impl::IsParam" ) ;
311 bool Port_Impl::IsGate() {
312 // beginService( "Port_Impl::IsGate" ) ;
313 bool RetVal = _DataFlowPort->IsGate() ;
314 // endService( "Port_Impl::IsGate" ) ;
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" ) ;
326 bool Port_Impl::IsLoop() {
327 // beginService( "Port_Impl::IsLoop" ) ;
328 bool RetVal = _DataFlowPort->IsLoop() ;
329 // endService( "Port_Impl::IsLoop" ) ;
333 bool Port_Impl::IsSwitch() {
334 // beginService( "Port_Impl::IsSwitch" ) ;
335 bool RetVal = _DataFlowPort->IsSwitch() ;
336 // endService( "Port_Impl::IsSwitch" ) ;
340 bool Port_Impl::IsEndSwitch() {
341 // beginService( "Port_Impl::IsEndSwitch" ) ;
342 bool RetVal = _DataFlowPort->IsEndSwitch() ;
343 // endService( "Port_Impl::IsEndSwitch" ) ;
347 bool Port_Impl::HasInput() {
348 // beginService( "Port_Impl::" ) ;
349 bool RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
350 // endService( "Port_Impl::" ) ;
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() ) ;
364 // endService( "Port_Impl::State" );
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() ) ;
378 // endService( "Port_Impl::IsDone" );