Main Page · Modules · All Classes · Class Hierarchy
MSElement.hpp
1 /*
2  * This file is part of the AiBO+ project
3  *
4  * Copyright (C) 2005-2016 Csaba Kertész (csaba.kertesz@gmail.com)
5  *
6  * AiBO+ is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * AiBO+ is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
19  *
20  */
21 
22 #pragma once
23 
29 #include <qlist.h>
30 #include <qmap.h>
31 #include <qmetatype.h>
32 #include <qmutex.h>
33 #include <qobject.h>
34 #include <qstringlist.h>
35 #include <QTime>
36 
37 class MSData;
38 class MSElement;
39 class MSHeart;
40 
41 namespace MS
42 {
44 typedef enum
45 {
46  Source,
47  Sink,
48  SinkGui,
49  NormalElement,
50 } ElementType;
51 
53 typedef QMap<QString, MSElement*> StringElementMap;
54 
56 typedef QMap<QString, MSData*> StringDataMap;
57 
59 typedef QList<MSElement*> ElementPtrList;
60 }
61 
65 class MSElement : public QObject
66 {
67  Q_OBJECT;
68 
69  friend class MSHeart;
70  friend class MSSessionStorage;
71 
72 public:
73 
87  explicit MSElement(MS::ElementType element_type, bool dedicated_thread = false);
89  virtual ~MSElement();
90 
101  bool IsDedicatedThread() const;
102 
112  int GetElementID() const;
113 
126  void SetElementID(int new_id);
127 
137  int GetBeatID() const;
138 
148  MS::ElementType GetType() const;
149 
157  QString GetClass() const;
158 
159 public Q_SLOTS:
160 
170  void BeatBegin(int beat_id);
171 
179  void Stop();
180 
181 private Q_SLOTS:
182 
190  void ProgressIdle();
191 
192 private:
193 
205  bool DoTasks(bool be_hurry);
206 
207 protected:
208 
217  virtual void StartActivities();
218 
235  virtual bool ProgressTasks(bool be_hurry);
236 
245  virtual void StopActivities();
246 
247 public:
248 
261  QStringList GetInputList() const;
262 
272  bool HasOutputs() const;
273 
286  QStringList GetOutputList() const;
287 
298  void AddReceiverElement(const QString& output_name, MSElement& element);
299 
310  void RemoveReceiverElement(const QString& output_name, MSElement& element);
311 
312 protected:
313 
325  MSData* GetOutputData(const QString& output_name) const;
326 
337  void SetInputData(const QString& input_name, const MSData& new_data);
338 
346  void Feeding();
347 
348 Q_SIGNALS:
349 
360  void BeatEnd(int beat_id, MSElement* element);
361 
362 protected:
370  MS::StringElementMap ReceiverElements;
374  QStringList CurrentOutputList;
376  QStringList CurrentInputList;
378  MS::ElementType Type;
380  MS::StringDataMap InputList;
382  MS::StringDataMap OutputList;
386  MSHeart* Heart;
389 };
390 
391 Q_DECLARE_METATYPE(MSElement*); // -V566 (PVS Studio suppression)
392 
MS::StringDataMap InputList
Input list.
Definition: MSElement.hpp:380
MS::StringElementMap ReceiverElements
Receiver elements.
Definition: MSElement.hpp:370
Load or store the source elements&#39; output of a session.
QMutex TasksExecutionMutex
Mutex for the element tasks.
Definition: MSElement.hpp:388
bool PlaybackMode
Playback mode.
Definition: MSElement.hpp:372
bool EmergencyStop
Emergency stop.
Definition: MSElement.hpp:384
MS::StringDataMap OutputList
Output list.
Definition: MSElement.hpp:382
int ElementID
Element ID.
Definition: MSElement.hpp:366
Basic ancestor class of the elements.
Definition: MSElement.hpp:65
QStringList CurrentInputList
Specifies the available input data list for the current heart beat.
Definition: MSElement.hpp:376
Definition: MSElement.hpp:41
QStringList CurrentOutputList
Specifies the available output data for the current heart beat.
Definition: MSElement.hpp:374
Base class for the data exchange of the elements.
Definition: MSData.hpp:54
int CurrentBeat
Current Beat ID.
Definition: MSElement.hpp:368
bool DedicatedThread
Dedicated thread.
Definition: MSElement.hpp:364
MSHeart * Heart
Heart where the element is registered.
Definition: MSElement.hpp:386
MS::ElementType Type
Specifies the type of the element.
Definition: MSElement.hpp:378
void BeatEnd(int beat_id)
This slot is being called by the end of a heart beat.