#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
