#ifndef DEVICE_H
#define DEVICE_H


#include <stdint.h>


#ifdef _WIN32
typedef HANDLE DeviceHandle;
#else
typedef int    DeviceHandle;
#endif


class Device
{
  Device();
  virtual ~Device();
  virtual bool open() = 0;
  virtual void close() = 0;
  virtual size_t read(vector<uint8_t>& bytes, size_t count, size_t offset=0) = 0;
  virtual size_t write(const vector<uint8_t>& bytes, size_t offset=0) = 0;
  virtual DeviceHandle getDeviceHandle() = 0;
};


class DeviceNotifier
{
public:
  enum WaitForFlag {
    WaitCanRead       = 1,
    WaitCanWrite      = 2,
    WaitForException  = 4,
    WaitForTimeout    = 8
  };
  DeviceNotifier(Device d, std::function<void(DeviceNotifier&)> callback, WaitForFlag flags, Duration timeout = 0ULL);
  //virtual ~DeviceNotifier();
private:
  int m_flags;
  Device m_device;
  std::function<void(DeviceNotifier&)> m_callback;
  Duration m_timeout;
};


#endif // DEVICE_H

