1 // Copyright (C) 2007-2012 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
23 // SuperVisionTest AddComponent : example of component that adds two numbers
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 "Addition_Adder_Impl.hxx"
41 #include "COMPONENT_version.h"
45 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
46 PortableServer::POA_ptr poa ,
47 PortableServer::ObjectId * contId ,
48 const char * instanceName ,
49 const char * interfaceName ,
50 const char * graphName ,
51 const char * nodeName ) :
52 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
53 Names( graphName , nodeName ) ;
54 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
55 << instanceName << ") interfaceName(" << interfaceName << ") --> "
56 << hex << (void *) this << dec )
57 beginService( "Adder_Impl::Adder_Impl" );
59 _id = _poa->activate_object(_thisObj);
61 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
62 endService( "Adder_Impl::Adder_Impl" );
65 Adder_Impl::Adder_Impl() {
69 char* Adder_Impl::getVersion()
71 #if COMPONENT_DEVELOPMENT
72 return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
74 return CORBA::string_dup(COMPONENT_VERSION_STR);
78 Adder_Impl::~Adder_Impl() {
79 beginService( "Adder_Impl::~Adder_Impl" );
80 endService( "Adder_Impl::~Adder_Impl" );
83 void Adder_Impl::destroy() {
84 _poa->deactivate_object(*_id) ;
85 CORBA::release(_poa) ;
87 _thisObj->_remove_ref();
90 CORBA::Double Adder_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
91 beginService( " Adder_Impl::Add" );
95 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
96 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
101 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
102 << " ) returns " << -(x - y) << " after " << S << " seconds" )
104 endService( " Adder_Impl::Add" );
108 CORBA::Double Adder_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
109 beginService( " Adder_Impl::AddWithoutSleep" );
111 endService( " Adder_Impl::AddWithoutSleep" );
115 CORBA::Double Adder_Impl::AddAndCompare( CORBA::Double x , CORBA::Double y ,
116 AdditionComponent::Adder_ptr anOtherAdder ,
117 CORBA::Double & z ) {
118 beginService( " Adder_Impl::AddAndCompare" );
122 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
123 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
128 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
129 << " ) returns " << -(x - y) << " after " << S << " seconds" )
132 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
134 anOtherAdder->LastResult( RetVal ) ;
141 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
142 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
143 endService( " Adder_Impl::AddAndCompare" );
147 void Adder_Impl::SetLastResult( CORBA::Double z ) {
148 beginService( " Adder_Impl::SetLastResult" );
149 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
151 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
157 endService( " Adder_Impl::SetLastResult" );
161 void Adder_Impl::LastResult( CORBA::Double & z ) {
162 beginService( " Adder_Impl::LastResult" );
163 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
165 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
171 endService( " Adder_Impl::LastResult" );
175 Engines::EngineComponent_ptr Adder_Impl::LccAdditionInterface( char * aContainer ,
176 char * aComponentName ) {
177 beginService( "Adder_Impl::LccAddComponent" );
178 Engines::EngineComponent_ptr objComponent ;
179 objComponent = Engines::EngineComponent::_nil() ;
181 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
182 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
183 CORBA::ORB_var orb = init(0 , 0 ) ;
184 SALOME_NamingService *_NS ;
185 _NS = new SALOME_NamingService();
186 _NS->init_orb( CORBA::ORB::_duplicate(orb) ) ;
188 SALOME_LifeCycleCORBA LCC( _NS ) ;
189 objComponent = LCC.FindOrLoad_Component( aContainer ,
191 endService( "Adder_Impl::LccAddComponent" );
192 return objComponent ;