fort/src/ui/db/databasemanager.h

64 lines
1.3 KiB
C
Raw Normal View History

2017-12-01 14:13:06 +00:00
#ifndef DATABASEMANAGER_H
#define DATABASEMANAGER_H
#include <QObject>
#include <QHash>
#include <QStringList>
#include <QVector>
class SqliteDb;
class SqliteStmt;
class DatabaseManager : public QObject
{
Q_OBJECT
public:
explicit DatabaseManager(const QString &filePath,
QObject *parent = nullptr);
virtual ~DatabaseManager();
bool initialize();
2017-12-02 08:09:41 +00:00
SqliteDb *sqliteDb() const { return m_sqliteDb; }
2017-12-05 05:06:15 +00:00
void addApp(const QString &appPath, bool &isNew);
void addTraffic(quint16 procCount, const quint8 *procBits,
const quint32 *trafBytes);
2017-12-05 12:50:10 +00:00
void getAppList(QStringList &list);
2017-12-01 14:13:06 +00:00
signals:
public slots:
private:
bool createTables();
2017-12-05 05:06:15 +00:00
qint64 getAppId(const QString &appPath, bool &isNew);
2017-12-01 14:13:06 +00:00
SqliteStmt *getSqliteStmt(const char *sql);
2017-12-04 13:55:03 +00:00
void insertTraffic(SqliteStmt *stmt, qint64 appId = 0);
void updateTraffic(SqliteStmt *stmt, quint32 inBytes,
quint32 outBytes, qint64 appId = 0);
static qint32 getUnixDay(qint64 unixTime);
static qint32 getUnixMonth(qint64 unixTime);
2017-12-01 14:13:06 +00:00
private:
2017-12-04 13:55:03 +00:00
qint32 m_lastUnixHour;
qint32 m_lastUnixDay;
qint32 m_lastUnixMonth;
2017-12-01 14:13:06 +00:00
QString m_filePath;
SqliteDb *m_sqliteDb;
QHash<const char *, SqliteStmt *> m_sqliteStmts;
QVector<qint64> m_appIds;
};
#endif // DATABASEMANAGER_H