Salome HOME
DCQ : Merge with Ecole_Ete_a6.
[modules/superv.git] / src / Supervision / StreamLink_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   : StreamLink_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30
31 #include "StreamLink_Impl.hxx"
32
33 StreamLink_Impl::StreamLink_Impl( CORBA::ORB_ptr orb ,
34                                   PortableServer::POA_ptr poa ,
35                                   PortableServer::ObjectId * contId , 
36                                   const char *instanceName ,
37                                   const char *interfaceName ,
38                                   GraphEditor::DataFlow * DataFlowEditor ,
39                                   GraphEditor::InNode * DataFlowNode ,
40                                   const char *InputParameterName ,
41                                   GraphEditor::InNode * DataFlowOutNode ,
42                                   const char *OutputParameterName ,
43                                   const bool Create ,
44                                   bool & Success ) :
45   Link_Impl( orb , poa , contId , instanceName , interfaceName , DataFlowEditor ,
46              DataFlowNode , InputParameterName , DataFlowOutNode ,
47              OutputParameterName , false , false , Success ) {
48 //  MESSAGE("StreamLink_Impl::StreamLink_Impl activate object instanceName("
49 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
50 //          << hex << (void *) this << dec )
51 //  bool linksts ;
52 //  beginService( "StreamLink_Impl::Link_Impl" );
53   _Orb = CORBA::ORB::_duplicate(orb);
54   _Poa = poa ;
55   _ContId = contId ;
56   if ( Create ) {
57     Success = DataFlowEditor->AddLink( DataFlowOutNode->Name() ,
58                                        OutputParameterName , 
59                                        DataFlowNode->Name() ,
60                                        InputParameterName ) ;
61   }
62   else {
63     char * DataFlowOutNodeName = NULL ;
64     char * OutParamName = NULL ;
65     Success = DataFlowEditor->GetLink( DataFlowNode->Name() ,
66                                        InputParameterName , 
67                                        &DataFlowOutNodeName ,
68                                        &OutParamName ) ;
69   }
70   _thisObj = this ;
71   _id = _poa->activate_object(_thisObj);
72 //  endService( "StreamLink_Impl::Link_Impl" );
73 }
74
75 StreamLink_Impl::StreamLink_Impl() {
76 }
77
78 StreamLink_Impl::~StreamLink_Impl() {
79   beginService( "Link_Impl::~Link_Impl" );
80   endService( "Link_Impl::~Link_Impl" );
81 }
82
83 void StreamLink_Impl::destroy() {
84   beginService( "StreamLink_Impl::destroy" );
85   Delete() ;
86   _poa->deactivate_object(*_id) ;
87   CORBA::release(_poa) ;
88   delete(_id) ;
89   _thisObj->_remove_ref();
90   endService( "StreamLink_Impl::destroy" );
91 }
92
93 bool StreamLink_Impl::Delete() {
94 //  beginService( "StreamLink_Impl::Delete" ) ;
95   bool RetVal = DataFlowEditor()->RemoveLink( DataFlowOutNode()->Name() ,
96                                               OutputParameterName() ,
97                                               DataFlowNode()->Name() ,
98                                               InputParameterName() ) ;
99   if ( RetVal ) {
100     DataFlowEditor()->UnValid() ;
101   }
102 //  endService( "StreamLink_Impl::Delete" );
103   return RetVal ;
104 }
105
106 SUPERV::StreamPort_ptr StreamLink_Impl::InStreamPort() {
107 //  beginService( "Link_Impl::InStreamPort" );
108   SUPERV::StreamPort_var iobject = SUPERV::StreamPort::_nil() ;
109   GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( InputParameterName() ) ;
110   if ( anInPort && anInPort->IsDataStream() ) {
111     iobject = SUPERV::StreamPort::_narrow( anInPort->ObjRef() ) ;
112     if ( CORBA::is_nil( iobject ) ) {
113 //      MESSAGE( "StreamLink_Impl::InStreamPort creates myStreamPort "
114 //               << DataFlowNode()->Name() << "( " << anInPort->PortName() << " )" ) ;
115       StreamPort_Impl * myStreamPort = new StreamPort_Impl(
116                                        _Orb , _Poa , _ContId ,
117                                        instanceName() , interfaceName() ,
118                                        DataFlowEditor() ,
119                                        DataFlowNode() ,
120                                        (GraphBase::Port * ) anInPort ,
121                                        true ) ;
122       PortableServer::ObjectId * id = myStreamPort->getId() ;
123       CORBA::Object_var obj = _poa->id_to_reference(*id);
124       iobject = SUPERV::StreamPort::_narrow(obj) ;
125       anInPort->ObjRef( SUPERV::StreamPort::_duplicate( iobject ) ) ;
126     }
127     else {
128 //      MESSAGE( "StreamLink_Impl::InStreamPort Gets ObjRef "
129 //               << iobject->Node()->Name() << "( " << iobject->Name() << " )" ) ;
130     }
131   }
132 //  endService( "StreamLink_Impl::InStreamPort" );
133   return SUPERV::StreamPort::_duplicate( iobject ) ;
134 }
135
136 SUPERV::StreamPort_ptr StreamLink_Impl::OutStreamPort() {
137 //  beginService( "StreamLink_Impl::OutStreamPort" );
138   SUPERV::StreamPort_var iobject ;
139   GraphBase::OutPort * anOutPort = DataFlowOutNode()->GetChangeOutPort( OutputParameterName() ) ;
140   if ( anOutPort && anOutPort->IsDataStream() ) {
141     iobject = SUPERV::StreamPort::_narrow( anOutPort->ObjRef() ) ;
142     if ( CORBA::is_nil( iobject ) ) {
143 //      MESSAGE( "StreamLink_Impl::OutStreamPort creates myStreamPort "
144 //               << DataFlowNode()->Name() << "( " << anOutPort->PortName() << " )" ) ;
145       StreamPort_Impl * myStreamPort = new StreamPort_Impl(
146                                        _Orb , _Poa , _ContId ,
147                                        instanceName() , interfaceName() ,
148                                        DataFlowEditor() ,
149                                        DataFlowOutNode() ,
150                                        (GraphBase::Port * ) anOutPort ,
151                                        false ) ;
152       PortableServer::ObjectId * id = myStreamPort->getId() ;
153       CORBA::Object_var obj = _poa->id_to_reference(*id);
154       iobject = SUPERV::StreamPort::_narrow(obj) ;
155       anOutPort->ObjRef( SUPERV::StreamPort::_duplicate( iobject ) ) ;
156     }
157     else {
158 //      MESSAGE( "StreamLink_Impl::OutStreamPort Gets ObjRef "
159 //               << iobject->Node()->Name() << "( " << iobject->Name() << " )" ) ;
160     }
161   }
162 //  endService( "StreamLink_Impl::OutStreamPort" );
163   return SUPERV::StreamPort::_duplicate( iobject ) ;
164 }
165