Salome HOME
Copyright update 2021
[samples/component.git] / src / AddComponent / AddComponent_Impl.cxx
index 491e79b79f6aaa2c2bee6ac1ea802de33226b801..2e0dbd1acda2ea17f4e7c6322d51d5ab1c032e88 100644 (file)
@@ -1,41 +1,51 @@
-//  SuperVisionTest AddComponent : example of component that adds two numbers
+// Copyright (C) 2007-2021  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-//  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
-// 
-//  This library is free software; you can redistribute it and/or 
-//  modify it under the terms of the GNU Lesser General Public 
-//  License as published by the Free Software Foundation; either 
-//  version 2.1 of the License. 
-// 
-//  This library is distributed in the hope that it will be useful, 
-//  but WITHOUT ANY WARRANTY; without even the implied warranty of 
-//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-//  Lesser General Public License for more details. 
-// 
-//  You should have received a copy of the GNU Lesser General Public 
-//  License along with this library; if not, write to the Free Software 
-//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
-// 
-//  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
 //
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
 //
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+
+//  SuperVisionTest AddComponent : example of component that adds two numbers
 //  File   : AddComponent_Impl.cxx
 //  Author : Jean Rahuel, CEA
 //  Module : SuperVisionTest
-
-using namespace std;
+//
 #include <stdio.h>
+#ifndef WIN32
 #include <unistd.h>
+#else
+#include <process.h>
+#endif
 #include <fstream>
 #include <sstream>
 #include <string>
 
-//#include "utilities.h"
+#include "utilities.h"
+#include "Utils_ORB_INIT.hxx"
+#include "Utils_SINGLETON.hxx"
+#include "SALOME_NamingService.hxx"
+#include "SALOME_LifeCycleCORBA.hxx"
 
 #include "AddComponent_Impl.hxx"
 #include "Adder_Impl.hxx"
+#include "COMPONENT_version.h"
+
+using namespace std;
 
 AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
                                      PortableServer::POA_ptr poa,
