Salome HOME
updated copyright message
[modules/kernel.git] / src / ParallelContainer / SALOME_ParallelContainerNodeDummy.cxx
index 61f5eda5c626218d2b63ede561af0d7be70458f4..dfc323c8819a5ca6eba63ec00d8773a238815bfd 100644 (file)
@@ -1,27 +1,28 @@
-//  Copyright (C) 2007-2008  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
+// Copyright (C) 2003-2007  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 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.
+// 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
+// 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
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
+
 //  SALOME ParallelContainerNodeDummy : launcher of a PaCO++ object
 //  File   : SALOME_ParallelContainerNodeDummy.cxx
-//  Author : André Ribes, EDF
+//  Author : Andr Ribes, EDF
 //  Module : SALOME PARALLEL
 //
 #include <iostream>
 #include "SALOME_NamingService.hxx"
 
 #include "utilities.h"
-#include "Utils_ORB_INIT.hxx"
-#include "Utils_SINGLETON.hxx"
+#include "ArgvKeeper.hxx"
+#include "Basics_Utils.hxx"
 #include "SALOMETraceCollector.hxx"
 #include "OpUtil.hxx"
 
-using namespace std;
+#include "Container_init_python.hxx"
 
 #ifdef _DEBUG_
 #include <signal.h>
 
 void handler(int t) {
-  cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
-  cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
-  cerr << "SIGSEGV in :" << getpid() << endl;
-  cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
-  cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
+  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+  std::cerr << "SIGSEGV in :" << getpid() << std::endl;
+  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
+  std::cerr << "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << std::endl;
   while (1) {}
 }
 #endif
@@ -118,16 +119,21 @@ int main(int argc, char* argv[])
   }
 
   // Initialise the ORB.
-  CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
+  SetArgcArgv(argc, argv);
+  CORBA::ORB_var orb = KERNEL::GetRefToORB();
+  KERNEL_PYTHON::init_python(argc,argv);
 
   std::string containerName("");
   if(argc > 1) {
     containerName = argv[1];
   }
-  std::string hostname("");
+  std::string proxy_hostname("");
   if(argc > 3) {
-    hostname = argv[3];
+    proxy_hostname = argv[3];
   }
+  int myid = 0;
+  if(argc > 4) 
+    sscanf(argv[4],"%d",&myid);
 
   try {  
     CORBA::Object_var obj = orb->resolve_initial_references("RootPOA");
@@ -141,21 +147,20 @@ int main(int argc, char* argv[])
     system(aCommand);
 #endif
 
-    SALOME_NamingService * ns = new SALOME_NamingService(CORBA::ORB::_duplicate(orb));
+    SALOME_NamingService * ns = new SALOME_NamingService(orb);
     // Get the proxy
-    string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(), 
-                                                      hostname.c_str());
+    std::string proxyNameInNS = ns->BuildContainerNameForNS(containerName.c_str(), 
+                                                       proxy_hostname.c_str());
     obj = ns->Resolve(proxyNameInNS.c_str());
     char * proxy_ior = orb->object_to_string(obj);
 
     // Creating a node
-    string node_name = containerName + "Node";
+    std::string node_name = containerName + "Node";
     Engines_Parallel_Container_i * servant = new Engines_Parallel_Container_i(CORBA::ORB::_duplicate(orb), 
-                                                                             proxy_ior,
-                                                                             0,
-                                                                             root_poa,
-                                                                             (char*) node_name.c_str(),
-                                                                             argc, argv);
+                                                                              proxy_ior,
+                                                                              myid,
+                                                                              root_poa,
+                                                                              node_name);
     // PaCO++ init
     paco_fabrique_manager * pfm = paco_getFabriqueManager();
     pfm->register_com("dummy", new paco_dummy_fabrique());
@@ -164,22 +169,24 @@ int main(int argc, char* argv[])
     servant->setLibThread("omni");
 
     // Activation
-    PortableServer::ObjectId * _id = root_poa->activate_object(servant);
-    servant->set_id(_id);
-    obj = root_poa->id_to_reference(*_id);
+    obj = servant->_this();
 
     // In the NamingService
     string hostname = Kernel_Utils::GetHostname();
-    int myid = 0;
     char buffer [5];
     snprintf(buffer, 5, "%d", myid);
     node_name = node_name + buffer;
     string _containerName = ns->BuildContainerNameForNS((char*) node_name.c_str(),
-                                                       hostname.c_str());
-    cerr << "---------" << _containerName << "----------" << endl;
+                                                        hostname.c_str());
+    std::cerr << "---------" << _containerName << "----------" << std::endl;
     ns->Register(obj, _containerName.c_str());
     pman->activate();
     orb->run();
+    PyGILState_Ensure();
+    //Delete python container that destroy orb from python (pyCont._orb.destroy())
+    Py_Finalize();
+    CORBA::string_free(proxy_ior);
+    delete ns;
   }
   catch (PaCO::PACO_Exception& e)
   {
@@ -198,6 +205,13 @@ int main(int argc, char* argv[])
   {
     INFOS("Caught CORBA::Exception.");
   }
+  catch(omniORB::fatalException& fe) 
+  {
+    INFOS("Caught omniORB::fatalException:");
+    INFOS(" file: " << fe.file());
+    INFOS(" line: " << fe.line());
+    INFOS(" mesg: " << fe.errmsg());
+  }
   catch(std::exception& exc)
   {
     INFOS("Caught std::exception - "<<exc.what());