Main Page · Modules · All Classes · Class Hierarchy
MSContext.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 <qstring.h>
30 #include <qstringlist.h>
31 #include <qfile.h>
32 #include <qtextstream.h>
33 #include <qvector.h>
34 
35 class MSElement;
37 
42 class MSContext : public QObject
43 {
44  Q_OBJECT
45  Q_DISABLE_COPY(MSContext)
46 
47 public:
48 
50  typedef enum {
51  ca_Min = 0,
56  } CmdArgument;
57 
58  static QStringList CmdArgumentMsgs;
59 
61  typedef struct
62  {
63  CmdArgument SearchResult;
64  QString* Parameter;
66 
79  MSContext(int& argc, char **argv, bool graphical_context = false);
81  ~MSContext();
82 
92  static MSContext* GetInstance();
93 
94  /*
95  -------------------------------------------------------------------
96  Parameter handling
97  -------------------------------------------------------------------
98  */
99 
100 public:
101 
111  QString GetDefaultDebugItems() const;
112 
122  void SetDefaultDebugItems(const QString& items);
123 
133  QString GetPlaybackPath() const;
134 
145  void SetPlaybackPath(const QString& play_path);
146 
156  QString GetRecordPath() const;
157 
168  void SetRecordPath(const QString& record_path);
169 
179  QString GenerateRecordPath();
180 
190  int GetMaxBeats() const;
191 
202  void SetMaxBeats(int max_beats);
203 
213  int GetPlayedBeats() const;
214 
224  int GetCurrentBeat() const;
225 
235  bool HasRegisteredElements() const;
236 
246  bool IsPaused() const;
247 
257  bool IsBeatingFinished() const;
258 
268  bool IsMalfunctionHappened() const;
269 
270  /*
271  -------------------------------------------------------------------
272  Processing command line arguments
273  -------------------------------------------------------------------
274  */
275 
288  ArgSearchResult FindArgument(const QString& arg, const QString& long_arg);
289 
290 private:
291 
299  void FindMindSessionArgs();
300 
301  /*
302  -------------------------------------------------------------------
303  Context functions
304  -------------------------------------------------------------------
305  */
306 
307 private Q_SLOTS:
308 
316  void HeartFinished();
317 
318 protected:
319 
330 
331 public:
332 
342  void RegisterElement(MSElement& element);
343 
353  void UnregisterElement(MSElement& element);
354 
364  void SetBeatDurationLimit(int new_limit);
365 
366 public Q_SLOTS:
367 
377  virtual bool PrepareSession();
378 
386  virtual void FinishSession();
387 
395  virtual void StartHeartBeating();
396 
404  virtual void StopHeartBeating();
405 
413  virtual void Pause();
414 
422  virtual void Resume();
423 
424 public:
425 
436  static void RegisterTimer(const QString& id, const QString& description);
437 
447  static void StartTimer(const QString& id);
448 
461  static void StopTimer(const QString& id);
462 
472  static void ResetTimer(const QString& id);
473 
485  static int GetTimerElapsedTime(const QString& id);
486 
487 private:
488 
496  static void PauseTimers();
497 
505  static void ResumeTimers();
506 
507 Q_SIGNALS:
508 
516  void Stop();
517 
527  void NewHeartBeat(int beat_id);
528 
536  void HeartStopped();
537 
545  void PlayedSessionFinished();
546 
547 protected:
549  QStringList ProgramArguments;
551  QList<MSElement*> RegElements;
559  const QString SessionRuntimeTimerName;
560 };
561 
int GetCurrentBeat() const
Get the current beat ID.
Definition: MSContext.cpp:346
static void RegisterTimer(const QString &id, const QString &description)
Register a timer.
Definition: MSContext.cpp:644
QString GenerateRecordPath()
Generate a record path.
Definition: MSContext.cpp:316
void FindMindSessionArgs()
Find libmindsession specific command line arguments.
Definition: MSContext.cpp:418
Creates a context for an application.
Definition: MSContext.hpp:42
void HeartFinished()
Listen to the end of the heart.
Definition: MSContext.cpp:457
Interface class to handle new types in the storage.
static void PauseTimers()
Pause the timers.
Definition: MSContext.cpp:760
bool IsPaused() const
Whenever the context is paused.
Definition: MSContext.cpp:358
void SetRecordPath(const QString &record_path)
Set the path of the record directory.
Definition: MSContext.cpp:308
QString GetDefaultDebugItems() const
Get default active debug items.
Definition: MSContext.cpp:278
QString DefaultDebugItems
Default active debugged items.
Definition: MSContext.hpp:555
Basic ancestor class of the elements.
Definition: MSElement.hpp:65
bool IsMalfunctionHappened() const
Whenever a malfunction happened in the context.
Definition: MSContext.cpp:370
static void ResumeTimers()
Resume the timers.
Definition: MSContext.cpp:772
static void StartTimer(const QString &id)
Start a timer.
Definition: MSContext.cpp:669
bool SessionPrepared
The heart beating is prepared.
Definition: MSContext.hpp:557
virtual void StartHeartBeating()
Start the heart beating.
Definition: MSContext.cpp:597
bool IsBeatingFinished() const
Whenever the heart beating is finished.
Definition: MSContext.cpp:364
void PlayedSessionFinished()
The played session is finished.
virtual void StopHeartBeating()
Stop the heart beating.
Definition: MSContext.cpp:623
QString GetRecordPath() const
Get the path of the record directory.
Definition: MSContext.cpp:302
virtual void Resume()
Resume the context.
Definition: MSContext.cpp:637
bool CPUProfiling
CPU profiling.
Definition: MSContext.hpp:553
ArgSearchResult FindArgument(const QString &arg, const QString &long_arg)
Find an argument.
Definition: MSContext.cpp:376
void UnregisterElement(MSElement &element)
Unregister an element.
Definition: MSContext.cpp:519
static int GetTimerElapsedTime(const QString &id)
Get the elapsed time of a timer.
Definition: MSContext.cpp:734
void NewHeartBeat(int beat_id)
New heart beat.
void RegisterSessionStorage(MSSessionStorageInterface &storage)
Register a session storage.
Definition: MSContext.cpp:485
int GetPlayedBeats() const
Get the played beats.
Definition: MSContext.cpp:340
static void ResetTimer(const QString &id)
Reset a timer.
Definition: MSContext.cpp:712
void SetMaxBeats(int max_beats)
Set the limit of the beats.
Definition: MSContext.cpp:334
virtual bool PrepareSession()
Prepare a session.
Definition: MSContext.cpp:553
void HeartStopped()
The heart has been stopped.
bool HasRegisteredElements() const
Has registered elements.
Definition: MSContext.cpp:352
void SetPlaybackPath(const QString &play_path)
Set the path of the play directory.
Definition: MSContext.cpp:296
virtual void FinishSession()
Finish a session.
Definition: MSContext.cpp:584
void SetBeatDurationLimit(int new_limit)
Set the beat duration limit.
Definition: MSContext.cpp:547
QString GetPlaybackPath() const
Get the path of the play directory.
Definition: MSContext.cpp:290
QList< MSElement * > RegElements
Elements to be registered by the heart beat.
Definition: MSContext.hpp:551
~MSContext()
Class destructor.
Definition: MSContext.cpp:227
void Stop()
Stop the activities in the context.
QStringList ProgramArguments
Command line arguments.
Definition: MSContext.hpp:549
MSContext(int &argc, char **argv, bool graphical_context=false)
Class constructor.
Definition: MSContext.cpp:163
void SetDefaultDebugItems(const QString &items)
Set default active debug items.
Definition: MSContext.cpp:284
virtual void Pause()
Pause the context.
Definition: MSContext.cpp:630
static void StopTimer(const QString &id)
Stop a timer.
Definition: MSContext.cpp:690
void RegisterElement(MSElement &element)
Register a new element.
Definition: MSContext.cpp:491
static MSContext * GetInstance()
Get a static instance of the class.
Definition: MSContext.cpp:268
int GetMaxBeats() const
Get the limit of the beats.
Definition: MSContext.cpp:328
const QString SessionRuntimeTimerName
Session runtime timer name.
Definition: MSContext.hpp:559