#ifndef WatchUdev_h
#define WatchUdev_h

#include <QObject>
#include <QMap>
#include <QSet>
#include <QStringList>
#include <stdarg.h>
struct udev;
struct udev_monitor;
class QSocketNotifier;
struct udev_device;

class WatchUdev : public QObject {

   Q_OBJECT

public:
   WatchUdev();

   ~WatchUdev();

   void
   IncludeProperty(QString propname);

      // Go look for already plugged devices that match the given subsystems
      // and property lists and invoke the seeDevice() signal for any
      // that are found in the list.
      //
   void
   ScanDevices(QStringList subsystems, QStringList properties);

signals:

      // When a new device is monitored, emit this signal. The signal
      // arguments input the action ("add", "remove"), device path
      // ("/devices/pci..."), subsystem ("usb"), plus a map with all the
      // properties and values ever requested by calling IncludeProperty().
      //
   void
   seeDevice(QString action,
             QString path,
             QString subsystem,
             QMap<QString, QString> properties);

private slots:

   void
   SeeMonitor(int fd);

private:

   void
   HandleNewDevice(struct udev_device *device);

   struct udev *         udev;
   struct udev_monitor * udev_monitor;
   int                   monitor_fd;

   QSocketNotifier *     notice_monitor;

   QSet<QString>         included_properties;
};

#endif // WatchUdev_h
