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));
68 RetVal = ( anInteger & 1 ) == 0 ;
69 endService( " SyrComponent_Impl::C_ISEVEN" );
73 long SyrComponent_Impl::C_ISONE( const long anOddInteger ) {
75 beginService( " SyrComponent_Impl::C_ISONE" );
76 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_ISONE is Computing");
77 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
79 RetVal = ( anOddInteger == 1 ) ;
80 endService( " SyrComponent_Impl::C_ISONE" );
84 long SyrComponent_Impl::C_M3( const long anOddInteger ) {
85 beginService( " SyrComponent_Impl::C_M3" );
86 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3 is Computing");
87 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
89 endService( " SyrComponent_Impl::C_M3" );
90 if ( C_ISEVEN( anOddInteger ) )
92 return ( 3*anOddInteger ) ;
95 long SyrComponent_Impl::C_M3P1( const long anOddInteger ) {
96 beginService( " SyrComponent_Impl::C_M3P1" );
97 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_M3P1 is Computing");
98 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
100 endService( " SyrComponent_Impl::C_M3P1" );
101 if ( C_ISEVEN( anOddInteger ) )
103 return ( 3*anOddInteger + 1 ) ;
106 long SyrComponent_Impl::C_DIV2( const long anEvenInteger ) {
107 beginService( " SyrComponent_Impl::C_DIV2" );
108 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_DIV2 is Computing");
109 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
111 endService( " SyrComponent_Impl::C_DIV2" );
112 if ( !C_ISEVEN( anEvenInteger ) )
114 return ( anEvenInteger >> 1 ) ;
117 long SyrComponent_Impl::C_INCR( const long aCount ) {
118 beginService( " SyrComponent_Impl::C_INCR" );
119 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_INCR is Computing");
120 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
122 endService( " SyrComponent_Impl::C_INCR" );
123 return ( aCount + 1 ) ;
126 long SyrComponent_Impl::C_MIN( const long aMinVal , const long anInteger ) {
127 beginService( " SyrComponent_Impl::C_MIN" );
128 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MIN is Computing");
129 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
132 if ( anInteger < min || aMinVal == 0 ) {
135 string trace = "SyrComponent_Impl::C_MIN : " ;
137 sprintf( cmin , "%d" , min ) ;
139 sendMessage(NOTIF_TRACE, trace.c_str() );
140 endService( " SyrComponent_Impl::C_MIN" );
144 long SyrComponent_Impl::C_MAX( const long aMaxVal , const long anInteger ) {
145 beginService( " SyrComponent_Impl::C_MAX" );
146 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_MAX is Computing");
147 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
150 if ( anInteger > max ) {
153 string trace = "SyrComponent_Impl::C_MAX : " ;
155 sprintf( cmax , "%d" , max ) ;
157 sendMessage(NOTIF_TRACE, trace.c_str() );
158 endService( " SyrComponent_Impl::C_MAX" );
162 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_LISTOFSYR() {
163 beginService( " SyrComponent_Impl::C_LISTOFSYR" );
164 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_LISTOFSYR is Computing");
165 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
167 ListOfSyr_Impl * aNewListOfSyr = new ListOfSyr_Impl( _orb , _poa, _contId,
168 instanceName() , interfaceName() ,
169 graphName() , nodeName() ) ;
170 SuperVisionTest::ListOfSyr_var iobject = (SuperVisionTest::ListOfSyr_var ) NULL ;
171 PortableServer::ObjectId * id = aNewListOfSyr->getId() ;
172 CORBA::Object_var obj = _poa->id_to_reference(*id);
173 iobject = SuperVisionTest::ListOfSyr::_narrow(obj) ;
174 endService( " SyrComponent_Impl::C_LISTOFSYR" );
175 return SuperVisionTest::ListOfSyr::_duplicate( iobject ) ;
176 // return ( aNewListOfSyr._retn() ) ;
179 SuperVisionTest::ListOfSyr_ptr SyrComponent_Impl::C_AVERAGE(
180 const SuperVisionTest::ListOfSyr_ptr aListOfSyr ,
181 const long anInteger ,
183 double & anAverage ) {
184 beginService( " SyrComponent_Impl::C_AVERAGE" );
185 sendMessage(NOTIF_STEP, "SyrComponent_Impl::C_AVERAGE is Computing");
186 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
188 SuperVisionTest::SeqOfSyr * aSeqOfSyr = aListOfSyr->GetSeqOfSyr() ;
189 int len = aSeqOfSyr->length() ;
190 aSeqOfSyr->length( len + 1 ) ;
191 (*aSeqOfSyr)[ len ] = anInteger ;
192 aListOfSyr->SetSeqOfSyr( *aSeqOfSyr ) ;
195 for ( i = 0 ; i < len + 1 ; i++ ) {
196 anAverage += (*aSeqOfSyr)[ i ] ;
198 anAverage = anAverage / ( len + 1 ) ;
199 string end = " SyrComponent_Impl::C_AVERAGE " ;
200 char caverage[ 30 ] ;
201 sprintf( caverage , "%fd" , anAverage ) ;
203 endService( end.c_str() );
204 return SuperVisionTest::ListOfSyr::_duplicate( aListOfSyr ) ;
207 SuperVisionTest::Syr_ptr SyrComponent_Impl::Init( const long anOddInteger ) {
208 beginService( "SyrComponent_Impl::Init" );
209 sendMessage(NOTIF_STEP, "SyrComponent_Impl creates Syr_Impl");
210 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
213 mySyr = new Syr_Impl( _orb , _poa, _contId,
214 instanceName() , interfaceName() ,
215 graphName() , nodeName() , anOddInteger ) ;
216 SuperVisionTest::Syr_var iobject = (SuperVisionTest::Syr_var ) NULL ;
217 PortableServer::ObjectId * id = mySyr->getId() ;
218 CORBA::Object_var obj = _poa->id_to_reference(*id);
219 iobject = SuperVisionTest::Syr::_narrow(obj) ;
220 endService( "SyrComponent_Impl::Init" );
221 return SuperVisionTest::Syr::_duplicate(iobject) ;
224 ListOfSyr_Impl::ListOfSyr_Impl( CORBA::ORB_ptr orb ,
225 PortableServer::POA_ptr poa ,
226 PortableServer::ObjectId * contId ,
227 const char * instanceName ,
228 const char * interfaceName ,
229 const char * graphName ,
230 const char * nodeName ) :
231 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
232 Names( graphName , nodeName ) ;
233 MESSAGE("ListOfSyr_Impl::ListOfSyr_Impl activate object instanceName("
234 << instanceName << ") interfaceName(" << interfaceName << ") --> "
235 << hex << (void *) this << dec )
236 beginService( "ListOfSyr_Impl::ListOfSyr_Impl" );
238 _id = _poa->activate_object(_thisObj);
239 sendMessage(NOTIF_STEP, "ListOfSyr_Impl is Created");
240 endService( "ListOfSyr_Impl::ListOfSyr_Impl" );
243 ListOfSyr_Impl::ListOfSyr_Impl() {
246 ListOfSyr_Impl::~ListOfSyr_Impl() {
247 beginService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
248 endService( "ListOfSyr_Impl::~ListOfSyr_Impl" );
251 SuperVisionTest::SeqOfSyr * ListOfSyr_Impl::GetSeqOfSyr() {
252 SuperVisionTest::SeqOfSyr_var aSeqOfSyr = new SuperVisionTest::SeqOfSyr( _SeqOfSyr ) ;
253 return ( aSeqOfSyr._retn() ) ;
256 void ListOfSyr_Impl::SetSeqOfSyr( const SuperVisionTest::SeqOfSyr & aSeqOfSyr ) {
257 _SeqOfSyr = aSeqOfSyr ;
263 PortableServer::ObjectId * SyrComponentEngine_factory
265 PortableServer::POA_ptr poa,
266 PortableServer::ObjectId * contId,
267 const char *instanceName,
268 const char *interfaceName)
270 MESSAGE("SyrComponentEngine_factory SyrComponentEngine ("
271 << instanceName << "," << interfaceName << "," << getpid() << ")");
272 SyrComponent_Impl * mySyrComponent
273 = new SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName);
274 return mySyrComponent->getId() ;
278 Syr_Impl::Syr_Impl( CORBA::ORB_ptr orb ,
279 PortableServer::POA_ptr poa ,
280 PortableServer::ObjectId * contId ,
281 const char * instanceName ,
282 const char * interfaceName ,
283 const char * graphName ,
284 const char * nodeName ,
285 const long anOddInteger ) :
286 SyrComponent_Impl(orb, poa, contId, instanceName, interfaceName,false) {
287 Names( graphName , nodeName ) ;
288 MESSAGE("Syr_Impl::Syr_Impl activate object instanceName("
289 << instanceName << ") interfaceName(" << interfaceName << ") --> "
290 << hex << (void *) this << dec )
291 beginService( "Syr_Impl::Syr_Impl" );
293 _id = _poa->activate_object(_thisObj);
294 _InitialInteger = anOddInteger ;
295 _CurrentInteger = anOddInteger ;
297 sendMessage(NOTIF_STEP, "Syr_Impl is Created");
298 endService( "Syr_Impl::Syr_Impl" );
301 Syr_Impl::Syr_Impl() {
304 Syr_Impl::~Syr_Impl() {
305 beginService( "Syr_Impl::~Syr_Impl" );
306 endService( "Syr_Impl::~Syr_Impl" );
309 long Syr_Impl::Initial() {
310 beginService( " Syr_Impl::Initial" );
311 sendMessage(NOTIF_STEP, "Syr_Impl::Initial is Computing");
312 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
314 endService( " Syr_Impl::Initial" );
315 return _InitialInteger ;
318 long Syr_Impl::Current() {
319 beginService( " Syr_Impl::Current" );
320 sendMessage(NOTIF_STEP, "Syr_Impl::Current is Computing");
321 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
323 endService( " Syr_Impl::Current" );
324 return _CurrentInteger ;
327 long Syr_Impl::IsEven() {
329 beginService( " Syr_Impl::IsEven" );
330 sendMessage(NOTIF_STEP, "Syr_Impl::IsEven is Computing");
331 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
333 RetVal = ( _CurrentInteger & 1 ) == 0 ;
334 MESSAGE( " Syr_Impl::IsEven " << _CurrentInteger << " " << RetVal );
335 endService( " Syr_Impl::IsEven" );
339 long Syr_Impl::IsOne() {
341 beginService( " Syr_Impl::IsOne" );
342 sendMessage(NOTIF_STEP, "Syr_Impl::IsOne is Computing");
343 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
345 RetVal = ( _CurrentInteger == 1 ) ;
346 MESSAGE( " Syr_Impl::IsOne " << _CurrentInteger << " " << RetVal );
347 endService( " Syr_Impl::IsOne" );
351 long Syr_Impl::Count() {
352 beginService( " Syr_Impl::Count" );
353 sendMessage(NOTIF_STEP, "Syr_Impl::Count is Computing");
354 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
356 MESSAGE( " Syr_Impl::Count " << _Count );
357 endService( " Syr_Impl::Count" );
361 void Syr_Impl::M3p1() {
362 beginService( " Syr_Impl::M3p1" );
363 sendMessage(NOTIF_STEP, "Syr_Impl::M3p1 is Computing");
364 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
367 _CurrentInteger = 0 ;
369 _CurrentInteger = 3*_CurrentInteger + 1 ;
370 MESSAGE( " Syr_Impl::M3p1 " << _CurrentInteger );
371 endService( " Syr_Impl::M3p1" );
374 void Syr_Impl::Div2() {
375 beginService( " Syr_Impl::Div2" );
376 sendMessage(NOTIF_STEP, "Syr_Impl::Div2 is Computing");
377 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
380 _CurrentInteger = 0 ;
382 _CurrentInteger = ( _CurrentInteger >> 1 ) ;
383 MESSAGE( " Syr_Impl::Div2 " << _CurrentInteger );
384 endService( " Syr_Impl::Div2" );
387 void Syr_Impl::Incr() {
388 beginService( " Syr_Impl::Incr" );
389 sendMessage(NOTIF_STEP, "Syr_Impl::Incr is Computing");
390 int S = 1+(int) (2.0*rand()/(RAND_MAX+1.0));
392 _Count = _Count + 1 ;
393 MESSAGE( " Syr_Impl::Incr " << _Count );
394 endService( " Syr_Impl::Incr" );