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"
42 #include "SALOME_Container_i.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, bool withRegistry) :
55 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
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 = this->BuildNewAdderImplObj();
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 return iobject._retn() ;
194 // return SuperVisionTest::Adder::_duplicate(iobject) ;
197 Adder_Impl *AddComponent_Impl::BuildNewAdderImplObj()
199 Engines::Container_var cont = this->GetContainerRef();
200 if( cont->is_SSL_mode() )
202 return new Adder_Impl_SSL( _orb , _poa, _contId, instanceName() , interfaceName() , graphName() , nodeName() ) ;
206 return new Adder_Impl_No_SSL( _orb , _poa, _contId, instanceName() , interfaceName() , graphName() , nodeName() ) ;
210 CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
211 beginService( "AddComponent_Impl::Addition" );
212 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
213 Adder_Impl * myAdder = nullptr;
214 myAdder = this->BuildNewAdderImplObj();
215 SuperVisionTest::Adder_var iobject ;
216 PortableServer::ObjectId * id = myAdder->getId() ;
217 CORBA::Object_var obj = _poa->id_to_reference(*id);
218 iobject = SuperVisionTest::Adder::_narrow(obj) ;
219 endService( "AddComponent_Impl::Addition" );
220 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
224 void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
225 SuperVisionTest::Adder_out aAdder ) {
226 beginService( "AddComponent_Impl::Addition" );
227 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
228 Adder_Impl * myAdder ;
229 myAdder = this->BuildNewAdderImplObj();
230 SuperVisionTest::Adder_var iobject ;
231 PortableServer::ObjectId * id = myAdder->getId() ;
232 CORBA::Object_var obj = _poa->id_to_reference(*id);
233 iobject = SuperVisionTest::Adder::_narrow(obj) ;
234 endService( "AddComponent_Impl::Addition" );
235 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
239 CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
240 SuperVisionTest::AddComponent_ptr Adder2 ,
241 SuperVisionTest::AddComponent_ptr Adder3 ,
242 SuperVisionTest::AddComponent_out RetAddComponent1 ,
243 SuperVisionTest::AddComponent_out RetAdder2 ,
244 SuperVisionTest::AddComponent_out RetAdder3 ) {
246 beginService( "AddComponent_Impl::AdditionObjRefs" );
247 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
248 CORBA::ORB_var orb = KERNEL::GetRefToORB();
249 char * IOR = orb->object_to_string( AddComponent1 );
250 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
251 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
252 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
253 IOR = orb->object_to_string( Adder2 );
254 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
255 << CORBA::is_nil( Adder2 ) << endl ;
256 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
257 IOR = orb->object_to_string( Adder3 );
258 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
259 << CORBA::is_nil( Adder3 ) << endl ;
260 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
261 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
262 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
263 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
266 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
267 endService( "AddComponent_Impl::AdditionObjRefs" );
274 PortableServer::ObjectId * AddComponentEngine_factory
276 PortableServer::POA_ptr poa,
277 PortableServer::ObjectId * contId,
278 const char *instanceName,
279 const char *interfaceName)
282 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
283 << instanceName << "," << interfaceName << "," << getpid() << ")");
285 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
286 << instanceName << "," << interfaceName << "," << _getpid() << ")");
288 CORBA::Object_var o = poa->id_to_reference(*contId);
289 Engines::Container_var cont = Engines::Container::_narrow(o);
290 AddComponent_Impl * myAddComponent = nullptr;
291 if(cont->is_SSL_mode())
293 myAddComponent = new AddComponent_Impl_SSL(orb, poa, contId, instanceName, interfaceName);
297 myAddComponent = new AddComponent_Impl_No_SSL(orb, poa, contId, instanceName, interfaceName);
299 return myAddComponent->getId() ;