Salome HOME
updated copyright message
[modules/kernel.git] / src / Launcher / SALOME_ExternalServerLauncher.hxx
1 // Copyright (C) 2019-2023  CEA, EDF, OPEN CASCADE
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19 // Author : Anthony GEAY (EDF R&D)
20
21 #pragma once
22
23 #include "SALOME_Launcher_defs.hxx"
24
25 #include <SALOMEconfig.h>
26
27 #include CORBA_SERVER_HEADER(SALOME_ExternalServerLauncher)
28
29 #include <vector>
30 #include <string>
31
32 class SALOME_NamingService_Abstract;
33 class SALOME_CPythonHelper;
34
35 class SALOMELAUNCHER_EXPORT SALOME_ExternalServerLauncher : public POA_SALOME::ExternalServerLauncher
36 {
37  public:
38   SALOME_ExternalServerLauncher(const SALOME_CPythonHelper *pyHelper, CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns = nullptr);
39   virtual ~SALOME_ExternalServerLauncher();
40  public:
41   SALOME::ExternalServerHandler_ptr launchServer(const char *server_name, const char *working_dir, const SALOME::CmdList& command_list ) override;
42   void registerToKill(const char *server_name, CORBA::Long PID) override;
43   void cleanServersInNS() override;
44   void shutdownServers() override;
45   SALOME::StringVec *listServersInNS() override;
46   SALOME::ExternalServerHandler_ptr retrieveServerRefGivenNSEntry( const char *ns_entry ) override;
47   char *gethostname() override;
48   SALOME::ByteVec *fetchContentOfFileAndRm(const char *file_name) override;
49   const SALOME_CPythonHelper *getPyHelper() const { return _pyHelper; }
50  private:
51   static std::string CreateAbsNameInNSFromServerName(const std::string& scopeName);
52   static std::vector<std::string> ListOfExternalServersCpp(SALOME_NamingService_Abstract *ns);
53   static bool IsAliveAndKicking(SALOME::ExternalServerHandler_ptr server);
54   static bool IsAliveAndKicking(SALOME_NamingService_Abstract *ns, const std::string& serverName);
55   static SALOME::ExternalServerHandler_var GetServerHandlerGivenName(SALOME_NamingService_Abstract *ns, const std::string& serverName);
56  private:
57   const SALOME_CPythonHelper *_pyHelper = nullptr;
58   SALOME_NamingService_Abstract *_NS = nullptr;
59   PortableServer::POA_var _poa;
60   static unsigned CNT;
61   std::vector<long> _list_of_pids_to_kill;
62  public:
63   static const char NAME_IN_NS[];
64 };