1 // Copyright (C) 2007-2022 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"
40 #include "SALOME_NamingService.hxx"
41 #include "SALOME_LifeCycleCORBA.hxx"
43 #include "AddComponent_Impl.hxx"
44 #include "Adder_Impl.hxx"
45 #include "COMPONENT_version.h"
49 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
50 PortableServer::POA_ptr poa,
51 PortableServer::ObjectId * contId,
52 const char *instanceName,
53 const char *interfaceName, bool withRegistry) :
54 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
55 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
56 << "activate object instanceName("
57 << instanceName << ") interfaceName(" << interfaceName << ")" )
59 _id = _poa->activate_object(_thisObj);
63 AddComponent_Impl::AddComponent_Impl() {
67 AddComponent_Impl::~AddComponent_Impl() {
70 char* AddComponent_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 AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
80 beginService( " AddComponent_Impl::Add" );
84 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
85 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
94 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
95 << " ) returns " << (x - y) << " after " << S << " seconds" )
97 endService( " AddComponent_Impl::Add" );
101 CORBA::Double AddComponent_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
102 beginService( " AddComponent_Impl::AddWithoutSleep" );
105 endService( " AddComponent_Impl::AddWithoutSleep" );
109 CORBA::Long AddComponent_Impl::Sigma( CORBA::Long n ) {
112 beginService( " AddComponent_Impl::Sigma" );
113 for ( j = 0 ; j < 1000000 ; j++ ) {
115 for ( i = 1 ; i <= n ; i++ ) {
119 endService( " AddComponent_Impl::Sigma" );
123 void AddComponent_Impl::Setx( CORBA::Double x ) {
124 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
135 void AddComponent_Impl::Sety( CORBA::Double y ) {
136 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
147 CORBA::Double AddComponent_Impl::Addxy() {
148 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
156 double zz = xx + yy ;
161 CORBA::Double AddComponent_Impl::AddyTox( CORBA::Double y ) {
162 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
175 CORBA::Double AddComponent_Impl::LastResult() {
176 beginService( " AddComponent_Impl::LastResult" );
177 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
178 endService( " AddComponent_Impl::LastResult" );
179 return LastAddition ;
182 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
183 beginService( "AddComponent_Impl::Addition" );
184 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
185 Adder_Impl * myAdder ;
186 myAdder = new Adder_Impl( _orb , _poa, _contId,
187 instanceName() , interfaceName() ,
188 graphName() , nodeName() ) ;
189 SuperVisionTest::Adder_var iobject ;
190 PortableServer::ObjectId * id = myAdder->getId() ;
191 CORBA::Object_var obj = _poa->id_to_reference(*id);
192 iobject = SuperVisionTest::Adder::_narrow(obj) ;
193 endService( "AddComponent_Impl::Addition" );
194 return iobject._retn() ;
195 // return SuperVisionTest::Adder::_duplicate(iobject) ;
198 CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
199 beginService( "AddComponent_Impl::Addition" );
200 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
201 Adder_Impl * myAdder ;
202 myAdder = new Adder_Impl( _orb , _poa, _contId,
203 instanceName() , interfaceName() ,
204 graphName() , nodeName() ) ;
205 SuperVisionTest::Adder_var iobject ;
206 PortableServer::ObjectId * id = myAdder->getId() ;
207 CORBA::Object_var obj = _poa->id_to_reference(*id);
208 iobject = SuperVisionTest::Adder::_narrow(obj) ;
209 endService( "AddComponent_Impl::Addition" );
210 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
214 void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
215 SuperVisionTest::Adder_out aAdder ) {
216 beginService( "AddComponent_Impl::Addition" );
217 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
218 Adder_Impl * myAdder ;
219 myAdder = new Adder_Impl( _orb , _poa, _contId,
220 instanceName() , interfaceName() ,
221 graphName() , nodeName() ) ;
222 SuperVisionTest::Adder_var iobject ;
223 PortableServer::ObjectId * id = myAdder->getId() ;
224 CORBA::Object_var obj = _poa->id_to_reference(*id);
225 iobject = SuperVisionTest::Adder::_narrow(obj) ;
226 endService( "AddComponent_Impl::Addition" );
227 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
231 CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
232 SuperVisionTest::AddComponent_ptr Adder2 ,
233 SuperVisionTest::AddComponent_ptr Adder3 ,
234 SuperVisionTest::AddComponent_out RetAddComponent1 ,
235 SuperVisionTest::AddComponent_out RetAdder2 ,
236 SuperVisionTest::AddComponent_out RetAdder3 ) {
238 beginService( "AddComponent_Impl::AdditionObjRefs" );
239 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
240 CORBA::ORB_var orb = KERNEL::GetRefToORB();
241 char * IOR = orb->object_to_string( AddComponent1 );
242 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
243 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
244 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
245 IOR = orb->object_to_string( Adder2 );
246 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
247 << CORBA::is_nil( Adder2 ) << endl ;
248 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
249 IOR = orb->object_to_string( Adder3 );
250 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
251 << CORBA::is_nil( Adder3 ) << endl ;
252 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
253 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
254 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
255 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
258 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
259 endService( "AddComponent_Impl::AdditionObjRefs" );
266 PortableServer::ObjectId * AddComponentEngine_factory
268 PortableServer::POA_ptr poa,
269 PortableServer::ObjectId * contId,
270 const char *instanceName,
271 const char *interfaceName)
274 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
275 << instanceName << "," << interfaceName << "," << getpid() << ")");
277 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
278 << instanceName << "," << interfaceName << "," << _getpid() << ")");
280 CORBA::Object_var o = poa->id_to_reference(*contId);
281 Engines::Container_var cont = Engines::Container::_narrow(o);
282 AddComponent_Impl * myAddComponent = nullptr;
283 if(cont->is_SSL_mode())
285 myAddComponent = new AddComponent_Impl_SSL(orb, poa, contId, instanceName, interfaceName);
289 myAddComponent = new AddComponent_Impl_No_SSL(orb, poa, contId, instanceName, interfaceName);
291 return myAddComponent->getId() ;