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);
58 AddComponent_Impl::AddComponent_Impl() {
62 AddComponent_Impl::~AddComponent_Impl() {
65 double AddComponent_Impl::Add( double x , double y , double & z ) {
66 beginService( " AddComponent_Impl::Add" );
70 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
71 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
76 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
77 << " ) returns " << (x - y) << " after " << S << " seconds" )
79 endService( " AddComponent_Impl::Add" );
83 double AddComponent_Impl::AddWithoutSleep( double x , double y , double & z ) {
84 beginService( " AddComponent_Impl::AddWithoutSleep" );
87 endService( " AddComponent_Impl::AddWithoutSleep" );
91 long AddComponent_Impl::Sigma( long n ) {
94 beginService( " AddComponent_Impl::Sigma" );
95 for ( j = 0 ; j < 1000000 ; j++ ) {
97 for ( i = 1 ; i <= n ; i++ ) {
101 endService( " AddComponent_Impl::Sigma" );
105 void AddComponent_Impl::Setx( double x ) {
106 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
113 void AddComponent_Impl::Sety( double y ) {
114 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
121 double AddComponent_Impl::Addxy() {
122 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
126 double zz = xx + yy ;
131 double AddComponent_Impl::AddyTox( double y ) {
132 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
141 double AddComponent_Impl::LastResult() {
142 beginService( " AddComponent_Impl::LastResult" );
143 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
144 endService( " AddComponent_Impl::LastResult" );
145 return LastAddition ;
148 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
149 beginService( "AddComponent_Impl::Addition" );
150 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
151 Adder_Impl * myAdder ;
152 myAdder = new Adder_Impl( _orb , _poa, _contId,
153 instanceName() , interfaceName() ,
154 graphName() , nodeName() ) ;
155 SuperVisionTest::Adder_var iobject ;
156 PortableServer::ObjectId * id = myAdder->getId() ;
157 CORBA::Object_var obj = _poa->id_to_reference(*id);
158 iobject = SuperVisionTest::Adder::_narrow(obj) ;
159 endService( "AddComponent_Impl::Addition" );
160 return iobject._retn() ;
161 // return SuperVisionTest::Adder::_duplicate(iobject) ;
164 bool AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
165 beginService( "AddComponent_Impl::Addition" );
166 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
167 Adder_Impl * myAdder ;
168 myAdder = new Adder_Impl( _orb , _poa, _contId,
169 instanceName() , interfaceName() ,
170 graphName() , nodeName() ) ;
171 SuperVisionTest::Adder_var iobject ;
172 PortableServer::ObjectId * id = myAdder->getId() ;
173 CORBA::Object_var obj = _poa->id_to_reference(*id);
174 iobject = SuperVisionTest::Adder::_narrow(obj) ;
175 endService( "AddComponent_Impl::Addition" );
176 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
180 void AddComponent_Impl::AdditionObjRef2( bool & FuncValue ,
181 SuperVisionTest::Adder_out aAdder ) {
182 beginService( "AddComponent_Impl::Addition" );
183 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
184 Adder_Impl * myAdder ;
185 myAdder = new Adder_Impl( _orb , _poa, _contId,
186 instanceName() , interfaceName() ,
187 graphName() , nodeName() ) ;
188 SuperVisionTest::Adder_var iobject ;
189 PortableServer::ObjectId * id = myAdder->getId() ;
190 CORBA::Object_var obj = _poa->id_to_reference(*id);
191 iobject = SuperVisionTest::Adder::_narrow(obj) ;
192 endService( "AddComponent_Impl::Addition" );
193 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
197 bool AddComponent_Impl::AdditionObjRefs( const SuperVisionTest::AddComponent_ptr AddComponent1 ,
198 const SuperVisionTest::AddComponent_ptr Adder2 ,
199 const SuperVisionTest::AddComponent_ptr Adder3 ,
200 SuperVisionTest::AddComponent_out RetAddComponent1 ,
201 SuperVisionTest::AddComponent_out RetAdder2 ,
202 SuperVisionTest::AddComponent_out RetAdder3 ) {
204 beginService( "AddComponent_Impl::AdditionObjRefs" );
205 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
206 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
207 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
208 CORBA::ORB_var orb = init(0 , 0 ) ;
209 char * IOR = orb->object_to_string( AddComponent1 );
210 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
211 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
212 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
213 IOR = orb->object_to_string( Adder2 );
214 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
215 << CORBA::is_nil( Adder2 ) << endl ;
216 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
217 IOR = orb->object_to_string( Adder3 );
218 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
219 << CORBA::is_nil( Adder3 ) << endl ;
220 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
221 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
222 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
223 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
226 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
227 endService( "AddComponent_Impl::AdditionObjRefs" );
234 PortableServer::ObjectId * AddComponentEngine_factory
236 PortableServer::POA_ptr poa,
237 PortableServer::ObjectId * contId,
238 const char *instanceName,
239 const char *interfaceName)
241 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
242 << instanceName << "," << interfaceName << "," << getpid() << ")");
243 AddComponent_Impl * myAddComponent
244 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
245 return myAddComponent->getId() ;