1 // Copyright (C) 2007-2013 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.
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
34 #include "utilities.h"
35 #include "Utils_ORB_INIT.hxx"
36 #include "Utils_SINGLETON.hxx"
37 #include "SALOME_NamingService.hxx"
38 #include "SALOME_LifeCycleCORBA.hxx"
40 #include "AddComponent_Impl.hxx"
41 #include "Adder_Impl.hxx"
42 #include "COMPONENT_version.h"
46 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
47 PortableServer::POA_ptr poa,
48 PortableServer::ObjectId * contId,
49 const char *instanceName,
50 const char *interfaceName) :
51 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
52 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
53 << "activate object instanceName("
54 << instanceName << ") interfaceName(" << interfaceName << ")" )
56 _id = _poa->activate_object(_thisObj);
60 AddComponent_Impl::AddComponent_Impl() {
64 AddComponent_Impl::~AddComponent_Impl() {
67 char* AddComponent_Impl::getVersion()
69 #if COMPONENT_DEVELOPMENT
70 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
72 return CORBA::string_dup(COMPONENT_VERSION_STR);
76 CORBA::Double AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
77 beginService( " AddComponent_Impl::Add" );
81 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
82 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
87 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
88 << " ) returns " << (x - y) << " after " << S << " seconds" )
90 endService( " AddComponent_Impl::Add" );
94 CORBA::Double AddComponent_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
95 beginService( " AddComponent_Impl::AddWithoutSleep" );
98 endService( " AddComponent_Impl::AddWithoutSleep" );
102 CORBA::Long AddComponent_Impl::Sigma( CORBA::Long n ) {
105 beginService( " AddComponent_Impl::Sigma" );
106 for ( j = 0 ; j < 1000000 ; j++ ) {
108 for ( i = 1 ; i <= n ; i++ ) {
112 endService( " AddComponent_Impl::Sigma" );
116 void AddComponent_Impl::Setx( CORBA::Double x ) {
117 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
124 void AddComponent_Impl::Sety( CORBA::Double y ) {
125 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
132 CORBA::Double AddComponent_Impl::Addxy() {
133 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
137 double zz = xx + yy ;
142 CORBA::Double AddComponent_Impl::AddyTox( CORBA::Double y ) {
143 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
152 CORBA::Double AddComponent_Impl::LastResult() {
153 beginService( " AddComponent_Impl::LastResult" );
154 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
155 endService( " AddComponent_Impl::LastResult" );
156 return LastAddition ;
159 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
160 beginService( "AddComponent_Impl::Addition" );
161 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
162 Adder_Impl * myAdder ;
163 myAdder = new Adder_Impl( _orb , _poa, _contId,
164 instanceName() , interfaceName() ,
165 graphName() , nodeName() ) ;
166 SuperVisionTest::Adder_var iobject ;
167 PortableServer::ObjectId * id = myAdder->getId() ;
168 CORBA::Object_var obj = _poa->id_to_reference(*id);
169 iobject = SuperVisionTest::Adder::_narrow(obj) ;
170 endService( "AddComponent_Impl::Addition" );
171 return iobject._retn() ;
172 // return SuperVisionTest::Adder::_duplicate(iobject) ;
175 CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
176 beginService( "AddComponent_Impl::Addition" );
177 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
178 Adder_Impl * myAdder ;
179 myAdder = new Adder_Impl( _orb , _poa, _contId,
180 instanceName() , interfaceName() ,
181 graphName() , nodeName() ) ;
182 SuperVisionTest::Adder_var iobject ;
183 PortableServer::ObjectId * id = myAdder->getId() ;
184 CORBA::Object_var obj = _poa->id_to_reference(*id);
185 iobject = SuperVisionTest::Adder::_narrow(obj) ;
186 endService( "AddComponent_Impl::Addition" );
187 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
191 void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
192 SuperVisionTest::Adder_out aAdder ) {
193 beginService( "AddComponent_Impl::Addition" );
194 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
195 Adder_Impl * myAdder ;
196 myAdder = new Adder_Impl( _orb , _poa, _contId,
197 instanceName() , interfaceName() ,
198 graphName() , nodeName() ) ;
199 SuperVisionTest::Adder_var iobject ;
200 PortableServer::ObjectId * id = myAdder->getId() ;
201 CORBA::Object_var obj = _poa->id_to_reference(*id);
202 iobject = SuperVisionTest::Adder::_narrow(obj) ;
203 endService( "AddComponent_Impl::Addition" );
204 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
208 CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
209 SuperVisionTest::AddComponent_ptr Adder2 ,
210 SuperVisionTest::AddComponent_ptr Adder3 ,
211 SuperVisionTest::AddComponent_out RetAddComponent1 ,
212 SuperVisionTest::AddComponent_out RetAdder2 ,
213 SuperVisionTest::AddComponent_out RetAdder3 ) {
215 beginService( "AddComponent_Impl::AdditionObjRefs" );
216 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
217 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
218 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
219 CORBA::ORB_var orb = init(0 , 0 ) ;
220 char * IOR = orb->object_to_string( AddComponent1 );
221 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
222 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
223 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
224 IOR = orb->object_to_string( Adder2 );
225 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
226 << CORBA::is_nil( Adder2 ) << endl ;
227 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
228 IOR = orb->object_to_string( Adder3 );
229 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
230 << CORBA::is_nil( Adder3 ) << endl ;
231 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
232 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
233 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
234 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
237 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
238 endService( "AddComponent_Impl::AdditionObjRefs" );
245 PortableServer::ObjectId * AddComponentEngine_factory
247 PortableServer::POA_ptr poa,
248 PortableServer::ObjectId * contId,
249 const char *instanceName,
250 const char *interfaceName)
252 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
253 << instanceName << "," << interfaceName << "," << getpid() << ")");
254 AddComponent_Impl * myAddComponent
255 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
256 return myAddComponent->getId() ;