Salome HOME
a42801f78a26b760b56596d4235dcfeb905cc000
[modules/kernel.git] / src / Container / SALOME_CPythonHelper.hxx
1 // Copyright (C) 2019-2023  CEA/DEN, EDF R&D, 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_Container.hxx"
24
25 #include "Python.h"
26
27 #include <string>
28 #include <vector>
29
30 class CONTAINER_EXPORT SALOME_CPythonHelper
31 {
32  public:
33   void initializePython(int argc, char *argv[]);
34   void allowPythonCallsFromDifferentThread() const;
35   void registerToSalomePiDict(const std::string& processName, long pid) const;
36   std::vector<long> evalVL(const std::string& pyCode) const;
37   std::string evalS(const std::string& pyCode) const;
38   virtual ~SALOME_CPythonHelper();
39   PyObject *getGlobals() const { return _globals; }
40   PyObject *getLocals() const { return _locals; }
41   PyObject *getPickler() const  { return _pickler; }
42   static SALOME_CPythonHelper *Singleton();
43   static void KillSingleton();
44  private:
45   static SALOME_CPythonHelper *_CPYTHONHELPER_INSTANCE;
46  private:
47   PyObject *_globals = nullptr;
48   PyObject *_locals = nullptr;
49   PyObject *_pickler = nullptr;
50   PyObject *_subprocess = nullptr;
51 };