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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "Adder_Impl.hxx"
44 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
45 PortableServer::POA_ptr poa ,
46 PortableServer::ObjectId * contId ,
47 const char * instanceName ,
48 const char * interfaceName ,
49 const char * graphName ,
50 const char * nodeName ) :
51 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
52 Names( graphName , nodeName ) ;
53 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
54 << instanceName << ") interfaceName(" << interfaceName << ") --> "
55 << hex << (void *) this << dec )
56 beginService( "Adder_Impl::Adder_Impl" );
58 _id = _poa->activate_object(_thisObj);
60 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
61 endService( "Adder_Impl::Adder_Impl" );
64 Adder_Impl::Adder_Impl() {
68 Adder_Impl::~Adder_Impl() {
69 beginService( "Adder_Impl::~Adder_Impl" );
70 endService( "Adder_Impl::~Adder_Impl" );
73 void Adder_Impl::destroy() {
74 _poa->deactivate_object(*_id) ;
75 CORBA::release(_poa) ;
77 _thisObj->_remove_ref();
80 CORBA::Double Adder_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
81 beginService( " Adder_Impl::Add" );
85 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
86 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
91 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
92 << " ) returns " << -(x - y) << " after " << S << " seconds" )
94 endService( " Adder_Impl::Add" );
98 CORBA::Double Adder_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
99 beginService( " Adder_Impl::AddWithoutSleep" );
101 endService( " Adder_Impl::AddWithoutSleep" );
105 CORBA::Double Adder_Impl::AddAndCompare( CORBA::Double x , CORBA::Double y ,
106 SuperVisionTest::Adder_ptr anOtherAdder ,
107 CORBA::Double & z ) {
108 beginService( " Adder_Impl::AddAndCompare" );
112 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
113 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
118 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
119 << " ) returns " << -(x - y) << " after " << S << " seconds" )
122 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
124 anOtherAdder->LastResult( RetVal ) ;
131 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
132 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
133 endService( " Adder_Impl::AddAndCompare" );
137 void Adder_Impl::SetLastResult( CORBA::Double z ) {
138 beginService( " Adder_Impl::SetLastResult" );
139 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
141 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
147 endService( " Adder_Impl::SetLastResult" );
151 void Adder_Impl::LastResult( CORBA::Double & z ) {
152 beginService( " Adder_Impl::LastResult" );
153 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
155 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
161 endService( " Adder_Impl::LastResult" );
165 Engines::Component_ptr Adder_Impl::LccAddComponent( const char * aContainer ,
166 const char * aComponentName ) {
167 beginService( "Adder_Impl::LccAddComponent" );
168 Engines::Component_ptr objComponent ;
169 objComponent = Engines::Component::_nil() ;
171 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
172 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
173 CORBA::ORB_var orb = init(0 , 0 ) ;
174 SALOME_NamingService *_NS ;
175 _NS = new SALOME_NamingService();
176 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
178 SALOME_LifeCycleCORBA LCC( _NS ) ;
179 objComponent = LCC.FindOrLoad_Component( aContainer ,
181 endService( "Adder_Impl::LccAddComponent" );
182 return objComponent ;