1 // Copyright (C) 2007-2022 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, or (at your option) any later version.
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
36 #include "utilities.h"
38 #include "SALOME_NamingService.hxx"
39 #include "SALOME_LifeCycleCORBA.hxx"
41 #include "Adder_Impl.hxx"
42 #include "COMPONENT_version.h"
46 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
47 PortableServer::POA_ptr poa ,
48 PortableServer::ObjectId * contId ,
49 const char * instanceName ,
50 const char * interfaceName ,
51 const char * graphName ,
52 const char * nodeName, bool withRegistry ) :
53 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
54 Names( graphName , nodeName ) ;
55 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
56 << instanceName << ") interfaceName(" << interfaceName << ") --> "
57 << hex << (void *) this << dec );
58 beginService( "Adder_Impl::Adder_Impl" );
60 _id = _poa->activate_object(_thisObj);
62 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
63 endService( "Adder_Impl::Adder_Impl" );
66 Adder_Impl::Adder_Impl() {
70 Adder_Impl::~Adder_Impl() {
71 beginService( "Adder_Impl::~Adder_Impl" );
72 endService( "Adder_Impl::~Adder_Impl" );
75 char* Adder_Impl::getVersion()
77 #if COMPONENT_DEVELOPMENT
78 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
80 return CORBA::string_dup(COMPONENT_VERSION_STR);
84 void Adder_Impl::destroy() {
85 _poa->deactivate_object(*_id) ;
86 CORBA::release(_poa) ;
88 _thisObj->_remove_ref();
91 CORBA::Double Adder_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
92 beginService( " Adder_Impl::Add" );
96 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
97 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
106 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
107 << " ) returns " << -(x - y) << " after " << S << " seconds" );
109 endService( " Adder_Impl::Add" );
113 CORBA::Double Adder_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
114 beginService( " Adder_Impl::AddWithoutSleep" );
116 endService( " Adder_Impl::AddWithoutSleep" );
120 CORBA::Double Adder_Impl::AddAndCompare( CORBA::Double x , CORBA::Double y ,
121 SuperVisionTest::Adder_ptr anOtherAdder ,
122 CORBA::Double & z ) {
123 beginService( " Adder_Impl::AddAndCompare" );
127 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
128 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
137 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
138 << " ) returns " << -(x - y) << " after " << S << " seconds" );
141 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
143 anOtherAdder->LastResult( RetVal ) ;
150 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
151 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
152 endService( " Adder_Impl::AddAndCompare" );
156 void Adder_Impl::SetLastResult( CORBA::Double z ) {
157 beginService( " Adder_Impl::SetLastResult" );
158 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
160 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
170 endService( " Adder_Impl::SetLastResult" );
174 void Adder_Impl::LastResult( CORBA::Double & z ) {
175 beginService( " Adder_Impl::LastResult" );
176 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
178 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
188 endService( " Adder_Impl::LastResult" );
192 Engines::EngineComponent_ptr Adder_Impl::LccAddComponent( const char * aContainer ,
193 const char * aComponentName ) {
194 beginService( "Adder_Impl::LccAddComponent" );
195 Engines::EngineComponent_ptr objComponent ;
196 objComponent = Engines::EngineComponent::_nil() ;
198 CORBA::ORB_var orb = KERNEL::GetRefToORB();
199 SALOME_NamingService *_NS ;
200 _NS = new SALOME_NamingService();
201 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
203 SALOME_LifeCycleCORBA LCC( _NS ) ;
204 objComponent = LCC.FindOrLoad_Component( aContainer ,
206 endService( "Adder_Impl::LccAddComponent" );
207 return objComponent ;