You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.3 KiB
C++

#ifndef _QDBWORKER_H_
#define _QDBWORKER_H_
#include <QObject>
#include <QSqlDatabase>
#include <QThread>
#include "threadsafe_list.hpp"
#include <QPair>
#include <QList>
namespace SystemLog {
typedef QPair<QString, QString> SysLogMsg;
typedef QList<SysLogMsg> SysLogMsgList;
class QDBSqlite :public QSqlDatabase
{
public:
QDBSqlite(const QString& dbName, const QString& dbUser = NULL, const QString& dbpw = NULL) :QSqlDatabase("QSQLITE")
{
setDatabaseName(dbName);
if (!dbUser.isEmpty()) {
setUserName(dbUser);
setPassword(dbpw);
}
}
virtual ~QDBSqlite() {}
bool CreateTable();
bool InsertData(int type, QString strMsg);
SysLogMsgList checkByDatetime(QString start, QString end, int type);
};
class lpLogDB : public QThread
{
Q_OBJECT
public:
lpLogDB(QObject *parent = nullptr);
~lpLogDB();
void startProcess();
Q_SLOT void stopProcess();
void onRecvData(int nTypeID, const char* msg, int len);
SysLogMsgList checkByDate(QString strDate, int type);
SysLogMsgList checkByDateTime(QString startTime, QString endTime, int type);
protected:
virtual void run();
private:
typedef struct tag_MsgItem {
QString strMsg;
int typeID;
}MsgItem;
QDBSqlite* m_pDBSqlite{ nullptr };
bool m_abort{ false };
mutable std::mutex m;
int m_sleepms{ 10 };
threadsafe_list< tag_MsgItem> _list;
};
};
#endif