1 // SUPERV Supervision : contains the implementation of interfaces of SuperVision described in SUPERV.idl
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Port_Impl.cxx
25 // Author : Jean Rahuel
35 #include "utilities.h"
37 #include "Graph_Impl.hxx"
38 #include "Port_Impl.hxx"
40 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
41 PortableServer::POA_ptr poa ,
42 PortableServer::ObjectId * contId ,
43 const char *instanceName ,
44 const char *interfaceName ,
45 GraphEditor::DataFlow * DataFlowEditor ,
46 GraphEditor::InNode * DataFlowNode ,
47 // const char *ParameterName ,
48 GraphBase::Port * DataFlowPort ,
50 const CORBA::Any * anAny ) :
51 // const SUPERV::Value_ptr aValue ) :
52 Value_Impl(orb, poa, contId, instanceName, interfaceName,
53 // DataFlowEditor , DataFlowNode , ParameterName, aValue->ToAny() ,
54 DataFlowEditor , DataFlowNode , DataFlowPort->PortName(), anAny ,
56 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
57 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
58 // << hex << (void *) this << dec )
59 _Orb = CORBA::ORB::_duplicate(orb);
63 _id = _poa->activate_object(_thisObj);
64 _DataFlowEditor = DataFlowEditor ;
65 _DataFlowNode = DataFlowNode ;
66 // _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
67 _DataFlowPort = DataFlowPort ;
68 // _InputPort = true ;
69 _InputPort = InputPort ;
70 // if ( _DataFlowPort == NULL ) {
71 // _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
72 // _InputPort = false ;
74 InPort( _InputPort ) ;
77 Port_Impl::Port_Impl( CORBA::ORB_ptr orb ,
78 PortableServer::POA_ptr poa ,
79 PortableServer::ObjectId * contId ,
80 const char *instanceName ,
81 const char *interfaceName ,
82 GraphEditor::DataFlow * DataFlowEditor ,
83 GraphEditor::InNode * DataFlowNode ,
84 // const char *ParameterName ) :
85 GraphBase::Port * DataFlowPort ,
87 Value_Impl(orb, poa, contId, instanceName, interfaceName,
88 DataFlowEditor , DataFlowNode , DataFlowPort->PortName() , false ) {
89 // DataFlowEditor , DataFlowNode , ParameterName , false ) {
90 // MESSAGE("Value_Impl::Value_Impl activate object instanceName("
91 // << instanceName << ") interfaceName(" << interfaceName << ") --> "
92 // << hex << (void *) this << dec )
93 _Orb = CORBA::ORB::_duplicate(orb);
97 _id = _poa->activate_object(_thisObj);
98 _DataFlowEditor = DataFlowEditor ;
99 _DataFlowNode = DataFlowNode ;
100 // _DataFlowPort = _DataFlowNode->GetChangeInPort( ParameterName ) ;
101 _DataFlowPort = DataFlowPort ;
102 // _InputPort = true ;
103 _InputPort = InputPort ;
104 // if ( _DataFlowPort == NULL ) {
105 // _DataFlowPort = _DataFlowNode->GetChangeOutPort( ParameterName ) ;
106 // _InputPort = false ;
108 InPort( _InputPort ) ;
111 Port_Impl::Port_Impl() {
114 Port_Impl::~Port_Impl() {
115 beginService( "Port_Impl::~Port_Impl" );
116 endService( "Port_Impl::~Port_Impl" );
119 void Port_Impl::destroy() {
120 beginService( "Port_Impl::destroy" );
121 bool destroyed = false ;
122 if ( _DataFlowNode->IsOneOfInLineNodes() ) {
124 GraphBase::InPort * anInPort = (GraphBase::InPort * ) _DataFlowPort ;
125 if ( anInPort->GetOutPort() ) {
126 anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
128 _DataFlowNode->DelInPort( _DataFlowPort->PortName() ) ;
129 if ( _DataFlowNode->IsLoopNode() ) {
130 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
131 _DataFlowNode->CoupledNode()->DelInPort( _DataFlowPort->PortName() ) ;
132 _DataFlowNode->CoupledNode()->DelOutPort( _DataFlowPort->PortName() ) ;
136 else if ( !_DataFlowNode->IsLoopNode() ) {
137 _DataFlowNode->DelOutPort( _DataFlowPort->PortName() ) ;
141 _DataFlowEditor->UnValid() ;
142 // _DataFlowEditor->IsValid() ;
146 _poa->deactivate_object(*_id) ;
147 CORBA::release(_poa) ;
149 _thisObj->_remove_ref();
151 endService( "Port_Impl::destroy" );
154 bool Port_Impl::Input( const SUPERV::Value_ptr aValue ) {
155 return Input( aValue->ToAny() ) ;
158 bool Port_Impl::Input( const CORBA::Any * anAny ) {
159 beginService( "Port_Impl::Input" );
160 bool RetVal = false ;
161 if ( _InputPort && _DataFlowEditor->IsEditing() ) {
163 Value_Impl::Input( anAny ) ;
164 RetVal = _DataFlowEditor->AddInputData( _DataFlowNode->Name() ,
165 _DataFlowPort->PortName() ,
168 else if ( _DataFlowEditor->IsExecuting() ) {
169 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
170 // if ( _DataFlowExecutor && ( _DataFlowExecutor->IsSuspended() ||
171 // _DataFlowExecutor->IsSuspended( _DataFlowNode->Name() ) ) ) {
172 if ( _DataFlowExecutor ) {
173 RetVal = _DataFlowExecutor->ChangeInputData( _DataFlowNode->Name() ,
174 _DataFlowPort->PortName() ,
178 endService( "Port_Impl::Input" );
182 char * Port_Impl::Name() {
183 // beginService( "Port_Impl::Name" ) ;
184 const char * RetVal = _DataFlowPort->PortName() ;
185 // endService( "Port_Impl::Name" ) ;
186 return CORBA::string_dup( RetVal ) ;
189 char * Port_Impl::Type() {
190 // beginService( "Port_Impl::Type" ) ;
191 const char * RetVal = _DataFlowPort->PortType() ;
192 // endService( "Port_Impl::Type" ) ;
193 return CORBA::string_dup( RetVal ) ;
196 SUPERV::CNode_ptr Port_Impl::Node() {
198 SUPERV::CNode_var iobject = SUPERV::CNode::_nil() ;
199 if ( CORBA::is_nil( _DataFlowNode->ObjRef() ) ) {
201 beginService( "Port_Impl::Node" ) ;
204 CNode_Impl * myNode = new CNode_Impl( _Orb , _Poa , _ContId ,
205 instanceName() , interfaceName() ,
208 PortableServer::ObjectId * id = myNode->getId() ;
209 CORBA::Object_var obj = _poa->id_to_reference(*id);
210 SUPERV::CNode_var iobject ;
211 iobject = SUPERV::CNode::_narrow(obj) ;
212 myNode->SetObjRef( SUPERV::CNode::_duplicate( iobject ) ) ;
215 iobject = _DataFlowNode->ObjRef() ;
218 endService( "Port_Impl::Node" ) ;
220 return SUPERV::CNode::_duplicate( iobject ) ;
223 SUPERV::ListOfLinks * Port_Impl::Links() {
224 beginService( "Port_Impl::Links" ) ;
225 SUPERV::ListOfLinks_var RetVal = new SUPERV::ListOfLinks ;
226 RetVal = _DataFlowEditor->ObjImpl()->Links( _DataFlowNode->ComputingNode() ,
227 _DataFlowPort->PortName() ) ;
228 endService( "Port_Impl::Links" ) ;
229 return ( RetVal._retn() ) ;
232 SUPERV::Link_ptr Port_Impl::Link() {
234 SUPERV::Link_var iobject = SUPERV::Link::_nil() ;
235 if ( _DataFlowNode->IsEndSwitchNode() ) {
236 beginService( "Port_Impl::Link" ) ;
238 SUPERV::ListOfLinks_var Links = new SUPERV::ListOfLinks ;
239 cout << "Port_Impl::Link " << _DataFlowNode->Name() << " "
240 << _DataFlowPort->PortName() << endl ;
241 Links = _DataFlowEditor->ObjImpl()->Links(
242 _DataFlowNode->ComputingNode() ,
243 _DataFlowPort->PortName() ) ;
244 if ( Links->length() ) {
245 iobject = Links[ 0 ] ;
249 char * FromNodeName = NULL ;
250 char * FromServiceParameterName = NULL ;
251 bool status = _DataFlowEditor->GetLink( _DataFlowNode->Name() ,
252 _DataFlowPort->PortName() ,
254 & FromServiceParameterName ) ;
256 // cout << "Port_Impl::Link " << FromNodeName << "("
257 // << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
258 // << "(" << _DataFlowPort->PortName() << ")" << endl ;
259 // SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
261 GraphBase::InPort * anInPort = _DataFlowNode->GetChangeInPort( _DataFlowPort->PortName() ) ;
262 if ( anInPort->GetOutPort() ) {
263 GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
264 if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
266 beginService( "Port_Impl::Link" ) ;
269 Link_Impl * myLink = new Link_Impl( _Orb , _Poa , _ContId ,
270 instanceName() , interfaceName() ,
273 _DataFlowPort->PortName() ,
274 (GraphEditor::InNode * ) _DataFlowEditor->GetChangeGraphNode( FromNodeName )->GetInNode() ,
275 FromServiceParameterName ,
277 PortableServer::ObjectId * id = myLink->getId() ;
278 CORBA::Object_var obj = _poa->id_to_reference(*id);
279 iobject = SUPERV::Link::_narrow(obj) ;
280 anOutPort->AddInPortObjRef( anInPort , SUPERV::Link::_duplicate( iobject ) ) ;
283 iobject = anOutPort->InPortObjRef( anInPort ) ;
289 endService( "Port_Impl::Link" ) ;
291 return SUPERV::Link::_duplicate( iobject ) ;
294 bool Port_Impl::IsInput() {
295 // beginService( "Port_Impl::IsInput" ) ;
296 bool RetVal = _InputPort ;
297 // endService( "Port_Impl::IsInput" ) ;
301 bool Port_Impl::IsLinked() {
302 // beginService( "Port_Impl::IsLinked" ) ;
305 if ( _DataFlowNode->IsEndSwitchNode() && _DataFlowPort->IsBus() ) {
309 RetVal = _DataFlowNode->IsLinked( _DataFlowPort->PortName() ) ;
313 // endService( "Port_Impl::IsLinked" ) ;
317 SUPERV::KindOfPort Port_Impl::Kind() {
318 // beginService( "Port_Impl::Kind" ) ;
319 SUPERV::KindOfPort RetVal = _DataFlowPort->Kind() ;
320 // endService( "Port_Impl::Kind" ) ;
324 bool Port_Impl::IsParam() {
325 // beginService( "Port_Impl::IsParam" ) ;
326 bool RetVal = _DataFlowPort->IsParam() ;
327 // endService( "Port_Impl::IsParam" ) ;
331 bool Port_Impl::IsGate() {
332 // beginService( "Port_Impl::IsGate" ) ;
333 bool RetVal = _DataFlowPort->IsGate() ;
334 // endService( "Port_Impl::IsGate" ) ;
338 bool Port_Impl::IsInLine() {
339 // beginService( "Port_Impl::IsInLine" ) ;
340 // bool RetVal = _DataFlowPort->IsBus() ;
341 bool RetVal = _DataFlowPort->IsInLine() ;
342 // endService( "Port_Impl::IsInLine" ) ;
346 bool Port_Impl::IsLoop() {
347 // beginService( "Port_Impl::IsLoop" ) ;
348 bool RetVal = _DataFlowPort->IsLoop() ;
349 // endService( "Port_Impl::IsLoop" ) ;
353 bool Port_Impl::IsSwitch() {
354 // beginService( "Port_Impl::IsSwitch" ) ;
355 bool RetVal = _DataFlowPort->IsSwitch() ;
356 // endService( "Port_Impl::IsSwitch" ) ;
360 bool Port_Impl::IsEndSwitch() {
361 // beginService( "Port_Impl::IsEndSwitch" ) ;
362 bool RetVal = _DataFlowPort->IsEndSwitch() ;
363 // endService( "Port_Impl::IsEndSwitch" ) ;
367 bool Port_Impl::HasInput() {
368 // beginService( "Port_Impl::" ) ;
369 bool RetVal = _DataFlowNode->HasInput( _DataFlowPort->PortName() ) ;
370 // endService( "Port_Impl::" ) ;
374 SUPERV::GraphState Port_Impl::State() {
375 // beginService( "Port_Impl::State" );
376 SUPERV::GraphState RetVal = SUPERV::EditingState ;
377 if ( _DataFlowEditor ) {
378 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
379 if ( _DataFlowExecutor ) {
380 RetVal = _DataFlowExecutor->State( _DataFlowPort->NodeName() ,
381 _DataFlowPort->PortName() ) ;
384 // endService( "Port_Impl::State" );
388 bool Port_Impl::IsDone() {
389 // beginService( "Port_Impl::IsDone" );
390 bool RetVal = false ;
391 if ( _DataFlowEditor ) {
392 GraphExecutor::DataFlow * _DataFlowExecutor = _DataFlowEditor->Executor() ;
393 if ( _DataFlowExecutor ) {
394 RetVal = _DataFlowExecutor->IsDone( _DataFlowPort->NodeName() ,
395 _DataFlowPort->PortName() ) ;
398 // endService( "Port_Impl::IsDone" );