1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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
38 #include "COMPONENT_version.h"
39 #include "SyrComponent_Impl.hxx"
40 #include "Adder_Impl.hxx"
44 SyrComponent_Impl::SyrComponent_Impl( CORBA::ORB_ptr orb ,
45 PortableServer::POA_ptr poa ,
46 PortableServer::ObjectId * contId ,
47 const char *instanceName ,
48 const char *interfaceName ,
49 const bool kactivate , bool withRegistry ) :
50 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,true/*notif is true here for message*/,withRegistry) {
51 MESSAGE("SyrComponent_Impl::SyrComponent_Impl this " << hex << this << dec
52 << "activate object instanceName("
53 << instanceName << ") interfaceName(" << interfaceName << ")" )
56 _id = _poa->activate_object(_thisObj);
60 SyrComponent_Impl::SyrComponent_Impl() {
63 SyrComponent_Impl::~SyrComponent_Impl() {
66 char* SyrComponent_Impl::getVersion()
68 #if COMPONENT_DEVELOPMENT
69 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
71 return CORBA::string_dup(COMPONENT_VERSION_STR);
75 CORBA::Long SyrComponent_Impl::C_ISEVEN( CORBA::Long anInteger ) {
77 beginService( " SyrComponent_Impl::C_ISEVEN" );
78 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISEVEN is Computing");
79 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
88 RetVal = ( anInteger & 1 ) == 0 ;
89 endService( " SyrComponent_Impl::C_ISEVEN" );
93 CORBA::Long SyrComponent_Impl::C_ISONE( CORBA::Long anOddInteger ) {
95 beginService( " SyrComponent_Impl::C_ISONE" );
96 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISONE is Computing");
97 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
106 RetVal = ( anOddInteger == 1 ) ;
107 endService( " SyrComponent_Impl::C_ISONE" );
111 CORBA::Long SyrComponent_Impl::C_M3( CORBA::Long anOddInteger ) {
112 beginService( " SyrComponent_Impl::C_M3" );
113 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3 is Computing");
114 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
122 #endif endService( " SyrComponent_Impl::C_M3" );
123 if ( C_ISEVEN( anOddInteger ) )
125 return ( 3*anOddInteger ) ;
128 CORBA::Long SyrComponent_Impl::C_M3P1( CORBA::Long anOddInteger ) {
129 beginService( " SyrComponent_Impl::C_M3P1" );
130 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3P1 is Computing");
131 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
140 endService( " SyrComponent_Impl::C_M3P1" );
141 if ( C_ISEVEN( anOddInteger ) )
143 return ( 3*anOddInteger + 1 ) ;
146 CORBA::Long SyrComponent_Impl::C_DIV2( CORBA::Long anEvenInteger ) {
147 beginService( " SyrComponent_Impl::C_DIV2" );
148 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_DIV2 is Computing");
149 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
158 endService( " SyrComponent_Impl::C_DIV2" );
159 if ( !C_ISEVEN( anEvenInteger ) )
161 return ( anEvenInteger >> 1 ) ;
164 CORBA::Long SyrComponent_Impl::C_INCR( CORBA::Long aCount ) {
165 beginService( " SyrComponent_Impl::C_INCR" );
166 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_INCR is Computing");
167 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
176 endService( " SyrComponent_Impl::C_INCR" );
177 return ( aCount + 1 ) ;
180 void SyrComponent_Impl::CPP_SETLONG( CORBA::Long aCount ) {
181 beginService( " SyrComponent_Impl::CPP_SETLONG" );
182 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_SETLONG is Computing");
183 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
193 endService( " SyrComponent_Impl::CPP_SETLONG" );
197 CORBA::Long SyrComponent_Impl::CPP_ADDTOLONG( CORBA::Long anIncr ) {
198 beginService( " SyrComponent_Impl::CPP_ADDTOLONG" );
199 sendMessage(NOTIF_STEP, "SyrComponent_Impl::CPP_ADDTOLONG is Computing");
200 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
209 endService( " SyrComponent_Impl::CPP_ADDTOLONG" );
210 return ( _Count + anIncr ) ;
213 CORBA::Long SyrComponent_Impl::C_MIN( CORBA::Long aMinVal , CORBA::Long anInteger ) {
214 beginService( " SyrComponent_Impl::C_MIN" );
215 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
216 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
226 if ( anInteger < min || aMinVal == 0 ) {
229 string trace = "SyrComponent_Impl::C_MIN : " ;
231 sprintf( cmin , "%d" , min ) ;
233 sendMessage(NOTIF_TRACE, trace.c_str() );
234 endService( " SyrComponent_Impl::C_MIN" );
238 CORBA::Long SyrComponent_Impl::C_MAX( CORBA::Long aMaxVal , CORBA::Long anInteger ) {
239 beginService( " SyrComponent_Impl::C_MAX" );
240 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
241 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
251 if ( anInteger > max ) {
254 string trace = "SyrComponent_Impl::C_MAX : " ;
256 sprintf( cmax , "%d" , max ) ;
258 sendMessage(NOTIF_TRACE, trace.c_str() );
259 endService( " SyrComponent_Impl::C_MAX" );
263 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
264 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
265 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
266 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
275 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
276 instanceName() , interfaceName() ,
277 graphName() , nodeName() ) ;
278 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
279 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
280 CORBA::Object_var obj = _poa->id_to_reference(*id);
281 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
282 endService( " SyrComponent_Impl::C_LISTOFSYR" );
283 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
284 // return ( aNewListOfSyr._retn() ) ;
287 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
288 SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
289 CORBA::Long anInteger ,
291 CORBA::Double & anAverage ) {
292 beginService( " SyrComponent_Impl::C_AVERAGE" );
293 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
294 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
303 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
304 int len = aSeqOfSyr->length() ;
305 aSeqOfSyr->length( len + 1 ) ;
306 (*aSeqOfSyr)[ len ] = anInteger ;
307 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
310 for ( i = 0 ; i < len + 1 ; i++ ) {
311 anAverage += (*aSeqOfSyr)[ i ] ;
313 anAverage = anAverage / ( len + 1 ) ;
314 string end = " SyrComponent_Impl::C_AVERAGE " ;
315 char caverage[ 30 ] ;
316 sprintf( caverage , "%fd" , anAverage ) ;
318 endService( end.c_str() );
319 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
322 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( CORBA::Long anOddInteger ) {
323 beginService( "SyrComponent_Impl::Init" );
324 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
325 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
334 Syr_Impl * mySyr = nullptr;
335 if ( this->isSSLMode() )
337 mySyr = new Syr_Impl_SSL( _orb , _poa, _contId,
338 instanceName() , interfaceName() ,
339 graphName() , nodeName() , anOddInteger ) ;
343 mySyr = new Syr_Impl_No_SSL( _orb , _poa, _contId,
344 instanceName() , interfaceName() ,
345 graphName() , nodeName() , anOddInteger ) ;
347 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
348 PortableServer::ObjectId * id = mySyr->getId() ;
349 CORBA::Object_var obj = _poa->id_to_reference(*id);
350 iobject = SuperVisionTest::Syr::_narrow(obj) ;
351 endService( "SyrComponent_Impl::Init" );
352 return SuperVisionTest::Syr::_duplicate(iobject) ;
355 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
356 PortableServer::POA_ptr poa ,
357 PortableServer::ObjectId * contId ,
358 const char * instanceName ,
359 const char * interfaceName ,
360 const char * graphName ,
361 const char * nodeName ) :
362 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
363 Names( graphName , nodeName ) ;
364 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
365 << instanceName << ") interfaceName(" << interfaceName << ") --> "
366 << hex << (void *) this << dec )
367 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
369 _id = _poa->activate_object(_thisObj);
370 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
371 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
374 ListOfSyr_Impl::ListOfSyr_Impl() {
377 ListOfSyr_Impl::~ListOfSyr_Impl() {
378 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
379 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
382 char* ListOfSyr_Impl::getVersion()
384 #if COMPONENT_DEVELOPMENT
385 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
387 return CORBA::string_dup(COMPONENT_VERSION_STR);
391 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
392 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
393 return ( aSeqOfSyr._retn() ) ;
396 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
397 _SeqOfSyr = aSeqOfSyr ;
403 PortableServer::ObjectId * SyrComponentEngine_factory
405 PortableServer::POA_ptr poa,
406 PortableServer::ObjectId * contId,
407 const char *instanceName,
408 const char *interfaceName)
411 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
412 << instanceName << "," << interfaceName << "," << getpid() << ")");
414 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
415 << instanceName << "," << interfaceName << "," << _getpid() << ")");
417 SyrComponent_Impl * mySyrComponent = nullptr;
418 CORBA::Object_var o = poa->id_to_reference(*contId);
419 Engines::Container_var cont = Engines::Container::_narrow(o);
420 if(cont->is_SSL_mode())
422 mySyrComponent = new SyrComponent_Impl_SSL(orb, poa, contId, instanceName, interfaceName);
426 mySyrComponent = new SyrComponent_Impl_No_SSL(orb, poa, contId, instanceName, interfaceName);
428 return mySyrComponent->getId() ;
432 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
433 PortableServer::POA_ptr poa ,
434 PortableServer::ObjectId * contId ,
435 const char * instanceName ,
436 const char * interfaceName ,
437 const char * graphName ,
438 const char * nodeName ,
439 const CORBA::Long anOddInteger, bool withRegistry) :
440 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false,withRegistry) {
441 Names( graphName , nodeName ) ;
442 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
443 << instanceName << ") interfaceName(" << interfaceName << ") --> "
444 << hex << (void *) this << dec )
445 beginService( "Syr_Impl::Syr_Impl" );
447 _id = _poa->activate_object(_thisObj);
448 _InitialInteger = anOddInteger ;
449 _CurrentInteger = anOddInteger ;
451 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
452 endService( "Syr_Impl::Syr_Impl" );
455 Syr_Impl::Syr_Impl() {
458 Syr_Impl::~Syr_Impl() {
459 beginService( "Syr_Impl::~Syr_Impl" );
460 endService( "Syr_Impl::~Syr_Impl" );
463 CORBA::Long Syr_Impl::Initial() {
464 beginService( " Syr_Impl::Initial" );
465 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
466 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
475 endService( " Syr_Impl::Initial" );
476 return _InitialInteger ;
479 CORBA::Long Syr_Impl::Current() {
480 beginService( " Syr_Impl::Current" );
481 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
482 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
491 endService( " Syr_Impl::Current" );
492 return _CurrentInteger ;
495 CORBA::Long Syr_Impl::IsEven() {
497 beginService( " Syr_Impl::IsEven" );
498 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
499 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
508 RetVal = ( _CurrentInteger & 1 ) == 0 ;
509 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
510 endService( " Syr_Impl::IsEven" );
514 CORBA::Long Syr_Impl::IsOne() {
516 beginService( " Syr_Impl::IsOne" );
517 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
518 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
527 RetVal = ( _CurrentInteger == 1 ) ;
528 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
529 endService( " Syr_Impl::IsOne" );
533 CORBA::Long Syr_Impl::Count() {
534 beginService( " Syr_Impl::Count" );
535 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
536 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
545 MESSAGE( " Syr_Impl::Count " << _Count );
546 endService( " Syr_Impl::Count" );
550 void Syr_Impl::M3p1() {
551 beginService( " Syr_Impl::M3p1" );
552 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
553 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
563 _CurrentInteger = 0 ;
565 _CurrentInteger = 3*_CurrentInteger + 1 ;
566 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
567 endService( " Syr_Impl::M3p1" );
570 void Syr_Impl::Div2() {
571 beginService( " Syr_Impl::Div2" );
572 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
573 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
583 _CurrentInteger = 0 ;
585 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
586 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
587 endService( " Syr_Impl::Div2" );
590 void Syr_Impl::Incr() {
591 beginService( " Syr_Impl::Incr" );
592 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
593 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
602 _Count = _Count + 1 ;
603 MESSAGE( " Syr_Impl::Incr " << _Count );
604 endService( " Syr_Impl::Incr" );