1 // Copyright (C) 2007-2008 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
22 // SuperVisionTest AdditionComponent : example of component that adds two numbers
23 // File : AdditionComponent_Impl.cxx
24 // Author : Jean Rahuel, CEA
25 // Module : SuperVisionTest
33 #include "utilities.h"
34 #include "Utils_ORB_INIT.hxx"
35 #include "Utils_SINGLETON.hxx"
36 #include "SALOME_NamingService.hxx"
37 #include "SALOME_LifeCycleCORBA.hxx"
39 #include "AdditionComponent_Impl.hxx"
40 #include "Adder_Impl.hxx"
44 AdditionInterface_Impl::AdditionInterface_Impl( CORBA::ORB_ptr orb,
45 PortableServer::POA_ptr poa,
46 PortableServer::ObjectId * contId,
47 const char *instanceName,
48 const char *interfaceName) :
49 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
50 MESSAGE("AdditionInterface_Impl::AdditionInterface_Impl this " << hex << this << dec
51 << "activate object instanceName("
52 << instanceName << ") interfaceName(" << interfaceName << ")" )
54 _id = _poa->activate_object(_thisObj);
58 AdditionInterface_Impl::AdditionInterface_Impl() {
62 AdditionInterface_Impl::~AdditionInterface_Impl() {
65 CORBA::Double AdditionInterface_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
66 beginService( " AdditionInterface_Impl::Add" );
70 sendMessage(NOTIF_STEP, "AdditionInterface_Impl::Add is Computing");
71 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
76 MESSAGE( "AdditionInterface_Impl::Add( " << x << " , " << y << " , " << z
77 << " ) returns " << (x - y) << " after " << S << " seconds" )
79 endService( " AdditionInterface_Impl::Add" );
83 CORBA::Double AdditionInterface_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
84 beginService( " AdditionInterface_Impl::AddWithoutSleep" );
87 endService( " AdditionInterface_Impl::AddWithoutSleep" );
91 CORBA::Long AdditionInterface_Impl::Sigma( CORBA::Long n ) {
94 beginService( " AdditionInterface_Impl::Sigma" );
95 for ( j = 0 ; j < 1000000 ; j++ ) {
97 for ( i = 1 ; i <= n ; i++ ) {
101 endService( " AdditionInterface_Impl::Sigma" );
105 void AdditionInterface_Impl::Setx( CORBA::Double x ) {
106 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
113 void AdditionInterface_Impl::Sety( CORBA::Double y ) {
114 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
121 CORBA::Double AdditionInterface_Impl::Addxy() {
122 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
126 double zz = xx + yy ;
131 CORBA::Double AdditionInterface_Impl::AddyTox( CORBA::Double y ) {
132 int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
141 CORBA::Double AdditionInterface_Impl::LastResult() {
142 beginService( " AdditionInterface_Impl::LastResult" );
143 sendMessage(NOTIF_STEP, "AdditionInterface_Impl::LastResult is Computing");
144 endService( " AdditionInterface_Impl::LastResult" );
145 return LastAddition ;
148 AdditionComponent::Adder_ptr AdditionInterface_Impl::Addition() {
149 beginService( "AdditionInterface_Impl::Addition" );
150 sendMessage(NOTIF_STEP, "AdditionInterface_Impl creates Adder_Impl");
151 Adder_Impl * myAdder ;
152 myAdder = new Adder_Impl( _orb , _poa, _contId,
153 instanceName() , interfaceName() ,
154 graphName() , nodeName() ) ;
155 AdditionComponent::Adder_var iobject ;
156 PortableServer::ObjectId * id = myAdder->getId() ;
157 CORBA::Object_var obj = _poa->id_to_reference(*id);
158 iobject = AdditionComponent::Adder::_narrow(obj) ;
159 endService( "AdditionInterface_Impl::Addition" );
160 return iobject._retn() ;
161 // return AdditionComponent::Adder::_duplicate(iobject) ;
164 bool AdditionInterface_Impl::AdditionObjRef1( AdditionComponent::Adder_out aAdder ) {
165 beginService( "AdditionInterface_Impl::Addition" );
166 sendMessage(NOTIF_STEP, "AdditionInterface_Impl creates Adder_Impl");
167 Adder_Impl * myAdder ;
168 myAdder = new Adder_Impl( _orb , _poa, _contId,
169 instanceName() , interfaceName() ,
170 graphName() , nodeName() ) ;
171 AdditionComponent::Adder_var iobject ;
172 PortableServer::ObjectId * id = myAdder->getId() ;
173 CORBA::Object_var obj = _poa->id_to_reference(*id);
174 iobject = AdditionComponent::Adder::_narrow(obj) ;
175 endService( "AdditionInterface_Impl::Addition" );
176 aAdder = AdditionComponent::Adder::_duplicate(iobject) ;
180 void AdditionInterface_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
181 AdditionComponent::Adder_out aAdder ) {
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 aAdder = AdditionComponent::Adder::_duplicate(iobject) ;
197 CORBA::Boolean AdditionInterface_Impl::AdditionObjRefs( AdditionComponent::AdditionInterface_ptr AdditionInterface1 ,
198 AdditionComponent::AdditionInterface_ptr Adder2 ,
199 AdditionComponent::AdditionInterface_ptr Adder3 ,
200 AdditionComponent::AdditionInterface_out RetAdditionInterface1 ,
201 AdditionComponent::AdditionInterface_out RetAdder2 ,
202 AdditionComponent::AdditionInterface_out RetAdder3 ) {
204 beginService( "AdditionInterface_Impl::AdditionObjRefs" );
205 cout << "beginService AdditionInterface_Impl::AdditionObjRefs" << endl ;
206 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
207 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
208 CORBA::ORB_var orb = init(0 , 0 ) ;
209 char * IOR = orb->object_to_string( AdditionInterface1 );
210 cout << "AdditionInterface_Impl::AdditionObjRefs AdditionInterface1 " << AdditionInterface1 << " IOR "
211 << IOR << " nil " << CORBA::is_nil( AdditionInterface1 ) << endl ;
212 RetAdditionInterface1 = AdditionComponent::AdditionInterface::_duplicate( AdditionInterface1 ) ;
213 IOR = orb->object_to_string( Adder2 );
214 cout << "AdditionInterface_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
215 << CORBA::is_nil( Adder2 ) << endl ;
216 RetAdder2 = AdditionComponent::AdditionInterface::_duplicate( Adder2 ) ;
217 IOR = orb->object_to_string( Adder3 );
218 cout << "AdditionInterface_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
219 << CORBA::is_nil( Adder3 ) << endl ;
220 RetAdder3 = AdditionComponent::AdditionInterface::_duplicate( Adder3 ) ;
221 if ( CORBA::is_nil( AdditionInterface1 ) || CORBA::is_nil( Adder2 ) ||
222 CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAdditionInterface1 ) ||
223 CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
226 cout << "endService AdditionInterface_Impl::AdditionObjRefs" << endl ;
227 endService( "AdditionInterface_Impl::AdditionObjRefs" );
231 //AdditionComponentEngine_factory
234 PortableServer::ObjectId * AdditionComponentEngine_factory
236 PortableServer::POA_ptr poa,
237 PortableServer::ObjectId * contId,
238 const char *instanceName,
239 const char *interfaceName)
241 MESSAGE("AdditionComponentEngine_factory AdditionInterfaceEngine ("
242 << instanceName << "," << interfaceName << "," << getpid() << ")");
243 AdditionInterface_Impl * myAdditionInterface
244 = new AdditionInterface_Impl(orb, poa, contId, instanceName, interfaceName);
245 return myAdditionInterface->getId() ;