1 // Copyright (C) 2007-2021 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 AdditionComponent : example of component that adds two numbers
24 // File : AdditionComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
38 #include "utilities.h"
40 #include "SALOME_NamingService.hxx"
41 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "AdditionComponent_Impl.hxx"
44 #include "Addition_Adder_Impl.hxx"
45 #include "COMPONENT_version.h"
49 AdditionInterface_Impl::AdditionInterface_Impl( CORBA::ORB_ptr orb,
50 PortableServer::POA_ptr poa,
51 PortableServer::ObjectId * contId,
52 const char *instanceName,
53 const char *interfaceName) :
54 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
55 MESSAGE("AdditionInterface_Impl::AdditionInterface_Impl this " << hex << this << dec
56 << "activate object instanceName("
57 << instanceName << ") interfaceName(" << interfaceName << ")" )
59 _id = _poa->activate_object(_thisObj);
63 AdditionInterface_Impl::AdditionInterface_Impl() {
67 AdditionInterface_Impl::~AdditionInterface_Impl() {
70 char* AdditionInterface_Impl::getVersion()
72 #if COMPONENT_DEVELOPMENT
73 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
75 return CORBA::string_dup(COMPONENT_VERSION_STR);
79 CORBA::Double AdditionInterface_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
80 beginService( " AdditionInterface_Impl::Add" );
84 sendMessage(NOTIF_STEP, "AdditionInterface_Impl::Add is Computing");
85 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
94 MESSAGE( "AdditionInterface_Impl::Add( " << x << " , " << y << " , " << z << " ) returns " << (x - y) << " after " << S << " seconds" )
96 endService( " AdditionInterface_Impl::Add" );
100 CORBA::Double AdditionInterface_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
101 beginService( " AdditionInterface_Impl::AddWithoutSleep" );
104 endService( " AdditionInterface_Impl::AddWithoutSleep" );
108 CORBA::Long AdditionInterface_Impl::Sigma( CORBA::Long n ) {
111 beginService( " AdditionInterface_Impl::Sigma" );
112 for ( j = 0 ; j < 1000000 ; j++ ) {
114 for ( i = 1 ; i <= n ; i++ ) {
118 endService( " AdditionInterface_Impl::Sigma" );
122 void AdditionInterface_Impl::Setx( CORBA::Double x ) {
123 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
134 void AdditionInterface_Impl::Sety( CORBA::Double y ) {
135 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
146 CORBA::Double AdditionInterface_Impl::Addxy() {
147 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
155 double zz = xx + yy ;
160 CORBA::Double AdditionInterface_Impl::AddyTox( CORBA::Double y ) {
161 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
174 CORBA::Double AdditionInterface_Impl::LastResult() {
175 beginService( " AdditionInterface_Impl::LastResult" );
176 sendMessage(NOTIF_STEP, "AdditionInterface_Impl::LastResult is Computing");
177 endService( " AdditionInterface_Impl::LastResult" );
178 return LastAddition ;
181 AdditionComponent::Adder_ptr AdditionInterface_Impl::Addition() {
182 beginService( "AdditionInterface_Impl::Addition" );
183 sendMessage(NOTIF_STEP, "AdditionInterface_Impl creates Adder_Impl");
184 Adder_Impl * myAdder ;
185 myAdder = new Adder_Impl( _orb , _poa, _contId,
186 instanceName() , interfaceName() ,
187 graphName() , nodeName() ) ;
188 AdditionComponent::Adder_var iobject ;
189 PortableServer::ObjectId * id = myAdder->getId() ;
190 CORBA::Object_var obj = _poa->id_to_reference(*id);
191 iobject = AdditionComponent::Adder::_narrow(obj) ;
192 endService( "AdditionInterface_Impl::Addition" );
193 return iobject._retn() ;
194 // return AdditionComponent::Adder::_duplicate(iobject) ;
197 bool AdditionInterface_Impl::AdditionObjRef1( AdditionComponent::Adder_out aAdder ) {
198 beginService( "AdditionInterface_Impl::Addition" );
199 sendMessage(NOTIF_STEP, "AdditionInterface_Impl creates Adder_Impl");
200 Adder_Impl * myAdder ;
201 myAdder = new Adder_Impl( _orb , _poa, _contId,
202 instanceName() , interfaceName() ,
203 graphName() , nodeName() ) ;
204 AdditionComponent::Adder_var iobject ;
205 PortableServer::ObjectId * id = myAdder->getId() ;
206 CORBA::Object_var obj = _poa->id_to_reference(*id);
207 iobject = AdditionComponent::Adder::_narrow(obj) ;
208 endService( "AdditionInterface_Impl::Addition" );
209 aAdder = AdditionComponent::Adder::_duplicate(iobject) ;
213 void AdditionInterface_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
214 AdditionComponent::Adder_out aAdder ) {
215 beginService( "AdditionInterface_Impl::Addition" );
216 sendMessage(NOTIF_STEP, "AdditionInterface_Impl creates Adder_Impl");
217 Adder_Impl * myAdder ;
218 myAdder = new Adder_Impl( _orb , _poa, _contId,
219 instanceName() , interfaceName() ,
220 graphName() , nodeName() ) ;
221 AdditionComponent::Adder_var iobject ;
222 PortableServer::ObjectId * id = myAdder->getId() ;
223 CORBA::Object_var obj = _poa->id_to_reference(*id);
224 iobject = AdditionComponent::Adder::_narrow(obj) ;
225 endService( "AdditionInterface_Impl::Addition" );
226 aAdder = AdditionComponent::Adder::_duplicate(iobject) ;
230 CORBA::Boolean AdditionInterface_Impl::AdditionObjRefs( AdditionComponent::AdditionInterface_ptr AdditionInterface1 ,
231 AdditionComponent::AdditionInterface_ptr Adder2 ,
232 AdditionComponent::AdditionInterface_ptr Adder3 ,
233 AdditionComponent::AdditionInterface_out RetAdditionInterface1 ,
234 AdditionComponent::AdditionInterface_out RetAdder2 ,
235 AdditionComponent::AdditionInterface_out RetAdder3 ) {
237 beginService( "AdditionInterface_Impl::AdditionObjRefs" );
238 cout << "beginService AdditionInterface_Impl::AdditionObjRefs" << endl ;
239 CORBA::ORB_var orb = KERNEL::GetRefToORB();
240 char * IOR = orb->object_to_string( AdditionInterface1 );
241 cout << "AdditionInterface_Impl::AdditionObjRefs AdditionInterface1 " << AdditionInterface1 << " IOR "
242 << IOR << " nil " << CORBA::is_nil( AdditionInterface1 ) << endl ;
243 RetAdditionInterface1 = AdditionComponent::AdditionInterface::_duplicate( AdditionInterface1 ) ;
244 IOR = orb->object_to_string( Adder2 );
245 cout << "AdditionInterface_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
246 << CORBA::is_nil( Adder2 ) << endl ;
247 RetAdder2 = AdditionComponent::AdditionInterface::_duplicate( Adder2 ) ;
248 IOR = orb->object_to_string( Adder3 );
249 cout << "AdditionInterface_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
250 << CORBA::is_nil( Adder3 ) << endl ;
251 RetAdder3 = AdditionComponent::AdditionInterface::_duplicate( Adder3 ) ;
252 if ( CORBA::is_nil( AdditionInterface1 ) || CORBA::is_nil( Adder2 ) ||
253 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAdditionInterface1 ) ||
254 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
257 cout << "endService AdditionInterface_Impl::AdditionObjRefs" << endl ;
258 endService( "AdditionInterface_Impl::AdditionObjRefs" );
262 //AdditionComponentEngine_factory
265 PortableServer::ObjectId * AdditionComponentEngine_factory
267 PortableServer::POA_ptr poa,
268 PortableServer::ObjectId * contId,
269 const char *instanceName,
270 const char *interfaceName)
273 MESSAGE("AdditionComponentEngine_factory AdditionInterfaceEngine ("
274 << instanceName << "," << interfaceName << "," << getpid() << ")");
276 MESSAGE("AdditionComponentEngine_factory AdditionInterfaceEngine ("
277 << instanceName << "," << interfaceName << "," << _getpid() << ")");
279 AdditionInterface_Impl * myAdditionInterface
280 = new AdditionInterface_Impl(orb, poa, contId, instanceName, interfaceName);
281 return myAdditionInterface->getId() ;