arcsgenerallogger.h
1 /*
2  name: include/arcs/arcsgenerallogger.h
3 
4  This file is part of ARCS - Augmented Reality Component System
5  (version 2-current), written by Jean-Yves Didier
6  for IBISC Laboratory (http://www.ibisc.univ-evry.fr)
7 
8  Copyright (C) 2013 Université d'Evry-Val d'Essonne
9 
10  This program is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 2 of the License, or
13  (at your option) any later version.
14 
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with this program. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Please send bugreports with examples or suggestions to
25  jean-yves.didier__at__ibisc.univ-evry.fr
26 */
27 
28 
29 #ifndef __ARCSGENERALLOGGER_H__
30 #define __ARCSGENERALLOGGER_H__
31 
32 #include <arcs/arcsqdynamicobject.h>
33 #include <QObject>
34 #include <QMutex>
35 #include <QMap>
36 #include <QList>
37 #include <QMetaType>
38 #include <iostream>
39 #include <fstream>
40 
41 
43 
47 class ARCSGeneralLoggerBase : public QObject
48 {
49  Q_OBJECT
50 
51 public:
52  ARCSGeneralLoggerBase(QObject* parent= 0) : QObject(parent) { separator = " "; }
53  ~ARCSGeneralLoggerBase() { if (logFile.is_open() ) logFile.close(); }
54 
55 public slots:
56  void setFilename(QString s);
57  void setSeparator(QString sep) { separator = sep; }
58  void endLine() { logFile << std::endl; }
59 
60 protected:
61  bool canLog();
62  std::ofstream logFile;
63  QString separator;
64 };
65 
67 
72 {
73 public:
74  ARCSGeneralLogger(QObject* parent=0) ;
75  virtual ~ARCSGeneralLogger() {}
76 
77  virtual int qt_metacall(QMetaObject::Call call, int id, void ** arguments);
78  virtual QStringList getSignalList() ;
79  virtual QStringList getSlotList() ;
80  virtual int prepareSlotConnect(QString sigName, QString sltName, QString objectName = QString::null, QString actualSignal = QString::null, bool simulate = false) ;
81  virtual int prepareSignalConnect(QString sigName, QString sltName, QString objectName = QString::null, QString actualSlot = QString::null, bool simulate = false);
82  virtual int cleanSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal);
83  virtual int cleanSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot);
84 
85 private:
86  class LogDetails
87  {
88  public:
89  LogDetails(const LogDetails& ld);
90  LogDetails(QString sn = QString::null);
91 
92  void addType(int id) { typeIds.append(id); }
93  int count() { return typeIds.count(); }
94 
95  QString getSignature() { return signature; }
96 
97  int getArgument(int i)
98  {
99  int id = QMetaType::Void;
100  if (i < count())
101  {
102  id = typeIds[i];
103  }
104  return id;
105  }
106 
107  private:
108  QString signature;
109  QList<int> typeIds;
110  };
111 
112 
113  QMutex mutex;
114  int idx;
115 
116  QMap<QString, int> map; // this should map a signal to a an integer, which is a slot.
117  QMap<int, LogDetails> invertMap;
118 };
119 
120 
121 
122 
123 #endif // __ARCSGENERALLOGGER_H__
virtual int prepareSlotConnect(QString sigName, QString sltName, QString objectName=QString::null, QString actualSignal=QString::null, bool simulate=false)
Prepares a connection with a slot which is belonging to this object.
General purpose logging component.
virtual QStringList getSignalList()
virtual int cleanSlotConnect(QString sigName, QString sltName, QString objectName, QString actualSignal)
virtual int qt_metacall(QMetaObject::Call call, int id, void **arguments)
Method performing the actual callback task.
virtual QStringList getSlotList()
Interface to extend QObject functionnalities in order to make objects with dynamic signals or slots...
virtual int prepareSignalConnect(QString sigName, QString sltName, QString objectName=QString::null, QString actualSlot=QString::null, bool simulate=false)
Prepares a connection with a slot which does not belong to this object.
virtual int cleanSignalConnect(QString sigName, QString sltName, QString objectName, QString actualSlot)
Base class for ARCSGeneralLogger.