Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Hotplug implementation #674

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Connection callback: fix LeaveCriticalSection not being called after …
…EnterCriticalSection (#689)
d3xMachina authored Aug 20, 2024
commit b6606ca241e2e500638669141e21249865f8cc4a
57 changes: 26 additions & 31 deletions windows/hid.c
Original file line number Diff line number Diff line change
@@ -1054,48 +1054,43 @@ DWORD WINAPI hid_internal_notify_callback(HCMNOTIFICATION notify, PVOID context,
read_handle = open_device(event_data->u.DeviceInterface.SymbolicLink, FALSE);

/* Check validity of read_handle. */
if (read_handle == INVALID_HANDLE_VALUE) {
/* Unable to open the device. */
return ERROR_SUCCESS;
}

device = hid_internal_get_device_info(event_data->u.DeviceInterface.SymbolicLink, read_handle);

/* Append to the end of the device list */
if (hid_hotplug_context.devs != NULL) {
struct hid_device_info *last = hid_hotplug_context.devs;
while (last->next != NULL) {
last = last->next;
if (read_handle != INVALID_HANDLE_VALUE) {
device = hid_internal_get_device_info(event_data->u.DeviceInterface.SymbolicLink, read_handle);

/* Append to the end of the device list */
if (hid_hotplug_context.devs != NULL) {
struct hid_device_info *last = hid_hotplug_context.devs;
while (last->next != NULL) {
last = last->next;
}
last->next = device;
} else {
hid_hotplug_context.devs = device;
}
last->next = device;
} else {
hid_hotplug_context.devs = device;
}

CloseHandle(read_handle);
CloseHandle(read_handle);
}
} else if (action == CM_NOTIFY_ACTION_DEVICEINTERFACEREMOVAL) {
char *path;

hotplug_event = HID_API_HOTPLUG_EVENT_DEVICE_LEFT;

path = hid_internal_UTF16toUTF8(event_data->u.DeviceInterface.SymbolicLink);

if (path == NULL) {
return ERROR_SUCCESS;
}

/* Get and remove this device from the device list */
for (struct hid_device_info **current = &hid_hotplug_context.devs; *current; current = &(*current)->next) {
/* Case-independent path comparison is mandatory */
if (_stricmp((*current)->path, path) == 0) {
struct hid_device_info *next = (*current)->next;
device = *current;
*current = next;
break;
if (path != NULL) {
/* Get and remove this device from the device list */
for (struct hid_device_info **current = &hid_hotplug_context.devs; *current; current = &(*current)->next) {
/* Case-independent path comparison is mandatory */
if (_stricmp((*current)->path, path) == 0) {
struct hid_device_info *next = (*current)->next;
device = *current;
*current = next;
break;
}
}
}

free(path);
free(path);
}
}

if (device) {