-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlogger.h
70 lines (53 loc) · 1.68 KB
/
logger.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef LOGGER_H
#define LOGGER_H
#include <QObject>
#include <QSqlDatabase>
#include <QThread>
#include <QDateTime>
#include <QVariantMap>
#include <QtGlobal>
class LoggerWorker;
class Database;
/// Log step counts and other events.
class Logger: public QObject {
Q_OBJECT
public:
static Logger *instance();
static void close();
/// Log step count, with optional tags.
Q_INVOKABLE void log(int steps, const QVariantMap &tags);
/// Upgrade old databases to current format
Q_INVOKABLE void upgrade();
protected:
explicit Logger(QObject *parent = 0);
virtual ~Logger();
LoggerWorker *worker;
QThread *workerThread;
};
/// Do the real logging work.
class LoggerWorker: public QObject {
Q_OBJECT
public:
explicit LoggerWorker(QObject *parent = 0);
~LoggerWorker();
public slots:
/// Log step count, with optional tags.
void log(int steps, const QVariantMap &tags);
/// Upgrade old databases to current format.
void upgrade();
protected slots:
/// Initialize database with schema.
void onAddSchema();
protected:
/// Insert a log entry into an existing database.
/// If logging was successful, set lastInsertId to the last record ID and totalSteps to steps.
void insertLog(int steps, const QVariantMap &tags);
/// Return database, create it if doesn't exist.
Database *db();
/// Upgrade "B" format database file to "C".
void upgradeDbToDc(const QString &srcName);
Database *database; ///< Database, created on demand.
int logCount; ///< The number of times log() has been called.
bool diskFull; ///< Was the disk full when we last checked.
};
#endif // LOGGER_H