Salome HOME
Shutdown data servers scopes in driver command.
[modules/yacs.git] / src / yacsloader / driver.cxx
index 529cb599f705019aacca303123b979fbdfb1e6d7..95f0e4de67035ac0b07e5b6df04a61f94328a5d6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006-2016  CEA/DEN, EDF R&D
+// Copyright (C) 2006-2021  CEA/DEN, EDF R&D
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 #include "Exception.hxx"
 #include "Executor.hxx"
 #include "parsers.hxx"
-#include "VisitorSaveState.hxx"
+#include "VisitorSalomeSaveState.hxx"
 #include "VisitorSaveSalomeSchema.hxx"
 #include "LoadState.hxx"
 #include "Dispatcher.hxx"
 #include "LinkInfo.hxx"
+#include "ObserverAsPlugin.hxx"
 
-#ifdef SALOME_KERNEL
+#include "KernelBasis.hxx"
+#include "SALOME_Launcher.hxx"
+#include "ServiceUnreachable.hxx"
+#include "SALOME_NamingService_Wrapper.hxx"
 #include "SALOME_NamingService.hxx"
 #include "SALOME_ModuleCatalog.hh"
+#include "SALOMESDS_DataServerManager.hxx"
 #include "Basics_Utils.hxx"
-#endif
 
 #include <iostream>
 #include <fstream>
 #include <signal.h>
 #include <list>
 
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
 #include <argp.h>
 #endif
