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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SyrComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
35 //#include "utilities.h"
37 #include "SyrComponent_Impl.hxx"
38 #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 long SyrComponent_Impl::C_ISEVEN( const 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 long SyrComponent_Impl::C_ISONE( const 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 long SyrComponent_Impl::C_M3( const 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 long SyrComponent_Impl::C_M3P1( const 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 long SyrComponent_Impl::C_DIV2( const 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 long SyrComponent_Impl::C_INCR( const 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 long SyrComponent_Impl::C_MIN( const long aMinVal , const long anInteger ) {
145 beginService( " SyrComponent_Impl::C_MIN" );
146 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
147 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
153 if ( anInteger < min || aMinVal == 0 ) {
156 string trace = "SyrComponent_Impl::C_MIN : " ;
158 sprintf( cmin , "%d" , min ) ;
160 sendMessage(NOTIF_TRACE, trace.c_str() );
161 endService( " SyrComponent_Impl::C_MIN" );
165 long SyrComponent_Impl::C_MAX( const long aMaxVal , const long anInteger ) {
166 beginService( " SyrComponent_Impl::C_MAX" );
167 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
168 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
174 if ( anInteger > max ) {
177 string trace = "SyrComponent_Impl::C_MAX : " ;
179 sprintf( cmax , "%d" , max ) ;
181 sendMessage(NOTIF_TRACE, trace.c_str() );
182 endService( " SyrComponent_Impl::C_MAX" );
186 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
187 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
188 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
189 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
194 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
195 instanceName() , interfaceName() ,
196 graphName() , nodeName() ) ;
197 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
198 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
199 CORBA::Object_var obj = _poa->id_to_reference(*id);
200 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
201 endService( " SyrComponent_Impl::C_LISTOFSYR" );
202 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
203 // return ( aNewListOfSyr._retn() ) ;
206 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
207 const SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
208 const long anInteger ,
210 double & anAverage ) {
211 beginService( " SyrComponent_Impl::C_AVERAGE" );
212 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
213 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
218 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
219 int len = aSeqOfSyr->length() ;
220 aSeqOfSyr->length( len + 1 ) ;
221 (*aSeqOfSyr)[ len ] = anInteger ;
222 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
225 for ( i = 0 ; i < len + 1 ; i++ ) {
226 anAverage += (*aSeqOfSyr)[ i ] ;
228 anAverage = anAverage / ( len + 1 ) ;
229 string end = " SyrComponent_Impl::C_AVERAGE " ;
230 char caverage[ 30 ] ;
231 sprintf( caverage , "%fd" , anAverage ) ;
233 endService( end.c_str() );
234 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
237 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( const long anOddInteger ) {
238 beginService( "SyrComponent_Impl::Init" );
239 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
240 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
246 mySyr = new Syr_Impl( _orb , _poa, _contId,
247 instanceName() , interfaceName() ,
248 graphName() , nodeName() , anOddInteger ) ;
249 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
250 PortableServer::ObjectId * id = mySyr->getId() ;
251 CORBA::Object_var obj = _poa->id_to_reference(*id);
252 iobject = SuperVisionTest::Syr::_narrow(obj) ;
253 endService( "SyrComponent_Impl::Init" );
254 return SuperVisionTest::Syr::_duplicate(iobject) ;
257 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
258 PortableServer::POA_ptr poa ,
259 PortableServer::ObjectId * contId ,
260 const char * instanceName ,
261 const char * interfaceName ,
262 const char * graphName ,
263 const char * nodeName ) :
264 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
265 Names( graphName , nodeName ) ;
266 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
267 << instanceName << ") interfaceName(" << interfaceName << ") --> "
268 << hex << (void *) this << dec )
269 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
271 _id = _poa->activate_object(_thisObj);
272 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
273 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
276 ListOfSyr_Impl::ListOfSyr_Impl() {
279 ListOfSyr_Impl::~ListOfSyr_Impl() {
280 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
281 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
284 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
285 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
286 return ( aSeqOfSyr._retn() ) ;
289 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
290 _SeqOfSyr = aSeqOfSyr ;
296 PortableServer::ObjectId * SyrComponentEngine_factory
298 PortableServer::POA_ptr poa,
299 PortableServer::ObjectId * contId,
300 const char *instanceName,
301 const char *interfaceName)
303 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
304 << instanceName << "," << interfaceName << "," << getpid() << ")");
305 SyrComponent_Impl * mySyrComponent
306 = new SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName);
307 return mySyrComponent->getId() ;
311 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
312 PortableServer::POA_ptr poa ,
313 PortableServer::ObjectId * contId ,
314 const char * instanceName ,
315 const char * interfaceName ,
316 const char * graphName ,
317 const char * nodeName ,
318 const long anOddInteger ) :
319 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false) {
320 Names( graphName , nodeName ) ;
321 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
322 << instanceName << ") interfaceName(" << interfaceName << ") --> "
323 << hex << (void *) this << dec )
324 beginService( "Syr_Impl::Syr_Impl" );
326 _id = _poa->activate_object(_thisObj);
327 _InitialInteger = anOddInteger ;
328 _CurrentInteger = anOddInteger ;
330 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
331 endService( "Syr_Impl::Syr_Impl" );
334 Syr_Impl::Syr_Impl() {
337 Syr_Impl::~Syr_Impl() {
338 beginService( "Syr_Impl::~Syr_Impl" );
339 endService( "Syr_Impl::~Syr_Impl" );
342 long Syr_Impl::Initial() {
343 beginService( " Syr_Impl::Initial" );
344 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
345 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
350 endService( " Syr_Impl::Initial" );
351 return _InitialInteger ;
354 long Syr_Impl::Current() {
355 beginService( " Syr_Impl::Current" );
356 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
357 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
362 endService( " Syr_Impl::Current" );
363 return _CurrentInteger ;
366 long Syr_Impl::IsEven() {
368 beginService( " Syr_Impl::IsEven" );
369 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
370 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
375 RetVal = ( _CurrentInteger & 1 ) == 0 ;
376 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
377 endService( " Syr_Impl::IsEven" );
381 long Syr_Impl::IsOne() {
383 beginService( " Syr_Impl::IsOne" );
384 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
385 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
390 RetVal = ( _CurrentInteger == 1 ) ;
391 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
392 endService( " Syr_Impl::IsOne" );
396 long Syr_Impl::Count() {
397 beginService( " Syr_Impl::Count" );
398 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
399 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
404 MESSAGE( " Syr_Impl::Count " << _Count );
405 endService( " Syr_Impl::Count" );
409 void Syr_Impl::M3p1() {
410 beginService( " Syr_Impl::M3p1" );
411 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
412 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
418 _CurrentInteger = 0 ;
420 _CurrentInteger = 3*_CurrentInteger + 1 ;
421 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
422 endService( " Syr_Impl::M3p1" );
425 void Syr_Impl::Div2() {
426 beginService( " Syr_Impl::Div2" );
427 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
428 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
434 _CurrentInteger = 0 ;
436 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
437 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
438 endService( " Syr_Impl::Div2" );
441 void Syr_Impl::Incr() {
442 beginService( " Syr_Impl::Incr" );
443 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
444 // int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
449 _Count = _Count + 1 ;
450 MESSAGE( " Syr_Impl::Incr " << _Count );
451 endService( " Syr_Impl::Incr" );