4#include <pybind11/embed.h>
12#include <pybind11/stl.h>
19using namespace py::literals;
27 py::gil_scoped_acquire gil;
29 auto locals = py::dict(
"theModule"_a = *
this);
31 def mainLoopWrapper2(self):
33 self.mainLoopWrapper()
34 except ThreadInterrupted as e:
36 except Exception as e:
37 print("Exception in module "+self.getName()+":")
38 traceback.print_exception(e)
39 theModule.mainLoopWrapper2 = mainLoopWrapper2.__get__(theModule)
41 py::globals(), locals);
42 _myThread = py::eval("threading.Thread(target=theModule.mainLoopWrapper2)", py::globals(), locals);
44 _myThread.attr(
"start")();
62 py::gil_scoped_acquire gil;
63 while(_myThread.attr(
"is_alive")().cast<
bool>()) {
65 auto el{var.getAppAccessorNoType().getHighLevelImplElement()};
69 _myThread.attr(
"join")(0.01);
79 std::unique_ptr<PyApplicationModule, py::nodelete>>
80 cam(m,
"ApplicationModule", py::multiple_inheritance());
82 cam.def(py::init([](
ModuleGroup& owner,
const std::string& name,
const std::string& description,
83 const std::unordered_set<std::string>& tags) {
84 return dynamic_cast<PyOwningObject&
>(owner).make_child<PythonApplicationModuleTrampoline>(
85 &owner, name, description, tags);
87 py::return_value_policy::reference,
89 "", py::arg(
"owner"), py::arg(
"name"), py::arg(
"description"),
90 py::arg(
"tags") = std::unordered_set<std::string>{});
96 "Return the data validity flag.\n\nIf any This function will be called by all output accessors in their "
99 "Return the current version number which has been received with the last push-type read operation.")
101 "Set the current version number.\n\nThis function is called by the push-type input accessors in their read "
103 py::arg(
"versionNumber"))
106 "Set the data validity flag to fault and increment the fault counter.\n\nThis function will be called by "
107 "all input accessors when receiving the a faulty update if the previous update was ok. The caller of this "
108 "function must ensure that calls to this function are paired to a subsequent call to "
109 "decrementDataFaultCounter().")
111 "Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.\n\nThis "
112 "function will be called by all input accessors when receiving the an ok update if the previous update was "
113 "faulty. The caller of this function must ensure that calles to this function are paired to a previous "
114 "call to incrementDataFaultCounter().")
116 "Get the Number of inputs which report DataValidity::faulty.")
121 auto pythonClassName = py::cast(&module).get_type().attr(
"__name__").cast<std::string>();
124 "Convenicene function to obtain a logger stream with the given Severity.\n\nThe context string will be "
125 "obtained from the class name of the module.")
127 "Disable the module such that it is not part of the Application.");
detail::TestableMode & getTestableMode()
Get the TestableMode control object of this application.
static Application & getInstance()
Obtain instance of the application.
DataValidity getDataValidity() const override
Return the data validity flag.
void terminate() override
Terminate the module.
void decrementDataFaultCounter() override
Decrement the fault counter and set the data validity flag to ok if the counter has reached 0.
void setCurrentVersionNumber(VersionNumber versionNumber) override
Set the current version number.
VersionNumber getCurrentVersionNumber() const override
Return the current version number which has been received with the last push-type read operation.
void incrementDataFaultCounter() override
Set the data validity flag to fault and increment the fault counter.
size_t getDataFaultCounter() const
Get the Number of inputs which report DataValidity::faulty.
std::list< VariableNetworkNode > getAccessorListRecursive() const
Obtain the list of accessors/variables associated with this instance and any submodules.
Severity
Severity levels used by the Logger.
void disable()
Disable the module such that it is not part of the Application.
static ConfigReader & appConfig()
Obtain the ConfigReader instance of the application.
void terminate() override
Terminate the module.
static void bind(py::module &mod)
void mainLoopWrapper()
Wrapper around mainLoop(), to execute additional tasks in the thread before entering the main loop.
void run() override
Execute the module.
Base class used for all objects in the Python world which can own other objects and can be owned them...
InvalidityTracer application module.