1 // SuperVisionTest SyrComponent : example of component performing some mathinatical operations
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SyrComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
34 //#include "utilities.h"
36 #include "SyrComponent_Impl.hxx"
37 #include "Adder_Impl.hxx"
41 SyrComponent_Impl::SyrComponent_Impl( CORBA::ORB_ptr orb ,
42 PortableServer::POA_ptr poa ,
43 PortableServer::ObjectId * contId ,
44 const char *instanceName ,
45 const char *interfaceName ,
46 const bool kactivate ) :
47 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
48 MESSAGE("SyrComponent_Impl::SyrComponent_Impl this " << hex << this << dec
49 << "activate object instanceName("
50 << instanceName << ") interfaceName(" << interfaceName << ")" )
53 _id = _poa->activate_object(_thisObj);
57 SyrComponent_Impl::SyrComponent_Impl() {
60 SyrComponent_Impl::~SyrComponent_Impl() {
63 CORBA::Long SyrComponent_Impl::C_ISEVEN( CORBA::Long anInteger ) {
65 beginService( " SyrComponent_Impl::C_ISEVEN" );
66 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISEVEN is Computing");
67 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
72 RetVal = ( anInteger & 1 ) == 0 ;
73 endService( " SyrComponent_Impl::C_ISEVEN" );
77 CORBA::Long SyrComponent_Impl::C_ISONE( CORBA::Long anOddInteger ) {
79 beginService( " SyrComponent_Impl::C_ISONE" );
80 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISONE is Computing");
81 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
86 RetVal = ( anOddInteger == 1 ) ;
87 endService( " SyrComponent_Impl::C_ISONE" );
91 CORBA::Long SyrComponent_Impl::C_M3( CORBA::Long anOddInteger ) {
92 beginService( " SyrComponent_Impl::C_M3" );
93 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3 is Computing");
94 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
99 endService( " SyrComponent_Impl::C_M3" );
100 if ( C_ISEVEN( anOddInteger ) )
102 return ( 3*anOddInteger ) ;
105 CORBA::Long SyrComponent_Impl::C_M3P1( CORBA::Long anOddInteger ) {
106 beginService( " SyrComponent_Impl::C_M3P1" );
107 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3P1 is Computing");
108 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
113 endService( " SyrComponent_Impl::C_M3P1" );
114 if ( C_ISEVEN( anOddInteger ) )
116 return ( 3*anOddInteger + 1 ) ;
119 CORBA::Long SyrComponent_Impl::C_DIV2( CORBA::Long anEvenInteger ) {
120 beginService( " SyrComponent_Impl::C_DIV2" );
121 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_DIV2 is Computing");
122 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
127 endService( " SyrComponent_Impl::C_DIV2" );
128 if ( !C_ISEVEN( anEvenInteger ) )
130 return ( anEvenInteger >> 1 ) ;
133 CORBA::Long SyrComponent_Impl::C_INCR( CORBA::Long aCount ) {
134 beginService( " SyrComponent_Impl::C_INCR" );
135 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_INCR is Computing");
136 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
141 endService( " SyrComponent_Impl::C_INCR" );
142 return ( aCount + 1 ) ;
145 void SyrComponent_Impl::CPP_SETLONG( CORBA::Long aCount ) {
146 beginService( " SyrComponent_Impl::CPP_SETLONG" );
147 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_SETLONG is Computing");
148 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
154 endService( " SyrComponent_Impl::CPP_SETLONG" );
158 CORBA::Long SyrComponent_Impl::CPP_ADDTOLONG( CORBA::Long anIncr ) {
159 beginService( " SyrComponent_Impl::CPP_ADDTOLONG" );
160 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_ADDTOLONG is Computing");
161 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
166 endService( " SyrComponent_Impl::CPP_ADDTOLONG" );
167 return ( _Count + anIncr ) ;
170 CORBA::Long SyrComponent_Impl::C_MIN( CORBA::Long aMinVal , CORBA::Long anInteger ) {
171 beginService( " SyrComponent_Impl::C_MIN" );
172 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
173 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
179 if ( anInteger < min || aMinVal == 0 ) {
182 string trace = "SyrComponent_Impl::C_MIN : " ;
184 sprintf( cmin , "%d" , min ) ;
186 sendMessage(NOTIF_TRACE, trace.c_str() );
187 endService( " SyrComponent_Impl::C_MIN" );
191 CORBA::Long SyrComponent_Impl::C_MAX( CORBA::Long aMaxVal , CORBA::Long anInteger ) {
192 beginService( " SyrComponent_Impl::C_MAX" );
193 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
194 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
200 if ( anInteger > max ) {
203 string trace = "SyrComponent_Impl::C_MAX : " ;
205 sprintf( cmax , "%d" , max ) ;
207 sendMessage(NOTIF_TRACE, trace.c_str() );
208 endService( " SyrComponent_Impl::C_MAX" );
212 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
213 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
214 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
215 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
220 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
221 instanceName() , interfaceName() ,
222 graphName() , nodeName() ) ;
223 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
224 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
225 CORBA::Object_var obj = _poa->id_to_reference(*id);
226 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
227 endService( " SyrComponent_Impl::C_LISTOFSYR" );
228 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
229 // return ( aNewListOfSyr._retn() ) ;
232 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
233 SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
234 CORBA::Long anInteger ,
236 CORBA::Double & anAverage ) {
237 beginService( " SyrComponent_Impl::C_AVERAGE" );
238 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
239 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
244 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
245 int len = aSeqOfSyr->length() ;
246 aSeqOfSyr->length( len + 1 ) ;
247 (*aSeqOfSyr)[ len ] = anInteger ;
248 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
251 for ( i = 0 ; i < len + 1 ; i++ ) {
252 anAverage += (*aSeqOfSyr)[ i ] ;
254 anAverage = anAverage / ( len + 1 ) ;
255 string end = " SyrComponent_Impl::C_AVERAGE " ;
256 char caverage[ 30 ] ;
257 sprintf( caverage , "%fd" , anAverage ) ;
259 endService( end.c_str() );
260 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
263 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( CORBA::Long anOddInteger ) {
264 beginService( "SyrComponent_Impl::Init" );
265 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
266 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
272 mySyr = new Syr_Impl( _orb , _poa, _contId,
273 instanceName() , interfaceName() ,
274 graphName() , nodeName() , anOddInteger ) ;
275 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
276 PortableServer::ObjectId * id = mySyr->getId() ;
277 CORBA::Object_var obj = _poa->id_to_reference(*id);
278 iobject = SuperVisionTest::Syr::_narrow(obj) ;
279 endService( "SyrComponent_Impl::Init" );
280 return SuperVisionTest::Syr::_duplicate(iobject) ;
283 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
284 PortableServer::POA_ptr poa ,
285 PortableServer::ObjectId * contId ,
286 const char * instanceName ,
287 const char * interfaceName ,
288 const char * graphName ,
289 const char * nodeName ) :
290 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
291 Names( graphName , nodeName ) ;
292 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
293 << instanceName << ") interfaceName(" << interfaceName << ") --> "
294 << hex << (void *) this << dec )
295 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
297 _id = _poa->activate_object(_thisObj);
298 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
299 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
302 ListOfSyr_Impl::ListOfSyr_Impl() {
305 ListOfSyr_Impl::~ListOfSyr_Impl() {
306 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
307 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
310 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
311 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
312 return ( aSeqOfSyr._retn() ) ;
315 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
316 _SeqOfSyr = aSeqOfSyr ;
322 PortableServer::ObjectId * SyrComponentEngine_factory
324 PortableServer::POA_ptr poa,
325 PortableServer::ObjectId * contId,
326 const char *instanceName,
327 const char *interfaceName)
329 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
330 << instanceName << "," << interfaceName << "," << getpid() << ")");
331 SyrComponent_Impl * mySyrComponent
332 = new SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName);
333 return mySyrComponent->getId() ;
337 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
338 PortableServer::POA_ptr poa ,
339 PortableServer::ObjectId * contId ,
340 const char * instanceName ,
341 const char * interfaceName ,
342 const char * graphName ,
343 const char * nodeName ,
344 const CORBA::Long anOddInteger ) :
345 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false) {
346 Names( graphName , nodeName ) ;
347 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
348 << instanceName << ") interfaceName(" << interfaceName << ") --> "
349 << hex << (void *) this << dec )
350 beginService( "Syr_Impl::Syr_Impl" );
352 _id = _poa->activate_object(_thisObj);
353 _InitialInteger = anOddInteger ;
354 _CurrentInteger = anOddInteger ;
356 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
357 endService( "Syr_Impl::Syr_Impl" );
360 Syr_Impl::Syr_Impl() {
363 Syr_Impl::~Syr_Impl() {
364 beginService( "Syr_Impl::~Syr_Impl" );
365 endService( "Syr_Impl::~Syr_Impl" );
368 CORBA::Long Syr_Impl::Initial() {
369 beginService( " Syr_Impl::Initial" );
370 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
371 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
376 endService( " Syr_Impl::Initial" );
377 return _InitialInteger ;
380 CORBA::Long Syr_Impl::Current() {
381 beginService( " Syr_Impl::Current" );
382 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
383 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
388 endService( " Syr_Impl::Current" );
389 return _CurrentInteger ;
392 CORBA::Long Syr_Impl::IsEven() {
394 beginService( " Syr_Impl::IsEven" );
395 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
396 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
401 RetVal = ( _CurrentInteger & 1 ) == 0 ;
402 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
403 endService( " Syr_Impl::IsEven" );
407 CORBA::Long Syr_Impl::IsOne() {
409 beginService( " Syr_Impl::IsOne" );
410 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
411 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
416 RetVal = ( _CurrentInteger == 1 ) ;
417 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
418 endService( " Syr_Impl::IsOne" );
422 CORBA::Long Syr_Impl::Count() {
423 beginService( " Syr_Impl::Count" );
424 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
425 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
430 MESSAGE( " Syr_Impl::Count " << _Count );
431 endService( " Syr_Impl::Count" );
435 void Syr_Impl::M3p1() {
436 beginService( " Syr_Impl::M3p1" );
437 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
438 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
444 _CurrentInteger = 0 ;
446 _CurrentInteger = 3*_CurrentInteger + 1 ;
447 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
448 endService( " Syr_Impl::M3p1" );
451 void Syr_Impl::Div2() {
452 beginService( " Syr_Impl::Div2" );
453 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
454 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
460 _CurrentInteger = 0 ;
462 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
463 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
464 endService( " Syr_Impl::Div2" );
467 void Syr_Impl::Incr() {
468 beginService( " Syr_Impl::Incr" );
469 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
470 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
475 _Count = _Count + 1 ;
476 MESSAGE( " Syr_Impl::Incr " << _Count );
477 endService( " Syr_Impl::Incr" );