1 // Copyright (C) 2007-2013 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
23 // SuperVisionTest SyrComponent : example of component performing some mathinatical operations
24 // File : SyrComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
34 #include "COMPONENT_version.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 char* SyrComponent_Impl::getVersion()
64 #if COMPONENT_DEVELOPMENT
65 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
67 return CORBA::string_dup(COMPONENT_VERSION_STR);
71 CORBA::Long SyrComponent_Impl::C_ISEVEN( CORBA::Long anInteger ) {
73 beginService( " SyrComponent_Impl::C_ISEVEN" );
74 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISEVEN is Computing");
75 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
80 RetVal = ( anInteger & 1 ) == 0 ;
81 endService( " SyrComponent_Impl::C_ISEVEN" );
85 CORBA::Long SyrComponent_Impl::C_ISONE( CORBA::Long anOddInteger ) {
87 beginService( " SyrComponent_Impl::C_ISONE" );
88 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISONE is Computing");
89 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
94 RetVal = ( anOddInteger == 1 ) ;
95 endService( " SyrComponent_Impl::C_ISONE" );
99 CORBA::Long SyrComponent_Impl::C_M3( CORBA::Long anOddInteger ) {
100 beginService( " SyrComponent_Impl::C_M3" );
101 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3 is Computing");
102 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
107 endService( " SyrComponent_Impl::C_M3" );
108 if ( C_ISEVEN( anOddInteger ) )
110 return ( 3*anOddInteger ) ;
113 CORBA::Long SyrComponent_Impl::C_M3P1( CORBA::Long anOddInteger ) {
114 beginService( " SyrComponent_Impl::C_M3P1" );
115 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3P1 is Computing");
116 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
121 endService( " SyrComponent_Impl::C_M3P1" );
122 if ( C_ISEVEN( anOddInteger ) )
124 return ( 3*anOddInteger + 1 ) ;
127 CORBA::Long SyrComponent_Impl::C_DIV2( CORBA::Long anEvenInteger ) {
128 beginService( " SyrComponent_Impl::C_DIV2" );
129 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_DIV2 is Computing");
130 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
135 endService( " SyrComponent_Impl::C_DIV2" );
136 if ( !C_ISEVEN( anEvenInteger ) )
138 return ( anEvenInteger >> 1 ) ;
141 CORBA::Long SyrComponent_Impl::C_INCR( CORBA::Long aCount ) {
142 beginService( " SyrComponent_Impl::C_INCR" );
143 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_INCR is Computing");
144 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
149 endService( " SyrComponent_Impl::C_INCR" );
150 return ( aCount + 1 ) ;
153 void SyrComponent_Impl::CPP_SETLONG( CORBA::Long aCount ) {
154 beginService( " SyrComponent_Impl::CPP_SETLONG" );
155 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_SETLONG is Computing");
156 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
162 endService( " SyrComponent_Impl::CPP_SETLONG" );
166 CORBA::Long SyrComponent_Impl::CPP_ADDTOLONG( CORBA::Long anIncr ) {
167 beginService( " SyrComponent_Impl::CPP_ADDTOLONG" );
168 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_ADDTOLONG is Computing");
169 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
174 endService( " SyrComponent_Impl::CPP_ADDTOLONG" );
175 return ( _Count + anIncr ) ;
178 CORBA::Long SyrComponent_Impl::C_MIN( CORBA::Long aMinVal , CORBA::Long anInteger ) {
179 beginService( " SyrComponent_Impl::C_MIN" );
180 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
181 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
187 if ( anInteger < min || aMinVal == 0 ) {
190 string trace = "SyrComponent_Impl::C_MIN : " ;
192 sprintf( cmin , "%d" , min ) ;
194 sendMessage(NOTIF_TRACE, trace.c_str() );
195 endService( " SyrComponent_Impl::C_MIN" );
199 CORBA::Long SyrComponent_Impl::C_MAX( CORBA::Long aMaxVal , CORBA::Long anInteger ) {
200 beginService( " SyrComponent_Impl::C_MAX" );
201 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
202 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
208 if ( anInteger > max ) {
211 string trace = "SyrComponent_Impl::C_MAX : " ;
213 sprintf( cmax , "%d" , max ) ;
215 sendMessage(NOTIF_TRACE, trace.c_str() );
216 endService( " SyrComponent_Impl::C_MAX" );
220 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
221 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
222 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
223 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
228 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
229 instanceName() , interfaceName() ,
230 graphName() , nodeName() ) ;
231 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
232 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
233 CORBA::Object_var obj = _poa->id_to_reference(*id);
234 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
235 endService( " SyrComponent_Impl::C_LISTOFSYR" );
236 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
237 // return ( aNewListOfSyr._retn() ) ;
240 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
241 SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
242 CORBA::Long anInteger ,
244 CORBA::Double & anAverage ) {
245 beginService( " SyrComponent_Impl::C_AVERAGE" );
246 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
247 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
252 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
253 int len = aSeqOfSyr->length() ;
254 aSeqOfSyr->length( len + 1 ) ;
255 (*aSeqOfSyr)[ len ] = anInteger ;
256 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
259 for ( i = 0 ; i < len + 1 ; i++ ) {
260 anAverage += (*aSeqOfSyr)[ i ] ;
262 anAverage = anAverage / ( len + 1 ) ;
263 string end = " SyrComponent_Impl::C_AVERAGE " ;
264 char caverage[ 30 ] ;
265 sprintf( caverage , "%fd" , anAverage ) ;
267 endService( end.c_str() );
268 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
271 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( CORBA::Long anOddInteger ) {
272 beginService( "SyrComponent_Impl::Init" );
273 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
274 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
280 mySyr = new Syr_Impl( _orb , _poa, _contId,
281 instanceName() , interfaceName() ,
282 graphName() , nodeName() , anOddInteger ) ;
283 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
284 PortableServer::ObjectId * id = mySyr->getId() ;
285 CORBA::Object_var obj = _poa->id_to_reference(*id);
286 iobject = SuperVisionTest::Syr::_narrow(obj) ;
287 endService( "SyrComponent_Impl::Init" );
288 return SuperVisionTest::Syr::_duplicate(iobject) ;
291 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
292 PortableServer::POA_ptr poa ,
293 PortableServer::ObjectId * contId ,
294 const char * instanceName ,
295 const char * interfaceName ,
296 const char * graphName ,
297 const char * nodeName ) :
298 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
299 Names( graphName , nodeName ) ;
300 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
301 << instanceName << ") interfaceName(" << interfaceName << ") --> "
302 << hex << (void *) this << dec )
303 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
305 _id = _poa->activate_object(_thisObj);
306 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
307 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
310 ListOfSyr_Impl::ListOfSyr_Impl() {
313 ListOfSyr_Impl::~ListOfSyr_Impl() {
314 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
315 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
318 char* ListOfSyr_Impl::getVersion()
320 #if COMPONENT_DEVELOPMENT
321 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
323 return CORBA::string_dup(COMPONENT_VERSION_STR);
327 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
328 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
329 return ( aSeqOfSyr._retn() ) ;
332 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
333 _SeqOfSyr = aSeqOfSyr ;
339 PortableServer::ObjectId * SyrComponentEngine_factory
341 PortableServer::POA_ptr poa,
342 PortableServer::ObjectId * contId,
343 const char *instanceName,
344 const char *interfaceName)
346 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
347 << instanceName << "," << interfaceName << "," << getpid() << ")");
348 SyrComponent_Impl * mySyrComponent
349 = new SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName);
350 return mySyrComponent->getId() ;
354 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
355 PortableServer::POA_ptr poa ,
356 PortableServer::ObjectId * contId ,
357 const char * instanceName ,
358 const char * interfaceName ,
359 const char * graphName ,
360 const char * nodeName ,
361 const CORBA::Long anOddInteger ) :
362 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false) {
363 Names( graphName , nodeName ) ;
364 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
365 << instanceName << ") interfaceName(" << interfaceName << ") --> "
366 << hex << (void *) this << dec )
367 beginService( "Syr_Impl::Syr_Impl" );
369 _id = _poa->activate_object(_thisObj);
370 _InitialInteger = anOddInteger ;
371 _CurrentInteger = anOddInteger ;
373 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
374 endService( "Syr_Impl::Syr_Impl" );
377 Syr_Impl::Syr_Impl() {
380 Syr_Impl::~Syr_Impl() {
381 beginService( "Syr_Impl::~Syr_Impl" );
382 endService( "Syr_Impl::~Syr_Impl" );
385 CORBA::Long Syr_Impl::Initial() {
386 beginService( " Syr_Impl::Initial" );
387 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
388 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
393 endService( " Syr_Impl::Initial" );
394 return _InitialInteger ;
397 CORBA::Long Syr_Impl::Current() {
398 beginService( " Syr_Impl::Current" );
399 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
400 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
405 endService( " Syr_Impl::Current" );
406 return _CurrentInteger ;
409 CORBA::Long Syr_Impl::IsEven() {
411 beginService( " Syr_Impl::IsEven" );
412 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
413 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
418 RetVal = ( _CurrentInteger & 1 ) == 0 ;
419 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
420 endService( " Syr_Impl::IsEven" );
424 CORBA::Long Syr_Impl::IsOne() {
426 beginService( " Syr_Impl::IsOne" );
427 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
428 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
433 RetVal = ( _CurrentInteger == 1 ) ;
434 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
435 endService( " Syr_Impl::IsOne" );
439 CORBA::Long Syr_Impl::Count() {
440 beginService( " Syr_Impl::Count" );
441 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
442 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
447 MESSAGE( " Syr_Impl::Count " << _Count );
448 endService( " Syr_Impl::Count" );
452 void Syr_Impl::M3p1() {
453 beginService( " Syr_Impl::M3p1" );
454 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
455 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
461 _CurrentInteger = 0 ;
463 _CurrentInteger = 3*_CurrentInteger + 1 ;
464 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
465 endService( " Syr_Impl::M3p1" );
468 void Syr_Impl::Div2() {
469 beginService( " Syr_Impl::Div2" );
470 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
471 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
477 _CurrentInteger = 0 ;
479 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
480 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
481 endService( " Syr_Impl::Div2" );
484 void Syr_Impl::Incr() {
485 beginService( " Syr_Impl::Incr" );
486 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
487 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
492 _Count = _Count + 1 ;
493 MESSAGE( " Syr_Impl::Incr " << _Count );
494 endService( " Syr_Impl::Incr" );