HLCC Documentation 3.0.1
Loading...
Searching...
No Matches
pyRunner.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020-2025 European Southern Observatory (ESO)
2//
3// SPDX-License-Identifier: LGPL-3.0-only
4
13
14#ifndef HLCC_TELIF_TELMON_PYRUNNER_HPP
15#define HLCC_TELIF_TELMON_PYRUNNER_HPP
16
17#include <string>
18#include <vector>
19#include <mutex>
20#include <pybind11/embed.h>
21
22#include "telmon/config.hpp"
23
24
25namespace py = pybind11;
26
27namespace hlcc::telmon {
28
37#pragma GCC visibility push(hidden) // When removing this pragma should also remove the pop
38 // '#pragma GCC visibility pop' further down in the code.
39
40class PyRunner {
41
42 struct ScriptData {
44 std::string m_py_mod_name;
46 std::string m_py_obj_name;
48 std::string m_python_file_name;
50 py::module m_python_module;
52 py::object m_python_obj;
54 py::function m_python_execute_function;
56 py::function m_python_terminate_function;
57 };
58
59public:
60 PyRunner(const PyRunner&) = delete;
61 PyRunner& operator=(const PyRunner&) = delete;
62
65 explicit PyRunner(const ConfigPack &config_pack);
68 virtual ~PyRunner();
80 void UpdateConfiguration(const ConfigPack &config_pack);
81
84
85private:
86 /* Name of method name to be called in every script*/
87 static std::string py_execute_method_name;
88 /* Name of method name to be called before Exit*/
89 static std::string py_terminate_method_name;
90 /* List containin all the modules to be processed */
91 std::vector<std::string> m_modules_name_list;
92 /* Interpreter initialized flag */
93 bool m_interpreter_initialized;
94 /* container for all scripts data */
95 std::vector<ScriptData> m_scripts;
96 /* Application configuration */
97 py::dict m_configuration;
98 /* Scripts shared data */
99 py::dict m_scripts_data;
100
103 void InitializeInterpreter();
106 void FinalizeInterpreter();
110 void LoadPythonModules(const std::vector<std::string> &modules_name);
113 void UnloadPythonModules();
118 void BuildPyConfiguration(py::dict cfg, const ConfigPack &cfg_pack);
124 std::string ExtractNameOfObject(const std::string &name_of_module) const;
125
126};
127
128#pragma GCC visibility pop
129
130} // namespace hlcc::telmon
131
132#endif // HLCC_TELIF_TELMON_PYRUNNER_HPP
Config class header file.
void RunPythonExecuteFunctions()
Definition pyRunner.cpp:216
void RunPythonTerminateFunctions()
Definition pyRunner.cpp:243
PyRunner & operator=(const PyRunner &)=delete
Disable copy constructor.
int GetNumberModulesLoaded()
Definition pyRunner.cpp:357
void ReloadPythonModules()
Definition pyRunner.cpp:168
void UpdateConfiguration(const ConfigPack &config_pack)
Definition pyRunner.cpp:266
PyRunner(const PyRunner &)=delete
virtual ~PyRunner()
Definition pyRunner.cpp:48
Definition actionMgr.cpp:31
Definition config.hpp:230