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"
37 #include "AddComponent_Impl.hxx"
38 #include "Adder_Impl.hxx"
40 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
41 PortableServer::POA_ptr poa,
42 PortableServer::ObjectId * contId,
43 const char *instanceName,
44 const char *interfaceName) :
45 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
46 MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
47 << "activate object instanceName("
48 << instanceName << ") interfaceName(" << interfaceName << ")" )
50 _id = _poa->activate_object(_thisObj);
54 AddComponent_Impl::AddComponent_Impl() {
58 AddComponent_Impl::~AddComponent_Impl() {
61 SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
62 beginService( "AddComponent_Impl::Addition" );
63 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
64 Adder_Impl * myAdder ;
65 myAdder = new Adder_Impl( _orb , _poa, _contId,
66 instanceName() , interfaceName() ,
67 graphName() , nodeName() ) ;
68 SuperVisionTest::Adder_var iobject ;
69 PortableServer::ObjectId * id = myAdder->getId() ;
70 CORBA::Object_var obj = _poa->id_to_reference(*id);
71 iobject = SuperVisionTest::Adder::_narrow(obj) ;
72 endService( "AddComponent_Impl::Addition" );
73 return SuperVisionTest::Adder::_duplicate(iobject) ;
76 bool AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
77 beginService( "AddComponent_Impl::Addition" );
78 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
79 Adder_Impl * myAdder ;
80 myAdder = new Adder_Impl( _orb , _poa, _contId,
81 instanceName() , interfaceName() ,
82 graphName() , nodeName() ) ;
83 SuperVisionTest::Adder_var iobject ;
84 PortableServer::ObjectId * id = myAdder->getId() ;
85 CORBA::Object_var obj = _poa->id_to_reference(*id);
86 iobject = SuperVisionTest::Adder::_narrow(obj) ;
87 endService( "AddComponent_Impl::Addition" );
88 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
92 void AddComponent_Impl::AdditionObjRef2( bool & FuncValue ,
93 SuperVisionTest::Adder_out aAdder ) {
94 beginService( "AddComponent_Impl::Addition" );
95 sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
96 Adder_Impl * myAdder ;
97 myAdder = new Adder_Impl( _orb , _poa, _contId,
98 instanceName() , interfaceName() ,
99 graphName() , nodeName() ) ;
100 SuperVisionTest::Adder_var iobject ;
101 PortableServer::ObjectId * id = myAdder->getId() ;
102 CORBA::Object_var obj = _poa->id_to_reference(*id);
103 iobject = SuperVisionTest::Adder::_narrow(obj) ;
104 endService( "AddComponent_Impl::Addition" );
105 aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
109 double AddComponent_Impl::Add( double x , double y , double & z ) {
110 beginService( " AddComponent_Impl::Add" );
114 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
115 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
120 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
121 << " ) returns " << (x - y) << " after " << S << " seconds" )
123 endService( " AddComponent_Impl::Add" );
127 long AddComponent_Impl::Sigma( long n ) {
130 beginService( " AddComponent_Impl::Sigma" );
131 for ( j = 0 ; j < 1000000 ; j++ ) {
133 for ( i = 1 ; i <= n ; i++ ) {
137 endService( " AddComponent_Impl::Sigma" );
141 double AddComponent_Impl::LastResult() {
142 beginService( " AddComponent_Impl::LastResult" );
143 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
145 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
150 endService( " AddComponent_Impl::LastResult" );
151 return LastAddition ;
156 PortableServer::ObjectId * AddComponentEngine_factory
158 PortableServer::POA_ptr poa,
159 PortableServer::ObjectId * contId,
160 const char *instanceName,
161 const char *interfaceName)
163 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
164 << instanceName << "," << interfaceName << "," << getpid() << ")");
165 AddComponent_Impl * myAddComponent
166 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
167 return myAddComponent->getId() ;
171 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
172 PortableServer::POA_ptr poa ,
173 PortableServer::ObjectId * contId ,
174 const char * instanceName ,
175 const char * interfaceName ,
176 const char * graphName ,
177 const char * nodeName ) :
178 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
179 Names( graphName , nodeName ) ;
180 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
181 << instanceName << ") interfaceName(" << interfaceName << ") --> "
182 << hex << (void *) this << dec )
183 beginService( "Adder_Impl::Adder_Impl" );
185 _id = _poa->activate_object(_thisObj);
187 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
188 endService( "Adder_Impl::Adder_Impl" );
191 Adder_Impl::Adder_Impl() {
195 Adder_Impl::~Adder_Impl() {
196 beginService( "Adder_Impl::~Adder_Impl" );
197 endService( "Adder_Impl::~Adder_Impl" );
200 double Adder_Impl::Add( double x , double y , double & z ) {
201 beginService( " Adder_Impl::Add" );
205 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
206 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
211 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
212 << " ) returns " << -(x - y) << " after " << S << " seconds" )
214 endService( " Adder_Impl::Add" );
218 double Adder_Impl::AddAndCompare( const double x , const double y ,
219 const SuperVisionTest::Adder_ptr anOtherAdder ,
221 beginService( " Adder_Impl::AddAndCompare" );
225 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
226 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
231 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
232 << " ) returns " << -(x - y) << " after " << S << " seconds" )
235 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
237 anOtherAdder->LastResult( RetVal ) ;
244 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
245 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
246 endService( " Adder_Impl::AddAndCompare" );
250 void Adder_Impl::SetLastResult( double z ) {
251 beginService( " Adder_Impl::SetLastResult" );
252 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
254 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
260 endService( " Adder_Impl::SetLastResult" );
264 void Adder_Impl::LastResult( double & z ) {
265 beginService( " Adder_Impl::LastResult" );
266 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
268 // S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
274 endService( " Adder_Impl::LastResult" );