@@ -58,7 +62,7 @@ const char *argp_program_bug_address ="<nepal@nepal.edf.fr>";
 static char doc[] ="driver -- a SALOME YACS graph executor";
 static char args_doc[] = "graph.xml";
 
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
 static struct argp_option options[] =
   {
@@ -101,14 +105,14 @@ typedef struct {
   string lockFile;
 } thread_st;
 
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 static int
 #else
 static error_t
 #endif
 parse_opt (int key, char *arg, struct argp_state *state)
 {
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
   // Get the input argument from argp_parse, which we
   // know is a pointer to our arguments structure. 
@@ -186,14 +190,14 @@ parse_opt (int key, char *arg, struct argp_state *state)
 }
 
 // Our argp parser.
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
 static struct argp argp = { options, parse_opt, args_doc, doc };
 #endif
 
 void timer(std::string msg)
 {
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
   struct timeval tv;
   gettimeofday(&tv,NULL);
@@ -216,7 +220,7 @@ void Handler(int theSigId)
       bool isFinalDump = (strlen(myArgs.finalDump) != 0);
       if (isFinalDump)
         {
-          YACS::ENGINE::VisitorSaveState vst(p);
+          YACS::ENGINE::VisitorSalomeSaveState vst(p);
           vst.openFileDump(myArgs.finalDump);
           p->accept(&vst);
           vst.closeFileDump();
@@ -252,7 +256,7 @@ void * dumpState(void *arg)
 #endif
     string cmd = "touch " + st->lockFile;
     system(cmd.c_str());
-    YACS::ENGINE::VisitorSaveState vst(p);
+    YACS::ENGINE::VisitorSalomeSaveState vst(p);
     vst.openFileDump(st->dumpFile);
     p->accept(&vst);
     vst.closeFileDump();
@@ -293,6 +297,39 @@ bool parse_init_port(const std::string& input, std::string& node, std::string& p
   return true;
 }
 
+void InitializeSSL()
+{
+  setSSLMode(true);
+  KERNEL::getLauncherSA();
+}
+
+void shutdownServers()
+{
+  // shutdown data server scopes
+  try
+    {
+      YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
+      runTime->loadModulCatalog();
+      CORBA::ORB_ptr orb = runTime->getOrb();
+      if (orb)
+      {
+        SALOME_NamingService_Wrapper namingService(orb);
+        CORBA::Object_var objDSM(namingService.Resolve(SALOMESDS::DataServerManager::NAME_IN_NS));
+        SALOME::DataServerManager_var dsm(SALOME::DataServerManager::_narrow(objDSM));
+        if ( !CORBA::is_nil(dsm) )
+          dsm->shutdownScopes();
+      }
+    }
+  catch(const CORBA::Exception& )
+    {
+       // ignore and continue
+    }
+  catch(ServiceUnreachable& e)
+    {
+       // ignore and continue
+    }
+}
+
 int main (int argc, char* argv[])
 {
      
@@ -305,13 +342,13 @@ int main (int argc, char* argv[])
   myArgs.dump = 0;
   myArgs.loadState = (char *)"";
   myArgs.xmlSchema = (char *)"";
-  myArgs.shutdown = 1;
+  myArgs.shutdown = 10;
   myArgs.reset = 0;
   myArgs.killPort = 0;
   myArgs.init_ports.clear();
 
   // Parse our arguments; every option seen by parse_opt will be reflected in arguments.
-#ifdef WIN32
+#if defined WIN32 || defined __APPLE__
 #else
   argp_parse (&argp, argc, argv, 0, 0, &myArgs);
   std::cerr << "graph = " << myArgs.args[0];
@@ -338,6 +375,8 @@ int main (int argc, char* argv[])
   setsig(SIGTERM,&Handler);
 #endif
 
+  InitializeSSL();
+
   timer("Starting ");
   long flags = RuntimeSALOME::UsePython + RuntimeSALOME::UseCorba + RuntimeSALOME::UseXml + \
                RuntimeSALOME::UseCpp + RuntimeSALOME::UseSalome;
@@ -347,10 +386,11 @@ int main (int argc, char* argv[])
   try
     {
       YACS::ENGINE::RuntimeSALOME* runTime = YACS::ENGINE::getSALOMERuntime();
+      runTime->loadModulCatalog();
       CORBA::ORB_ptr orb = runTime->getOrb();
       if (orb)
         {
-          SALOME_NamingService namingService(orb);
+          SALOME_NamingService_Wrapper namingService(orb);
           CORBA::Object_var obj = namingService.Resolve("/Kernel/ModulCatalog");
           SALOME_ModuleCatalog::ModuleCatalog_var aModuleCatalog = SALOME_ModuleCatalog::ModuleCatalog::_narrow(obj);
           if (! CORBA::is_nil(aModuleCatalog))
@@ -486,11 +526,12 @@ int main (int argc, char* argv[])
         }
 
       if (myArgs.stop)
+      {
         if (strlen(myArgs.dumpErrorFile) >0)
           executor.setStopOnError(true, myArgs.dumpErrorFile);
         else
           executor.setStopOnError(false, myArgs.dumpErrorFile);
-
+      }
       if(myArgs.display>0)
         {
           std::ofstream f("toto");
@@ -509,7 +550,7 @@ int main (int argc, char* argv[])
           st->lockFile = rootFile + ".lock";
           pthread_create(&th,NULL,&dumpState,(void*)st);
         }
-
+      YACS::ENGINE::LoadObserversPluginIfAny(p,&executor);
       cerr << "+++++++++++++++++++ start calculation +++++++++++++++++++" << endl;
       executor.RunW(p,myArgs.display, fromScratch);
       cerr << "+++++++++++++++++++  end calculation  +++++++++++++++++++" << endl;
@@ -544,7 +585,7 @@ int main (int argc, char* argv[])
       bool isFinalDump = (strlen(myArgs.finalDump) != 0);
       if (isFinalDump)
         {
-          YACS::ENGINE::VisitorSaveState vst(p);
+          YACS::ENGINE::VisitorSalomeSaveState vst(p);
           vst.openFileDump(myArgs.finalDump);
           p->accept(&vst);
           vst.closeFileDump();
@@ -552,6 +593,7 @@ int main (int argc, char* argv[])
       if(myArgs.shutdown < 999)
         {
           p->shutdown(myArgs.shutdown);
+          shutdownServers();
         }
       delete p;
       Runtime* r=YACS::ENGINE::getRuntime();
@@ -559,6 +601,7 @@ int main (int argc, char* argv[])
       r->fini();
       delete r;
       delete disp;
+      YACS::ENGINE::UnLoadObserversPluginIfAny();
       return return_value;
     }
   catch (YACS::Exception& e)