Salome HOME
*** empty log message ***
[modules/superv.git] / src / Supervision / StreamPort_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   : StreamPort_Impl.cxx
25 //  Author : Jean Rahuel
26 //  Module : SUPERV
27 //  $Header: 
28
29 using namespace std;
30
31 #include "StreamPort_Impl.hxx"
32
33 StreamPort_Impl::StreamPort_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                                   GraphBase::Port * DataFlowPort ,
41                                   bool InputPort ,
42                                   const CORBA::Any * anAny ) :
43   Port_Impl( orb , poa , contId , instanceName , interfaceName ,
44              DataFlowEditor , DataFlowNode , DataFlowPort , InputPort , anAny ) {
45 //  MESSAGE("StreamPort_Impl::StreamPort_Impl activate object instanceName("
46 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
47 //          << hex << (void *) this << dec )
48   _Orb = CORBA::ORB::_duplicate(orb);
49   _Poa = poa ;
50   _ContId = contId ;
51   _thisObj = this ;
52   _id = _poa->activate_object(_thisObj);
53 }
54
55 StreamPort_Impl::StreamPort_Impl( CORBA::ORB_ptr orb ,
56                       PortableServer::POA_ptr poa ,
57                       PortableServer::ObjectId * contId , 
58                       const char *instanceName ,
59                       const char *interfaceName ,
60                       GraphEditor::DataFlow * DataFlowEditor ,
61                       GraphEditor::InNode * DataFlowNode ,
62                       GraphBase::Port * DataFlowPort ,
63                       bool InputPort ) :
64   Port_Impl( orb , poa , contId , instanceName , interfaceName ,
65              DataFlowEditor , DataFlowNode , DataFlowPort , InputPort ) {
66 //  MESSAGE("StreamPort_Impl::StreamPorte_Impl activate object instanceName("
67 //          << instanceName << ") interfaceName(" << interfaceName << ") --> "
68 //          << hex << (void *) this << dec )
69   _Orb = CORBA::ORB::_duplicate(orb);
70   _Poa = poa ;
71   _ContId = contId ;
72   _thisObj = this ;
73   _id = _poa->activate_object(_thisObj);
74 }
75
76 StreamPort_Impl::StreamPort_Impl() {
77 }
78
79 StreamPort_Impl::~StreamPort_Impl() {
80   beginService( "StreamPort_Impl::~StreamPort_Impl" );
81   endService( "StreamPort_Impl::~StreamPort_Impl" );
82 }
83
84 void StreamPort_Impl::destroy() {
85   beginService( "StreamPort_Impl::destroy" );
86   bool destroyed = false ;
87   if ( DataFlowNode()->IsOneOfInLineNodes() ) {
88     if ( IsInput() ) {
89       GraphBase::InPort * anInPort = (GraphBase::InPort * ) DataFlowPort() ;
90       if ( anInPort->GetOutPort() ) {
91         anInPort->GetOutPort()->RemoveInPort( anInPort ) ;
92       }
93       DataFlowNode()->DelInPort( DataFlowPort()->PortName() ) ;
94       destroyed = true ;
95     }
96     else {
97       DataFlowNode()->DelOutPort( DataFlowPort()->PortName() ) ;
98       destroyed = true ;
99     }
100     if ( destroyed ) {
101       DataFlowEditor()->UnValid() ;
102     }
103   }
104   if ( destroyed ) {
105     _poa->deactivate_object(*_id) ;
106     CORBA::release(_poa) ;
107     delete(_id) ;
108     _thisObj->_remove_ref();
109   }
110   endService( "StreamPort_Impl::destroy" );
111 }
112
113
114 SUPERV::StreamLink_ptr StreamPort_Impl::StreamLink() {
115   bool begin = true ;
116   SUPERV::StreamLink_var iobject = SUPERV::StreamLink::_nil() ;
117   char * FromNodeName = NULL ;
118   char * FromServiceParameterName = NULL ;
119   bool status = DataFlowEditor()->GetLink( DataFlowNode()->Name() ,
120                                            DataFlowPort()->PortName() ,
121                                            & FromNodeName ,
122                                            & FromServiceParameterName ) ;
123   if ( status ) {
124 //    cout << "Port_Impl::Link " << FromNodeName << "("
125 //         << FromServiceParameterName << ") --> " << _DataFlowNode->Name()
126 //         << "(" << _DataFlowPort->PortName() << ")" << endl ;
127 //    SUPERV::Port_ptr theOutPort = Port( FromServiceParameterName ) ;
128
129     GraphBase::InPort * anInPort = DataFlowNode()->GetChangeInPort( DataFlowPort()->PortName() ) ;
130     if ( anInPort->GetOutPort() ) {
131       GraphBase::OutPort * anOutPort = anInPort->GetOutPort() ;
132       if ( CORBA::is_nil( anOutPort->InPortObjRef( anInPort ) ) ) {
133         if ( begin ) {
134           beginService( "Port_Impl::Link" ) ;
135           begin = false ;
136         }
137         StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
138                                     instanceName() , interfaceName() ,
139                                     DataFlowEditor() ,
140                                     DataFlowNode() ,
141                                     DataFlowPort()->PortName() ,
142                                     (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
143                                     FromServiceParameterName ,
144                                     false ) ;
145         PortableServer::ObjectId * id = myStreamLink->getId() ;
146         CORBA::Object_var obj = _poa->id_to_reference(*id);
147         iobject = SUPERV::StreamLink::_narrow(obj) ;
148         anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
149       }
150       else {
151         iobject = SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ;
152       }
153     }
154   }
155   if ( !begin ) {
156     MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
157              << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
158     endService( "StreamPort_Impl::StreamLink" ) ;
159   }
160   return SUPERV::StreamLink::_duplicate( iobject ) ;
161 }
162
163 SALOME_ModuleCatalog::DataStreamDependency StreamPort_Impl::Dependency() {
164 //  beginService( "StreamPort_Impl::Dependency" );
165   SALOME_ModuleCatalog::DataStreamDependency  RetVal = DataFlowPort()->Dependency() ;
166 //  endService( "StreamPort_Impl::Dependency" );
167   return RetVal ;
168 }
169
170 bool StreamPort_Impl::SetDependency( const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
171 //  beginService( "StreamPort_Impl::SetDependency" );
172   DataFlowPort()->Dependency( aDependency ) ;
173 //  endService( "StreamPort_Impl::SetDependency" );
174   return true ;
175 }
176
177 bool StreamPort_Impl::SetParams( const SUPERV::KindOfSchema aKindOfSchema ,
178                                  const SUPERV::KindOfInterpolation aKindOfInterpolation ,
179                                  const SUPERV::KindOfExtrapolation aKindOfExtrapolation ) {
180 //  beginService( "StreamPort_Impl::SetParams" );
181   bool RetVal = false ;
182   if ( IsInput() ) {
183     GraphBase::InDataStreamPort * anInStreamPort = (GraphBase::InDataStreamPort * ) DataFlowPort() ;
184     RetVal = anInStreamPort->SetParams( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
185     MESSAGE( "OutStreamPort_Impl::SetParams( " << aKindOfSchema << " , " << aKindOfInterpolation
186              << " , " << aKindOfExtrapolation << " ) sts " << RetVal ) ;
187   }
188   else {
189     MESSAGE( "OutStreamPort_Impl::SetParams( " << aKindOfSchema << " , " << aKindOfInterpolation
190              << " , " << aKindOfExtrapolation << " ) ERROR : OutPort" ) ;
191   }
192 //  endService( "StreamPort_Impl::SetParams" );
193   return RetVal ;
194 }
195
196 bool StreamPort_Impl::Params( SUPERV::KindOfSchema & aKindOfSchema ,
197                               SUPERV::KindOfInterpolation & aKindOfInterpolation ,
198                               SUPERV::KindOfExtrapolation & aKindOfExtrapolation ) {
199 //  beginService( "StreamPort_Impl::Params" );
200   bool RetVal = false ;
201   if ( IsInput() ) {
202     GraphBase::InDataStreamPort * anInStreamPort = (GraphBase::InDataStreamPort * ) DataFlowPort() ;
203     anInStreamPort->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
204     MESSAGE( "InStreamPort_Impl::Params( " << aKindOfSchema << " , " << aKindOfInterpolation << " , " << aKindOfExtrapolation << " )" ) ;
205     RetVal = true ;
206   }
207   else {
208     aKindOfSchema = (SUPERV::KindOfSchema ) -1 ;
209     aKindOfInterpolation = (SUPERV::KindOfInterpolation ) -1 ;
210     aKindOfExtrapolation = (SUPERV::KindOfExtrapolation ) -1 ;
211     MESSAGE( "OutStreamPort_Impl::Params( " << aKindOfSchema << " , " << aKindOfInterpolation
212              << " , " << aKindOfExtrapolation << " ) ERROR: OutPort" ) ;
213   }
214 //  endService( "StreamPort_Impl::Params" );
215   return RetVal ;
216 }
217
218 bool StreamPort_Impl::SetNumberOfValues( const long aNumberOfValues ) {
219 //  beginService( "StreamPort_Impl::SetNumberOfValues" );
220   bool RetVal = false ;
221   if ( !IsInput() ) {
222     GraphBase::OutDataStreamPort * anOutStreamPort = (GraphBase::OutDataStreamPort * ) DataFlowPort() ;
223     anOutStreamPort->NumberOfValues( aNumberOfValues ) ;
224     RetVal = true ;
225   }
226   else {
227     MESSAGE( "OutStreamPort_Impl::SetNumberOfValues( " << aNumberOfValues << " ) ERROR : InPort" ) ;
228   }
229 //  endService( "StreamPort_Impl::SetNumberOfValues" );
230   return RetVal ;
231 }
232
233 long StreamPort_Impl::NumberOfValues() {
234 //  beginService( "StreamPort_Impl::NumberOfValues" );
235   long RetVal = -1 ;
236   if ( !IsInput() ) {
237     GraphBase::OutDataStreamPort * anOutStreamPort = (GraphBase::OutDataStreamPort * ) DataFlowPort() ;
238     RetVal = anOutStreamPort->NumberOfValues() ;
239     MESSAGE( "OutStreamPort_Impl::NumberOfValues() " << RetVal ) ;
240   }
241   else {
242     MESSAGE( "OutStreamPort_Impl::NumberOfValues() ERROR : InPort" ) ;
243   }
244 //  endService( "StreamPort_Impl::NumberOfValues" );
245   return RetVal ;
246 }
247