1 // SuperVisionTest AddComponent : example of component that adds two numbers
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 : AddComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
35 #include "utilities.h"
36 #include "Utils_ORB_INIT.hxx"
37 #include "Utils_SINGLETON.hxx"
38 #include "SALOME_NamingService.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "AddComponent_Impl.hxx"
42 #include "Adder_Impl.hxx"
44 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
45 PortableServer::POA_ptr poa,
46 PortableServer::ObjectId * contId,
47 const char *instanceName,
48 const char *interfaceName) :
49 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
50 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
51 << "activate object instanceName("
52 << instanceName << ") interfaceName(" << interfaceName << ")" )
54 _id = _poa->activate_object(_thisObj);
59 AddComponent_Impl::AddComponent_Impl() {
63 AddComponent_Impl::~AddComponent_Impl() {
66 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
67 beginService( "AddComponent_Impl::Addition" );
68 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
69 Adder_Impl * myAdder ;
70 myAdder = new Adder_Impl( _orb , _poa, _contId,
71 instanceName() , interfaceName() ,
72 graphName() , nodeName() ) ;
73 SuperVisionTest::Adder_var iobject ;
74 PortableServer::ObjectId * id = myAdder->getId() ;
75 CORBA::Object_var obj = _poa->id_to_reference(*id);
76 iobject = SuperVisionTest::Adder::_narrow(obj) ;
77 endService( "AddComponent_Impl::Addition" );
78 return iobject._retn() ;
79 // return SuperVisionTest::Adder::_duplicate(iobject) ;
82 bool AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
83 beginService( "AddComponent_Impl::Addition" );
84 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
85 Adder_Impl * myAdder ;
86 myAdder = new Adder_Impl( _orb , _poa, _contId,
87 instanceName() , interfaceName() ,
88 graphName() , nodeName() ) ;
89 SuperVisionTest::Adder_var iobject ;
90 PortableServer::ObjectId * id = myAdder->getId() ;
91 CORBA::Object_var obj = _poa->id_to_reference(*id);
92 iobject = SuperVisionTest::Adder::_narrow(obj) ;
93 endService( "AddComponent_Impl::Addition" );
94 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
98 void AddComponent_Impl::AdditionObjRef2( bool & FuncValue ,
99 SuperVisionTest::Adder_out aAdder ) {
100 beginService( "AddComponent_Impl::Addition" );
101 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
102 Adder_Impl * myAdder ;
103 myAdder = new Adder_Impl( _orb , _poa, _contId,
104 instanceName() , interfaceName() ,
105 graphName() , nodeName() ) ;
106 SuperVisionTest::Adder_var iobject ;
107 PortableServer::ObjectId * id = myAdder->getId() ;
108 CORBA::Object_var obj = _poa->id_to_reference(*id);
109 iobject = SuperVisionTest::Adder::_narrow(obj) ;
110 endService( "AddComponent_Impl::Addition" );
111 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
115 double AddComponent_Impl::Add( double x , double y , double & z ) {
116 beginService( " AddComponent_Impl::Add" );
120 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
121 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
126 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
127 << " ) returns " << (x - y) << " after " << S << " seconds" )
129 endService( " AddComponent_Impl::Add" );
133 double AddComponent_Impl::AddWithoutSleep( double x , double y , double & z ) {
134 beginService( " AddComponent_Impl::AddWithoutSleep" );
137 if ( !strcmp( graphName() , "GraphGOTOAddMemory" ) ) {
139 if ( CallCount == 10000 ) {
140 MESSAGE( " AddComponent_Impl::AddWithoutSleep pthread_exit CallCount " << CallCount );
141 endService( " AddComponent_Impl::AddWithoutSleep pthread_exit" );
142 pthread_exit( (void * ) NULL ) ;
145 MESSAGE( " AddComponent_Impl::AddWithoutSleep CallCount " << CallCount );
146 endService( " AddComponent_Impl::AddWithoutSleep" );
150 long AddComponent_Impl::Sigma( long n ) {
153 beginService( " AddComponent_Impl::Sigma" );
154 for ( j = 0 ; j < 1000000 ; j++ ) {
156 for ( i = 1 ; i <= n ; i++ ) {
160 endService( " AddComponent_Impl::Sigma" );
164 double AddComponent_Impl::LastResult() {
165 beginService( " AddComponent_Impl::LastResult" );
166 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
168 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
173 endService( " AddComponent_Impl::LastResult" );
174 return LastAddition ;
177 bool AddComponent_Impl::AdditionObjRefs( const SuperVisionTest::AddComponent_ptr AddComponent1 ,
178 const SuperVisionTest::AddComponent_ptr Adder2 ,
179 const SuperVisionTest::AddComponent_ptr Adder3 ,
180 SuperVisionTest::AddComponent_out RetAddComponent1 ,
181 SuperVisionTest::AddComponent_out RetAdder2 ,
182 SuperVisionTest::AddComponent_out RetAdder3 ) {
184 beginService( "AddComponent_Impl::AdditionObjRefs" );
185 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
186 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
187 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
188 CORBA::ORB_var orb = init(0 , 0 ) ;
189 char * IOR = orb->object_to_string( AddComponent1 );
190 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
191 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
192 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
193 IOR = orb->object_to_string( Adder2 );
194 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
195 << CORBA::is_nil( Adder2 ) << endl ;
196 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
197 IOR = orb->object_to_string( Adder3 );
198 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
199 << CORBA::is_nil( Adder3 ) << endl ;
200 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
201 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
202 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
203 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
206 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
207 endService( "AddComponent_Impl::AdditionObjRefs" );
214 PortableServer::ObjectId * AddComponentEngine_factory
216 PortableServer::POA_ptr poa,
217 PortableServer::ObjectId * contId,
218 const char *instanceName,
219 const char *interfaceName)
221 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
222 << instanceName << "," << interfaceName << "," << getpid() << ")");
223 AddComponent_Impl * myAddComponent
224 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
225 return myAddComponent->getId() ;
229 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
230 PortableServer::POA_ptr poa ,
231 PortableServer::ObjectId * contId ,
232 const char * instanceName ,
233 const char * interfaceName ,
234 const char * graphName ,
235 const char * nodeName ) :
236 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
237 Names( graphName , nodeName ) ;
238 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
239 << instanceName << ") interfaceName(" << interfaceName << ") --> "
240 << hex << (void *) this << dec )
241 beginService( "Adder_Impl::Adder_Impl" );
243 _id = _poa->activate_object(_thisObj);
245 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
246 endService( "Adder_Impl::Adder_Impl" );
249 Adder_Impl::Adder_Impl() {
253 Adder_Impl::~Adder_Impl() {
254 beginService( "Adder_Impl::~Adder_Impl" );
255 endService( "Adder_Impl::~Adder_Impl" );
258 void Adder_Impl::destroy() {
259 _poa->deactivate_object(*_id) ;
260 CORBA::release(_poa) ;
262 _thisObj->_remove_ref();
265 double Adder_Impl::Add( double x , double y , double & z ) {
266 beginService( " Adder_Impl::Add" );
270 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
271 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
276 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
277 << " ) returns " << -(x - y) << " after " << S << " seconds" )
279 endService( " Adder_Impl::Add" );
283 double Adder_Impl::AddWithoutSleep( double x , double y , double & z ) {
284 beginService( " Adder_Impl::AddWithoutSleep" );
286 endService( " Adder_Impl::AddWithoutSleep" );
290 double Adder_Impl::AddAndCompare( const double x , const double y ,
291 const SuperVisionTest::Adder_ptr anOtherAdder ,
293 beginService( " Adder_Impl::AddAndCompare" );
297 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
298 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
303 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
304 << " ) returns " << -(x - y) << " after " << S << " seconds" )
307 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
309 anOtherAdder->LastResult( RetVal ) ;
316 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
317 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
318 endService( " Adder_Impl::AddAndCompare" );
322 void Adder_Impl::SetLastResult( double z ) {
323 beginService( " Adder_Impl::SetLastResult" );
324 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
326 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
332 endService( " Adder_Impl::SetLastResult" );
336 void Adder_Impl::LastResult( double & z ) {
337 beginService( " Adder_Impl::LastResult" );
338 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
340 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
346 endService( " Adder_Impl::LastResult" );
350 Engines::Component_ptr Adder_Impl::LccAddComponent( const char * aContainer ,
351 const char * aComponentName ) {
352 beginService( "Adder_Impl::LccAddComponent" );
353 Engines::Component_ptr objComponent ;
354 objComponent = Engines::Component::_nil() ;
356 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
357 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
358 CORBA::ORB_var orb = init(0 , 0 ) ;
359 SALOME_NamingService *_NS ;
360 _NS = new SALOME_NamingService();
361 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
363 SALOME_LifeCycleCORBA LCC( _NS ) ;
364 objComponent = LCC.FindOrLoad_Component( aContainer ,
366 endService( "Adder_Impl::LccAddComponent" );
367 return objComponent ;