2023-07-11 19:02:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdatomic.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <threads.h>
|
|
|
|
|
|
|
|
#include <libusb-1.0/libusb.h>
|
|
|
|
|
2023-07-13 11:53:44 +00:00
|
|
|
typedef void (*hotplug_callback_f)();
|
|
|
|
|
2023-07-11 19:02:56 +00:00
|
|
|
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;
|
2023-07-13 11:53:44 +00:00
|
|
|
|
|
|
|
atomic_bool has_hotplug_callbacks;
|
|
|
|
hotplug_callback_f on_connected;
|
|
|
|
hotplug_callback_f on_disconnected;
|
2023-07-11 19:02:56 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct usb_detector* create_detector(uint16_t vendor_id, uint16_t product_id);
|
|
|
|
void destroy_detector(struct usb_detector*);
|