#ifndef RFKILL_H
#define RFKILL_H

#include <QObject>
#include <QDebug>
#include <QThread>
#include <QSocketNotifier>

extern "C" {
    #include <unistd.h>
    #include <fcntl.h>
}

class Rfkill : public QObject
{
    Q_OBJECT
public:
    enum State {
        Unblocked = 0,
        SoftBlocked = 1,
        HardBlocked = 2,
        Unknown = 3
    };

    explicit Rfkill(QObject *parent = nullptr);
    ~Rfkill();
    State state() const;
    bool block();
    bool unblock();
    size_t bluetooth_size(void);
public slots:
    void init();

private:
    void devReadyRead();
    void updateRfkillDevices();
    bool openForWriting();
    bool setSoftBlock(quint8);
signals:
    void stateChanged(State);
    void rfkillStatusChanged(quint64);

private:
    State _mState;
    int _mReadFd;
    int _mWriteFd;
    QHash<quint32, State> _mDevices;
};

#endif // RFKILL_H
