1 // Copyright (C) 2007-2012 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"
45 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
46 PortableServer::POA_ptr poa,
47 PortableServer::ObjectId * contId,
48 const char *instanceName,
49 const char *interfaceName) :
50 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
51 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
52 << "activate object instanceName("
53 << instanceName << ") interfaceName(" << interfaceName << ")" )
55 _id = _poa->activate_object(_thisObj);
59 AddComponent_Impl::AddComponent_Impl() {
63 AddComponent_Impl::~AddComponent_Impl() {
66 CORBA::Double AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
67 beginService( " AddComponent_Impl::Add" );
71 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
72 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
77 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
78 << " ) returns " << (x - y) << " after " << S << " seconds" )
80 endService( " AddComponent_Impl::Add" );
84 CORBA::Double AddComponent_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
85 beginService( " AddComponent_Impl::AddWithoutSleep" );
88 endService( " AddComponent_Impl::AddWithoutSleep" );
92 CORBA::Long AddComponent_Impl::Sigma( CORBA::Long n ) {
95 beginService( " AddComponent_Impl::Sigma" );
96 for ( j = 0 ; j < 1000000 ; j++ ) {
98 for ( i = 1 ; i <= n ; i++ ) {
102 endService( " AddComponent_Impl::Sigma" );
106 void AddComponent_Impl::Setx( CORBA::Double x ) {
107 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
114 void AddComponent_Impl::Sety( CORBA::Double y ) {
115 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
122 CORBA::Double AddComponent_Impl::Addxy() {
123 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
127 double zz = xx + yy ;
132 CORBA::Double AddComponent_Impl::AddyTox( CORBA::Double y ) {
133 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
142 CORBA::Double AddComponent_Impl::LastResult() {
143 beginService( " AddComponent_Impl::LastResult" );
144 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
145 endService( " AddComponent_Impl::LastResult" );
146 return LastAddition ;
149 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
150 beginService( "AddComponent_Impl::Addition" );
151 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
152 Adder_Impl * myAdder ;
153 myAdder = new Adder_Impl( _orb , _poa, _contId,
154 instanceName() , interfaceName() ,
155 graphName() , nodeName() ) ;
156 SuperVisionTest::Adder_var iobject ;
157 PortableServer::ObjectId * id = myAdder->getId() ;
158 CORBA::Object_var obj = _poa->id_to_reference(*id);
159 iobject = SuperVisionTest::Adder::_narrow(obj) ;
160 endService( "AddComponent_Impl::Addition" );
161 return iobject._retn() ;
162 // return SuperVisionTest::Adder::_duplicate(iobject) ;
165 CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
166 beginService( "AddComponent_Impl::Addition" );
167 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
168 Adder_Impl * myAdder ;
169 myAdder = new Adder_Impl( _orb , _poa, _contId,
170 instanceName() , interfaceName() ,
171 graphName() , nodeName() ) ;
172 SuperVisionTest::Adder_var iobject ;
173 PortableServer::ObjectId * id = myAdder->getId() ;
174 CORBA::Object_var obj = _poa->id_to_reference(*id);
175 iobject = SuperVisionTest::Adder::_narrow(obj) ;
176 endService( "AddComponent_Impl::Addition" );
177 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
181 void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
182 SuperVisionTest::Adder_out aAdder ) {
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 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
198 CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
199 SuperVisionTest::AddComponent_ptr Adder2 ,
200 SuperVisionTest::AddComponent_ptr Adder3 ,
201 SuperVisionTest::AddComponent_out RetAddComponent1 ,
202 SuperVisionTest::AddComponent_out RetAdder2 ,
203 SuperVisionTest::AddComponent_out RetAdder3 ) {
205 beginService( "AddComponent_Impl::AdditionObjRefs" );
206 cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
207 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
208 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
209 CORBA::ORB_var orb = init(0 , 0 ) ;
210 char * IOR = orb->object_to_string( AddComponent1 );
211 cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
212 << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
213 RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
214 IOR = orb->object_to_string( Adder2 );
215 cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
216 << CORBA::is_nil( Adder2 ) << endl ;
217 RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
218 IOR = orb->object_to_string( Adder3 );
219 cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
220 << CORBA::is_nil( Adder3 ) << endl ;
221 RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
222 if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
223 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
224 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
227 cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
228 endService( "AddComponent_Impl::AdditionObjRefs" );
235 PortableServer::ObjectId * AddComponentEngine_factory
237 PortableServer::POA_ptr poa,
238 PortableServer::ObjectId * contId,
239 const char *instanceName,
240 const char *interfaceName)
242 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
243 << instanceName << "," << interfaceName << "," << getpid() << ")");
244 AddComponent_Impl * myAddComponent
245 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
246 return myAddComponent->getId() ;