mirror of
https://github.com/tnodir/fort
synced 2024-11-15 08:25:20 +00:00
UI: Rename Database* to Stat*.
This commit is contained in:
parent
0c3e83f808
commit
66e7c88448
@ -2,8 +2,8 @@ TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS = \
|
||||
confutil \
|
||||
db \
|
||||
fileutil \
|
||||
logbuffer \
|
||||
logreader \
|
||||
netutil
|
||||
netutil \
|
||||
stat
|
||||
|
@ -6,11 +6,11 @@ SOURCES += \
|
||||
$$UIPATH/conf/addressgroup.cpp \
|
||||
$$UIPATH/conf/appgroup.cpp \
|
||||
$$UIPATH/conf/firewallconf.cpp \
|
||||
$$UIPATH/db/databasemanager.cpp \
|
||||
$$UIPATH/db/databasesql.cpp \
|
||||
$$UIPATH/db/quotamanager.cpp \
|
||||
$$UIPATH/fortcommon.cpp \
|
||||
$$UIPATH/fortsettings.cpp \
|
||||
$$UIPATH/stat/quotamanager.cpp \
|
||||
$$UIPATH/stat/statmanager.cpp \
|
||||
$$UIPATH/stat/statsql.cpp \
|
||||
$$UIPATH/util/dateutil.cpp \
|
||||
$$UIPATH/util/fileutil.cpp \
|
||||
$$UIPATH/util/net/netutil.cpp \
|
||||
@ -21,11 +21,11 @@ HEADERS += \
|
||||
$$UIPATH/conf/addressgroup.h \
|
||||
$$UIPATH/conf/appgroup.h \
|
||||
$$UIPATH/conf/firewallconf.h \
|
||||
$$UIPATH/db/databasemanager.h \
|
||||
$$UIPATH/db/databasesql.h \
|
||||
$$UIPATH/db/quotamanager.h \
|
||||
$$UIPATH/fortcommon.h \
|
||||
$$UIPATH/fortsettings.h \
|
||||
$$UIPATH/stat/quotamanager.h \
|
||||
$$UIPATH/stat/statmanager.h \
|
||||
$$UIPATH/stat/statsql.h \
|
||||
$$UIPATH/util/dateutil.h \
|
||||
$$UIPATH/util/fileutil.h \
|
||||
$$UIPATH/util/net/netutil.h \
|
||||
@ -35,8 +35,8 @@ HEADERS += \
|
||||
# Test Data
|
||||
RESOURCES += data.qrc
|
||||
|
||||
# Database Migrations
|
||||
RESOURCES += $$UIPATH/db/db-migrations.qrc
|
||||
# Stat Migrations
|
||||
RESOURCES += $$UIPATH/stat/stat-migrations.qrc
|
||||
|
||||
# 3rd party integrations
|
||||
CONFIG += sqlite
|
@ -2,23 +2,24 @@
|
||||
|
||||
#include <QElapsedTimer>
|
||||
|
||||
#include "commontest.h"
|
||||
#include "db/databasemanager.h"
|
||||
#include "db/quotamanager.h"
|
||||
#include "fortsettings.h"
|
||||
#include "util/dateutil.h"
|
||||
#include "util/fileutil.h"
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
#include "commontest.h"
|
||||
#include "fortsettings.h"
|
||||
#include "stat/quotamanager.h"
|
||||
#include "stat/statmanager.h"
|
||||
#include "util/dateutil.h"
|
||||
#include "util/fileutil.h"
|
||||
|
||||
void Test::dbWriteRead()
|
||||
{
|
||||
QStringList args("test");
|
||||
FortSettings fortSettings(args);
|
||||
QuotaManager quotaManager(&fortSettings);
|
||||
DatabaseManager databaseManager(":memory:", "aManager);
|
||||
StatManager statManager(":memory:", "aManager);
|
||||
|
||||
QVERIFY(databaseManager.initialize());
|
||||
QVERIFY(statManager.initialize());
|
||||
|
||||
const QStringList appPaths = QStringList()
|
||||
<< "C:\\test\\test.exe"
|
||||
@ -30,11 +31,11 @@ void Test::dbWriteRead()
|
||||
|
||||
// Add apps
|
||||
quint32 index = 0;
|
||||
foreach (const QString &appPath, appPaths) {
|
||||
databaseManager.logProcNew(++index * 10, appPath);
|
||||
for (const QString &appPath : appPaths) {
|
||||
statManager.logProcNew(++index * 10, appPath);
|
||||
}
|
||||
|
||||
debugProcNew(databaseManager.sqliteDb());
|
||||
debugProcNew(statManager.sqliteDb());
|
||||
|
||||
QElapsedTimer timer;
|
||||
timer.start();
|
||||
@ -47,8 +48,8 @@ void Test::dbWriteRead()
|
||||
30, 500, 600
|
||||
};
|
||||
|
||||
databaseManager.logStatTraf(procCount, trafBytes);
|
||||
databaseManager.logStatTraf(procCount, trafBytes);
|
||||
statManager.logStatTraf(procCount, trafBytes);
|
||||
statManager.logStatTraf(procCount, trafBytes);
|
||||
}
|
||||
|
||||
qDebug() << "elapsed>" << timer.restart() << "msec";
|
||||
@ -61,12 +62,12 @@ void Test::dbWriteRead()
|
||||
31, 50, 60
|
||||
};
|
||||
|
||||
databaseManager.logStatTraf(procCount, trafBytes);
|
||||
statManager.logStatTraf(procCount, trafBytes);
|
||||
}
|
||||
|
||||
qDebug() << "elapsed>" << timer.elapsed() << "msec";
|
||||
|
||||
debugStatTraf(databaseManager.sqliteDb());
|
||||
debugStatTraf(statManager.sqliteDb());
|
||||
}
|
||||
|
||||
void Test::debugProcNew(SqliteDb *sqliteDb)
|
2
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
2
src/ui/3rdparty/sqlite/sqlitedb.cpp
vendored
@ -338,7 +338,7 @@ bool SqliteDb::migrate(const QString &sqlDir, int version,
|
||||
|
||||
QFile file(filePath);
|
||||
if (!file.exists())
|
||||
break;
|
||||
continue;
|
||||
|
||||
if (!file.open(QFile::ReadOnly | QFile::Text)) {
|
||||
qWarning() << "SQLite: Cannot open migration file" << filePath
|
||||
|
@ -16,9 +16,6 @@ SOURCES += \
|
||||
conf/firewallconf.cpp \
|
||||
control/controlmanager.cpp \
|
||||
control/controlworker.cpp \
|
||||
db/databasemanager.cpp \
|
||||
db/databasesql.cpp \
|
||||
db/quotamanager.cpp \
|
||||
driver/drivermanager.cpp \
|
||||
driver/driverworker.cpp \
|
||||
fortcommon.cpp \
|
||||
@ -40,6 +37,9 @@ SOURCES += \
|
||||
log/model/stringlistmodel.cpp \
|
||||
log/model/traflistmodel.cpp \
|
||||
mainwindow.cpp \
|
||||
stat/quotamanager.cpp \
|
||||
stat/statmanager.cpp \
|
||||
stat/statsql.cpp \
|
||||
task/taskdownloader.cpp \
|
||||
task/taskinfo.cpp \
|
||||
task/taskmanager.cpp \
|
||||
@ -87,9 +87,6 @@ HEADERS += \
|
||||
conf/firewallconf.h \
|
||||
control/controlmanager.h \
|
||||
control/controlworker.h \
|
||||
db/databasemanager.h \
|
||||
db/databasesql.h \
|
||||
db/quotamanager.h \
|
||||
driver/drivermanager.h \
|
||||
driver/driverworker.h \
|
||||
fortcommon.h \
|
||||
@ -111,6 +108,9 @@ HEADERS += \
|
||||
log/model/stringlistmodel.h \
|
||||
log/model/traflistmodel.h \
|
||||
mainwindow.h \
|
||||
stat/quotamanager.h \
|
||||
stat/statmanager.h \
|
||||
stat/statsql.h \
|
||||
task/taskdownloader.h \
|
||||
task/taskinfo.h \
|
||||
task/taskmanager.h \
|
||||
@ -175,11 +175,11 @@ RESOURCES += fort_images.qrc
|
||||
|
||||
# Database Migrations
|
||||
OTHER_FILES += \
|
||||
db/migrations/*.sql \
|
||||
stat/migrations/*.sql \
|
||||
util/app/migrations/*.sql
|
||||
|
||||
RESOURCES += \
|
||||
db/db-migrations.qrc \
|
||||
stat/stat-migrations.qrc \
|
||||
util/app/app-migrations.qrc
|
||||
|
||||
# Shadow Build: Copy i18n/ to build path
|
||||
|
@ -1 +0,0 @@
|
||||
PRAGMA user_version = 2;
|
@ -15,8 +15,6 @@
|
||||
#include "conf/addressgroup.h"
|
||||
#include "conf/appgroup.h"
|
||||
#include "conf/firewallconf.h"
|
||||
#include "db/databasemanager.h"
|
||||
#include "db/quotamanager.h"
|
||||
#include "driver/drivermanager.h"
|
||||
#include "fortsettings.h"
|
||||
#include "graph/graphwindow.h"
|
||||
@ -25,6 +23,8 @@
|
||||
#include "log/model/appstatmodel.h"
|
||||
#include "log/model/iplistmodel.h"
|
||||
#include "log/model/traflistmodel.h"
|
||||
#include "stat/quotamanager.h"
|
||||
#include "stat/statmanager.h"
|
||||
#include "task/taskinfo.h"
|
||||
#include "task/taskmanager.h"
|
||||
#include "translationmanager.h"
|
||||
@ -61,10 +61,10 @@ FortManager::FortManager(FortSettings *fortSettings,
|
||||
m_stopTrafficAction(nullptr),
|
||||
m_stopInetTrafficAction(nullptr),
|
||||
m_quotaManager(new QuotaManager(fortSettings, this)),
|
||||
m_databaseManager(new DatabaseManager(fortSettings->statFilePath(),
|
||||
m_quotaManager, this)),
|
||||
m_statManager(new StatManager(fortSettings->statFilePath(),
|
||||
m_quotaManager, this)),
|
||||
m_driverManager(new DriverManager(this)),
|
||||
m_logManager(new LogManager(m_databaseManager,
|
||||
m_logManager(new LogManager(m_statManager,
|
||||
m_driverManager->driverWorker(), this)),
|
||||
m_nativeEventFilter(new NativeEventFilter(this)),
|
||||
m_hotKeyManager(new HotKeyManager(m_nativeEventFilter, this)),
|
||||
@ -75,7 +75,7 @@ FortManager::FortManager(FortSettings *fortSettings,
|
||||
|
||||
setupLogger();
|
||||
setupAppInfoCache();
|
||||
setupDatabaseManager();
|
||||
setupStatManager();
|
||||
|
||||
setupLogManager();
|
||||
setupDriver();
|
||||
@ -179,7 +179,7 @@ bool FortManager::setupDriver()
|
||||
void FortManager::closeDriver()
|
||||
{
|
||||
updateLogManager(false);
|
||||
updateDatabaseManager(nullptr);
|
||||
updateStatManager(nullptr);
|
||||
|
||||
m_driverManager->closeDevice();
|
||||
}
|
||||
@ -194,9 +194,9 @@ void FortManager::closeLogManager()
|
||||
m_logManager->close();
|
||||
}
|
||||
|
||||
void FortManager::setupDatabaseManager()
|
||||
void FortManager::setupStatManager()
|
||||
{
|
||||
m_databaseManager->initialize();
|
||||
m_statManager->initialize();
|
||||
|
||||
connect(m_quotaManager, &QuotaManager::alert,
|
||||
this, &FortManager::showInfoBox);
|
||||
@ -377,7 +377,7 @@ void FortManager::showGraphWindow()
|
||||
connect(m_graphWindow, &GraphWindow::mouseRightClick,
|
||||
this, &FortManager::showTrayMenu);
|
||||
|
||||
connect(m_databaseManager, &DatabaseManager::trafficAdded,
|
||||
connect(m_statManager, &StatManager::trafficAdded,
|
||||
m_graphWindow, &GraphWindow::addTraffic);
|
||||
}
|
||||
|
||||
@ -563,7 +563,7 @@ bool FortManager::updateDriverConf(FirewallConf *conf, bool onlyFlags)
|
||||
: m_driverManager->writeConf(*conf);
|
||||
|
||||
if (res) {
|
||||
updateDatabaseManager(conf);
|
||||
updateStatManager(conf);
|
||||
updateLogManager(true);
|
||||
} else {
|
||||
closeDriver();
|
||||
@ -577,9 +577,9 @@ void FortManager::updateLogManager(bool active)
|
||||
m_logManager->setActive(active);
|
||||
}
|
||||
|
||||
void FortManager::updateDatabaseManager(FirewallConf *conf)
|
||||
void FortManager::updateStatManager(FirewallConf *conf)
|
||||
{
|
||||
m_databaseManager->setFirewallConf(conf);
|
||||
m_statManager->setFirewallConf(conf);
|
||||
}
|
||||
|
||||
void FortManager::setLanguage(int language)
|
||||
|
@ -10,7 +10,6 @@ QT_FORWARD_DECLARE_CLASS(QQmlApplicationEngine)
|
||||
QT_FORWARD_DECLARE_CLASS(QSystemTrayIcon)
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(AppInfoCache)
|
||||
QT_FORWARD_DECLARE_CLASS(DatabaseManager)
|
||||
QT_FORWARD_DECLARE_CLASS(DriverManager)
|
||||
QT_FORWARD_DECLARE_CLASS(FirewallConf)
|
||||
QT_FORWARD_DECLARE_CLASS(FortSettings)
|
||||
@ -19,6 +18,7 @@ QT_FORWARD_DECLARE_CLASS(HotKeyManager)
|
||||
QT_FORWARD_DECLARE_CLASS(LogManager)
|
||||
QT_FORWARD_DECLARE_CLASS(NativeEventFilter)
|
||||
QT_FORWARD_DECLARE_CLASS(QuotaManager)
|
||||
QT_FORWARD_DECLARE_CLASS(StatManager)
|
||||
QT_FORWARD_DECLARE_CLASS(TaskManager)
|
||||
QT_FORWARD_DECLARE_CLASS(WidgetWindowStateWatcher)
|
||||
QT_FORWARD_DECLARE_CLASS(WindowStateWatcher)
|
||||
@ -107,7 +107,7 @@ private:
|
||||
void setupLogManager();
|
||||
void closeLogManager();
|
||||
|
||||
void setupDatabaseManager();
|
||||
void setupStatManager();
|
||||
|
||||
void setupLogger();
|
||||
|
||||
@ -129,7 +129,7 @@ private:
|
||||
bool updateDriverConf(FirewallConf *conf, bool onlyFlags = false);
|
||||
|
||||
void updateLogManager(bool active);
|
||||
void updateDatabaseManager(FirewallConf *conf);
|
||||
void updateStatManager(FirewallConf *conf);
|
||||
|
||||
FirewallConf *cloneConf(const FirewallConf &conf);
|
||||
|
||||
@ -176,7 +176,7 @@ private:
|
||||
QList<QAction *> m_appGroupActions;
|
||||
|
||||
QuotaManager *m_quotaManager;
|
||||
DatabaseManager *m_databaseManager;
|
||||
StatManager *m_statManager;
|
||||
DriverManager *m_driverManager;
|
||||
LogManager *m_logManager;
|
||||
NativeEventFilter *m_nativeEventFilter;
|
||||
|
@ -145,17 +145,17 @@
|
||||
<context>
|
||||
<name>QuotaManager</name>
|
||||
<message>
|
||||
<location filename="../db/quotamanager.cpp" line="86"/>
|
||||
<location filename="../stat/quotamanager.cpp" line="86"/>
|
||||
<source>Day traffic quota exceeded!</source>
|
||||
<translation>Квота трафика на день исчерпана!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../db/quotamanager.cpp" line="105"/>
|
||||
<location filename="../stat/quotamanager.cpp" line="105"/>
|
||||
<source>Month traffic quota exceeded!</source>
|
||||
<translation>Квота трафика на месяц исчерпана!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="../db/quotamanager.h" line="30"/>
|
||||
<location filename="../stat/quotamanager.h" line="30"/>
|
||||
<source>Quota Alert</source>
|
||||
<translation>Предупреждение о квоте трафика</translation>
|
||||
</message>
|
||||
|
@ -13,14 +13,14 @@
|
||||
#include "model/appblockedmodel.h"
|
||||
#include "model/appstatmodel.h"
|
||||
|
||||
LogManager::LogManager(DatabaseManager *databaseManager,
|
||||
LogManager::LogManager(StatManager *statManager,
|
||||
DriverWorker *driverWorker,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_active(false),
|
||||
m_driverWorker(driverWorker),
|
||||
m_appBlockedModel(new AppBlockedModel(this)),
|
||||
m_appStatModel(new AppStatModel(databaseManager, this))
|
||||
m_appStatModel(new AppStatModel(statManager, this))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(AppBlockedModel)
|
||||
QT_FORWARD_DECLARE_CLASS(AppStatModel)
|
||||
QT_FORWARD_DECLARE_CLASS(DatabaseManager)
|
||||
QT_FORWARD_DECLARE_CLASS(StatManager)
|
||||
QT_FORWARD_DECLARE_CLASS(DriverWorker)
|
||||
QT_FORWARD_DECLARE_CLASS(LogBuffer)
|
||||
QT_FORWARD_DECLARE_CLASS(LogEntry)
|
||||
@ -18,7 +18,7 @@ class LogManager : public QObject
|
||||
Q_PROPERTY(QString errorMessage READ errorMessage NOTIFY errorMessageChanged)
|
||||
|
||||
public:
|
||||
explicit LogManager(DatabaseManager *databaseManager,
|
||||
explicit LogManager(StatManager *statManager,
|
||||
DriverWorker *driverWorker,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
#include "appstatmodel.h"
|
||||
|
||||
#include "../../db/databasemanager.h"
|
||||
#include "../../stat/statmanager.h"
|
||||
#include "../logentryprocnew.h"
|
||||
#include "../logentrystattraf.h"
|
||||
#include "traflistmodel.h"
|
||||
|
||||
AppStatModel::AppStatModel(DatabaseManager *databaseManager,
|
||||
AppStatModel::AppStatModel(StatManager *statManager,
|
||||
QObject *parent) :
|
||||
StringListModel(parent),
|
||||
m_databaseManager(databaseManager),
|
||||
m_trafListModel(new TrafListModel(databaseManager, this))
|
||||
m_statManager(statManager),
|
||||
m_trafListModel(new TrafListModel(statManager, this))
|
||||
{
|
||||
connect(m_databaseManager, &DatabaseManager::appCreated,
|
||||
connect(m_statManager, &StatManager::appCreated,
|
||||
this, &AppStatModel::handleCreatedApp);
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ void AppStatModel::remove(int row)
|
||||
|
||||
const qint64 appId = m_appIds.at(row);
|
||||
|
||||
m_databaseManager->deleteApp(appId);
|
||||
m_statManager->deleteApp(appId);
|
||||
|
||||
m_appIds.remove(row);
|
||||
|
||||
@ -65,7 +65,7 @@ void AppStatModel::updateList()
|
||||
m_appIds.clear();
|
||||
m_appIds.append(0); // All
|
||||
|
||||
m_databaseManager->getAppList(list, m_appIds);
|
||||
m_statManager->getAppList(list, m_appIds);
|
||||
|
||||
setList(list);
|
||||
}
|
||||
@ -78,12 +78,12 @@ void AppStatModel::handleCreatedApp(qint64 appId, const QString &appPath)
|
||||
|
||||
void AppStatModel::handleProcNew(const LogEntryProcNew &procNewEntry)
|
||||
{
|
||||
m_databaseManager->logProcNew(procNewEntry.pid(),
|
||||
procNewEntry.path());
|
||||
m_statManager->logProcNew(procNewEntry.pid(),
|
||||
procNewEntry.path());
|
||||
}
|
||||
|
||||
void AppStatModel::handleStatTraf(const LogEntryStatTraf &statTrafEntry)
|
||||
{
|
||||
m_databaseManager->logStatTraf(statTrafEntry.procCount(),
|
||||
statTrafEntry.procTrafBytes());
|
||||
m_statManager->logStatTraf(statTrafEntry.procCount(),
|
||||
statTrafEntry.procTrafBytes());
|
||||
}
|
||||
|
@ -3,9 +3,9 @@
|
||||
|
||||
#include "stringlistmodel.h"
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(DatabaseManager)
|
||||
QT_FORWARD_DECLARE_CLASS(LogEntryProcNew)
|
||||
QT_FORWARD_DECLARE_CLASS(LogEntryStatTraf)
|
||||
QT_FORWARD_DECLARE_CLASS(StatManager)
|
||||
QT_FORWARD_DECLARE_CLASS(TrafListModel)
|
||||
|
||||
class AppStatModel : public StringListModel
|
||||
@ -13,7 +13,7 @@ class AppStatModel : public StringListModel
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit AppStatModel(DatabaseManager *databaseManager,
|
||||
explicit AppStatModel(StatManager *statManager,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
void initialize();
|
||||
@ -38,8 +38,7 @@ private:
|
||||
void updateList();
|
||||
|
||||
private:
|
||||
DatabaseManager *m_databaseManager;
|
||||
|
||||
StatManager *m_statManager;
|
||||
TrafListModel *m_trafListModel;
|
||||
|
||||
QVector<qint64> m_appIds;
|
||||
|
@ -3,12 +3,12 @@
|
||||
#include <QLocale>
|
||||
|
||||
#include "../../conf/firewallconf.h"
|
||||
#include "../../db/databasemanager.h"
|
||||
#include "../../db/databasesql.h"
|
||||
#include "../../stat/statmanager.h"
|
||||
#include "../../stat/statsql.h"
|
||||
#include "../../util/dateutil.h"
|
||||
#include "../../util/net/netutil.h"
|
||||
|
||||
TrafListModel::TrafListModel(DatabaseManager *databaseManager,
|
||||
TrafListModel::TrafListModel(StatManager *statManager,
|
||||
QObject *parent) :
|
||||
QAbstractItemModel(parent),
|
||||
m_isEmpty(false),
|
||||
@ -17,7 +17,7 @@ TrafListModel::TrafListModel(DatabaseManager *databaseManager,
|
||||
m_minTrafTime(0),
|
||||
m_maxTrafTime(0),
|
||||
m_trafCount(0),
|
||||
m_databaseManager(databaseManager)
|
||||
m_statManager(statManager)
|
||||
{
|
||||
}
|
||||
|
||||
@ -98,14 +98,14 @@ Qt::ItemFlags TrafListModel::flags(const QModelIndex &index) const
|
||||
|
||||
void TrafListModel::clear()
|
||||
{
|
||||
m_databaseManager->clear();
|
||||
m_statManager->clear();
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void TrafListModel::resetAppTotals()
|
||||
{
|
||||
m_databaseManager->resetAppTotals();
|
||||
m_statManager->resetAppTotals();
|
||||
|
||||
reset();
|
||||
}
|
||||
@ -116,8 +116,7 @@ void TrafListModel::reset()
|
||||
|
||||
beginResetModel();
|
||||
|
||||
m_minTrafTime = m_databaseManager->getTrafficTime(
|
||||
sqlMinTrafTime, m_appId);
|
||||
m_minTrafTime = m_statManager->getTrafficTime(sqlMinTrafTime, m_appId);
|
||||
|
||||
m_maxTrafTime = getMaxTrafTime(m_type);
|
||||
|
||||
@ -157,10 +156,9 @@ void TrafListModel::updateRowCache(int row) const
|
||||
|
||||
const char *sqlSelectTraffic = getSqlSelectTraffic(m_type, m_appId);
|
||||
|
||||
m_databaseManager->getTraffic(
|
||||
sqlSelectTraffic, m_rowCache.trafTime,
|
||||
m_rowCache.inBytes, m_rowCache.outBytes,
|
||||
m_appId);
|
||||
m_statManager->getTraffic(sqlSelectTraffic, m_rowCache.trafTime,
|
||||
m_rowCache.inBytes, m_rowCache.outBytes,
|
||||
m_appId);
|
||||
}
|
||||
|
||||
QString TrafListModel::formatTrafUnit(qint64 bytes) const
|
||||
@ -178,7 +176,7 @@ QString TrafListModel::formatTrafUnit(qint64 bytes) const
|
||||
return QLatin1String("0");
|
||||
}
|
||||
|
||||
const FirewallConf *conf = m_databaseManager->firewallConf();
|
||||
const FirewallConf *conf = m_statManager->firewallConf();
|
||||
const int trafUnit = conf ? conf->trafUnit() : 0;
|
||||
const int trafPrec = (trafUnit == FirewallConf::UnitBytes) ? 0 : 2;
|
||||
|
||||
@ -255,14 +253,14 @@ qint32 TrafListModel::getMaxTrafTime(TrafType type)
|
||||
const char *TrafListModel::getSqlMinTrafTime(TrafType type, qint64 appId)
|
||||
{
|
||||
switch (type) {
|
||||
case TrafHourly: return appId ? DatabaseSql::sqlSelectMinTrafAppHour
|
||||
: DatabaseSql::sqlSelectMinTrafHour;
|
||||
case TrafDaily: return appId ? DatabaseSql::sqlSelectMinTrafAppDay
|
||||
: DatabaseSql::sqlSelectMinTrafDay;
|
||||
case TrafMonthly: return appId ? DatabaseSql::sqlSelectMinTrafAppMonth
|
||||
: DatabaseSql::sqlSelectMinTrafMonth;
|
||||
case TrafTotal: return appId ? DatabaseSql::sqlSelectMinTrafAppTotal
|
||||
: DatabaseSql::sqlSelectMinTrafTotal;
|
||||
case TrafHourly: return appId ? StatSql::sqlSelectMinTrafAppHour
|
||||
: StatSql::sqlSelectMinTrafHour;
|
||||
case TrafDaily: return appId ? StatSql::sqlSelectMinTrafAppDay
|
||||
: StatSql::sqlSelectMinTrafDay;
|
||||
case TrafMonthly: return appId ? StatSql::sqlSelectMinTrafAppMonth
|
||||
: StatSql::sqlSelectMinTrafMonth;
|
||||
case TrafTotal: return appId ? StatSql::sqlSelectMinTrafAppTotal
|
||||
: StatSql::sqlSelectMinTrafTotal;
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
@ -272,14 +270,14 @@ const char *TrafListModel::getSqlMinTrafTime(TrafType type, qint64 appId)
|
||||
const char *TrafListModel::getSqlSelectTraffic(TrafType type, qint64 appId)
|
||||
{
|
||||
switch (type) {
|
||||
case TrafHourly: return appId ? DatabaseSql::sqlSelectTrafAppHour
|
||||
: DatabaseSql::sqlSelectTrafHour;
|
||||
case TrafDaily: return appId ? DatabaseSql::sqlSelectTrafAppDay
|
||||
: DatabaseSql::sqlSelectTrafDay;
|
||||
case TrafMonthly: return appId ? DatabaseSql::sqlSelectTrafAppMonth
|
||||
: DatabaseSql::sqlSelectTrafMonth;
|
||||
case TrafTotal: return appId ? DatabaseSql::sqlSelectTrafAppTotal
|
||||
: DatabaseSql::sqlSelectTrafTotal;
|
||||
case TrafHourly: return appId ? StatSql::sqlSelectTrafAppHour
|
||||
: StatSql::sqlSelectTrafHour;
|
||||
case TrafDaily: return appId ? StatSql::sqlSelectTrafAppDay
|
||||
: StatSql::sqlSelectTrafDay;
|
||||
case TrafMonthly: return appId ? StatSql::sqlSelectTrafAppMonth
|
||||
: StatSql::sqlSelectTrafMonth;
|
||||
case TrafTotal: return appId ? StatSql::sqlSelectTrafAppTotal
|
||||
: StatSql::sqlSelectTrafTotal;
|
||||
}
|
||||
|
||||
Q_UNREACHABLE();
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(DatabaseManager)
|
||||
QT_FORWARD_DECLARE_CLASS(StatManager)
|
||||
|
||||
struct TrafficRow {
|
||||
bool isValid(int row) const { return row == this->row; }
|
||||
@ -28,7 +28,7 @@ public:
|
||||
};
|
||||
Q_ENUM(TrafType)
|
||||
|
||||
explicit TrafListModel(DatabaseManager *databaseManager,
|
||||
explicit TrafListModel(StatManager *statManager,
|
||||
QObject *parent = nullptr);
|
||||
|
||||
TrafListModel::TrafType type() const { return m_type; }
|
||||
@ -90,7 +90,7 @@ private:
|
||||
|
||||
mutable TrafficRow m_rowCache;
|
||||
|
||||
DatabaseManager *m_databaseManager;
|
||||
StatManager *m_statManager;
|
||||
};
|
||||
|
||||
#endif // TRAFLISTMODEL_H
|
||||
|
@ -1,6 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/db">
|
||||
<qresource prefix="/stat">
|
||||
<file>migrations/1.sql</file>
|
||||
<file>migrations/2.sql</file>
|
||||
</qresource>
|
||||
</RCC>
|
@ -1,19 +1,20 @@
|
||||
#include "databasemanager.h"
|
||||
#include "statmanager.h"
|
||||
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
#include "../conf/firewallconf.h"
|
||||
#include "../fortcommon.h"
|
||||
#include "../util/dateutil.h"
|
||||
#include "../util/fileutil.h"
|
||||
#include "../util/osutil.h"
|
||||
#include "databasesql.h"
|
||||
#include "quotamanager.h"
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
#include "statsql.h"
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(CLOG_DATABASE_MANAGER)
|
||||
Q_LOGGING_CATEGORY(CLOG_DATABASE_MANAGER, "fort.databaseManager")
|
||||
Q_DECLARE_LOGGING_CATEGORY(CLOG_STAT_MANAGER)
|
||||
Q_LOGGING_CATEGORY(CLOG_STAT_MANAGER, "fort.statManager")
|
||||
|
||||
#define DATABASE_USER_VERSION 2
|
||||
|
||||
@ -51,9 +52,9 @@ bool migrateFunc(SqliteDb *db, int version, void *ctx)
|
||||
|
||||
}
|
||||
|
||||
DatabaseManager::DatabaseManager(const QString &filePath,
|
||||
QuotaManager *quotaManager,
|
||||
QObject *parent) :
|
||||
StatManager::StatManager(const QString &filePath,
|
||||
QuotaManager *quotaManager,
|
||||
QObject *parent) :
|
||||
QObject(parent),
|
||||
m_isActivePeriodSet(false),
|
||||
m_isActivePeriod(false),
|
||||
@ -73,14 +74,14 @@ DatabaseManager::DatabaseManager(const QString &filePath,
|
||||
{
|
||||
}
|
||||
|
||||
DatabaseManager::~DatabaseManager()
|
||||
StatManager::~StatManager()
|
||||
{
|
||||
clearStmts();
|
||||
|
||||
delete m_sqliteDb;
|
||||
}
|
||||
|
||||
void DatabaseManager::setFirewallConf(const FirewallConf *conf)
|
||||
void StatManager::setFirewallConf(const FirewallConf *conf)
|
||||
{
|
||||
m_conf = conf;
|
||||
|
||||
@ -92,29 +93,29 @@ void DatabaseManager::setFirewallConf(const FirewallConf *conf)
|
||||
initializeQuota();
|
||||
}
|
||||
|
||||
bool DatabaseManager::initialize()
|
||||
bool StatManager::initialize()
|
||||
{
|
||||
m_lastTrafHour = m_lastTrafDay = m_lastTrafMonth = 0;
|
||||
|
||||
if (!m_sqliteDb->open(m_filePath)) {
|
||||
qCritical(CLOG_DATABASE_MANAGER()) << "File open error:"
|
||||
<< m_filePath
|
||||
<< m_sqliteDb->errorMessage();
|
||||
qCritical(CLOG_STAT_MANAGER()) << "File open error:"
|
||||
<< m_filePath
|
||||
<< m_sqliteDb->errorMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
m_sqliteDb->execute(DatabaseSql::sqlPragmas);
|
||||
m_sqliteDb->execute(StatSql::sqlPragmas);
|
||||
|
||||
if (!m_sqliteDb->migrate(":/db/migrations", DATABASE_USER_VERSION,
|
||||
if (!m_sqliteDb->migrate(":/stat/migrations", DATABASE_USER_VERSION,
|
||||
false, &migrateFunc)) {
|
||||
qCritical(CLOG_DATABASE_MANAGER()) << "Migration error" << m_filePath;
|
||||
qCritical(CLOG_STAT_MANAGER()) << "Migration error" << m_filePath;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void DatabaseManager::initializeActivePeriod()
|
||||
void StatManager::initializeActivePeriod()
|
||||
{
|
||||
m_isActivePeriodSet = false;
|
||||
|
||||
@ -126,7 +127,7 @@ void DatabaseManager::initializeActivePeriod()
|
||||
activePeriodToHour, activePeriodToMinute);
|
||||
}
|
||||
|
||||
void DatabaseManager::initializeQuota()
|
||||
void StatManager::initializeQuota()
|
||||
{
|
||||
if (!m_conf) return;
|
||||
|
||||
@ -140,14 +141,14 @@ void DatabaseManager::initializeQuota()
|
||||
|
||||
qint64 inBytes, outBytes;
|
||||
|
||||
getTraffic(DatabaseSql::sqlSelectTrafDay, trafDay, inBytes, outBytes);
|
||||
getTraffic(StatSql::sqlSelectTrafDay, trafDay, inBytes, outBytes);
|
||||
m_quotaManager->setTrafDayBytes(inBytes);
|
||||
|
||||
getTraffic(DatabaseSql::sqlSelectTrafMonth, trafMonth, inBytes, outBytes);
|
||||
getTraffic(StatSql::sqlSelectTrafMonth, trafMonth, inBytes, outBytes);
|
||||
m_quotaManager->setTrafMonthBytes(inBytes);
|
||||
}
|
||||
|
||||
void DatabaseManager::clear()
|
||||
void StatManager::clear()
|
||||
{
|
||||
clearAppIds();
|
||||
clearStmts();
|
||||
@ -161,23 +162,23 @@ void DatabaseManager::clear()
|
||||
m_quotaManager->clear();
|
||||
}
|
||||
|
||||
void DatabaseManager::clearStmts()
|
||||
void StatManager::clearStmts()
|
||||
{
|
||||
qDeleteAll(m_sqliteStmts);
|
||||
m_sqliteStmts.clear();
|
||||
}
|
||||
|
||||
void DatabaseManager::replaceAppPathAt(int index, const QString &appPath)
|
||||
void StatManager::replaceAppPathAt(int index, const QString &appPath)
|
||||
{
|
||||
m_appPaths.replace(index, appPath);
|
||||
}
|
||||
|
||||
void DatabaseManager::replaceAppIdAt(int index, qint64 appId)
|
||||
void StatManager::replaceAppIdAt(int index, qint64 appId)
|
||||
{
|
||||
m_appIds.replace(index, appId);
|
||||
}
|
||||
|
||||
void DatabaseManager::clearAppId(qint64 appId)
|
||||
void StatManager::clearAppId(qint64 appId)
|
||||
{
|
||||
const int index = m_appIds.indexOf(appId);
|
||||
|
||||
@ -186,7 +187,7 @@ void DatabaseManager::clearAppId(qint64 appId)
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::clearAppIds()
|
||||
void StatManager::clearAppIds()
|
||||
{
|
||||
int index = m_appIds.size();
|
||||
|
||||
@ -195,7 +196,7 @@ void DatabaseManager::clearAppIds()
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::logClear()
|
||||
void StatManager::logClear()
|
||||
{
|
||||
m_appFreeIndex = INVALID_APP_INDEX;
|
||||
m_appFreeIndexes.clear();
|
||||
@ -204,7 +205,7 @@ void DatabaseManager::logClear()
|
||||
m_appIds.clear();
|
||||
}
|
||||
|
||||
void DatabaseManager::logClearApp(quint32 pid, int index)
|
||||
void StatManager::logClearApp(quint32 pid, int index)
|
||||
{
|
||||
m_appIndexes.remove(pid);
|
||||
|
||||
@ -223,7 +224,7 @@ void DatabaseManager::logClearApp(quint32 pid, int index)
|
||||
}
|
||||
}
|
||||
|
||||
void DatabaseManager::logProcNew(quint32 pid, const QString &appPath)
|
||||
void StatManager::logProcNew(quint32 pid, const QString &appPath)
|
||||
{
|
||||
Q_ASSERT(!m_appIndexes.contains(pid));
|
||||
|
||||
@ -257,7 +258,7 @@ void DatabaseManager::logProcNew(quint32 pid, const QString &appPath)
|
||||
m_appIndexes.insert(pid, procIndex);
|
||||
}
|
||||
|
||||
void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafBytes)
|
||||
void StatManager::logStatTraf(quint16 procCount, const quint32 *procTrafBytes)
|
||||
{
|
||||
if (!m_conf || !m_conf->logStat())
|
||||
return;
|
||||
@ -311,27 +312,27 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
|
||||
// Insert Statements
|
||||
const QStmtList insertTrafAppStmts = QStmtList()
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafAppHour, trafHour)
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafAppDay, trafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafAppMonth, trafMonth)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafAppTotal, -1);
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafAppHour, trafHour)
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafAppDay, trafDay)
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafAppMonth, trafMonth)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafAppTotal, -1);
|
||||
|
||||
const QStmtList insertTrafStmts = QStmtList()
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafHour, trafHour)
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafDay, trafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlInsertTrafMonth, trafMonth);
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafHour, trafHour)
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafDay, trafDay)
|
||||
<< getTrafficStmt(StatSql::sqlInsertTrafMonth, trafMonth);
|
||||
|
||||
// Update Statements
|
||||
const QStmtList updateTrafAppStmts = QStmtList()
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafAppHour, trafHour)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafAppDay, trafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafAppMonth, trafMonth)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafAppTotal, -1);
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafAppHour, trafHour)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafAppDay, trafDay)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafAppMonth, trafMonth)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafAppTotal, -1);
|
||||
|
||||
const QStmtList updateTrafStmts = QStmtList()
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafHour, trafHour)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafDay, trafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlUpdateTrafMonth, trafMonth);
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafHour, trafHour)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafDay, trafDay)
|
||||
<< getTrafficStmt(StatSql::sqlUpdateTrafMonth, trafMonth);
|
||||
|
||||
for (int i = 0; i < procCount; ++i) {
|
||||
quint32 pid = *procTrafBytes++;
|
||||
@ -345,9 +346,9 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
|
||||
const int procIndex = m_appIndexes.value(pid, INVALID_APP_INDEX);
|
||||
if (Q_UNLIKELY(procIndex == INVALID_APP_INDEX)) {
|
||||
qCritical(CLOG_DATABASE_MANAGER()) << "UI & Driver's states mismatch! Expected processes:"
|
||||
<< m_appIndexes.keys() << "Got:" << procCount
|
||||
<< "(" << i << pid << inactive << ")";
|
||||
qCritical(CLOG_STAT_MANAGER()) << "UI & Driver's states mismatch! Expected processes:"
|
||||
<< m_appIndexes.keys() << "Got:" << procCount
|
||||
<< "(" << i << pid << inactive << ")";
|
||||
abort();
|
||||
}
|
||||
|
||||
@ -395,8 +396,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
const qint32 oldTrafHour = trafHour - 24 * trafHourKeepDays;
|
||||
|
||||
deleteTrafStmts
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafAppHour, oldTrafHour)
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafHour, oldTrafHour);
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafAppHour, oldTrafHour)
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafHour, oldTrafHour);
|
||||
}
|
||||
|
||||
// Traffic Day
|
||||
@ -405,8 +406,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
const qint32 oldTrafDay = trafHour - 24 * trafDayKeepDays;
|
||||
|
||||
deleteTrafStmts
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafAppDay, oldTrafDay)
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafDay, oldTrafDay);
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafAppDay, oldTrafDay)
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafDay, oldTrafDay);
|
||||
}
|
||||
|
||||
// Traffic Month
|
||||
@ -416,8 +417,8 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
trafHour, -trafMonthKeepMonths);
|
||||
|
||||
deleteTrafStmts
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafAppMonth, oldTrafMonth)
|
||||
<< getTrafficStmt(DatabaseSql::sqlDeleteTrafMonth, oldTrafMonth);
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafAppMonth, oldTrafMonth)
|
||||
<< getTrafficStmt(StatSql::sqlDeleteTrafMonth, oldTrafMonth);
|
||||
}
|
||||
|
||||
stepStmtList(deleteTrafStmts);
|
||||
@ -435,25 +436,25 @@ void DatabaseManager::logStatTraf(quint16 procCount, const quint32 *procTrafByte
|
||||
emit trafficAdded(unixTime, sumInBytes, sumOutBytes);
|
||||
}
|
||||
|
||||
void DatabaseManager::deleteApp(qint64 appId)
|
||||
void StatManager::deleteApp(qint64 appId)
|
||||
{
|
||||
clearAppId(appId);
|
||||
|
||||
// Delete Statements
|
||||
const QStmtList deleteAppStmts = QStmtList()
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafHour, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafDay, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppTrafMonth, appId)
|
||||
<< getAppStmt(DatabaseSql::sqlDeleteAppId, appId);
|
||||
<< getAppStmt(StatSql::sqlDeleteAppTrafHour, appId)
|
||||
<< getAppStmt(StatSql::sqlDeleteAppTrafDay, appId)
|
||||
<< getAppStmt(StatSql::sqlDeleteAppTrafMonth, appId)
|
||||
<< getAppStmt(StatSql::sqlDeleteAppId, appId);
|
||||
|
||||
stepStmtList(deleteAppStmts);
|
||||
}
|
||||
|
||||
void DatabaseManager::resetAppTotals()
|
||||
void StatManager::resetAppTotals()
|
||||
{
|
||||
m_sqliteDb->beginTransaction();
|
||||
|
||||
SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlResetAppTrafTotals);
|
||||
SqliteStmt *stmt = getSqliteStmt(StatSql::sqlResetAppTrafTotals);
|
||||
const qint64 unixTime = DateUtil::getUnixTime();
|
||||
|
||||
stmt->bindInt(1, DateUtil::getUnixHour(unixTime));
|
||||
@ -464,11 +465,11 @@ void DatabaseManager::resetAppTotals()
|
||||
m_sqliteDb->commitTransaction();
|
||||
}
|
||||
|
||||
qint64 DatabaseManager::getAppId(const QString &appPath)
|
||||
qint64 StatManager::getAppId(const QString &appPath)
|
||||
{
|
||||
qint64 appId = INVALID_APP_ID;
|
||||
|
||||
SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlSelectAppId);
|
||||
SqliteStmt *stmt = getSqliteStmt(StatSql::sqlSelectAppId);
|
||||
|
||||
stmt->bindText(1, appPath);
|
||||
if (stmt->step() == SqliteStmt::StepRow) {
|
||||
@ -479,11 +480,11 @@ qint64 DatabaseManager::getAppId(const QString &appPath)
|
||||
return appId;
|
||||
}
|
||||
|
||||
qint64 DatabaseManager::createAppId(const QString &appPath, qint64 unixTime)
|
||||
qint64 StatManager::createAppId(const QString &appPath, qint64 unixTime)
|
||||
{
|
||||
qint64 appId = INVALID_APP_ID;
|
||||
|
||||
SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlInsertAppId);
|
||||
SqliteStmt *stmt = getSqliteStmt(StatSql::sqlInsertAppId);
|
||||
|
||||
stmt->bindText(1, appPath);
|
||||
stmt->bindInt64(2, unixTime);
|
||||
@ -499,9 +500,9 @@ qint64 DatabaseManager::createAppId(const QString &appPath, qint64 unixTime)
|
||||
return appId;
|
||||
}
|
||||
|
||||
void DatabaseManager::getAppList(QStringList &list, QVector<qint64> &appIds)
|
||||
void StatManager::getAppList(QStringList &list, QVector<qint64> &appIds)
|
||||
{
|
||||
SqliteStmt *stmt = getSqliteStmt(DatabaseSql::sqlSelectAppPaths);
|
||||
SqliteStmt *stmt = getSqliteStmt(StatSql::sqlSelectAppPaths);
|
||||
|
||||
while (stmt->step() == SqliteStmt::StepRow) {
|
||||
appIds.append(stmt->columnInt64(0));
|
||||
@ -510,26 +511,26 @@ void DatabaseManager::getAppList(QStringList &list, QVector<qint64> &appIds)
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
void DatabaseManager::updateTrafficList(const QStmtList &insertStmtList,
|
||||
const QStmtList &updateStmtList,
|
||||
quint32 inBytes, quint32 outBytes,
|
||||
qint64 appId)
|
||||
void StatManager::updateTrafficList(const QStmtList &insertStmtList,
|
||||
const QStmtList &updateStmtList,
|
||||
quint32 inBytes, quint32 outBytes,
|
||||
qint64 appId)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (SqliteStmt *stmtUpdate, updateStmtList) {
|
||||
for (SqliteStmt *stmtUpdate : updateStmtList) {
|
||||
if (!updateTraffic(stmtUpdate, inBytes, outBytes, appId)) {
|
||||
SqliteStmt *stmtInsert = insertStmtList.at(i);
|
||||
if (!updateTraffic(stmtInsert, inBytes, outBytes, appId)) {
|
||||
qCritical(CLOG_DATABASE_MANAGER()) << "Update traffic error:"
|
||||
<< m_sqliteDb->errorMessage();
|
||||
qCritical(CLOG_STAT_MANAGER()) << "Update traffic error:"
|
||||
<< m_sqliteDb->errorMessage();
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
}
|
||||
|
||||
bool DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
quint32 outBytes, qint64 appId)
|
||||
bool StatManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
quint32 outBytes, qint64 appId)
|
||||
{
|
||||
stmt->bindInt64(2, inBytes);
|
||||
stmt->bindInt64(3, outBytes);
|
||||
@ -546,15 +547,15 @@ bool DatabaseManager::updateTraffic(SqliteStmt *stmt, quint32 inBytes,
|
||||
&& m_sqliteDb->changes() != 0;
|
||||
}
|
||||
|
||||
void DatabaseManager::stepStmtList(const QStmtList &stmtList)
|
||||
void StatManager::stepStmtList(const QStmtList &stmtList)
|
||||
{
|
||||
foreach (SqliteStmt *stmtDelete, stmtList) {
|
||||
for (SqliteStmt *stmtDelete : stmtList) {
|
||||
stmtDelete->step();
|
||||
stmtDelete->reset();
|
||||
}
|
||||
}
|
||||
|
||||
qint32 DatabaseManager::getTrafficTime(const char *sql, qint64 appId)
|
||||
qint32 StatManager::getTrafficTime(const char *sql, qint64 appId)
|
||||
{
|
||||
qint32 trafTime = 0;
|
||||
|
||||
@ -572,9 +573,9 @@ qint32 DatabaseManager::getTrafficTime(const char *sql, qint64 appId)
|
||||
return trafTime;
|
||||
}
|
||||
|
||||
void DatabaseManager::getTraffic(const char *sql, qint32 trafTime,
|
||||
qint64 &inBytes, qint64 &outBytes,
|
||||
qint64 appId)
|
||||
void StatManager::getTraffic(const char *sql, qint32 trafTime,
|
||||
qint64 &inBytes, qint64 &outBytes,
|
||||
qint64 appId)
|
||||
{
|
||||
SqliteStmt *stmt = getSqliteStmt(sql);
|
||||
|
||||
@ -594,7 +595,7 @@ void DatabaseManager::getTraffic(const char *sql, qint32 trafTime,
|
||||
stmt->reset();
|
||||
}
|
||||
|
||||
SqliteStmt *DatabaseManager::getTrafficStmt(const char *sql, qint32 trafTime)
|
||||
SqliteStmt *StatManager::getTrafficStmt(const char *sql, qint32 trafTime)
|
||||
{
|
||||
SqliteStmt *stmt = getSqliteStmt(sql);
|
||||
|
||||
@ -603,7 +604,7 @@ SqliteStmt *DatabaseManager::getTrafficStmt(const char *sql, qint32 trafTime)
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SqliteStmt *DatabaseManager::getAppStmt(const char *sql, qint64 appId)
|
||||
SqliteStmt *StatManager::getAppStmt(const char *sql, qint64 appId)
|
||||
{
|
||||
SqliteStmt *stmt = getSqliteStmt(sql);
|
||||
|
||||
@ -612,7 +613,7 @@ SqliteStmt *DatabaseManager::getAppStmt(const char *sql, qint64 appId)
|
||||
return stmt;
|
||||
}
|
||||
|
||||
SqliteStmt *DatabaseManager::getSqliteStmt(const char *sql)
|
||||
SqliteStmt *StatManager::getSqliteStmt(const char *sql)
|
||||
{
|
||||
SqliteStmt *stmt = m_sqliteStmts.value(sql);
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef DATABASEMANAGER_H
|
||||
#define DATABASEMANAGER_H
|
||||
#ifndef STATMANAGER_H
|
||||
#define STATMANAGER_H
|
||||
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
@ -13,16 +13,16 @@ QT_FORWARD_DECLARE_CLASS(QuotaManager)
|
||||
QT_FORWARD_DECLARE_CLASS(SqliteDb)
|
||||
QT_FORWARD_DECLARE_CLASS(SqliteStmt)
|
||||
|
||||
class DatabaseManager : public QObject
|
||||
class StatManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit DatabaseManager(const QString &filePath,
|
||||
QuotaManager *quotaManager,
|
||||
QObject *parent = nullptr);
|
||||
~DatabaseManager() override;
|
||||
CLASS_DELETE_COPY_MOVE(DatabaseManager)
|
||||
explicit StatManager(const QString &filePath,
|
||||
QuotaManager *quotaManager,
|
||||
QObject *parent = nullptr);
|
||||
~StatManager() override;
|
||||
CLASS_DELETE_COPY_MOVE(StatManager)
|
||||
|
||||
const FirewallConf *firewallConf() const { return m_conf; }
|
||||
void setFirewallConf(const FirewallConf *conf);
|
||||
@ -120,4 +120,4 @@ private:
|
||||
QVector<qint64> m_appIds;
|
||||
};
|
||||
|
||||
#endif // DATABASEMANAGER_H
|
||||
#endif // STATMANAGER_H
|
@ -1,230 +1,230 @@
|
||||
#include "databasesql.h"
|
||||
#include "statsql.h"
|
||||
|
||||
const char * const DatabaseSql::sqlPragmas =
|
||||
"PRAGMA locking_mode=EXCLUSIVE;"
|
||||
"PRAGMA synchronous=NORMAL;"
|
||||
const char * const StatSql::sqlPragmas =
|
||||
"PRAGMA locking_mode = EXCLUSIVE;"
|
||||
"PRAGMA synchronous = NORMAL;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectAppId =
|
||||
const char * const StatSql::sqlSelectAppId =
|
||||
"SELECT app_id FROM app WHERE path = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertAppId =
|
||||
const char * const StatSql::sqlInsertAppId =
|
||||
"INSERT INTO app(path, creat_time, traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?1, ?2, ?3, 0, 0);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppId =
|
||||
const char * const StatSql::sqlDeleteAppId =
|
||||
"DELETE FROM app WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectAppPaths =
|
||||
const char * const StatSql::sqlSelectAppPaths =
|
||||
"SELECT app_id, path FROM app ORDER BY creat_time;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafAppHour =
|
||||
const char * const StatSql::sqlInsertTrafAppHour =
|
||||
"INSERT INTO traffic_app_hour(app_id, traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?4, ?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafAppDay =
|
||||
const char * const StatSql::sqlInsertTrafAppDay =
|
||||
"INSERT INTO traffic_app_day(app_id, traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?4, ?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafAppMonth =
|
||||
const char * const StatSql::sqlInsertTrafAppMonth =
|
||||
"INSERT INTO traffic_app_month(app_id, traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?4, ?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafHour =
|
||||
const char * const StatSql::sqlInsertTrafHour =
|
||||
"INSERT INTO traffic_hour(traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafDay =
|
||||
const char * const StatSql::sqlInsertTrafDay =
|
||||
"INSERT INTO traffic_day(traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlInsertTrafMonth =
|
||||
const char * const StatSql::sqlInsertTrafMonth =
|
||||
"INSERT INTO traffic_month(traf_time, in_bytes, out_bytes)"
|
||||
" VALUES(?1, ?2, ?3);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafAppHour =
|
||||
const char * const StatSql::sqlUpdateTrafAppHour =
|
||||
"UPDATE traffic_app_hour"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE app_id = ?4 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafAppDay =
|
||||
const char * const StatSql::sqlUpdateTrafAppDay =
|
||||
"UPDATE traffic_app_day"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE app_id = ?4 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafAppMonth =
|
||||
const char * const StatSql::sqlUpdateTrafAppMonth =
|
||||
"UPDATE traffic_app_month"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE app_id = ?4 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafAppTotal =
|
||||
const char * const StatSql::sqlUpdateTrafAppTotal =
|
||||
"UPDATE app"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE app_id = ?4 and 0 != ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafHour =
|
||||
const char * const StatSql::sqlUpdateTrafHour =
|
||||
"UPDATE traffic_hour"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafDay =
|
||||
const char * const StatSql::sqlUpdateTrafDay =
|
||||
"UPDATE traffic_day"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlUpdateTrafMonth =
|
||||
const char * const StatSql::sqlUpdateTrafMonth =
|
||||
"UPDATE traffic_month"
|
||||
" SET in_bytes = in_bytes + ?2,"
|
||||
" out_bytes = out_bytes + ?3"
|
||||
" WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafAppHour =
|
||||
const char * const StatSql::sqlSelectMinTrafAppHour =
|
||||
"SELECT min(traf_time) FROM traffic_app_hour"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafAppDay =
|
||||
const char * const StatSql::sqlSelectMinTrafAppDay =
|
||||
"SELECT min(traf_time) FROM traffic_app_day"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafAppMonth =
|
||||
const char * const StatSql::sqlSelectMinTrafAppMonth =
|
||||
"SELECT min(traf_time) FROM traffic_app_month"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafAppTotal =
|
||||
const char * const StatSql::sqlSelectMinTrafAppTotal =
|
||||
"SELECT traf_time FROM app WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafHour =
|
||||
const char * const StatSql::sqlSelectMinTrafHour =
|
||||
"SELECT min(traf_time) FROM traffic_hour;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafDay =
|
||||
const char * const StatSql::sqlSelectMinTrafDay =
|
||||
"SELECT min(traf_time) FROM traffic_app_day;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafMonth =
|
||||
const char * const StatSql::sqlSelectMinTrafMonth =
|
||||
"SELECT min(traf_time) FROM traffic_app_month;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectMinTrafTotal =
|
||||
const char * const StatSql::sqlSelectMinTrafTotal =
|
||||
"SELECT min(traf_time) FROM app;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafAppHour =
|
||||
const char * const StatSql::sqlSelectTrafAppHour =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_app_hour"
|
||||
" WHERE app_id = ?2 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafAppDay =
|
||||
const char * const StatSql::sqlSelectTrafAppDay =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_app_day"
|
||||
" WHERE app_id = ?2 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafAppMonth =
|
||||
const char * const StatSql::sqlSelectTrafAppMonth =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_app_month"
|
||||
" WHERE app_id = ?2 and traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafAppTotal =
|
||||
const char * const StatSql::sqlSelectTrafAppTotal =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM app"
|
||||
" WHERE app_id = ?2 and 0 != ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafHour =
|
||||
const char * const StatSql::sqlSelectTrafHour =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_hour WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafDay =
|
||||
const char * const StatSql::sqlSelectTrafDay =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_day WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafMonth =
|
||||
const char * const StatSql::sqlSelectTrafMonth =
|
||||
"SELECT in_bytes, out_bytes"
|
||||
" FROM traffic_month WHERE traf_time = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlSelectTrafTotal =
|
||||
const char * const StatSql::sqlSelectTrafTotal =
|
||||
"SELECT sum(in_bytes), sum(out_bytes)"
|
||||
" FROM app WHERE 0 != ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafAppHour =
|
||||
const char * const StatSql::sqlDeleteTrafAppHour =
|
||||
"DELETE FROM traffic_app_hour"
|
||||
" WHERE traf_time < ?1"
|
||||
" and app_id in (SELECT app_id FROM app);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafAppDay =
|
||||
const char * const StatSql::sqlDeleteTrafAppDay =
|
||||
"DELETE FROM traffic_app_day"
|
||||
" WHERE traf_time < ?1"
|
||||
" and app_id in (SELECT app_id FROM app);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafAppMonth =
|
||||
const char * const StatSql::sqlDeleteTrafAppMonth =
|
||||
"DELETE FROM traffic_app_month"
|
||||
" WHERE traf_time < ?1"
|
||||
" and app_id in (SELECT app_id FROM app);"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafHour =
|
||||
const char * const StatSql::sqlDeleteTrafHour =
|
||||
"DELETE FROM traffic_hour WHERE traf_time < ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafDay =
|
||||
const char * const StatSql::sqlDeleteTrafDay =
|
||||
"DELETE FROM traffic_day WHERE traf_time < ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteTrafMonth =
|
||||
const char * const StatSql::sqlDeleteTrafMonth =
|
||||
"DELETE FROM traffic_month WHERE traf_time < ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafHour =
|
||||
const char * const StatSql::sqlDeleteAppTrafHour =
|
||||
"DELETE FROM traffic_app_hour"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafDay =
|
||||
const char * const StatSql::sqlDeleteAppTrafDay =
|
||||
"DELETE FROM traffic_app_day"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlDeleteAppTrafMonth =
|
||||
const char * const StatSql::sqlDeleteAppTrafMonth =
|
||||
"DELETE FROM traffic_app_month"
|
||||
" WHERE app_id = ?1;"
|
||||
;
|
||||
|
||||
const char * const DatabaseSql::sqlResetAppTrafTotals =
|
||||
const char * const StatSql::sqlResetAppTrafTotals =
|
||||
"UPDATE app SET traf_time = ?1, in_bytes = 0, out_bytes = 0;"
|
||||
;
|
@ -1,7 +1,7 @@
|
||||
#ifndef DATABASESQL_H
|
||||
#define DATABASESQL_H
|
||||
#ifndef STATSQL_H
|
||||
#define STATSQL_H
|
||||
|
||||
class DatabaseSql
|
||||
class StatSql
|
||||
{
|
||||
public:
|
||||
static const char * const sqlPragmas;
|
||||
@ -65,4 +65,4 @@ public:
|
||||
static const char * const sqlResetAppTrafTotals;
|
||||
};
|
||||
|
||||
#endif // DATABASESQL_H
|
||||
#endif // STATSQL_H
|
@ -3,11 +3,12 @@
|
||||
#include <QImage>
|
||||
#include <QLoggingCategory>
|
||||
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
#include "appinfojob.h"
|
||||
#include "appinfoworker.h"
|
||||
#include "apputil.h"
|
||||
#include <sqlite/sqlitedb.h>
|
||||
#include <sqlite/sqlitestmt.h>
|
||||
|
||||
Q_DECLARE_LOGGING_CATEGORY(CLOG_APPINFOCACHE)
|
||||
Q_LOGGING_CATEGORY(CLOG_APPINFOCACHE, "fort.appInfoWorker")
|
||||
|
Loading…
Reference in New Issue
Block a user