fort/src/ui/db/databasemanager.h

90 lines
2.2 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>
2017-12-11 06:05:49 +00:00
QT_FORWARD_DECLARE_CLASS(FirewallConf)
2017-12-06 02:51:40 +00:00
QT_FORWARD_DECLARE_CLASS(SqliteDb)
QT_FORWARD_DECLARE_CLASS(SqliteStmt)
2017-12-01 14:13:06 +00:00
class DatabaseManager : public QObject
{
Q_OBJECT
public:
explicit DatabaseManager(const QString &filePath,
QObject *parent = nullptr);
virtual ~DatabaseManager();
2017-12-11 06:05:49 +00:00
const FirewallConf *firewallConf() const { return m_conf; }
void setFirewallConf(const FirewallConf *conf);
2017-12-01 14:13:06 +00:00
2017-12-02 08:09:41 +00:00
SqliteDb *sqliteDb() const { return m_sqliteDb; }
2017-12-11 06:05:49 +00:00
bool initialize();
qint64 logProcNew(const QString &appPath, bool &isNew);
2017-12-08 02:38:02 +00:00
void logStatTraf(quint16 procCount, const quint8 *procBits,
const quint32 *trafBytes);
void logClear();
2017-12-05 05:06:15 +00:00
2017-12-08 02:38:02 +00:00
void getAppList(QStringList &list, QVector<qint64> &appIds);
2017-12-01 14:13:06 +00:00
2017-12-06 13:40:58 +00:00
qint64 getAppId(const QString &appPath);
2017-12-08 07:18:37 +00:00
qint32 getTrafficTime(const char *sql, qint64 appId = 0);
2017-12-01 14:13:06 +00:00
2017-12-08 07:18:37 +00:00
void getTraffic(const char *sql, qint32 trafTime,
qint64 &inBytes, qint64 &outBytes,
qint64 appId = 0);
signals:
public slots:
void clear();
2017-12-01 14:13:06 +00:00
private:
2017-12-09 09:38:32 +00:00
typedef QList<SqliteStmt *> QStmtList;
2017-12-01 14:13:06 +00:00
bool createTables();
void clearStmts();
2017-12-06 13:40:58 +00:00
qint64 createAppId(const QString &appPath);
2017-12-01 14:13:06 +00:00
2017-12-09 09:38:32 +00:00
void updateTrafficList(const QStmtList &insertStmtList,
const QStmtList &updateStmtList,
quint32 inBytes, quint32 outBytes,
qint64 appId = 0);
2017-12-01 14:13:06 +00:00
2017-12-09 09:38:32 +00:00
bool updateTraffic(SqliteStmt *stmt, quint32 inBytes,
2017-12-06 09:45:31 +00:00
quint32 outBytes, qint64 appId = 0);
2017-12-04 13:55:03 +00:00
2017-12-11 06:05:49 +00:00
void deleteTrafficList(const QStmtList &deleteStmtList);
2017-12-09 09:38:32 +00:00
SqliteStmt *getTrafficStmt(const char *sql, qint32 trafTime);
SqliteStmt *getSqliteStmt(const char *sql);
2017-12-01 14:13:06 +00:00
private:
2017-12-06 09:45:31 +00:00
qint32 m_lastTrafHour;
qint32 m_lastTrafDay;
qint32 m_lastTrafMonth;
2017-12-04 13:55:03 +00:00
2017-12-01 14:13:06 +00:00
QString m_filePath;
2017-12-11 06:05:49 +00:00
const FirewallConf *m_conf;
2017-12-01 14:13:06 +00:00
SqliteDb *m_sqliteDb;
QHash<const char *, SqliteStmt *> m_sqliteStmts;
2017-12-08 02:38:02 +00:00
QStringList m_appPaths;
2017-12-01 14:13:06 +00:00
QVector<qint64> m_appIds;
};
#endif // DATABASEMANAGER_H