Salome HOME
Crash in the destructor with omniORB4
[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         bool Success ;
138         StreamLink_Impl * myStreamLink = new StreamLink_Impl( _Orb , _Poa , _ContId ,
139                                     instanceName() , interfaceName() ,
140                                     DataFlowEditor() ,
141                                     DataFlowNode() ,
142                                     DataFlowPort()->PortName() ,
143                                     (GraphEditor::InNode * ) DataFlowEditor()->Graph()->GetChangeGraphNode( FromNodeName )->GetInNode() ,
144                                     FromServiceParameterName ,
145                                     false , Success ) ;
146         if ( Success ) {
147           PortableServer::ObjectId * id = myStreamLink->getId() ;
148           CORBA::Object_var obj = _poa->id_to_reference(*id);
149           iobject = SUPERV::StreamLink::_narrow(obj) ;
150           anOutPort->AddInPortObjRef( anInPort , SUPERV::StreamLink::_duplicate( iobject ) ) ;
151         }
152       }
153       else {
154         iobject = SUPERV::StreamLink::_narrow( anOutPort->InPortObjRef( anInPort ) ) ;
155       }
156     }
157   }
158   if ( !begin ) {
159     MESSAGE( "Link " << iobject->OutPort()->Node()->Name() << "( " << iobject->OutPort()->Name() << " ) --> "
160              << iobject->InPort()->Node()->Name() << "( " << iobject->InPort()->Name() << " ) " ) ;
161     endService( "StreamPort_Impl::StreamLink" ) ;
162   }
163   return SUPERV::StreamLink::_duplicate( iobject ) ;
164 }
165
166 SALOME_ModuleCatalog::DataStreamDependency StreamPort_Impl::Dependency() {
167 //  beginService( "StreamPort_Impl::Dependency" );
168   SALOME_ModuleCatalog::DataStreamDependency  RetVal = DataFlowPort()->Dependency() ;
169 //  endService( "StreamPort_Impl::Dependency" );
170   return RetVal ;
171 }
172
173 bool StreamPort_Impl::SetDependency( const SALOME_ModuleCatalog::DataStreamDependency aDependency ) {
174 //  beginService( "StreamPort_Impl::SetDependency" );
175   DataFlowPort()->Dependency( aDependency ) ;
176 //  endService( "StreamPort_Impl::SetDependency" );
177   return true ;
178 }
179
180 bool StreamPort_Impl::SetParams( const SUPERV::KindOfSchema aKindOfSchema ,
181                                  const SUPERV::KindOfInterpolation aKindOfInterpolation ,
182                                  const SUPERV::KindOfExtrapolation aKindOfExtrapolation ) {
183 //  beginService( "StreamPort_Impl::SetParams" );
184   bool RetVal = false ;
185   if ( IsInput() ) {
186     GraphBase::InDataStreamPort * anInStreamPort = (GraphBase::InDataStreamPort * ) DataFlowPort() ;
187     RetVal = anInStreamPort->SetParams( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
188     if ( RetVal ) {
189       MESSAGE( "OutStreamPort_Impl::SetParams( " << aKindOfSchema << " , " << aKindOfInterpolation
190                << " , " << aKindOfExtrapolation << " ) SUCCESS " ) ;
191       DataFlowEditor()->UnValid() ;
192     }
193     else {
194       MESSAGE( "OutStreamPort_Impl::SetParams( " << aKindOfSchema << " , " << aKindOfInterpolation
195                << " , " << aKindOfExtrapolation << " ) FAILED " ) ;
196     }
197   }
198   else {
199     MESSAGE( "OutStreamPort_Impl::SetParams( " << aKindOfSchema << " , " << aKindOfInterpolation
200              << " , " << aKindOfExtrapolation << " ) ERROR : OutPort" ) ;
201   }
202 //  endService( "StreamPort_Impl::SetParams" );
203   return RetVal ;
204 }
205
206 bool StreamPort_Impl::Params( SUPERV::KindOfSchema & aKindOfSchema ,
207                               SUPERV::KindOfInterpolation & aKindOfInterpolation ,
208                               SUPERV::KindOfExtrapolation & aKindOfExtrapolation ) {
209 //  beginService( "StreamPort_Impl::Params" );
210   bool RetVal = false ;
211   if ( IsInput() ) {
212     GraphBase::InDataStreamPort * anInStreamPort = (GraphBase::InDataStreamPort * ) DataFlowPort() ;
213     anInStreamPort->Params( aKindOfSchema , aKindOfInterpolation , aKindOfExtrapolation ) ;
214     MESSAGE( "InStreamPort_Impl::Params( " << aKindOfSchema << " , " << aKindOfInterpolation << " , " << aKindOfExtrapolation << " )" ) ;
215     RetVal = true ;
216   }
217   else {
218     aKindOfSchema = (SUPERV::KindOfSchema ) -1 ;
219     aKindOfInterpolation = (SUPERV::KindOfInterpolation ) -1 ;
220     aKindOfExtrapolation = (SUPERV::KindOfExtrapolation ) -1 ;
221     MESSAGE( "OutStreamPort_Impl::Params( " << aKindOfSchema << " , " << aKindOfInterpolation
222              << " , " << aKindOfExtrapolation << " ) ERROR: OutPort" ) ;
223   }
224 //  endService( "StreamPort_Impl::Params" );
225   return RetVal ;
226 }
227
228 bool StreamPort_Impl::SetNumberOfValues( const long aNumberOfValues ) {
229 //  beginService( "StreamPort_Impl::SetNumberOfValues" );
230   bool RetVal = false ;
231   if ( !IsInput() ) {
232     GraphBase::OutDataStreamPort * anOutStreamPort = (GraphBase::OutDataStreamPort * ) DataFlowPort() ;
233     anOutStreamPort->NumberOfValues( aNumberOfValues ) ;
234     DataFlowEditor()->UnValid() ;
235     RetVal = true ;
236   }
237   else {
238     MESSAGE( "OutStreamPort_Impl::SetNumberOfValues( " << aNumberOfValues << " ) ERROR : InPort" ) ;
239   }
240 //  endService( "StreamPort_Impl::SetNumberOfValues" );
241   return RetVal ;
242 }
243
244 long StreamPort_Impl::NumberOfValues() {
245 //  beginService( "StreamPort_Impl::NumberOfValues" );
246   long RetVal = -1 ;
247   if ( !IsInput() ) {
248     GraphBase::OutDataStreamPort * anOutStreamPort = (GraphBase::OutDataStreamPort * ) DataFlowPort() ;
249     RetVal = anOutStreamPort->NumberOfValues() ;
250     MESSAGE( "OutStreamPort_Impl::NumberOfValues() " << RetVal ) ;
251   }
252   else {
253     MESSAGE( "OutStreamPort_Impl::NumberOfValues() ERROR : InPort" ) ;
254   }
255 //  endService( "StreamPort_Impl::NumberOfValues" );
256   return RetVal ;
257 }
258