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_RTCTK_CCSSIM_PYRUNNER_HPP
15#define HLCC_RTCTK_CCSSIM_PYRUNNER_HPP
16
17#include <string>
18#include <vector>
19#include <mutex>
20
21#include <pybind11/embed.h>
22
23#include "rtcccssim/config.hpp"
25#include <rad/smAdapter.hpp>
26
27
28namespace py = pybind11;
29
30namespace hlcc::rtcccssim {
31
40#pragma GCC visibility push(hidden) // When removing this pragma should also remove the pop
41 // '#pragma GCC visibility pop' further down in the code.
42
43class PyRunner {
44
45 struct ScriptData {
47 std::string m_py_mod_name;
49 std::string m_py_obj_name;
51 std::string m_python_file_name;
53 py::module m_python_module;
55 py::object m_python_obj;
57 py::function m_python_execute_function;
59 py::function m_python_terminate_function;
61 std::shared_ptr<ExecTimeStats> exec_stats_ptr;
62 };
63
64public:
65 PyRunner(const PyRunner&) = delete;
66 PyRunner& operator=(const PyRunner&) = delete;
67
70 explicit PyRunner(const ConfigPack &config_pack, rad::SMAdapter &m_sm);
73 virtual ~PyRunner();
83 void RunPythonExecuteFunctions(int64_t iteration_timestamp_ms);
89 void UpdateConfiguration(const ConfigPack &config_pack);
90
93
98 std::vector<ExecTimeStats::StatisticsCollection> GetExecutionStatistics();
99
100private:
101 /* Name of method name to be called in every script*/
102 static std::string py_execute_method_name;
103 /* Name of method name to be called before Exit*/
104 static std::string py_terminate_method_name;
105 /* List containin all the modules to be processed */
106 std::vector<SvDescription> m_sv_list;
107 /* Interpreter initialized flag */
108 bool m_interpreter_initialized;
109 /* container for all scripts data */
110 std::vector<ScriptData> m_scripts;
111 /* Application configuration */
112 py::dict m_configuration;
113 /* Scripts shared data */
114 py::dict m_scripts_data;
115 rad::SMAdapter& m_sm;
118 void InitializeInterpreter();
121 void FinalizeInterpreter();
125 void LoadPythonModules(const std::vector<SvDescription> &modules_name);
128 void UnloadPythonModules();
133 void BuildPyConfiguration(py::dict cfg, const ConfigPack &cfg_pack);
139 std::string ExtractNameOfObject(const std::string &name_of_module) const;
140
141};
142
143#pragma GCC visibility pop
144
145} // namespace hlcc::rtcccssim
146
147#endif // HLCC_RTCTK_CCSSIM_PYRUNNER_HPP
void UpdateConfiguration(const ConfigPack &config_pack)
Definition pyRunner.cpp:319
PyRunner(const PyRunner &)=delete
int GetNumberModulesLoaded()
Definition pyRunner.cpp:381
void RunPythonTerminateFunctions()
Definition pyRunner.cpp:296
std::vector< ExecTimeStats::StatisticsCollection > GetExecutionStatistics()
Definition pyRunner.cpp:385
void ReloadPythonModules()
Definition pyRunner.cpp:174
void RunPythonExecuteFunctions(int64_t iteration_timestamp_ms)
Definition pyRunner.cpp:237
PyRunner & operator=(const PyRunner &)=delete
Disable copy constructor.
virtual ~PyRunner()
Definition pyRunner.cpp:50
Definition actionMgr.cpp:30
Config class header file.
Code execution statistics.
Definition config.hpp:116