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 double AddComponent_Impl::Add( double x , double y , double & z ) {
77 beginService( " AddComponent_Impl::Add" );
81 sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
82 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
84 MESSAGE( "AddComponent_Impl::Add( " << x << " , " << y << " , " << z
85 << " ) returns " << (x - y) << " after " << S << " seconds" )
87 endService( " AddComponent_Impl::Add" );
91 long AddComponent_Impl::Sigma( long n ) {
94 beginService( " AddComponent_Impl::Sigma" );
95 for ( j = 0 ; j < 1000000 ; j++ ) {
97 for ( i = 1 ; i <= n ; i++ ) {
101 endService( " AddComponent_Impl::Sigma" );
105 double AddComponent_Impl::LastResult() {
106 beginService( " AddComponent_Impl::LastResult" );
107 sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
109 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
111 endService( " AddComponent_Impl::LastResult" );
112 return LastAddition ;
117 PortableServer::ObjectId * AddComponentEngine_factory
119 PortableServer::POA_ptr poa,
120 PortableServer::ObjectId * contId,
121 const char *instanceName,
122 const char *interfaceName)
124 MESSAGE("AddComponentEngine_factory AddComponentEngine ("
125 << instanceName << "," << interfaceName << "," << getpid() << ")");
126 AddComponent_Impl * myAddComponent
127 = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
128 return myAddComponent->getId() ;
132 Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
133 PortableServer::POA_ptr poa ,
134 PortableServer::ObjectId * contId ,
135 const char * instanceName ,
136 const char * interfaceName ,
137 const char * graphName ,
138 const char * nodeName ) :
139 Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
140 Names( graphName , nodeName ) ;
141 MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
142 << instanceName << ") interfaceName(" << interfaceName << ") --> "
143 << hex << (void *) this << dec )
144 beginService( "Adder_Impl::Adder_Impl" );
146 _id = _poa->activate_object(_thisObj);
148 sendMessage(NOTIF_STEP, "Adder_Impl is Created");
149 endService( "Adder_Impl::Adder_Impl" );
152 Adder_Impl::Adder_Impl() {
156 Adder_Impl::~Adder_Impl() {
157 beginService( "Adder_Impl::~Adder_Impl" );
158 endService( "Adder_Impl::~Adder_Impl" );
161 double Adder_Impl::Add( double x , double y , double & z ) {
162 beginService( " Adder_Impl::Add" );
166 sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
167 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
169 MESSAGE( "Adder_Impl::Add( " << x << " , " << y << " , " << z
170 << " ) returns " << -(x - y) << " after " << S << " seconds" )
172 endService( " Adder_Impl::Add" );
176 double Adder_Impl::AddAndCompare( const double x , const double y ,
177 const SuperVisionTest::Adder_ptr anOtherAdder ,
179 beginService( " Adder_Impl::AddAndCompare" );
183 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
184 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
186 MESSAGE( "Adder_Impl::AddAndCompare( " << x << " , " << y << " , " << z
187 << " ) returns " << -(x - y) << " after " << S << " seconds" )
190 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
192 anOtherAdder->LastResult( RetVal ) ;
199 sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
200 sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
201 endService( " Adder_Impl::AddAndCompare" );
205 void Adder_Impl::SetLastResult( double z ) {
206 beginService( " Adder_Impl::SetLastResult" );
207 sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
209 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
212 endService( " Adder_Impl::SetLastResult" );
216 void Adder_Impl::LastResult( double & z ) {
217 beginService( " Adder_Impl::LastResult" );
218 sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
220 S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
223 endService( " Adder_Impl::LastResult" );