qt/ledset/pcaprethread.h

36 lines
690 B
C
Raw Normal View History

2023-03-20 11:30:19 +08:00
#ifndef PCAPRETHREAD_H
#define PCAPRETHREAD_H
#include <QThread>
#define HAVE_REMOTE
#include "pcap.h"
struct Resp {
int id;
std::function<void(const QByteArray)> callback;
};
class PcapReThread : public QThread {
Q_OBJECT
public:
explicit PcapReThread(pcap *pcap);
~PcapReThread() {
pcap_close(pcap);
}
void addResp(const Resp &resp) {
std::lock_guard<std::mutex> lock(mtx);
resps.append(resp);
}
std::atomic<char> status{0};
QList<Resp> resps;
std::mutex mtx;
pcap *pcap;
signals:
void onMsg(Resp resp, const QByteArray data);
void onError(char *);
protected:
void run();
};
#endif // PCAPRETHREAD_H