#ifndef LOGID_HIDPP_DEVICE_H #define LOGID_HIDPP_DEVICE_H #include #include #include #include #include "../raw/RawDevice.h" #include "Report.h" #include "defs.h" namespace logid { namespace backend { namespace hidpp { struct EventHandler { std::function condition; std::function callback; }; class Device { public: class InvalidDevice : std::exception { public: enum Reason { NoHIDPPReport, InvalidRawDevice }; InvalidDevice(Reason reason) : _reason (reason) {} virtual const char *what() const noexcept; virtual Reason code() const noexcept; private: Reason _reason; }; Device(const std::string& path, DeviceIndex index); Device(std::shared_ptr raw_device, DeviceIndex index); ~Device(); std::string devicePath() const { return path; } DeviceIndex deviceIndex() const { return _index; } std::tuple version() const { return _version; } void listen(); // Runs asynchronously void stopListening(); void addEventHandler(const std::string& nickname, const std::shared_ptr& handler); void removeEventHandler(const std::string& nickname); Report sendReport(Report& report); void handleEvent(Report& report); private: void _init(); std::shared_ptr raw_device; std::string path; DeviceIndex _index; uint8_t supported_reports; std::tuple _version; std::map> event_handlers; }; } } } #endif //LOGID_HIDPP_DEVICE_H