1 // SuperVisionTest AddComponent : example of component that adds two numbers
3 // Copyright (C) 2003 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : AddComponent_Impl.cxx
25 // Author : Jean Rahuel, CEA
26 // Module : SuperVisionTest
35 #include "utilities.h"
36 #include "Utils_ORB_INIT.hxx"
37 #include "Utils_SINGLETON.hxx"
38 #include "SALOME_NamingService.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "Adder_Impl.hxx"
43 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
44 PortableServer::POA_ptr poa ,
45 PortableServer::ObjectId * contId ,
46 const char * instanceName ,
47 const char * interfaceName ,
48 const char * graphName ,
49 const char * nodeName ) :
50 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
51 Names( graphName , nodeName ) ;
52 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
53 << instanceName << ") interfaceName(" << interfaceName << ") --> "
54 << hex << (void *) this << dec )
55 beginService( "Adder_Impl::Adder_Impl" );
57 _id = _poa->activate_object(_thisObj);
59 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
60 endService( "Adder_Impl::Adder_Impl" );
63 Adder_Impl::Adder_Impl() {
67 Adder_Impl::~Adder_Impl() {
68 beginService( "Adder_Impl::~Adder_Impl" );
69 endService( "Adder_Impl::~Adder_Impl" );
72 void Adder_Impl::destroy() {
73 _poa->deactivate_object(*_id) ;
74 CORBA::release(_poa) ;
76 _thisObj->_remove_ref();
79 double Adder_Impl::Add( double x , double y , double & z ) {
80 beginService( " Adder_Impl::Add" );
84 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
85 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
90 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
91 << " ) returns " << -(x - y) << " after " << S << " seconds" )
93 endService( " Adder_Impl::Add" );
97 double Adder_Impl::AddWithoutSleep( double x , double y , double & z ) {
98 beginService( " Adder_Impl::AddWithoutSleep" );
100 endService( " Adder_Impl::AddWithoutSleep" );
104 double Adder_Impl::AddAndCompare( const double x , const double y ,
105 const SuperVisionTest::Adder_ptr anOtherAdder ,
107 beginService( " Adder_Impl::AddAndCompare" );
111 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
112 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
117 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
118 << " ) returns " << -(x - y) << " after " << S << " seconds" )
121 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
123 anOtherAdder->LastResult( RetVal ) ;
130 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
131 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
132 endService( " Adder_Impl::AddAndCompare" );
136 void Adder_Impl::SetLastResult( double z ) {
137 beginService( " Adder_Impl::SetLastResult" );
138 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
140 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
146 endService( " Adder_Impl::SetLastResult" );
150 void Adder_Impl::LastResult( double & z ) {
151 beginService( " Adder_Impl::LastResult" );
152 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
154 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
160 endService( " Adder_Impl::LastResult" );
164 Engines::Component_ptr Adder_Impl::LccAddComponent( const char * aContainer ,
165 const char * aComponentName ) {
166 beginService( "Adder_Impl::LccAddComponent" );
167 Engines::Component_ptr objComponent ;
168 objComponent = Engines::Component::_nil() ;
170 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
171 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
172 CORBA::ORB_var orb = init(0 , 0 ) ;
173 SALOME_NamingService *_NS ;
174 _NS = new SALOME_NamingService();
175 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
177 SALOME_LifeCycleCORBA LCC( _NS ) ;
178 objComponent = LCC.FindOrLoad_Component( aContainer ,
180 endService( "Adder_Impl::LccAddComponent" );
181 return objComponent ;