13 py::bind_vector<DynExpModule::PyStreamListType>(m,
"StreamListType");
14 py::bind_vector<decltype(DynExpModule::PyStreamManipulatorOutputData::LastConsumedSampleIDsPerInputStream)>(m,
"SampleIDListType");
16 py::class_<PyStreamManipulatorInputData>(m,
"InputData")
23 py::class_<PyStreamManipulatorOutputData>(m,
"OutputData")
64 bool IsNewDataAvlbl =
false;
68 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
75 IsNewDataAvlbl =
true;
78 const auto now = std::chrono::system_clock::now();
115 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
126 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
139 py::gil_scoped_acquire acquire;
142 if (!PyResult.is_none())
153 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
166 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
179 auto ModuleParams = DynExp::dynamic_Params_cast<StreamManipulator>(Instance->
ParamsGetter());
186 PythonCode = std::regex_replace(PythonCode, std::regex(
"\r\n"),
"\n");
187 PythonCode = std::regex_replace(PythonCode, std::regex(
"\n"), std::string(
"\n") +
Util::PyTab);
189 py::gil_scoped_acquire acquire;
191 py::exec(
"import PyModuleStreamManipulator as StreamManipulator");
194 Util::PyTab +
"if 'on_init' in locals() and callable(on_init):\n" +
196 Util::PyTab +
"if 'on_step' in locals() and callable(on_step):\n" +
198 Util::PyTab +
"if 'on_exit' in locals() and callable(on_exit):\n" +
202 ManipulatorPyFuncInit = py::hasattr(ManipulatorPyFunc,
"init") ? py::getattr(ManipulatorPyFunc,
"init") : py::none();
203 ManipulatorPyFuncStep = py::hasattr(ManipulatorPyFunc,
"step") ? py::getattr(ManipulatorPyFunc,
"step") : py::none();
204 ManipulatorPyFuncExit = py::hasattr(ManipulatorPyFunc,
"exit") ? py::getattr(ManipulatorPyFunc,
"exit") : py::none();
207 for (
size_t i = 0; i <
ModuleData->GetInputDataStreams().GetList().size(); ++i)
210 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
216 for (
size_t i = 0; i <
ModuleData->GetOutputDataStreams().GetList().size(); ++i)
219 auto InstrData = DynExp::dynamic_InstrumentData_cast<DynExpInstr::DataStreamInstrument>(
Instrument->GetInstrumentData());
239 py::gil_scoped_acquire acquire;
PYBIND11_EMBEDDED_MODULE(PyModuleStreamManipulator, m)
PYBIND11_MAKE_OPAQUE(DynExpModule::PyStreamListType)
Implementation of a module to process data stored in data stream instrument(s) with a Python script a...
Base class for all circular data streams based on Util::circularbuf.
void WriteBasicSamples(const BasicSampleListType &Samples)
Writes a list of basic sample to the stream.
static void import()
Make the Python interpreter import this module as PyModuleDataStreamInstrument. GIL has to be acquire...
void Init()
Called by ResetImpl(dispatch_tag<DynExp::ModuleDataBase>) overridden by this class to initialize the ...
void ResetImpl(dispatch_tag< ModuleDataBase >) override final
Refer to DynExp::ModuleDataBase::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of ...
void OnInit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread starts. Override it to lock instruments this m...
size_t NumFailedUpdateAttempts
Counts how often StreamManipulator::ModuleMainLoop() contiguously failed due to an exception of type ...
std::chrono::time_point< std::chrono::system_clock > LastManipulatorPyFuncExecution
Time point when the on_step() Python function was invoked last.
std::atomic< bool > IsInitialized
Indicates whether the module has been fully initialized by finishing OnInit(). The variable is atomic...
PyFuncType ManipulatorPyFuncStep
Handle to a Python function called for each manipulation step.
PyStreamManipulatorOutputData ManipulatorPyFuncOutput
Output data returned from the on_step() Python function.
Util::DynExpErrorCodes::DynExpErrorCodes ModuleMainLoop(DynExp::ModuleInstance &Instance) override final
Module main loop. The function is executed periodically by the module thread. Also refer to GetMainLo...
PyFuncType ManipulatorPyFuncExit
Handle to a Python function called on module termination.
void ResetImpl(dispatch_tag< ModuleBase >) override final
Refer to DynExp::Object::Reset(). Using tag dispatch mechanism to ensure that ResetImpl() of every de...
PyFuncType ManipulatorPyFuncInit
Handle to a Python function called on module initialization.
void OnExit(DynExp::ModuleInstance *Instance) const override final
This event is triggered right before the module thread terminates (not due to an exception,...
std::string ManipulatorPyFuncName
Unique name of the Python function all the code of this StreamManipulator instance is declared in....
PyStreamManipulatorInputData ManipulatorPyFuncInput
Input data passed to the on_step() Python function.
void Step(Util::SynchronizedPointer< ModuleDataType > &ModuleData)
Performs a single manipulation step by preparing input data for a call to the Python function on_step...
const std::unique_ptr< ModuleDataType > ModuleData
Module data belonging to this ModuleBase instance.
Refer to ParamsBase::dispatch_tag.
Defines data for a thread belonging to a ModuleBase instance. Refer to RunnableInstance.
const ModuleBase::ModuleDataGetterType ModuleDataGetter
Getter for module's data. Refer to ModuleBase::ModuleDataGetterType.
ItemIDType GetID() const noexcept
Returns the ID of this Object instance. Thread-safe since ID is const.
auto GetObjectName(const std::chrono::milliseconds Timeout=GetParamsTimeoutDefault) const
Returns the name of this Object instance.
Refer to ParamsBase::dispatch_tag.
const Object::ParamsGetterType ParamsGetter
Invoke to obtain the parameters (derived from ParamsBase) of Owner.
void UnlockObject(LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer)
Unlocks an Object instance stored in the LinkedObjectWrapperContainer ObjectWrapperContainer....
void LockObject(const ParamsBase::Param< ObjectLink< ObjectT >> &LinkParam, LinkedObjectWrapperContainer< ObjectT > &ObjectWrapperContainer, std::chrono::milliseconds Timeout=ObjectLinkBase::LockObjectTimeoutDefault)
Locks an Object instance referenced by a parameter LinkParam of type ParamsBase::Param< ObjectLink< O...
const auto & GetOwner() const noexcept
Returns Owner.
Logs events like errors and writes them immediately to a HTML file in a human-readable format....
void Log(const std::string &Message, const ErrorType Type=ErrorType::Info, const size_t Line=0, const std::string &Function="", const std::string &File="", const int ErrorCode=0, const std::stacktrace &Trace={}) noexcept
Logs an event from information specified manually.
void Reset()
Removes the owned pybind11::object after locking the GIL.
Pointer to lock a class derived from ISynchronizedPointerLockable for synchronizing between threads....
Thrown when an operation timed out before it could be completed, especially used for locking shared d...
DynExp's module namespace contains the implementation of DynExp modules which extend DynExp's core fu...
std::vector< DynExpInstr::PyDataStreamInstrument > PyStreamListType
Type of a list of data stream instruments made available to Python.
constexpr auto Instrument
DynExpErrorCodes
DynExp's error codes
std::string ToStr(const T &Value, int Precision=-1)
Converts a (numeric) value of type T to a std::string using operator<< of std::stringstream.
static constexpr auto PyTab
Character sequence to indent a Python instruction by one level.
std::string ReadFromFile(const QString &Filename)
Reads the entire content from a text file.
Accumulates include statements to provide a precompiled header.
Output data type returned from on_step() Python function.
void Reset()
Resets all member variables of this PyStreamManipulatorOutputData instance back to their default valu...
std::chrono::milliseconds MinNextExecutionDelay
Time wo wait minimally before the on_step() Python function is called again when each input data stre...
std::chrono::milliseconds MaxNextExecutionDelay
Time to wait maximally before the on_step() Python function is called again when the input data strea...
std::vector< size_t > LastConsumedSampleIDsPerInputStream
Maintaining the order of input data streams in PyStreamManipulatorInputData::InputStreams as passed t...