Salome HOME
updated copyright message
[modules/kernel.git] / src / Launcher / SALOME_LauncherServer.cxx
index 4bb4ecfd9d13c1e991c17c1bec5f92fb0893ac4e..b0b84adceb873c7e03c305d6fc00e40a7105998e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023  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
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include "ArgvKeeper.hxx"
 #include "SALOME_Launcher.hxx"
+#include "SALOMESDS_DataServerManager.hxx"
+#include "SALOME_ExternalServerLauncher.hxx"
+#include "SALOME_CPythonHelper.hxx"
+#include "OpUtil.hxx"
 #include "utilities.h"
 #include <sstream>
 #include <iostream>
 #include <stdexcept>
+#include <string>
+#include <vector>
 #include <libxml/parser.h>
 
 void AttachDebugger();
@@ -64,7 +71,7 @@ int main(int argc, char* argv[])
     {
 //       setsig(SIGSEGV,&Handler);
       std::set_terminate(&terminateHandler);
-      std::set_unexpected(&unexpectedHandler);
+      //std::set_unexpected(&unexpectedHandler);
     }
   /* Init libxml 
    * To avoid memory leak, need to call xmlInitParser in the main thread
@@ -75,8 +82,16 @@ int main(int argc, char* argv[])
   PortableServer::POA_var root_poa;
   PortableServer::POAManager_var pman;
   CORBA::Object_var obj;
-
-  CORBA::ORB_var orb = CORBA::ORB_init( argc , argv ) ;
+  CORBA::ORB_var orb;
+  {
+    std::vector<std::string> args;
+    for(int i=0;i<argc;i++)
+      args.push_back(argv[i]);
+    args.push_back("-ORBsupportCurrent");
+    args.push_back("0");
+    SetArgcArgv(args);
+    orb = KERNEL::GetRefToORB();
+  }
   //  LocalTraceCollector *myThreadTrace = SALOMETraceCollector::instance(orb);
   INFOS_COMPILATION;
   BEGIN_OF(argv[0]);
@@ -85,18 +100,39 @@ int main(int argc, char* argv[])
     if(!CORBA::is_nil(obj))
       root_poa = PortableServer::POA::_narrow(obj);
     if(!CORBA::is_nil(root_poa))
-      pman = root_poa->the_POAManager();
+      {
+        pman = root_poa->the_POAManager();
+        pman->activate();
+      }
   }
   catch(CORBA::COMM_FAILURE&){
     MESSAGE( "Container: CORBA::COMM_FAILURE: Unable to contact the Naming Service" );
   }
-  try{
-    SALOME_Launcher *lServ=new SALOME_Launcher(orb,root_poa);
-    pman->activate();
-    lServ->_remove_ref();
-    orb->run();
-    orb->destroy();
-  }catch(CORBA::SystemException&){
+  try
+    {
+      CORBA::PolicyList policies;
+      policies.length(1);
+      PortableServer::ThreadPolicy_var threadPol(root_poa->create_thread_policy(PortableServer::SINGLE_THREAD_MODEL));
+      policies[0] = PortableServer::ThreadPolicy::_duplicate(threadPol);
+      PortableServer::POA_var safePOA = root_poa->create_POA("SingleThreadPOA",pman,policies);
+      threadPol->destroy();
+      SALOME_CPythonHelper cPyh;
+      cPyh.initializePython(argc,argv);
+      cPyh.allowPythonCallsFromDifferentThread();
+      SALOME_Launcher *lServ(new SALOME_Launcher(orb,safePOA));
+      lServ->DeclareUsingSalomeSession();
+      lServ->_remove_ref();
+      //
+      SALOMESDS::DataServerManager *dsm(new SALOMESDS::DataServerManager(&cPyh,orb,root_poa));
+      dsm->_remove_ref();
+      //
+      SALOME_ExternalServerLauncher *esm(new SALOME_ExternalServerLauncher(&cPyh,orb,safePOA));
+      esm->_remove_ref();
+      //
+      orb->run();
+      orb->destroy();
+    }
+  catch(CORBA::SystemException&){
     MESSAGE("Caught CORBA::SystemException.");
   }catch(PortableServer::POA::WrongPolicy&){
     MESSAGE("Caught CORBA::WrongPolicyException.");