1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SuperVisionTest SyrComponent : example of component performing some mathinatical operations
23 // File : SyrComponent_Impl.cxx
24 // Author : Jean Rahuel, CEA
25 // Module : SuperVisionTest
33 //#include "utilities.h"
35 #include "SyrComponent_Impl.hxx"
36 #include "Adder_Impl.hxx"
40 SyrComponent_Impl::SyrComponent_Impl( CORBA::ORB_ptr orb ,
41 PortableServer::POA_ptr poa ,
42 PortableServer::ObjectId * contId ,
43 const char *instanceName ,
44 const char *interfaceName ,
45 const bool kactivate ) :
46 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
47 MESSAGE("SyrComponent_Impl::SyrComponent_Impl this " << hex << this << dec
48 << "activate object instanceName("
49 << instanceName << ") interfaceName(" << interfaceName << ")" )
52 _id = _poa->activate_object(_thisObj);
56 SyrComponent_Impl::SyrComponent_Impl() {
59 SyrComponent_Impl::~SyrComponent_Impl() {
62 CORBA::Long SyrComponent_Impl::C_ISEVEN( CORBA::Long anInteger ) {
64 beginService( " SyrComponent_Impl::C_ISEVEN" );
65 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISEVEN is Computing");
66 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
71 RetVal = ( anInteger & 1 ) == 0 ;
72 endService( " SyrComponent_Impl::C_ISEVEN" );
76 CORBA::Long SyrComponent_Impl::C_ISONE( CORBA::Long anOddInteger ) {
78 beginService( " SyrComponent_Impl::C_ISONE" );
79 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISONE is Computing");
80 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
85 RetVal = ( anOddInteger == 1 ) ;
86 endService( " SyrComponent_Impl::C_ISONE" );
90 CORBA::Long SyrComponent_Impl::C_M3( CORBA::Long anOddInteger ) {
91 beginService( " SyrComponent_Impl::C_M3" );
92 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3 is Computing");
93 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
98 endService( " SyrComponent_Impl::C_M3" );
99 if ( C_ISEVEN( anOddInteger ) )
101 return ( 3*anOddInteger ) ;
104 CORBA::Long SyrComponent_Impl::C_M3P1( CORBA::Long anOddInteger ) {
105 beginService( " SyrComponent_Impl::C_M3P1" );
106 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3P1 is Computing");
107 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
112 endService( " SyrComponent_Impl::C_M3P1" );
113 if ( C_ISEVEN( anOddInteger ) )
115 return ( 3*anOddInteger + 1 ) ;
118 CORBA::Long SyrComponent_Impl::C_DIV2( CORBA::Long anEvenInteger ) {
119 beginService( " SyrComponent_Impl::C_DIV2" );
120 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_DIV2 is Computing");
121 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
126 endService( " SyrComponent_Impl::C_DIV2" );
127 if ( !C_ISEVEN( anEvenInteger ) )
129 return ( anEvenInteger >> 1 ) ;
132 CORBA::Long SyrComponent_Impl::C_INCR( CORBA::Long aCount ) {
133 beginService( " SyrComponent_Impl::C_INCR" );
134 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_INCR is Computing");
135 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
140 endService( " SyrComponent_Impl::C_INCR" );
141 return ( aCount + 1 ) ;
144 void SyrComponent_Impl::CPP_SETLONG( CORBA::Long aCount ) {
145 beginService( " SyrComponent_Impl::CPP_SETLONG" );
146 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_SETLONG is Computing");
147 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
153 endService( " SyrComponent_Impl::CPP_SETLONG" );
157 CORBA::Long SyrComponent_Impl::CPP_ADDTOLONG( CORBA::Long anIncr ) {
158 beginService( " SyrComponent_Impl::CPP_ADDTOLONG" );
159 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_ADDTOLONG is Computing");
160 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
165 endService( " SyrComponent_Impl::CPP_ADDTOLONG" );
166 return ( _Count + anIncr ) ;
169 CORBA::Long SyrComponent_Impl::C_MIN( CORBA::Long aMinVal , CORBA::Long anInteger ) {
170 beginService( " SyrComponent_Impl::C_MIN" );
171 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
172 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
178 if ( anInteger < min || aMinVal == 0 ) {
181 string trace = "SyrComponent_Impl::C_MIN : " ;
183 sprintf( cmin , "%d" , min ) ;
185 sendMessage(NOTIF_TRACE, trace.c_str() );
186 endService( " SyrComponent_Impl::C_MIN" );
190 CORBA::Long SyrComponent_Impl::C_MAX( CORBA::Long aMaxVal , CORBA::Long anInteger ) {
191 beginService( " SyrComponent_Impl::C_MAX" );
192 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
193 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
199 if ( anInteger > max ) {
202 string trace = "SyrComponent_Impl::C_MAX : " ;
204 sprintf( cmax , "%d" , max ) ;
206 sendMessage(NOTIF_TRACE, trace.c_str() );
207 endService( " SyrComponent_Impl::C_MAX" );
211 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
212 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
213 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
214 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
219 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
220 instanceName() , interfaceName() ,
221 graphName() , nodeName() ) ;
222 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
223 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
224 CORBA::Object_var obj = _poa->id_to_reference(*id);
225 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
226 endService( " SyrComponent_Impl::C_LISTOFSYR" );
227 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
228 // return ( aNewListOfSyr._retn() ) ;
231 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
232 SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
233 CORBA::Long anInteger ,
235 CORBA::Double & anAverage ) {
236 beginService( " SyrComponent_Impl::C_AVERAGE" );
237 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
238 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
243 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
244 int len = aSeqOfSyr->length() ;
245 aSeqOfSyr->length( len + 1 ) ;
246 (*aSeqOfSyr)[ len ] = anInteger ;
247 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
250 for ( i = 0 ; i < len + 1 ; i++ ) {
251 anAverage += (*aSeqOfSyr)[ i ] ;
253 anAverage = anAverage / ( len + 1 ) ;
254 string end = " SyrComponent_Impl::C_AVERAGE " ;
255 char caverage[ 30 ] ;
256 sprintf( caverage , "%fd" , anAverage ) ;
258 endService( end.c_str() );
259 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
262 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( CORBA::Long anOddInteger ) {
263 beginService( "SyrComponent_Impl::Init" );
264 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
265 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
271 mySyr = new Syr_Impl( _orb , _poa, _contId,
272 instanceName() , interfaceName() ,
273 graphName() , nodeName() , anOddInteger ) ;
274 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
275 PortableServer::ObjectId * id = mySyr->getId() ;
276 CORBA::Object_var obj = _poa->id_to_reference(*id);
277 iobject = SuperVisionTest::Syr::_narrow(obj) ;
278 endService( "SyrComponent_Impl::Init" );
279 return SuperVisionTest::Syr::_duplicate(iobject) ;
282 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
283 PortableServer::POA_ptr poa ,
284 PortableServer::ObjectId * contId ,
285 const char * instanceName ,
286 const char * interfaceName ,
287 const char * graphName ,
288 const char * nodeName ) :
289 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
290 Names( graphName , nodeName ) ;
291 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
292 << instanceName << ") interfaceName(" << interfaceName << ") --> "
293 << hex << (void *) this << dec )
294 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
296 _id = _poa->activate_object(_thisObj);
297 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
298 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
301 ListOfSyr_Impl::ListOfSyr_Impl() {
304 ListOfSyr_Impl::~ListOfSyr_Impl() {
305 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
306 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
309 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
310 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
311 return ( aSeqOfSyr._retn() ) ;
314 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
315 _SeqOfSyr = aSeqOfSyr ;
321 PortableServer::ObjectId * SyrComponentEngine_factory
323 PortableServer::POA_ptr poa,
324 PortableServer::ObjectId * contId,
325 const char *instanceName,
326 const char *interfaceName)
328 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
329 << instanceName << "," << interfaceName << "," << getpid() << ")");
330 SyrComponent_Impl * mySyrComponent
331 = new SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName);
332 return mySyrComponent->getId() ;
336 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
337 PortableServer::POA_ptr poa ,
338 PortableServer::ObjectId * contId ,
339 const char * instanceName ,
340 const char * interfaceName ,
341 const char * graphName ,
342 const char * nodeName ,
343 const CORBA::Long anOddInteger ) :
344 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false) {
345 Names( graphName , nodeName ) ;
346 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
347 << instanceName << ") interfaceName(" << interfaceName << ") --> "
348 << hex << (void *) this << dec )
349 beginService( "Syr_Impl::Syr_Impl" );
351 _id = _poa->activate_object(_thisObj);
352 _InitialInteger = anOddInteger ;
353 _CurrentInteger = anOddInteger ;
355 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
356 endService( "Syr_Impl::Syr_Impl" );
359 Syr_Impl::Syr_Impl() {
362 Syr_Impl::~Syr_Impl() {
363 beginService( "Syr_Impl::~Syr_Impl" );
364 endService( "Syr_Impl::~Syr_Impl" );
367 CORBA::Long Syr_Impl::Initial() {
368 beginService( " Syr_Impl::Initial" );
369 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
370 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
375 endService( " Syr_Impl::Initial" );
376 return _InitialInteger ;
379 CORBA::Long Syr_Impl::Current() {
380 beginService( " Syr_Impl::Current" );
381 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
382 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
387 endService( " Syr_Impl::Current" );
388 return _CurrentInteger ;
391 CORBA::Long Syr_Impl::IsEven() {
393 beginService( " Syr_Impl::IsEven" );
394 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
395 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
400 RetVal = ( _CurrentInteger & 1 ) == 0 ;
401 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
402 endService( " Syr_Impl::IsEven" );
406 CORBA::Long Syr_Impl::IsOne() {
408 beginService( " Syr_Impl::IsOne" );
409 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
410 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
415 RetVal = ( _CurrentInteger == 1 ) ;
416 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
417 endService( " Syr_Impl::IsOne" );
421 CORBA::Long Syr_Impl::Count() {
422 beginService( " Syr_Impl::Count" );
423 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
424 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
429 MESSAGE( " Syr_Impl::Count " << _Count );
430 endService( " Syr_Impl::Count" );
434 void Syr_Impl::M3p1() {
435 beginService( " Syr_Impl::M3p1" );
436 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
437 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
443 _CurrentInteger = 0 ;
445 _CurrentInteger = 3*_CurrentInteger + 1 ;
446 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
447 endService( " Syr_Impl::M3p1" );
450 void Syr_Impl::Div2() {
451 beginService( " Syr_Impl::Div2" );
452 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
453 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
459 _CurrentInteger = 0 ;
461 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
462 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
463 endService( " Syr_Impl::Div2" );
466 void Syr_Impl::Incr() {
467 beginService( " Syr_Impl::Incr" );
468 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
469 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
474 _Count = _Count + 1 ;
475 MESSAGE( " Syr_Impl::Incr " << _Count );
476 endService( " Syr_Impl::Incr" );