1 // Copyright (C) 2007-2019 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"
37 #include "Utils_ORB_INIT.hxx"
38 #include "Utils_SINGLETON.hxx"
39 #include "SALOME_NamingService.hxx"
40 #include "SALOME_LifeCycleCORBA.hxx"
42 #include "Adder_Impl.hxx"
43 #include "COMPONENT_version.h"
47 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
48 PortableServer::POA_ptr poa ,
49 PortableServer::ObjectId * contId ,
50 const char * instanceName ,
51 const char * interfaceName ,
52 const char * graphName ,
53 const char * nodeName ) :
54 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
55 Names( graphName , nodeName ) ;
56 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
57 << instanceName << ") interfaceName(" << interfaceName << ") --> "
58 << hex << (void *) this << dec )
59 beginService( "Adder_Impl::Adder_Impl" );
61 _id = _poa->activate_object(_thisObj);
63 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
64 endService( "Adder_Impl::Adder_Impl" );
67 Adder_Impl::Adder_Impl() {
71 Adder_Impl::~Adder_Impl() {
72 beginService( "Adder_Impl::~Adder_Impl" );
73 endService( "Adder_Impl::~Adder_Impl" );
76 char* Adder_Impl::getVersion()
78 #if COMPONENT_DEVELOPMENT
79 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
81 return CORBA::string_dup(COMPONENT_VERSION_STR);
85 void Adder_Impl::destroy() {
86 _poa->deactivate_object(*_id) ;
87 CORBA::release(_poa) ;
89 _thisObj->_remove_ref();
92 CORBA::Double Adder_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
93 beginService( " Adder_Impl::Add" );
97 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
98 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
107 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
108 << " ) returns " << -(x - y) << " after " << S << " seconds" )
110 endService( " Adder_Impl::Add" );
114 CORBA::Double Adder_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
115 beginService( " Adder_Impl::AddWithoutSleep" );
117 endService( " Adder_Impl::AddWithoutSleep" );
121 CORBA::Double Adder_Impl::AddAndCompare( CORBA::Double x , CORBA::Double y ,
122 SuperVisionTest::Adder_ptr anOtherAdder ,
123 CORBA::Double & z ) {
124 beginService( " Adder_Impl::AddAndCompare" );
128 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
129 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
138 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
139 << " ) returns " << -(x - y) << " after " << S << " seconds" )
142 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
144 anOtherAdder->LastResult( RetVal ) ;
151 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
152 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
153 endService( " Adder_Impl::AddAndCompare" );
157 void Adder_Impl::SetLastResult( CORBA::Double z ) {
158 beginService( " Adder_Impl::SetLastResult" );
159 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
161 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
171 endService( " Adder_Impl::SetLastResult" );
175 void Adder_Impl::LastResult( CORBA::Double & z ) {
176 beginService( " Adder_Impl::LastResult" );
177 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
179 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
189 endService( " Adder_Impl::LastResult" );
193 Engines::EngineComponent_ptr Adder_Impl::LccAddComponent( const char * aContainer ,
194 const char * aComponentName ) {
195 beginService( "Adder_Impl::LccAddComponent" );
196 Engines::EngineComponent_ptr objComponent ;
197 objComponent = Engines::EngineComponent::_nil() ;
199 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
200 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
201 CORBA::ORB_var orb = init(0 , 0 ) ;
202 SALOME_NamingService *_NS ;
203 _NS = new SALOME_NamingService();
204 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
206 SALOME_LifeCycleCORBA LCC( _NS ) ;
207 objComponent = LCC.FindOrLoad_Component( aContainer ,
209 endService( "Adder_Impl::LccAddComponent" );
210 return objComponent ;