#pragma once

#include "device_bus/monitor/IDeviceMonitor.h"

#if defined(__linux__)

#include <QSocketNotifier>
#include <QSet>
#include <QHash>
#include <vector>

namespace softbus::device_bus::monitor
{

class NetlinkDeviceMonitor : public IDeviceMonitor
{
    Q_OBJECT
public:
    explicit NetlinkDeviceMonitor(QObject* parent = nullptr);
    ~NetlinkDeviceMonitor() override;

    bool start() override;
    void stop() override;
    std::vector<DeviceEvent> snapshotExisting() override;

private:
    void onReadable();

private:
    int m_sock{-1};
    QSocketNotifier* m_notifier{nullptr};
    QSet<int> m_seenIfIndex;
    QHash<int, QString> m_lastIfNameByIndex;
    QHash<int, bool> m_lastLinkUpByIndex;
};

} // namespace softbus::device_bus::monitor

#endif // __linux__

