convertablet/daemon/usb_device_detection.h

27 lines
628 B
C

#pragma once
#include <stdatomic.h>
#include <stdint.h>
#include <threads.h>
#include <libusb-1.0/libusb.h>
typedef void (*hotplug_callback_f)();
struct usb_detector {
atomic_bool is_connected;
atomic_bool event_handler_should_exit;
thrd_t event_handler_thread;
struct libusb_context* usb_context;
libusb_hotplug_callback_handle hotplug_handle;
atomic_bool has_hotplug_callbacks;
hotplug_callback_f on_connected;
hotplug_callback_f on_disconnected;
};
struct usb_detector* create_detector(uint16_t vendor_id, uint16_t product_id);
void destroy_detector(struct usb_detector*);