Salome HOME
Updated copyright comment
[samples/component.git] / src / AddComponent / AddComponent_Impl.cxx
index c442da23b6d2a981cf02a9adf1d506989917f5c4..9568c8b10fc624071e20a9619b020422da4e7b22 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include <string>
 
 #include "utilities.h"
-#include "Utils_ORB_INIT.hxx"
-#include "Utils_SINGLETON.hxx"
+#include "OpUtil.hxx"
 #include "SALOME_NamingService.hxx"
 #include "SALOME_LifeCycleCORBA.hxx"
+#include "SALOME_Container_i.hxx"
 
 #include "AddComponent_Impl.hxx"
 #include "Adder_Impl.hxx"
@@ -51,11 +51,11 @@ AddComponent_Impl::AddComponent_Impl( CORBA::ORB_ptr orb,
                                      PortableServer::POA_ptr poa,
                                      PortableServer::ObjectId * contId, 
                                      const char *instanceName,
-                                      const char *interfaceName) :
-  Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,true) {
+              const char *interfaceName, bool withRegistry) :
+  Engines_Component_i(orb, poa, contId, instanceName, interfaceName,1,withRegistry) {
   MESSAGE("AddComponent_Impl::AddComponent_Impl this " << hex << this << dec
           << "activate object instanceName("
-          << instanceName << ") interfaceName(" << interfaceName << ")" )
+          << instanceName << ") interfaceName(" << interfaceName << ")" );
   _thisObj = this ;
   _id = _poa->activate_object(_thisObj);
   LastAddition = 0 ;
@@ -93,7 +93,7 @@ CORBA::Double AddComponent_Impl::Add( CORBA::Double x , CORBA::Double y , CORBA:
   Sleep(S*1000);
 #endif
   MESSAGE( "AddComponent_Impl::Add( " <<  x << " , " << y << " , " << z
-       << " ) returns " << (x - y) << " after " << S << " seconds" )
+       << " ) returns " << (x - y) << " after " << S << " seconds" );
   LastAddition = z ;
   endService( " AddComponent_Impl::Add"  );
   return (x - y) ;
@@ -184,9 +184,7 @@ 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() ) ;
+  myAdder = this->BuildNewAdderImplObj();
   SuperVisionTest::Adder_var iobject ;
   PortableServer::ObjectId * id = myAdder->getId() ;
   CORBA::Object_var obj = _poa->id_to_reference(*id);
@@ -196,13 +194,24 @@ SuperVisionTest::Adder_ptr AddComponent_Impl::Addition() {
 //  return SuperVisionTest::Adder::_duplicate(iobject) ;
 }
 
+Adder_Impl *AddComponent_Impl::BuildNewAdderImplObj()
+{
+  Engines::Container_var cont = this->GetContainerRef();
+  if( cont->is_SSL_mode() )
+  {
+    return new Adder_Impl_SSL( _orb , _poa, _contId, instanceName() , interfaceName() , graphName() , nodeName() ) ;
+  }
+  else
+  {
+    return new Adder_Impl_No_SSL( _orb , _poa, _contId, instanceName() , interfaceName() , graphName() , nodeName() ) ;
+  }
+}
+
 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() ) ;
+  Adder_Impl * myAdder = nullptr;
+  myAdder = this->BuildNewAdderImplObj();
   SuperVisionTest::Adder_var iobject ;
   PortableServer::ObjectId * id = myAdder->getId() ;
   CORBA::Object_var obj = _poa->id_to_reference(*id);
@@ -217,9 +226,7 @@ void AddComponent_Impl::AdditionObjRef2( CORBA::Boolean & FuncValue ,
   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() ) ;
+  myAdder = this->BuildNewAdderImplObj();
   SuperVisionTest::Adder_var iobject ;
   PortableServer::ObjectId * id = myAdder->getId() ;
   CORBA::Object_var obj = _poa->id_to_reference(*id);
@@ -238,9 +245,7 @@ CORBA::Boolean AddComponent_Impl::AdditionObjRefs( SuperVisionTest::AddComponent
   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 ) ;
+  CORBA::ORB_var orb = KERNEL::GetRefToORB();
   char * IOR = orb->object_to_string( AddComponent1 );
   cout << "AddComponent_Impl::AdditionObjRefs AddComponent1 " << AddComponent1 << " IOR "
        << IOR << " nil " << CORBA::is_nil( AddComponent1 ) << endl ;
@@ -280,8 +285,17 @@ extern "C"
     MESSAGE("AddComponentEngine_factory AddComponentEngine ("
             << instanceName << "," << interfaceName << "," << _getpid() << ")");
 #endif
-    AddComponent_Impl * myAddComponent 
-      = new AddComponent_Impl(orb, poa, contId, instanceName, interfaceName);
+    CORBA::Object_var o = poa->id_to_reference(*contId);
+    Engines::Container_var cont = Engines::Container::_narrow(o);
+    AddComponent_Impl * myAddComponent = nullptr;
+    if(cont->is_SSL_mode())
+    {
+      myAddComponent = new AddComponent_Impl_SSL(orb, poa, contId, instanceName, interfaceName);
+    }
+    else
+    {
+      myAddComponent = new AddComponent_Impl_No_SSL(orb, poa, contId, instanceName, interfaceName);
+    }
     return myAddComponent->getId() ;
   }
 }