1 // Copyright (C) 2007-2020 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 AddComponent : example of component that adds two numbers
24 // File : AddComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
38 #include "utilities.h"
39 #include "Utils_ORB_INIT.hxx"
40 #include "Utils_SINGLETON.hxx"
41 #include "SALOME_NamingService.hxx"
42 #include "SALOME_LifeCycleCORBA.hxx"
44 #include "AddComponent_Impl.hxx"
45 #include "Adder_Impl.hxx"
46 #include "COMPONENT_version.h"
50 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
51 PortableServer::POA_ptr poa,
52 PortableServer::ObjectId * contId,
53 const char *instanceName,
54 const char *interfaceName) :
55 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
56 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
57 << "activate object instanceName("
58 << instanceName << ") interfaceName(" << interfaceName << ")" )
60 _id = _poa->activate_object(_thisObj);
64 AddComponent_Impl::AddComponent_Impl() {
68 AddComponent_Impl::~AddComponent_Impl() {
71 char* AddComponent_Impl::getVersion()
73 #if COMPONENT_DEVELOPMENT
74 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
76 return CORBA::string_dup(COMPONENT_VERSION_STR);
80 CORBA::Double AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
81 beginService( " AddComponent_Impl::Add" );
85 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
86 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
95 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
96 << " ) returns " << (x - y) << " after " << S << " seconds" )
98 endService( " AddComponent_Impl::Add" );
102 CORBA::Double AddComponent_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
103 beginService( " AddComponent_Impl::AddWithoutSleep" );
106 endService( " AddComponent_Impl::AddWithoutSleep" );
110 CORBA::Long AddComponent_Impl::Sigma( CORBA::Long n ) {
113 beginService( " AddComponent_Impl::Sigma" );
114 for ( j = 0 ; j < 1000000 ; j++ ) {
116 for ( i = 1 ; i <= n ; i++ ) {
120 endService( " AddComponent_Impl::Sigma" );
124 void AddComponent_Impl::Setx( CORBA::Double x ) {
125 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
136 void AddComponent_Impl::Sety( CORBA::Double y ) {
137 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
148 CORBA::Double AddComponent_Impl::Addxy() {
149 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
157 double zz = xx + yy ;
162 CORBA::Double AddComponent_Impl::AddyTox( CORBA::Double y ) {
163 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
176 CORBA::Double AddComponent_Impl::LastResult() {
177 beginService( " AddComponent_Impl::LastResult" );
178 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
179 endService( " AddComponent_Impl::LastResult" );
180 return LastAddition ;
183 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
184 beginService( "AddComponent_Impl::Addition" );
185 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
186 Adder_Impl * myAdder ;
187 myAdder = new Adder_Impl( _orb , _poa, _contId,
188 instanceName() , interfaceName() ,
189 graphName() , nodeName() ) ;
190 SuperVisionTest::Adder_var iobject ;
191 PortableServer::ObjectId * id = myAdder->getId() ;
192 CORBA::Object_var obj = _poa->id_to_reference(*id);
193 iobject = SuperVisionTest::Adder::_narrow(obj) ;
194 endService( "AddComponent_Impl::Addition" );
195 return iobject._retn() ;
196 // return SuperVisionTest::Adder::_duplicate(iobject) ;
199 CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
200 beginService( "AddComponent_Impl::Addition" );
201 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
202 Adder_Impl * myAdder ;
203 myAdder = new Adder_Impl( _orb , _poa, _contId,
204 instanceName() , interfaceName() ,
205 graphName() , nodeName() ) ;
206 SuperVisionTest::Adder_var iobject ;
207 PortableServer::ObjectId * id = myAdder->getId() ;
208 CORBA::Object_var obj = _poa->id_to_reference(*id);
209 iobject = SuperVisionTest::Adder::_narrow(obj) ;
210 endService( "AddComponent_Impl::Addition" );
211 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
215 void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
216 SuperVisionTest::Adder_out aAdder ) {
217 beginService( "AddComponent_Impl::Addition" );
218 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
219 Adder_Impl * myAdder ;
220 myAdder = new Adder_Impl( _orb , _poa, _contId,
221 instanceName() , interfaceName() ,
222 graphName() , nodeName() ) ;
223 SuperVisionTest::Adder_var iobject ;
224 PortableServer::ObjectId * id = myAdder->getId() ;
225 CORBA::Object_var obj = _poa->id_to_reference(*id);
226 iobject = SuperVisionTest::Adder::_narrow(obj) ;
227 endService( "AddComponent_Impl::Addition" );
228 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
232 CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
233 SuperVisionTest::AddComponent_ptr Adder2 ,
234 SuperVisionTest::AddComponent_ptr Adder3 ,
235 SuperVisionTest::AddComponent_out RetAddComponent1 ,
236 SuperVisionTest::AddComponent_out RetAdder2 ,
237 SuperVisionTest::AddComponent_out RetAdder3 ) {
239 beginService( "AddComponent_Impl::AdditionObjRefs" );
240 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
241 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
242 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
243 CORBA::ORB_var orb = init(0 , 0 ) ;
244 char * IOR = orb->object_to_string( AddComponent1 );
245 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
246 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
247 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
248 IOR = orb->object_to_string( Adder2 );
249 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
250 << CORBA::is_nil( Adder2 ) << endl ;
251 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
252 IOR = orb->object_to_string( Adder3 );
253 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
254 << CORBA::is_nil( Adder3 ) << endl ;
255 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
256 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
257 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
258 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
261 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
262 endService( "AddComponent_Impl::AdditionObjRefs" );
269 PortableServer::ObjectId * AddComponentEngine_factory
271 PortableServer::POA_ptr poa,
272 PortableServer::ObjectId * contId,
273 const char *instanceName,
274 const char *interfaceName)
277 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
278 << instanceName << "," << interfaceName << "," << getpid() << ")");
280 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
281 << instanceName << "," << interfaceName << "," << _getpid() << ")");
283 AddComponent_Impl * myAddComponent
284 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
285 return myAddComponent->getId() ;