@@ -58,29 +68,30 @@ AddComponent_Impl::AddComponent_Impl() {
 AddComponent_Impl::~AddComponent_Impl() {
 }
 
-SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
-  beginService( "AddComponent_Impl::Addition" );
-  sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
-  Adder_Impl * myAdder ;
-  myAdder = new Adder_Impl( _orb , _poa, _contId,
-                            instanceName() , interfaceName() ,
-                            graphName() , nodeName() ) ;
-  SuperVisionTest::Adder_var iobject ;
-  PortableServer::ObjectId * id = myAdder->getId() ;
-  CORBA::Object_var obj = _poa->id_to_reference(*id);
-  iobject = SuperVisionTest::Adder::_narrow(obj) ;
-  endService( "AddComponent_Impl::Addition" );
-  return SuperVisionTest::Adder::_duplicate(iobject) ;
+char* AddComponent_Impl::getVersion()
+{
+#if COMPONENT_DEVELOPMENT
+  return CORBA::string_dup(COMPONENT_VERSION_STR"dev");
+#else
+  return CORBA::string_dup(COMPONENT_VERSION_STR);
+#endif
 }
 
-double AddComponent_Impl::Add( double x , double y , double & z ) {
+CORBA::Double AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
   beginService( " AddComponent_Impl::Add" );
   z = x + y ;
   int S;
   
   sendMessage(NOTIF_STEP, "AddComponent_Impl::Add is Computing");
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
+//  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
+  S = 5 ;
+#ifndef WIN32
+  while ( S ) {
+    S = sleep( S ) ;
+  }
+#else
+  Sleep(S*1000);
+#endif
   MESSAGE( "AddComponent_Impl::Add( " <<  x << " , " << y << " , " << z
        << " ) returns " << (x - y) << " after " << S << " seconds" )
   LastAddition = z ;
@@ -88,7 +99,15 @@ double AddComponent_Impl::Add( double x , double y , double & z ) {
   return (x - y) ;
 }
 
-long AddComponent_Impl::Sigma( long n ) {
+CORBA::Double AddComponent_Impl::AddWithoutSleep( CORBA::Double x , CORBA::Double y , CORBA::Double & z ) {
+  beginService( " AddComponent_Impl::AddWithoutSleep" );
+  z = x + y ;
+  LastAddition = z ;
+  endService( " AddComponent_Impl::AddWithoutSleep" );
+  return (x - y) ;
+}
+
+CORBA::Long AddComponent_Impl::Sigma( CORBA::Long n ) {
   long sigma = 0 ;
   int i , j ;
   beginService( " AddComponent_Impl::Sigma" );
@@ -102,16 +121,149 @@ long AddComponent_Impl::Sigma( long n ) {
   return sigma ;
 }
 
-double AddComponent_Impl::LastResult() {
+void AddComponent_Impl::Setx( CORBA::Double x ) {
+  int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
+#ifndef WIN32
+  while ( S ) {
+    S = sleep( S ) ;
+  }
+#else
+  Sleep(S*1000);
+#endif
+  xx = x ;
+}
+
+void AddComponent_Impl::Sety( CORBA::Double y ) {
+  int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
+#ifndef WIN32
+  while ( S ) {
+    S = sleep( S ) ;
+  }
+#else
+  Sleep(S*1000);
+#endif
+  yy = y ;
+}
+
+CORBA::Double AddComponent_Impl::Addxy() {
+  int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
+#ifndef WIN32
+  while ( S ) {
+    S = sleep( S ) ;
+  }
+#else
+  Sleep(S*1000);
+#endif
+  double zz = xx + yy ;
+  LastAddition = zz ;
+  return zz;
+}
+
+CORBA::Double AddComponent_Impl::AddyTox( CORBA::Double y ) {
+  int S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
+#ifndef WIN32
+  while ( S ) {
+    S = sleep( S ) ;
+  }
+#else
+  Sleep(S*1000);
+#endif
+  double zz = xx + y ;
+  LastAddition = zz ;
+  return zz;
+}
+
+CORBA::Double AddComponent_Impl::LastResult() {
   beginService( " AddComponent_Impl::LastResult" );
   sendMessage(NOTIF_STEP, "AddComponent_Impl::LastResult is Computing");
-  int S;
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
   endService( " AddComponent_Impl::LastResult"  );
   return LastAddition ;
 }
 
+SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
+  beginService( "AddComponent_Impl::Addition" );
+  sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
+  Adder_Impl * myAdder ;
+  myAdder = new Adder_Impl( _orb , _poa, _contId,
+                            instanceName() , interfaceName() ,
+                            graphName() , nodeName() ) ;
+  SuperVisionTest::Adder_var iobject ;
+  PortableServer::ObjectId * id = myAdder->getId() ;
+  CORBA::Object_var obj = _poa->id_to_reference(*id);
+  iobject = SuperVisionTest::Adder::_narrow(obj) ;
+  endService( "AddComponent_Impl::Addition" );
+  return iobject._retn() ;
+//  return SuperVisionTest::Adder::_duplicate(iobject) ;
+}
+
+CORBA::Boolean AddComponent_Impl::AdditionObjRef1( SuperVisionTest::Adder_out aAdder ) {
+  beginService( "AddComponent_Impl::Addition" );
+  sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
+  Adder_Impl * myAdder ;
+  myAdder = new Adder_Impl( _orb , _poa, _contId,
+                            instanceName() , interfaceName() ,
+                            graphName() , nodeName() ) ;
+  SuperVisionTest::Adder_var iobject ;
+  PortableServer::ObjectId * id = myAdder->getId() ;
+  CORBA::Object_var obj = _poa->id_to_reference(*id);
+  iobject = SuperVisionTest::Adder::_narrow(obj) ;
+  endService( "AddComponent_Impl::Addition" );
+  aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
+  return true ;
+}
+
+void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
+                                         SuperVisionTest::Adder_out aAdder ) {
+  beginService( "AddComponent_Impl::Addition" );
+  sendMessage(NOTIF_STEP, "AddComponent_Impl creates Adder_Impl");
+  Adder_Impl * myAdder ;
+  myAdder = new Adder_Impl( _orb , _poa, _contId,
+                            instanceName() , interfaceName() ,
+                            graphName() , nodeName() ) ;
+  SuperVisionTest::Adder_var iobject ;
+  PortableServer::ObjectId * id = myAdder->getId() ;
+  CORBA::Object_var obj = _poa->id_to_reference(*id);
+  iobject = SuperVisionTest::Adder::_narrow(obj) ;
+  endService( "AddComponent_Impl::Addition" );
+  aAdder = SuperVisionTest::Adder::_duplicate(iobject) ;
+  FuncValue = true ;
+}
+
+CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent_ptr AddComponent1 ,
+                                                   SuperVisionTest::AddComponent_ptr Adder2 ,
+                                                   SuperVisionTest::AddComponent_ptr Adder3 ,
+                                                   SuperVisionTest::AddComponent_out RetAddComponent1 ,
+                                                   SuperVisionTest::AddComponent_out RetAdder2 ,
+                                                   SuperVisionTest::AddComponent_out RetAdder3 ) {
+  bool RetVal = true ;
+  beginService( "AddComponent_Impl::AdditionObjRefs" );
+  cout << "beginService AddComponent_Impl::AdditionObjRefs" << endl ;
+  ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
+  ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
+  CORBA::ORB_var orb = init(0 , 0 ) ;
+  char * IOR = orb->object_to_string( AddComponent1 );
+  cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
+       << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
+  RetAddComponent1 = SuperVisionTest::AddComponent::_duplicate( AddComponent1 ) ;
+  IOR = orb->object_to_string( Adder2 );
+  cout << "AddComponent_Impl::AdditionObjRefs Adder2 " << Adder2 << " IOR " << IOR << " nil "
+       << CORBA::is_nil( Adder2 ) << endl ;
+  RetAdder2 = SuperVisionTest::AddComponent::_duplicate( Adder2 ) ;
+  IOR = orb->object_to_string( Adder3 );
+  cout << "AddComponent_Impl::AdditionObjRefs Adder3 " << Adder3 << " IOR " << IOR << " nil "
+       << CORBA::is_nil( Adder3 ) << endl ;
+  RetAdder3 = SuperVisionTest::AddComponent::_duplicate( Adder3 ) ;
+  if ( CORBA::is_nil( AddComponent1 ) || CORBA::is_nil( Adder2 ) ||
+       CORBA::is_nil( Adder3 ) || CORBA::is_nil( RetAddComponent1 ) ||
+       CORBA::is_nil( RetAdder2 ) || CORBA::is_nil( RetAdder3 ) ) {
+    RetVal = false ;
+  }
+  cout << "endService AddComponent_Impl::AdditionObjRefs" << endl ;
+  endService( "AddComponent_Impl::AdditionObjRefs" );
+  return RetVal ;
+}
+
+
 extern "C"
 {
   PortableServer::ObjectId * AddComponentEngine_factory
@@ -121,107 +273,16 @@ extern "C"
       const char *instanceName,
       const char *interfaceName)
   {
+#ifndef WIN32
     MESSAGE("AddComponentEngine_factory AddComponentEngine ("
             << instanceName << "," << interfaceName << "," << getpid() << ")");
+#else 
+    MESSAGE("AddComponentEngine_factory AddComponentEngine ("
+            << instanceName << "," << interfaceName << "," << _getpid() << ")");
+#endif
     AddComponent_Impl * myAddComponent 
       = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
     return myAddComponent->getId() ;
   }
 }
 
-Adder_Impl::Adder_Impl( CORBA::ORB_ptr orb ,
-                       PortableServer::POA_ptr poa ,
-                       PortableServer::ObjectId * contId , 
-                       const char * instanceName ,
-                        const char * interfaceName , 
-                       const char * graphName ,
-                        const char * nodeName ) :
-  Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
-  Names( graphName , nodeName ) ;
-  MESSAGE("Adder_Impl::Adder_Impl activate object instanceName("
-          << instanceName << ") interfaceName(" << interfaceName << ") --> "
-          << hex << (void *) this << dec )
-  beginService( "Adder_Impl::Adder_Impl" );
-  _thisObj = this ;
-  _id = _poa->activate_object(_thisObj);
-  LastAddition = 0 ;
-  sendMessage(NOTIF_STEP, "Adder_Impl is Created");
-  endService( "Adder_Impl::Adder_Impl" );
-}
-
-Adder_Impl::Adder_Impl() {
-  LastAddition = 0 ;
-}
-
-Adder_Impl::~Adder_Impl() {
-  beginService( "Adder_Impl::~Adder_Impl" );
-  endService( "Adder_Impl::~Adder_Impl" );
-}
-
-double Adder_Impl::Add( double x , double y , double & z ) {
-  beginService( " Adder_Impl::Add" );
-  z = x + y ;
-  int S;
-  
-  sendMessage(NOTIF_STEP, "Adder_Impl::Add is Computing");
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
-  MESSAGE( "Adder_Impl::Add( " <<  x << " , " << y << " , " << z
-       << " ) returns " << -(x - y) << " after " << S << " seconds" )
-  LastAddition = z ;
-  endService( " Adder_Impl::Add"  );
-  return -(x - y) ;
-}
-
-double Adder_Impl::AddAndCompare( const double x , const double y ,
-                                  const SuperVisionTest::Adder_ptr anOtherAdder ,
-                                  double & z ) {
-  beginService( " Adder_Impl::AddAndCompare" );
-  z = x + y ;
-  int S;
-  
-  sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Computing");
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
-  MESSAGE( "Adder_Impl::AddAndCompare( " <<  x << " , " << y << " , " << z
-       << " ) returns " << -(x - y) << " after " << S << " seconds" )
-  LastAddition = z ;
-  double ValFunc ;
-  sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare will call anOtherAdder->LastValue()");
-  double RetVal ;
-  anOtherAdder->LastResult( RetVal ) ;
-  if ( RetVal > 0 ) {
-    ValFunc = (x - y) ;
-  }
-  else {
-    ValFunc = -(x - y) ;
-  }
-  sendMessage(NOTIF_TRACE, "Adder_Impl::AddAndCompare has called anOtherAdder->LastValue()");
-  sendMessage(NOTIF_STEP, "Adder_Impl::AddAndCompare is Finished");
-  endService( " Adder_Impl::AddAndCompare"  );
-  return ValFunc ;
-}
-
-void Adder_Impl::SetLastResult( double z ) {
-  beginService( " Adder_Impl::SetLastResult" );
-  sendMessage(NOTIF_STEP, "Adder_Impl::SetLastResult is Computing");
-  int S;
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
-  LastAddition = z ;
-  endService( " Adder_Impl::SetLastResult"  );
-  return ;
-}
-
-void Adder_Impl::LastResult( double & z ) {
-  beginService( " Adder_Impl::LastResult" );
-  sendMessage(NOTIF_STEP, "Adder_Impl::LastResult is Computing");
-  int S;
-  S = 1+(int) (15.0*rand()/(RAND_MAX+1.0));
-  sleep(S);
-  z = LastAddition ;
-  endService( " Adder_Impl::LastResult"  );
-  return ;
-}
-
-