22 #include "MSElement.hpp" 24 #include "MSContext.hpp" 26 #include "MSHeart.hpp" 31 #include <QMutexLocker> 36 static QPointer<MSContext> Context =
nullptr;
37 static int ElementIDs = 0;
40 DedicatedThread(dedicated_thread), CurrentBeat(-1), PlaybackMode(false),
41 CurrentOutputList(), CurrentInputList(), Type(element_type), EmergencyStop(false),
42 Heart(nullptr), TasksExecutionMutex(QMutex::Recursive)
46 MC_LOG(
"New element: %s (ID: %d, %p) in thread %p", qPrintable(
GetClass()),
52 Context->RegisterElement(*
this);
61 MC_LOG(
"Delete element: %s (ID: %d, %p) in thread %p", qPrintable(
GetClass()),
67 Context->UnregisterElement(*
this);
69 if (!Context->HasRegisteredElements())
109 return QString(metaObject()->className());
202 if (output_name.isEmpty())
204 MC_WARNING(
"The output name is not specified.");
207 MC_LOG(
"Add receiver element: %s (%s) -> %s", qPrintable(
GetClass()), qPrintable(output_name),
215 if (output_name.isEmpty())
217 MC_WARNING(
"The output name is not specified.");
222 if (iter.key() == output_name && iter.value() == &element)
239 if (input_name.isEmpty())
241 MC_WARNING(
"The input name is not specified.");
246 MC_WARNING(
"The input name (%s) is not in the input list.", qPrintable(input_name));
269 iter.value()->SetInputData(iter.key(), *
OutputList[iter.key()]);
MS::StringDataMap InputList
Input list.
bool DoTasks(bool be_hurry)
Do tasks.
MS::StringElementMap ReceiverElements
Receiver elements.
virtual void StopActivities()
Stop activities.
QString GetClass() const
Get the class name.
void SetElementID(int new_id)
Set the element ID.
QMutex TasksExecutionMutex
Mutex for the element tasks.
void SetInputData(const QString &input_name, const MSData &new_data)
Set an input data of the element.
int GetElementID() const
Get the element ID.
bool PlaybackMode
Playback mode.
bool EmergencyStop
Emergency stop.
MS::StringDataMap OutputList
Output list.
Basic ancestor class of the elements.
#define MC_WARNING(...)
Warning macro.
QStringList CurrentInputList
Specifies the available input data list for the current heart beat.
int GetBeatID() const
Get the current beat ID.
void RemoveReceiverElement(const QString &output_name, MSElement &element)
Remove a receiver element for an output.
void Stop()
Emergency stop.
bool IsDedicatedThread() const
Thread mode of the element.
bool HasOutputs() const
Whenever the element has any outputs.
virtual void StartActivities()
Start activities.
void Feeding()
Feed the interested elements with output data.
void ProgressIdle()
Progress idle.
QStringList GetInputList() const
Get the input list.
QStringList CurrentOutputList
Specifies the available output data for the current heart beat.
void BeatEnd(int beat_id, MSElement *element)
End of a heart beat.
MSElement(MS::ElementType element_type, bool dedicated_thread=false)
Class constructor.
virtual ~MSElement()
Class destructor.
Base class for the data exchange of the elements.
void BeatBegin(int beat_id)
Begin of a heart beat.
int CurrentBeat
Current Beat ID.
virtual bool ProgressTasks(bool be_hurry)
Does the task.
bool DedicatedThread
Dedicated thread.
void AddReceiverElement(const QString &output_name, MSElement &element)
Add a receiver element for an output.
MSData * GetOutputData(const QString &output_name) const
Get an output data of the element.
MS::ElementType GetType() const
Get the type of the element.
MSHeart * Heart
Heart where the element is registered.
#define MC_LOG(...)
Debug macro.
QStringList GetOutputList() const
Get the output list.
static MSContext * GetInstance()
Get a static instance of the class.
MS::ElementType Type
Specifies the type of the element.