Main Page · Modules · All Classes · Class Hierarchy
MSSessionStorage.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 
24 #include "MSSessionStorageInterface.hpp"
25 
26 #include <MCDataContainer.hpp>
27 #include <MCDataStorage.hpp>
28 
29 #include <qmap.h>
30 #include <qobject.h>
31 #include <qpointer.h>
32 #include <qstring.h>
33 #include <qstringlist.h>
34 #include <QTime>
35 #include <qvector.h>
36 
37 #include <boost/scoped_ptr.hpp>
38 
39 class QSqlDatabase;
40 class MSElement;
41 
45 // cppcheck-suppress noConstructor
46 class MSSessionStorage : public QObject
47 {
48  Q_OBJECT
49  Q_DISABLE_COPY(MSSessionStorage)
50 
51 
53 public:
54  ~MSSessionStorage();
55 
63  static MSSessionStorage* GetInstance();
64 
72  QString GetPlaybackPath() const;
73 
83  void SetPlaybackPath(const QString& path);
84 
92  QString GetRecordPath() const;
93 
103  void SetRecordPath(const QString& record_path);
104 
112  bool IsStorageAvailable() const;
113 
121  int GetPlayedHeartBeats() const;
122 
123  /*
124  -------------------------------------------------------------------
125  General functions
126  -------------------------------------------------------------------
127  */
128 
129 public Q_SLOTS:
130 
138  void BeatEnd(int beat_id);
139 
140 public:
141 
150 
156  void RemoveStorages();
157 
163  void ResetTimers();
164 
172  void RegisterElement(MSElement& object);
173 
179  void PrepareRecord();
180 
186  void PreparePlay();
187 
193  void Finalize();
194 
195 private:
196 
210  QString ConstructFileName(int object_id, int beat_id,
211  const QString& base_path,
212  const QString& output_name,
213  const MSSessionStorageInterface::StorageDataType& storage_type) const;
214 
220  void CreateRecordDatabase();
221 
229  void CreateTableForAClass(MSElement& object);
230 
236  void LoadStatesFromDatabase();
237 
243  void RecordStatesToDatabase();
244 
254  MSSessionStorageInterface* GetStorage(const QString& type_name) const;
255 
269  QString ExecuteSqlQuery(const QSqlDatabase& database, const QString& query_str) const;
270 
276  void CloseRecordDatabase();
277 
283  void OpenPlaybackDatabase();
284 
290  void ClosePlaybackDatabase();
291 
297  void CreateRecordStorage();
298 
307 
313  void LoadStatesFromStorage();
314 
320  void RecordStatesToStorage();
321 
327  void CloseRecordStorage();
328 
334  void OpenPlaybackStorage();
335 
341  void ClosePlaybackStorage();
342 
343 Q_SIGNALS:
344 
352  void EndOfDatabase();
353 
354 private:
356  QList<QPointer<MSSessionStorageInterface> > SessionStorages;
358  QString PlaybackPath;
360  QString RecordPath;
362  boost::scoped_ptr<QSqlDatabase> PlaybackDatabase;
364  boost::scoped_ptr<QSqlDatabase> RecordDatabase;
366  boost::scoped_ptr<MCDataStorage> PlaybackStorage;
368  boost::scoped_ptr<MCDataStorage> RecordStorage;
371  // Re-mapped source element IDs
372  QMap<int, int> RemappedIDs;
374  QMap<QString, QStringList> TableColumns;
376  QStringList ElementClassNames;
378  QList<MSElement*> RegElements;
381 };
void CreateNewDataItemsForAClass(MSElement &object)
Create data container for an element class.
int GetPlayedHeartBeats() const
Get the number of the played heart beats.
MSSessionStorageInterface * GetStorage(const QString &type_name) const
Get the appropriate storage for a type.
Load or store the source elements&#39; output of a session.
QString ExecuteSqlQuery(const QSqlDatabase &database, const QString &query_str) const
Execute an SQL query.
void PreparePlay()
Prepare the play of a recorded session.
void CreateRecordDatabase()
Create an empty record database.
void OpenPlaybackDatabase()
Open a database.
void CreateTableForAClass(MSElement &object)
Create table for an element class.
void EndOfDatabase()
End of the data in the database.
Interface class to handle new types in the storage.
void ResetTimers()
Reset the internal timers.
MSSessionStorage()
Class constructor.
void SetPlaybackPath(const QString &path)
Set the playback path.
boost::scoped_ptr< MCDataStorage > PlaybackStorage
Play data storage.
static MSSessionStorage * GetInstance()
Get a static instance of the class.
Basic ancestor class of the elements.
Definition: MSElement.hpp:65
QString PlaybackPath
Playback path.
QMap< QString, QStringList > TableColumns
Cached class outputs.
boost::scoped_ptr< QSqlDatabase > RecordDatabase
Record database.
QStringList ElementClassNames
Registered class names with an instance.
void RemoveStorages()
Remove the session storages.
boost::scoped_ptr< QSqlDatabase > PlaybackDatabase
Playback database.
int PlayedHeartBeats
Played heart beats.
QList< QPointer< MSSessionStorageInterface > > SessionStorages
Storage implementations.
void CloseRecordStorage()
Close record storage.
void ClosePlaybackDatabase()
Close the database being played.
bool IsStorageAvailable() const
Check if any storage is available.
void LoadStatesFromDatabase()
Load the element states from the database.
QList< MSElement * > RegElements
Registered elements.
QString GetPlaybackPath() const
Get the playback path.
void CloseRecordDatabase()
Close the record database.
void OpenPlaybackStorage()
Open playback storage.
QString ConstructFileName(int object_id, int beat_id, const QString &base_path, const QString &output_name, const MSSessionStorageInterface::StorageDataType &storage_type) const
Construct a file name in the storage without extension.
QString RecordPath
Path where the recording goes.
boost::scoped_ptr< MCDataStorage > RecordStorage
Record data storage.
void Finalize()
Finalize the storage operations.
void RegisterStorage(MSSessionStorageInterface &storage)
Register a session storage.
void CreateRecordStorage()
Create a new record storage.
const int RecordStoragePeriod
Record storage period.
void RecordStatesToDatabase()
Record the element states to the database.
QString GetRecordPath() const
Get the record path.
void RecordStatesToStorage()
Record element states to storage.
void RegisterElement(MSElement &object)
Register an element.
void SetRecordPath(const QString &record_path)
Set the record path.
void LoadStatesFromStorage()
Load element states from storage.
void PrepareRecord()
Prepare the record of a new session.
void BeatEnd(int beat_id)
This slot is being called by the end of a heart beat.
void ClosePlaybackStorage()
Close playback storage.