]> SALOME platform Git repositories - modules/kernel.git/blob - src/Launcher/SALOME_LogManager.hxx
Salome HOME
80cc55514ddd5d97d94886e942127ea1a1035df2
[modules/kernel.git] / src / Launcher / SALOME_LogManager.hxx
1 // Copyright (C) 2024  CEA, EDF
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
20 #pragma once
21
22 #include "SALOME_Launcher_defs.hxx"
23
24 #include "Python.h"
25
26 #include "PythonCppUtils.hxx"
27 #include "Utils_CorbaException.hxx"
28 #include "SALOMEconfig.h"
29
30 #include CORBA_SERVER_HEADER(SALOME_LogManager)
31
32 #include <vector>
33 #include <string>
34 #include <memory>
35
36 class SALOME_NamingService_Abstract;
37 class SALOME_LogManager;
38 class SALOME_ContainerPerfLog;
39 class SALOME_ContainerScriptPerfLog;
40 class SALOME_ContainerScriptExecPerfLog;
41
42 class SALOMELAUNCHER_EXPORT SALOME_VisitorContainerLog
43 {
44 public:
45   virtual void enterLogManager(SALOME_LogManager& inst) = 0;
46   virtual void leaveLogManager(SALOME_LogManager& inst) = 0;
47   virtual void enterContainerPerfLog(SALOME_ContainerPerfLog& inst) = 0;
48   virtual void leaveContainerPerfLog(SALOME_ContainerPerfLog& inst) = 0;
49   virtual void enterContainerScriptPerfLog(SALOME_ContainerScriptPerfLog& inst) = 0;
50   virtual void leaveContainerScriptPerfLog(SALOME_ContainerScriptPerfLog& inst) = 0;
51   virtual void visitContainerScriptExecPerfLog(SALOME_ContainerScriptExecPerfLog& inst) = 0;
52 };
53
54 class SALOMELAUNCHER_EXPORT SALOME_ContainerScriptExecPerfLog : public POA_Engines::ContainerScriptExecPerfLog
55 {
56 public:
57   SALOME_ContainerScriptExecPerfLog(SALOME_ContainerScriptPerfLog *father):_father(father) { }
58   SALOME_ContainerScriptPerfLog *father() const { return _father; }
59   void setPyObj(PyObject *obj) { _pyExecutionLog.set(obj); }
60   PyObject *pyObj() { return _pyExecutionLog.get(); }
61   PortableServer::POA_var getPOA();
62   void assign(const SALOME::vectorOfByte& value) override;
63   SALOME::vectorOfByte *getObj() override;
64   const std::vector<char>& data() const { return _data; }
65   void setData(std::vector<char>&& data) { _data = std::move(data); }
66 public:
67   void accept(SALOME_VisitorContainerLog &visitor);
68 public:
69   void start();
70   AutoPyRef end();
71 private:
72   AutoPyRef _pyExecutionLog;
73   SALOME_ContainerScriptPerfLog *_father = nullptr;
74   std::vector<char> _data;
75 };
76
77 class SALOMELAUNCHER_EXPORT SALOME_ContainerScriptPerfLog : public POA_Engines::ContainerScriptPerfLog
78 {
79 public:
80   SALOME_ContainerScriptPerfLog(SALOME_ContainerPerfLog *father, const std::string& name, const std::string& code):_father(father),_name(name),_code(code) { }
81   SALOME_ContainerPerfLog *father() const { return _father; }
82   void setPyObj(PyObject *obj) { _pyScriptLog.set(obj); }
83   PyObject *pyObj() { return _pyScriptLog.get(); }
84   PortableServer::POA_var getPOA();
85   Engines::ContainerScriptExecPerfLog_ptr addExecutionSession() override;
86   Engines::ListOfContainerScriptExecPerfLog *listOfExecs() override;
87   char *getCode() override;
88   char *getName() override;
89   const std::string& name() const { return _name; }
90   const std::string& code() const { return _code; }
91   void setName(const std::string& name) { _name = name; }
92   void setCode(const std::string& code) { _code = code; }
93   std::size_t getNumberOfSessions() const { return _sessions.size(); }
94 public:
95   void accept(SALOME_VisitorContainerLog &visitor);
96 private:
97   AutoPyRef _pyScriptLog;
98   SALOME_ContainerPerfLog *_father = nullptr;
99   std::string _name;
100   std::string _code;
101   std::vector< Engines::ContainerScriptExecPerfLog_var > _sessions;
102 };
103
104 class SALOMELAUNCHER_EXPORT SALOME_ContainerPerfLog : public POA_Engines::ContainerPerfLog
105 {
106 public:
107   SALOME_ContainerPerfLog(SALOME_LogManager *father, const std::string& nameInNS, const std::string& logFile):_father(father),_name_in_ns(nameInNS),_log_file(logFile) { }
108   SALOME_LogManager *father() const { return _father; }
109   void setPyObj(PyObject *obj) { _pyContLog.set(obj); }
110   PyObject *pyObj() { return _pyContLog.get(); }
111   PortableServer::POA_var getPOA(); 
112   char *getLogFile() override;
113   char *getContainerEntryInNS() override;
114   Engines::ContainerScriptPerfLog_ptr addScript(const char *name, const char *code) override;
115   Engines::ListOfContainerScriptPerfLog *listOfScripts() override;
116   const std::string& nameInNS() const { return _name_in_ns; }
117   const std::string& logFile() const { return _log_file; }
118   void setNameInNS(const std::string& name) { _name_in_ns = name; }
119   void setLogFile(const std::string& logFile) { _log_file = logFile; }
120   std::size_t getNumberOfScripts() const { return _scripts.size(); }
121 public:
122   void accept(SALOME_VisitorContainerLog &visitor);
123 private:
124   AutoPyRef _pyContLog;
125   SALOME_LogManager *_father = nullptr;
126   std::string _name_in_ns;
127   std::string _log_file;
128   std::vector< Engines::ContainerScriptPerfLog_var > _scripts;
129 };
130
131 class SALOMELAUNCHER_EXPORT SALOME_LogManager : public POA_Engines::LogManager
132 {
133  public:
134   SALOME_LogManager(CORBA::ORB_ptr orb, PortableServer::POA_var poa, SALOME_NamingService_Abstract *ns = nullptr);
135   PortableServer::POA_var getPOA() { return _poa; }
136   PyObject *pyHelper() const { return _pyLogManager; }
137   virtual ~SALOME_LogManager() = default;
138   Engines::ContainerPerfLog_ptr declareContainer(const char *contInNS, const char *logfile) override;
139   Engines::ListOfContainerPerfLog *listOfContainerLogs() override;
140   SALOME::vectorOfByte *getAllStruct() override;
141   std::size_t getNumberOfContainers() const { return _containers.size(); }
142  public:
143   void accept(SALOME_VisitorContainerLog &visitor);
144  private:
145   std::vector<char> dumpCppInternalFrmt();
146  private:
147   PyObject *_pyLogManager = nullptr;
148   std::unique_ptr<SALOME_NamingService_Abstract> _NS;
149   PortableServer::POA_var _poa;
150   std::vector<Engines::ContainerPerfLog_var> _containers;
151  public:
152   static const char NAME_IN_NS[];
153 };