And use impl everywhere instead of inconsistent private / ext / device.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 254 ++++++++++++++++++------------------- 1 file changed, 127 insertions(+), 127 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 9f6596f5c7d..eaa0ed9329e 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -115,7 +115,7 @@ static Uint16 (*pSDL_JoystickGetProduct)(SDL_Joystick * joystick); static Uint16 (*pSDL_JoystickGetProductVersion)(SDL_Joystick * joystick); static Uint16 (*pSDL_JoystickGetVendor)(SDL_Joystick * joystick);
-struct platform_private +struct sdl_device { struct unix_device unix_device;
@@ -137,55 +137,55 @@ struct platform_private int haptic_effect_id; };
-static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +static inline struct sdl_device *impl_from_unix_device(struct unix_device *iface) { - return CONTAINING_RECORD(iface, struct platform_private, unix_device); + return CONTAINING_RECORD(iface, struct sdl_device, unix_device); }
-static struct platform_private *find_device_from_id(SDL_JoystickID id) +static struct sdl_device *find_device_from_id(SDL_JoystickID id) { - struct platform_private *device; + struct sdl_device *impl;
- LIST_FOR_EACH_ENTRY(device, &device_list, struct platform_private, unix_device.entry) - if (device->id == id) return device; + LIST_FOR_EACH_ENTRY(impl, &device_list, struct sdl_device, unix_device.entry) + if (impl->id == id) return impl;
return NULL; }
-static void set_button_value(struct platform_private *ext, int index, int value) +static void set_button_value(struct sdl_device *impl, int index, int value) { - int byte_index = ext->button_start + index / 8; + int byte_index = impl->button_start + index / 8; int bit_index = index % 8; BYTE mask = 1 << bit_index;
if (value) { - ext->report_buffer[byte_index] = ext->report_buffer[byte_index] | mask; + impl->report_buffer[byte_index] = impl->report_buffer[byte_index] | mask; } else { mask = ~mask; - ext->report_buffer[byte_index] = ext->report_buffer[byte_index] & mask; + impl->report_buffer[byte_index] = impl->report_buffer[byte_index] & mask; } }
-static void set_axis_value(struct platform_private *ext, int index, short value) +static void set_axis_value(struct sdl_device *impl, int index, short value) { - DWORD *report = (DWORD *)(ext->report_buffer + ext->axis_start); + DWORD *report = (DWORD *)(impl->report_buffer + impl->axis_start); report[index] = LE_DWORD(value); }
-static void set_ball_value(struct platform_private *ext, int index, int value1, int value2) +static void set_ball_value(struct sdl_device *impl, int index, int value1, int value2) { int offset; - offset = ext->ball_start + (index * sizeof(DWORD)); - *(DWORD *)&ext->report_buffer[offset] = LE_DWORD(value1); - *(DWORD *)&ext->report_buffer[offset + sizeof(DWORD)] = LE_DWORD(value2); + offset = impl->ball_start + (index * sizeof(DWORD)); + *(DWORD *)&impl->report_buffer[offset] = LE_DWORD(value1); + *(DWORD *)&impl->report_buffer[offset + sizeof(DWORD)] = LE_DWORD(value2); }
-static void set_hat_value(struct platform_private *ext, int index, int value) +static void set_hat_value(struct sdl_device *impl, int index, int value) { - int byte = ext->hat_start + index; + int byte = impl->hat_start + index; unsigned char val;
switch (value) @@ -205,35 +205,35 @@ static void set_hat_value(struct platform_private *ext, int index, int value) default: return; }
- ext->report_buffer[byte] = val; + impl->report_buffer[byte] = val; }
-static BOOL descriptor_add_haptic(struct platform_private *ext) +static BOOL descriptor_add_haptic(struct sdl_device *impl) { - if (pSDL_JoystickIsHaptic(ext->sdl_joystick)) + if (pSDL_JoystickIsHaptic(impl->sdl_joystick)) { - ext->sdl_haptic = pSDL_HapticOpenFromJoystick(ext->sdl_joystick); - if (ext->sdl_haptic && - ((pSDL_HapticQuery(ext->sdl_haptic) & SDL_HAPTIC_LEFTRIGHT) != 0 || - pSDL_HapticRumbleSupported(ext->sdl_haptic))) + impl->sdl_haptic = pSDL_HapticOpenFromJoystick(impl->sdl_joystick); + if (impl->sdl_haptic && + ((pSDL_HapticQuery(impl->sdl_haptic) & SDL_HAPTIC_LEFTRIGHT) != 0 || + pSDL_HapticRumbleSupported(impl->sdl_haptic))) { - pSDL_HapticStopAll(ext->sdl_haptic); - pSDL_HapticRumbleInit(ext->sdl_haptic); - if (!hid_descriptor_add_haptics(&ext->desc)) + pSDL_HapticStopAll(impl->sdl_haptic); + pSDL_HapticRumbleInit(impl->sdl_haptic); + if (!hid_descriptor_add_haptics(&impl->desc)) return FALSE; - ext->haptic_effect_id = -1; + impl->haptic_effect_id = -1; } else { - pSDL_HapticClose(ext->sdl_haptic); - ext->sdl_haptic = NULL; + pSDL_HapticClose(impl->sdl_haptic); + impl->sdl_haptic = NULL; } }
return TRUE; }
-static NTSTATUS build_joystick_report_descriptor(struct platform_private *ext) +static NTSTATUS build_joystick_report_descriptor(struct sdl_device *impl) { static const USAGE joystick_usages[] = { @@ -251,72 +251,72 @@ static NTSTATUS build_joystick_report_descriptor(struct platform_private *ext) int i, report_size = 1; int button_count, axis_count, ball_count, hat_count;
- axis_count = pSDL_JoystickNumAxes(ext->sdl_joystick); + axis_count = pSDL_JoystickNumAxes(impl->sdl_joystick); if (axis_count > 6) { FIXME("Clamping joystick to 6 axis\n"); axis_count = 6; } - ext->axis_start = report_size; + impl->axis_start = report_size; report_size += (sizeof(DWORD) * axis_count);
- ball_count = pSDL_JoystickNumBalls(ext->sdl_joystick); + ball_count = pSDL_JoystickNumBalls(impl->sdl_joystick); if (axis_count + ball_count * 2 > ARRAY_SIZE(joystick_usages)) { FIXME("Capping ball + axis at 9\n"); ball_count = (ARRAY_SIZE(joystick_usages) - axis_count) / 2; } - ext->ball_start = report_size; + impl->ball_start = report_size; report_size += (sizeof(DWORD) * 2 * ball_count);
- hat_count = pSDL_JoystickNumHats(ext->sdl_joystick); - ext->hat_start = report_size; + hat_count = pSDL_JoystickNumHats(impl->sdl_joystick); + impl->hat_start = report_size; report_size += hat_count;
/* For now lump all buttons just into incremental usages, Ignore Keys */ - button_count = pSDL_JoystickNumButtons(ext->sdl_joystick); - ext->button_start = report_size; + button_count = pSDL_JoystickNumButtons(impl->sdl_joystick); + impl->button_start = report_size; report_size += (button_count + 7) / 8;
TRACE("Report will be %i bytes\n", report_size);
- if (!hid_descriptor_begin(&ext->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) + if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) return STATUS_NO_MEMORY;
- if (axis_count && !hid_descriptor_add_axes(&ext->desc, axis_count, HID_USAGE_PAGE_GENERIC, + if (axis_count && !hid_descriptor_add_axes(&impl->desc, axis_count, HID_USAGE_PAGE_GENERIC, joystick_usages, FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (ball_count && !hid_descriptor_add_axes(&ext->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, + if (ball_count && !hid_descriptor_add_axes(&impl->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
- if (hat_count && !hid_descriptor_add_hatswitch(&ext->desc, hat_count)) + if (hat_count && !hid_descriptor_add_hatswitch(&impl->desc, hat_count)) return STATUS_NO_MEMORY;
- if (button_count && !hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (button_count && !hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
- if (!descriptor_add_haptic(ext)) + if (!descriptor_add_haptic(impl)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_end(&ext->desc)) + if (!hid_descriptor_end(&impl->desc)) return STATUS_NO_MEMORY;
- ext->buffer_length = report_size; - if (!(ext->report_buffer = calloc(1, report_size))) goto failed; + impl->buffer_length = report_size; + if (!(impl->report_buffer = calloc(1, report_size))) goto failed;
/* Initialize axis in the report */ for (i = 0; i < axis_count; i++) - set_axis_value(ext, i, pSDL_JoystickGetAxis(ext->sdl_joystick, i)); + set_axis_value(impl, i, pSDL_JoystickGetAxis(impl->sdl_joystick, i)); for (i = 0; i < hat_count; i++) - set_hat_value(ext, i, pSDL_JoystickGetHat(ext->sdl_joystick, i)); + set_hat_value(impl, i, pSDL_JoystickGetHat(impl->sdl_joystick, i));
return STATUS_SUCCESS;
failed: - free(ext->report_buffer); - hid_descriptor_free(&ext->desc); + free(impl->report_buffer); + hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
@@ -347,7 +347,7 @@ static SHORT compose_dpad_value(SDL_GameController *joystick) return SDL_HAT_CENTERED; }
-static NTSTATUS build_controller_report_descriptor(struct platform_private *ext) +static NTSTATUS build_controller_report_descriptor(struct sdl_device *impl) { static const USAGE left_axis_usages[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y}; static const USAGE right_axis_usages[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY}; @@ -355,52 +355,52 @@ static NTSTATUS build_controller_report_descriptor(struct platform_private *ext) ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1; C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
- ext->axis_start = 0; - ext->hat_start = SDL_CONTROLLER_AXIS_MAX * sizeof(DWORD); - ext->button_start = ext->hat_start + 1; - ext->buffer_length = ext->button_start + (button_count + 7) / 8; + impl->axis_start = 0; + impl->hat_start = SDL_CONTROLLER_AXIS_MAX * sizeof(DWORD); + impl->button_start = impl->hat_start + 1; + impl->buffer_length = impl->button_start + (button_count + 7) / 8;
- TRACE("Report will be %i bytes\n", ext->buffer_length); + TRACE("Report will be %i bytes\n", impl->buffer_length);
- if (!hid_descriptor_begin(&ext->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) + if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, + if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, + if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&ext->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, + if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, FALSE, 0, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_hatswitch(&ext->desc, 1)) + if (!hid_descriptor_add_hatswitch(&impl->desc, 1)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
- if (!descriptor_add_haptic(ext)) + if (!descriptor_add_haptic(impl)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_end(&ext->desc)) + if (!hid_descriptor_end(&impl->desc)) return STATUS_NO_MEMORY;
- if (!(ext->report_buffer = calloc(1, ext->buffer_length))) goto failed; + if (!(impl->report_buffer = calloc(1, impl->buffer_length))) goto failed;
/* Initialize axis in the report */ for (i = SDL_CONTROLLER_AXIS_LEFTX; i < SDL_CONTROLLER_AXIS_MAX; i++) - set_axis_value(ext, i, pSDL_GameControllerGetAxis(ext->sdl_controller, i)); - set_hat_value(ext, 0, compose_dpad_value(ext->sdl_controller)); + set_axis_value(impl, i, pSDL_GameControllerGetAxis(impl->sdl_controller, i)); + set_hat_value(impl, 0, compose_dpad_value(impl->sdl_controller));
return STATUS_SUCCESS;
failed: - free(ext->report_buffer); - hid_descriptor_free(&ext->desc); + free(impl->report_buffer); + hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
@@ -410,51 +410,51 @@ static void sdl_device_destroy(struct unix_device *iface)
static NTSTATUS sdl_device_start(struct unix_device *iface) { - struct platform_private *ext = impl_from_unix_device(iface); - if (ext->sdl_controller) return build_controller_report_descriptor(ext); - return build_joystick_report_descriptor(ext); + struct sdl_device *impl = impl_from_unix_device(iface); + if (impl->sdl_controller) return build_controller_report_descriptor(impl); + return build_joystick_report_descriptor(impl); }
static void sdl_device_stop(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct sdl_device *impl = impl_from_unix_device(iface);
- pSDL_JoystickClose(private->sdl_joystick); - if (private->sdl_controller) pSDL_GameControllerClose(private->sdl_controller); - if (private->sdl_haptic) pSDL_HapticClose(private->sdl_haptic); + pSDL_JoystickClose(impl->sdl_joystick); + if (impl->sdl_controller) pSDL_GameControllerClose(impl->sdl_controller); + if (impl->sdl_haptic) pSDL_HapticClose(impl->sdl_haptic);
pthread_mutex_lock(&sdl_cs); - list_remove(&private->unix_device.entry); + list_remove(&impl->unix_device.entry); pthread_mutex_unlock(&sdl_cs); }
static NTSTATUS sdl_device_get_reportdescriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *out_length) { - struct platform_private *ext = impl_from_unix_device(iface); + struct sdl_device *impl = impl_from_unix_device(iface);
- *out_length = ext->desc.size; - if (length < ext->desc.size) return STATUS_BUFFER_TOO_SMALL; + *out_length = impl->desc.size; + if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL;
- memcpy(buffer, ext->desc.data, ext->desc.size); + memcpy(buffer, impl->desc.data, impl->desc.size); return STATUS_SUCCESS; }
static void sdl_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { - struct platform_private *ext = impl_from_unix_device(iface); + struct sdl_device *impl = impl_from_unix_device(iface);
- if (ext->sdl_haptic && packet->reportId == 0) + if (impl->sdl_haptic && packet->reportId == 0) { WORD left = packet->reportBuffer[2] * 128; WORD right = packet->reportBuffer[3] * 128;
- if (ext->haptic_effect_id >= 0) + if (impl->haptic_effect_id >= 0) { - pSDL_HapticDestroyEffect(ext->sdl_haptic, ext->haptic_effect_id); - ext->haptic_effect_id = -1; + pSDL_HapticDestroyEffect(impl->sdl_haptic, impl->haptic_effect_id); + impl->haptic_effect_id = -1; } - pSDL_HapticStopAll(ext->sdl_haptic); + pSDL_HapticStopAll(impl->sdl_haptic); if (left != 0 || right != 0) { SDL_HapticEffect effect; @@ -465,15 +465,15 @@ static void sdl_device_set_output_report(struct unix_device *iface, HID_XFER_PAC effect.leftright.large_magnitude = left; effect.leftright.small_magnitude = right;
- ext->haptic_effect_id = pSDL_HapticNewEffect(ext->sdl_haptic, &effect); - if (ext->haptic_effect_id >= 0) + impl->haptic_effect_id = pSDL_HapticNewEffect(impl->sdl_haptic, &effect); + if (impl->haptic_effect_id >= 0) { - pSDL_HapticRunEffect(ext->sdl_haptic, ext->haptic_effect_id, 1); + pSDL_HapticRunEffect(impl->sdl_haptic, impl->haptic_effect_id, 1); } else { float i = (float)((left + right)/2.0) / 32767.0; - pSDL_HapticRumblePlay(ext->sdl_haptic, i, -1); + pSDL_HapticRumblePlay(impl->sdl_haptic, i, -1); } }
@@ -510,11 +510,11 @@ static const struct unix_device_vtbl sdl_device_vtbl = sdl_device_set_feature_report, };
-static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_Event *event) +static BOOL set_report_from_joystick_event(struct sdl_device *impl, SDL_Event *event) { - struct unix_device *iface = &device->unix_device; + struct unix_device *iface = &impl->unix_device;
- if (device->sdl_controller) return TRUE; /* use controller events instead */ + if (impl->sdl_controller) return TRUE; /* use controller events instead */
switch(event->type) { @@ -523,9 +523,9 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_ { SDL_JoyButtonEvent *ie = &event->jbutton;
- set_button_value(device, ie->button, ie->state); + set_button_value(impl, ie->button, ie->state);
- bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); break; } case SDL_JOYAXISMOTION: @@ -534,8 +534,8 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_
if (ie->axis < 6) { - set_axis_value(device, ie->axis, ie->value); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + set_axis_value(impl, ie->axis, ie->value); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); } break; } @@ -543,16 +543,16 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_ { SDL_JoyBallEvent *ie = &event->jball;
- set_ball_value(device, ie->ball, ie->xrel, ie->yrel); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + set_ball_value(impl, ie->ball, ie->xrel, ie->yrel); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); break; } case SDL_JOYHATMOTION: { SDL_JoyHatEvent *ie = &event->jhat;
- set_hat_value(device, ie->hat, ie->value); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + set_hat_value(impl, ie->hat, ie->value); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); break; } default: @@ -561,9 +561,9 @@ static BOOL set_report_from_joystick_event(struct platform_private *device, SDL_ return FALSE; }
-static BOOL set_report_from_controller_event(struct platform_private *device, SDL_Event *event) +static BOOL set_report_from_controller_event(struct sdl_device *impl, SDL_Event *event) { - struct unix_device *iface = &device->unix_device; + struct unix_device *iface = &impl->unix_device;
switch(event->type) { @@ -579,7 +579,7 @@ static BOOL set_report_from_controller_event(struct platform_private *device, SD case SDL_CONTROLLER_BUTTON_DPAD_DOWN: case SDL_CONTROLLER_BUTTON_DPAD_LEFT: case SDL_CONTROLLER_BUTTON_DPAD_RIGHT: - set_hat_value(device, 0, compose_dpad_value(device->sdl_controller)); + set_hat_value(impl, 0, compose_dpad_value(impl->sdl_controller)); break; case SDL_CONTROLLER_BUTTON_LEFTSHOULDER: button = 4; break; case SDL_CONTROLLER_BUTTON_RIGHTSHOULDER: button = 5; break; @@ -590,16 +590,16 @@ static BOOL set_report_from_controller_event(struct platform_private *device, SD case SDL_CONTROLLER_BUTTON_GUIDE: button = 10; break; }
- set_button_value(device, button, ie->state); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + set_button_value(impl, button, ie->state); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); break; } case SDL_CONTROLLERAXISMOTION: { SDL_ControllerAxisEvent *ie = &event->caxis;
- set_axis_value(device, ie->axis, ie->value); - bus_event_queue_input_report(&event_queue, iface, device->report_buffer, device->buffer_length); + set_axis_value(impl, ie->axis, ie->value); + bus_event_queue_input_report(&event_queue, iface, impl->report_buffer, impl->buffer_length); break; } default: @@ -616,7 +616,7 @@ static void sdl_add_device(unsigned int index) .manufacturer = {"SDL"}, .serialnumber = {"0000"}, }; - struct platform_private *private; + struct sdl_device *impl;
SDL_Joystick* joystick; SDL_JoystickID id; @@ -664,18 +664,18 @@ static void sdl_add_device(unsigned int index)
TRACE("%s id %d, desc %s.\n", controller ? "controller" : "joystick", id, debugstr_device_desc(&desc));
- if (!(private = unix_device_create(&sdl_device_vtbl, sizeof(struct platform_private)))) return; - list_add_tail(&device_list, &private->unix_device.entry); - private->sdl_joystick = joystick; - private->sdl_controller = controller; - private->id = id; + if (!(impl = unix_device_create(&sdl_device_vtbl, sizeof(struct sdl_device)))) return; + list_add_tail(&device_list, &impl->unix_device.entry); + impl->sdl_joystick = joystick; + impl->sdl_controller = controller; + impl->id = id;
- bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); + bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc); }
static void process_device_event(SDL_Event *event) { - struct platform_private *device; + struct sdl_device *impl; SDL_JoystickID id;
TRACE_(hid_report)("Received action %x\n", event->type); @@ -687,22 +687,22 @@ static void process_device_event(SDL_Event *event) else if (event->type == SDL_JOYDEVICEREMOVED) { id = ((SDL_JoyDeviceEvent *)event)->which; - device = find_device_from_id(id); - if (device) bus_event_queue_device_removed(&event_queue, &device->unix_device); + impl = find_device_from_id(id); + if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device); else WARN("failed to find device with id %d\n", id); } else if (event->type >= SDL_JOYAXISMOTION && event->type <= SDL_JOYBUTTONUP) { id = ((SDL_JoyButtonEvent *)event)->which; - device = find_device_from_id(id); - if (device) set_report_from_joystick_event(device, event); + impl = find_device_from_id(id); + if (impl) set_report_from_joystick_event(impl, event); else WARN("failed to find device with id %d\n", id); } else if (event->type >= SDL_CONTROLLERAXISMOTION && event->type <= SDL_CONTROLLERBUTTONUP) { id = ((SDL_ControllerButtonEvent *)event)->which; - device = find_device_from_id(id); - if (device) set_report_from_controller_event(device, event); + impl = find_device_from_id(id); + if (impl) set_report_from_controller_event(impl, event); else WARN("failed to find device with id %d\n", id); }
Introducing a struct base_device, and hidraw_device / lnxev_device depending on the sub-type of the device.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_udev.c | 319 +++++++++++++++++++----------------- 1 file changed, 165 insertions(+), 154 deletions(-)
diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index b9e5c968d0c..09b00e177a4 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -101,7 +101,7 @@ static struct list event_queue = LIST_INIT(event_queue); static struct list device_list = LIST_INIT(device_list); static struct udev_bus_options options;
-struct platform_private +struct base_device { struct unix_device unix_device; void (*read_report)(struct unix_device *iface); @@ -110,26 +110,63 @@ struct platform_private int device_fd; };
-static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +struct hidraw_device { - return CONTAINING_RECORD(iface, struct platform_private, unix_device); + struct base_device base; +}; + +#define HID_REL_MAX (REL_MISC+1) +#define HID_ABS_MAX (ABS_VOLUME+1) + +struct lnxev_device +{ + struct base_device base; + + int buffer_length; + BYTE *last_report_buffer; + BYTE *current_report_buffer; + enum { FIRST, NORMAL, DROPPED } report_state; + + struct hid_descriptor desc; + + int button_start; + BYTE button_map[KEY_MAX]; + BYTE rel_map[HID_REL_MAX]; + BYTE hat_map[8]; + int hat_values[8]; + int abs_map[HID_ABS_MAX]; +}; + +static inline struct base_device *impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(iface, struct base_device, unix_device); +} + +static inline struct hidraw_device *hidraw_impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(impl_from_unix_device(iface), struct hidraw_device, base); +} + +static inline struct lnxev_device *lnxev_impl_from_unix_device(struct unix_device *iface) +{ + return CONTAINING_RECORD(impl_from_unix_device(iface), struct lnxev_device, base); }
#define MAX_DEVICES 128 static int close_fds[MAX_DEVICES]; static struct pollfd poll_fds[MAX_DEVICES]; -static struct platform_private *poll_devs[MAX_DEVICES]; +static struct base_device *poll_devs[MAX_DEVICES]; static int close_count, poll_count;
static void stop_polling_device(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct base_device *impl = impl_from_unix_device(iface); int i;
- if (private->device_fd == -1) return; /* already removed */ + if (impl->device_fd == -1) return; /* already removed */
for (i = 2; i < poll_count; ++i) - if (poll_fds[i].fd == private->device_fd) break; + if (poll_fds[i].fd == impl->device_fd) break;
if (i == poll_count) ERR("could not find poll entry matching device %p fd\n", iface); @@ -138,21 +175,21 @@ static void stop_polling_device(struct unix_device *iface) poll_count--; poll_fds[i] = poll_fds[poll_count]; poll_devs[i] = poll_devs[poll_count]; - close_fds[close_count++] = private->device_fd; - private->device_fd = -1; + close_fds[close_count++] = impl->device_fd; + impl->device_fd = -1; } }
static void start_polling_device(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct base_device *impl = impl_from_unix_device(iface);
if (poll_count >= ARRAY_SIZE(poll_fds)) ERR("could not start polling device %p, too many fds\n", iface); else { - poll_devs[poll_count] = private; - poll_fds[poll_count].fd = private->device_fd; + poll_devs[poll_count] = impl; + poll_fds[poll_count].fd = impl->device_fd; poll_fds[poll_count].events = POLLIN; poll_fds[poll_count].revents = 0; poll_count++; @@ -161,7 +198,7 @@ static void start_polling_device(struct unix_device *iface) } }
-static struct platform_private *find_device_from_fd(int fd) +static struct base_device *find_device_from_fd(int fd) { int i;
@@ -184,22 +221,22 @@ static const char *get_device_syspath(struct udev_device *dev) return ""; }
-static struct platform_private *find_device_from_syspath(const char *path) +static struct base_device *find_device_from_syspath(const char *path) { - struct platform_private *device; + struct base_device *impl;
- LIST_FOR_EACH_ENTRY(device, &device_list, struct platform_private, unix_device.entry) - if (!strcmp(get_device_syspath(device->udev_device), path)) return device; + LIST_FOR_EACH_ENTRY(impl, &device_list, struct base_device, unix_device.entry) + if (!strcmp(get_device_syspath(impl->udev_device), path)) return impl;
return NULL; }
-static struct platform_private *find_device_from_udev(struct udev_device *dev) +static struct base_device *find_device_from_udev(struct udev_device *dev) { - struct platform_private *device; + struct base_device *impl;
- LIST_FOR_EACH_ENTRY(device, &device_list, struct platform_private, unix_device.entry) - if (device->udev_device == dev) return device; + LIST_FOR_EACH_ENTRY(impl, &device_list, struct base_device, unix_device.entry) + if (impl->udev_device == dev) return impl;
return NULL; } @@ -241,7 +278,6 @@ static const BYTE ABS_TO_HID_MAP[][2] = { {0, 0}, {HID_USAGE_PAGE_CONSUMER, HID_USAGE_CONSUMER_VOLUME} /*ABS_VOLUME*/ }; -#define HID_ABS_MAX (ABS_VOLUME+1) C_ASSERT(ARRAY_SIZE(ABS_TO_HID_MAP) == HID_ABS_MAX); #define TOP_ABS_PAGE (HID_USAGE_PAGE_DIGITIZER+1)
@@ -257,28 +293,8 @@ static const BYTE REL_TO_HID_MAP[][2] = { {HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_WHEEL}, /* REL_WHEEL */ {0, 0} /* REL_MISC */ }; - -#define HID_REL_MAX (REL_MISC+1) #define TOP_REL_PAGE (HID_USAGE_PAGE_CONSUMER+1)
-struct wine_input_private { - struct platform_private base; - - int buffer_length; - BYTE *last_report_buffer; - BYTE *current_report_buffer; - enum { FIRST, NORMAL, DROPPED } report_state; - - struct hid_descriptor desc; - - int button_start; - BYTE button_map[KEY_MAX]; - BYTE rel_map[HID_REL_MAX]; - BYTE hat_map[8]; - int hat_values[8]; - int abs_map[HID_ABS_MAX]; -}; - #define test_bit(arr,bit) (((BYTE*)(arr))[(bit)>>3]&(1<<((bit)&7)))
static const BYTE* what_am_I(struct udev_device *dev) @@ -333,62 +349,62 @@ static void set_button_value(int index, int value, BYTE* buffer) } }
-static void set_abs_axis_value(struct wine_input_private *ext, int code, int value) +static void set_abs_axis_value(struct lnxev_device *impl, int code, int value) { int index; /* check for hatswitches */ if (code <= ABS_HAT3Y && code >= ABS_HAT0X) { index = code - ABS_HAT0X; - ext->hat_values[index] = value; + impl->hat_values[index] = value; if ((code - ABS_HAT0X) % 2) index--; /* 8 1 2 * 7 0 3 * 6 5 4 */ - if (ext->hat_values[index] == 0) + if (impl->hat_values[index] == 0) { - if (ext->hat_values[index+1] == 0) + if (impl->hat_values[index+1] == 0) value = 0; - else if (ext->hat_values[index+1] < 0) + else if (impl->hat_values[index+1] < 0) value = 1; else value = 5; } - else if (ext->hat_values[index] > 0) + else if (impl->hat_values[index] > 0) { - if (ext->hat_values[index+1] == 0) + if (impl->hat_values[index+1] == 0) value = 3; - else if (ext->hat_values[index+1] < 0) + else if (impl->hat_values[index+1] < 0) value = 2; else value = 4; } else { - if (ext->hat_values[index+1] == 0) + if (impl->hat_values[index+1] == 0) value = 7; - else if (ext->hat_values[index+1] < 0) + else if (impl->hat_values[index+1] < 0) value = 8; else value = 6; } - ext->current_report_buffer[ext->hat_map[index]] = value; + impl->current_report_buffer[impl->hat_map[index]] = value; } else if (code < HID_ABS_MAX && ABS_TO_HID_MAP[code][0] != 0) { - index = ext->abs_map[code]; - *((DWORD*)&ext->current_report_buffer[index]) = LE_DWORD(value); + index = impl->abs_map[code]; + *((DWORD*)&impl->current_report_buffer[index]) = LE_DWORD(value); } }
-static void set_rel_axis_value(struct wine_input_private *ext, int code, int value) +static void set_rel_axis_value(struct lnxev_device *impl, int code, int value) { int index; if (code < HID_REL_MAX && REL_TO_HID_MAP[code][0] != 0) { - index = ext->rel_map[code]; - *(DWORD *)&ext->current_report_buffer[index] = LE_DWORD(value); + index = impl->rel_map[code]; + *(DWORD *)&impl->current_report_buffer[index] = LE_DWORD(value); } }
@@ -435,7 +451,7 @@ static INT count_abs_axis(int device_fd) return abs_count; }
-static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct udev_device *dev) +static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_device *dev) { struct input_absinfo abs_info[HID_ABS_MAX]; BYTE absbits[(ABS_MAX+7)/8]; @@ -446,12 +462,12 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u INT button_count, abs_count, rel_count, hat_count; const BYTE *device_usage = what_am_I(dev);
- if (ioctl(ext->base.device_fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits) == -1) + if (ioctl(impl->base.device_fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits) == -1) { WARN("ioctl(EVIOCGBIT, EV_REL) failed: %d %s\n", errno, strerror(errno)); memset(relbits, 0, sizeof(relbits)); } - if (ioctl(ext->base.device_fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) == -1) + if (ioctl(impl->base.device_fd, EVIOCGBIT(EV_ABS, sizeof(absbits)), absbits) == -1) { WARN("ioctl(EVIOCGBIT, EV_ABS) failed: %d %s\n", errno, strerror(errno)); memset(absbits, 0, sizeof(absbits)); @@ -459,23 +475,23 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u
report_size = 0;
- if (!hid_descriptor_begin(&ext->desc, device_usage[0], device_usage[1])) + if (!hid_descriptor_begin(&impl->desc, device_usage[0], device_usage[1])) return STATUS_NO_MEMORY;
abs_count = 0; for (i = 0; i < HID_ABS_MAX; i++) { if (!test_bit(absbits, i)) continue; - ioctl(ext->base.device_fd, EVIOCGABS(i), abs_info + i); + ioctl(impl->base.device_fd, EVIOCGABS(i), abs_info + i);
if (!(usage.UsagePage = ABS_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = ABS_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, FALSE, + if (!hid_descriptor_add_axes(&impl->desc, 1, usage.UsagePage, &usage.Usage, FALSE, LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) return STATUS_NO_MEMORY;
- ext->abs_map[i] = report_size; + impl->abs_map[i] = report_size; report_size += 4; abs_count++; } @@ -487,11 +503,11 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u if (!(usage.UsagePage = REL_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = REL_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&ext->desc, 1, usage.UsagePage, &usage.Usage, TRUE, + if (!hid_descriptor_add_axes(&impl->desc, 1, usage.UsagePage, &usage.Usage, TRUE, INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
- ext->rel_map[i] = report_size; + impl->rel_map[i] = report_size; report_size += 4; rel_count++; } @@ -500,55 +516,55 @@ static NTSTATUS build_report_descriptor(struct wine_input_private *ext, struct u for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2) { if (!test_bit(absbits, i)) continue; - ext->hat_map[i - ABS_HAT0X] = report_size; - ext->hat_values[i - ABS_HAT0X] = 0; - ext->hat_values[i - ABS_HAT0X + 1] = 0; + impl->hat_map[i - ABS_HAT0X] = report_size; + impl->hat_values[i - ABS_HAT0X] = 0; + impl->hat_values[i - ABS_HAT0X + 1] = 0; report_size++; hat_count++; }
if (hat_count) { - if (!hid_descriptor_add_hatswitch(&ext->desc, hat_count)) + if (!hid_descriptor_add_hatswitch(&impl->desc, hat_count)) return STATUS_NO_MEMORY; }
/* For now lump all buttons just into incremental usages, Ignore Keys */ - ext->button_start = report_size; - button_count = count_buttons(ext->base.device_fd, ext->button_map); + impl->button_start = report_size; + button_count = count_buttons(impl->base.device_fd, impl->button_map); if (button_count) { - if (!hid_descriptor_add_buttons(&ext->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
report_size += (button_count + 7) / 8; }
- if (!hid_descriptor_end(&ext->desc)) + if (!hid_descriptor_end(&impl->desc)) return STATUS_NO_MEMORY;
TRACE("Report will be %i bytes\n", report_size);
- ext->buffer_length = report_size; - if (!(ext->current_report_buffer = calloc(1, report_size))) goto failed; - if (!(ext->last_report_buffer = calloc(1, report_size))) goto failed; - ext->report_state = FIRST; + impl->buffer_length = report_size; + if (!(impl->current_report_buffer = calloc(1, report_size))) goto failed; + if (!(impl->last_report_buffer = calloc(1, report_size))) goto failed; + impl->report_state = FIRST;
/* Initialize axis in the report */ for (i = 0; i < HID_ABS_MAX; i++) if (test_bit(absbits, i)) - set_abs_axis_value(ext, i, abs_info[i].value); + set_abs_axis_value(impl, i, abs_info[i].value);
return STATUS_SUCCESS;
failed: - free(ext->current_report_buffer); - free(ext->last_report_buffer); - hid_descriptor_free(&ext->desc); + free(impl->current_report_buffer); + free(impl->last_report_buffer); + hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
-static BOOL set_report_from_event(struct wine_input_private *ext, struct input_event *ie) +static BOOL set_report_from_event(struct lnxev_device *impl, struct input_event *ie) { switch(ie->type) { @@ -557,21 +573,21 @@ static BOOL set_report_from_event(struct wine_input_private *ext, struct input_e switch (ie->code) { case SYN_REPORT: - if (ext->report_state == NORMAL) + if (impl->report_state == NORMAL) { - memcpy(ext->last_report_buffer, ext->current_report_buffer, ext->buffer_length); + memcpy(impl->last_report_buffer, impl->current_report_buffer, impl->buffer_length); return TRUE; } else { - if (ext->report_state == DROPPED) - memcpy(ext->current_report_buffer, ext->last_report_buffer, ext->buffer_length); - ext->report_state = NORMAL; + if (impl->report_state == DROPPED) + memcpy(impl->current_report_buffer, impl->last_report_buffer, impl->buffer_length); + impl->report_state = NORMAL; } break; case SYN_DROPPED: TRACE_(hid_report)("received SY_DROPPED\n"); - ext->report_state = DROPPED; + impl->report_state = DROPPED; } return FALSE; #endif @@ -580,13 +596,13 @@ static BOOL set_report_from_event(struct wine_input_private *ext, struct input_e return FALSE; #endif case EV_KEY: - set_button_value(ext->button_start * 8 + ext->button_map[ie->code], ie->value, ext->current_report_buffer); + set_button_value(impl->button_start * 8 + impl->button_map[ie->code], ie->value, impl->current_report_buffer); return FALSE; case EV_ABS: - set_abs_axis_value(ext, ie->code, ie->value); + set_abs_axis_value(impl, ie->code, ie->value); return FALSE; case EV_REL: - set_rel_axis_value(ext, ie->code, ie->value); + set_rel_axis_value(impl, ie->code, ie->value); return FALSE; default: ERR("TODO: Process Report (%i, %i)\n",ie->type, ie->code); @@ -597,9 +613,9 @@ static BOOL set_report_from_event(struct wine_input_private *ext, struct input_e
static void hidraw_device_destroy(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface);
- udev_device_unref(private->udev_device); + udev_device_unref(impl->base.udev_device); }
static NTSTATUS hidraw_device_start(struct unix_device *iface) @@ -612,11 +628,11 @@ static NTSTATUS hidraw_device_start(struct unix_device *iface)
static void hidraw_device_stop(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface);
pthread_mutex_lock(&udev_cs); stop_polling_device(iface); - list_remove(&private->unix_device.entry); + list_remove(&impl->base.unix_device.entry); pthread_mutex_unlock(&udev_cs); }
@@ -625,9 +641,9 @@ static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, B { #ifdef HAVE_LINUX_HIDRAW_H struct hidraw_report_descriptor descriptor; - struct platform_private *private = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface);
- if (ioctl(private->device_fd, HIDIOCGRDESCSIZE, &descriptor.size) == -1) + if (ioctl(impl->base.device_fd, HIDIOCGRDESCSIZE, &descriptor.size) == -1) { WARN("ioctl(HIDIOCGRDESCSIZE) failed: %d %s\n", errno, strerror(errno)); return STATUS_UNSUCCESSFUL; @@ -640,7 +656,7 @@ static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, B if (!descriptor.size) return STATUS_SUCCESS;
- if (ioctl(private->device_fd, HIDIOCGRDESC, &descriptor) == -1) + if (ioctl(impl->base.device_fd, HIDIOCGRDESC, &descriptor) == -1) { WARN("ioctl(HIDIOCGRDESC) failed: %d %s\n", errno, strerror(errno)); return STATUS_UNSUCCESSFUL; @@ -655,10 +671,10 @@ static NTSTATUS hidraw_device_get_report_descriptor(struct unix_device *iface, B
static void hidraw_device_read_report(struct unix_device *iface) { - struct platform_private* private = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); BYTE report_buffer[1024];
- int size = read(private->device_fd, report_buffer, sizeof(report_buffer)); + int size = read(impl->base.device_fd, report_buffer, sizeof(report_buffer)); if (size == -1) TRACE_(hid_report)("Read failed. Likely an unplugged device %d %s\n", errno, strerror(errno)); else if (size == 0) @@ -669,19 +685,19 @@ static void hidraw_device_read_report(struct unix_device *iface)
static void hidraw_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { - struct platform_private *ext = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); ULONG length = packet->reportBufferLen; BYTE buffer[8192]; int count = 0;
if ((buffer[0] = packet->reportId)) - count = write(ext->device_fd, packet->reportBuffer, length); + count = write(impl->base.device_fd, packet->reportBuffer, length); else if (length > sizeof(buffer) - 1) ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); else { memcpy(buffer + 1, packet->reportBuffer, length); - count = write(ext->device_fd, buffer, length + 1); + count = write(impl->base.device_fd, buffer, length + 1); }
if (count > 0) @@ -701,18 +717,18 @@ static void hidraw_device_get_feature_report(struct unix_device *iface, HID_XFER IO_STATUS_BLOCK *io) { #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCGFEATURE) - struct platform_private *ext = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); ULONG length = packet->reportBufferLen; BYTE buffer[8192]; int count = 0;
if ((buffer[0] = packet->reportId) && length <= 0x1fff) - count = ioctl(ext->device_fd, HIDIOCGFEATURE(length), packet->reportBuffer); + count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length), packet->reportBuffer); else if (length > sizeof(buffer) - 1) ERR_(hid_report)("id %d length %u >= 8192, cannot read\n", packet->reportId, length); else { - count = ioctl(ext->device_fd, HIDIOCGFEATURE(length + 1), buffer); + count = ioctl(impl->base.device_fd, HIDIOCGFEATURE(length + 1), buffer); memcpy(packet->reportBuffer, buffer + 1, length); }
@@ -737,19 +753,19 @@ static void hidraw_device_set_feature_report(struct unix_device *iface, HID_XFER IO_STATUS_BLOCK *io) { #if defined(HAVE_LINUX_HIDRAW_H) && defined(HIDIOCSFEATURE) - struct platform_private *ext = impl_from_unix_device(iface); + struct hidraw_device *impl = hidraw_impl_from_unix_device(iface); ULONG length = packet->reportBufferLen; BYTE buffer[8192]; int count = 0;
if ((buffer[0] = packet->reportId) && length <= 0x1fff) - count = ioctl(ext->device_fd, HIDIOCSFEATURE(length), packet->reportBuffer); + count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length), packet->reportBuffer); else if (length > sizeof(buffer) - 1) ERR_(hid_report)("id %d length %u >= 8192, cannot write\n", packet->reportId, length); else { memcpy(buffer + 1, packet->reportBuffer, length); - count = ioctl(ext->device_fd, HIDIOCSFEATURE(length + 1), buffer); + count = ioctl(impl->base.device_fd, HIDIOCSFEATURE(length + 1), buffer); }
if (count > 0) @@ -782,28 +798,23 @@ static const struct unix_device_vtbl hidraw_device_vtbl =
#ifdef HAS_PROPER_INPUT_HEADER
-static inline struct wine_input_private *input_impl_from_unix_device(struct unix_device *iface) -{ - return CONTAINING_RECORD(impl_from_unix_device(iface), struct wine_input_private, base); -} - static void lnxev_device_destroy(struct unix_device *iface) { - struct wine_input_private *ext = input_impl_from_unix_device(iface); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface);
- free(ext->current_report_buffer); - free(ext->last_report_buffer); - hid_descriptor_free(&ext->desc); + free(impl->current_report_buffer); + free(impl->last_report_buffer); + hid_descriptor_free(&impl->desc);
- udev_device_unref(ext->base.udev_device); + udev_device_unref(impl->base.udev_device); }
static NTSTATUS lnxev_device_start(struct unix_device *iface) { - struct wine_input_private *ext = input_impl_from_unix_device(iface); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface); NTSTATUS status;
- if ((status = build_report_descriptor(ext, ext->base.udev_device))) + if ((status = build_report_descriptor(impl, impl->base.udev_device))) return status;
pthread_mutex_lock(&udev_cs); @@ -814,42 +825,42 @@ static NTSTATUS lnxev_device_start(struct unix_device *iface)
static void lnxev_device_stop(struct unix_device *iface) { - struct wine_input_private *ext = input_impl_from_unix_device(iface); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface);
pthread_mutex_lock(&udev_cs); stop_polling_device(iface); - list_remove(&ext->base.unix_device.entry); + list_remove(&impl->base.unix_device.entry); pthread_mutex_unlock(&udev_cs); }
static NTSTATUS lnxev_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *out_length) { - struct wine_input_private *ext = input_impl_from_unix_device(iface); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface);
- *out_length = ext->desc.size; - if (length < ext->desc.size) return STATUS_BUFFER_TOO_SMALL; + *out_length = impl->desc.size; + if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL;
- memcpy(buffer, ext->desc.data, ext->desc.size); + memcpy(buffer, impl->desc.data, impl->desc.size); return STATUS_SUCCESS; }
static void lnxev_device_read_report(struct unix_device *iface) { - struct wine_input_private *private = input_impl_from_unix_device(iface); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface); struct input_event ie; int size;
- if (!private->current_report_buffer || private->buffer_length == 0) + if (!impl->current_report_buffer || impl->buffer_length == 0) return;
- size = read(private->base.device_fd, &ie, sizeof(ie)); + size = read(impl->base.device_fd, &ie, sizeof(ie)); if (size == -1) TRACE_(hid_report)("Read failed. Likely an unplugged device\n"); else if (size == 0) TRACE_(hid_report)("Failed to read report\n"); - else if (set_report_from_event(private, &ie)) - bus_event_queue_input_report(&event_queue, iface, private->current_report_buffer, private->buffer_length); + else if (set_report_from_event(impl, &ie)) + bus_event_queue_input_report(&event_queue, iface, impl->current_report_buffer, impl->buffer_length); }
static void lnxev_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) @@ -940,7 +951,7 @@ static void udev_add_device(struct udev_device *dev) { .input = -1, }; - struct platform_private *private; + struct base_device *impl; const char *subsystem; const char *devnode; int fd; @@ -957,7 +968,7 @@ static void udev_add_device(struct udev_device *dev) TRACE("udev %s syspath %s\n", debugstr_a(devnode), udev_device_get_syspath(dev));
#ifdef HAS_PROPER_INPUT_HEADER - if ((private = find_device_from_syspath(get_device_syspath(dev)))) + if ((impl = find_device_from_syspath(get_device_syspath(dev)))) { TRACE("duplicate device found, not adding the new one\n"); close(fd); @@ -1021,24 +1032,24 @@ static void udev_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0) { - if (!(private = unix_device_create(&hidraw_device_vtbl, sizeof(struct platform_private)))) return; - list_add_tail(&device_list, &private->unix_device.entry); - private->read_report = hidraw_device_read_report; - private->udev_device = udev_device_ref(dev); - private->device_fd = fd; + if (!(impl = unix_device_create(&hidraw_device_vtbl, sizeof(struct hidraw_device)))) return; + list_add_tail(&device_list, &impl->unix_device.entry); + impl->read_report = hidraw_device_read_report; + impl->udev_device = udev_device_ref(dev); + impl->device_fd = fd;
- bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); + bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc); } #ifdef HAS_PROPER_INPUT_HEADER else if (strcmp(subsystem, "input") == 0) { - if (!(private = unix_device_create(&lnxev_device_vtbl, sizeof(struct wine_input_private)))) return; - list_add_tail(&device_list, &private->unix_device.entry); - private->read_report = lnxev_device_read_report; - private->udev_device = udev_device_ref(dev); - private->device_fd = fd; + if (!(impl = unix_device_create(&lnxev_device_vtbl, sizeof(struct lnxev_device)))) return; + list_add_tail(&device_list, &impl->unix_device.entry); + impl->read_report = lnxev_device_read_report; + impl->udev_device = udev_device_ref(dev); + impl->device_fd = fd;
- bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); + bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc); } #endif } @@ -1134,7 +1145,7 @@ error:
static void process_monitor_event(struct udev_monitor *monitor) { - struct platform_private *device; + struct base_device *impl; struct udev_device *dev; const char *action;
@@ -1155,8 +1166,8 @@ static void process_monitor_event(struct udev_monitor *monitor) udev_add_device(dev); else if (strcmp(action, "remove") == 0) { - device = find_device_from_udev(dev); - if (device) bus_event_queue_device_removed(&event_queue, &device->unix_device); + impl = find_device_from_udev(dev); + if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device); else WARN("failed to find device for udev device %p\n", dev); } else @@ -1212,9 +1223,9 @@ error:
NTSTATUS udev_bus_wait(void *args) { - struct platform_private *device; struct bus_event *result = args; struct pollfd pfd[MAX_DEVICES]; + struct base_device *impl; char ctrl = 0; int i, count;
@@ -1240,8 +1251,8 @@ NTSTATUS udev_bus_wait(void *args) for (i = 2; i < count; ++i) { if (!pfd[i].revents) continue; - device = find_device_from_fd(pfd[i].fd); - if (device) device->read_report(&device->unix_device); + impl = find_device_from_fd(pfd[i].fd); + if (impl) impl->read_report(&impl->unix_device); } pthread_mutex_unlock(&udev_cs); }
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_iohid.c | 62 ++++++++++++++++++------------------ 1 file changed, 31 insertions(+), 31 deletions(-)
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 220dae92496..9b32289a1f6 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -108,24 +108,24 @@ static struct list event_queue = LIST_INIT(event_queue); static struct list device_list = LIST_INIT(device_list); static struct iohid_bus_options options;
-struct platform_private +struct iohid_device { struct unix_device unix_device; IOHIDDeviceRef device; uint8_t *buffer; };
-static inline struct platform_private *impl_from_unix_device(struct unix_device *iface) +static inline struct iohid_device *impl_from_unix_device(struct unix_device *iface) { - return CONTAINING_RECORD(iface, struct platform_private, unix_device); + return CONTAINING_RECORD(iface, struct iohid_device, unix_device); }
-static struct platform_private *find_device_from_iohid(IOHIDDeviceRef IOHIDDevice) +static struct iohid_device *find_device_from_iohid(IOHIDDeviceRef IOHIDDevice) { - struct platform_private *private; + struct iohid_device *impl;
- LIST_FOR_EACH_ENTRY(private, &device_list, struct platform_private, unix_device.entry) - if (!private->device == IOHIDDevice) return private; + LIST_FOR_EACH_ENTRY(impl, &device_list, struct iohid_device, unix_device.entry) + if (!impl->device == IOHIDDevice) return impl;
return NULL; } @@ -160,33 +160,33 @@ static void iohid_device_destroy(struct unix_device *iface) static NTSTATUS iohid_device_start(struct unix_device *iface) { DWORD length; - struct platform_private *private = impl_from_unix_device(iface); + struct iohid_device *impl = impl_from_unix_device(iface); CFNumberRef num;
- num = IOHIDDeviceGetProperty(private->device, CFSTR(kIOHIDMaxInputReportSizeKey)); + num = IOHIDDeviceGetProperty(impl->device, CFSTR(kIOHIDMaxInputReportSizeKey)); length = CFNumberToDWORD(num); - private->buffer = malloc(length); + impl->buffer = malloc(length);
- IOHIDDeviceRegisterInputReportCallback(private->device, private->buffer, length, handle_IOHIDDeviceIOHIDReportCallback, iface); + IOHIDDeviceRegisterInputReportCallback(impl->device, impl->buffer, length, handle_IOHIDDeviceIOHIDReportCallback, iface); return STATUS_SUCCESS; }
static void iohid_device_stop(struct unix_device *iface) { - struct platform_private *private = impl_from_unix_device(iface); + struct iohid_device *impl = impl_from_unix_device(iface);
- IOHIDDeviceRegisterInputReportCallback(private->device, NULL, 0, NULL, NULL); + IOHIDDeviceRegisterInputReportCallback(impl->device, NULL, 0, NULL, NULL);
pthread_mutex_lock(&iohid_cs); - list_remove(&private->unix_device.entry); + list_remove(&impl->unix_device.entry); pthread_mutex_unlock(&iohid_cs); }
static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *out_length) { - struct platform_private *private = impl_from_unix_device(iface); - CFDataRef data = IOHIDDeviceGetProperty(private->device, CFSTR(kIOHIDReportDescriptorKey)); + struct iohid_device *impl = impl_from_unix_device(iface); + CFDataRef data = IOHIDDeviceGetProperty(impl->device, CFSTR(kIOHIDReportDescriptorKey)); int data_length = CFDataGetLength(data); const UInt8 *ptr;
@@ -202,8 +202,8 @@ static NTSTATUS iohid_device_get_report_descriptor(struct unix_device *iface, BY static void iohid_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { IOReturn result; - struct platform_private *private = impl_from_unix_device(iface); - result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeOutput, packet->reportId, + struct iohid_device *impl = impl_from_unix_device(iface); + result = IOHIDDeviceSetReport(impl->device, kIOHIDReportTypeOutput, packet->reportId, packet->reportBuffer, packet->reportBufferLen); if (result == kIOReturnSuccess) { @@ -221,9 +221,9 @@ static void iohid_device_get_feature_report(struct unix_device *iface, HID_XFER_ { IOReturn ret; CFIndex report_length = packet->reportBufferLen; - struct platform_private *private = impl_from_unix_device(iface); + struct iohid_device *impl = impl_from_unix_device(iface);
- ret = IOHIDDeviceGetReport(private->device, kIOHIDReportTypeFeature, packet->reportId, + ret = IOHIDDeviceGetReport(impl->device, kIOHIDReportTypeFeature, packet->reportId, packet->reportBuffer, &report_length); if (ret == kIOReturnSuccess) { @@ -240,9 +240,9 @@ static void iohid_device_get_feature_report(struct unix_device *iface, HID_XFER_ static void iohid_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { IOReturn result; - struct platform_private *private = impl_from_unix_device(iface); + struct iohid_device *impl = impl_from_unix_device(iface);
- result = IOHIDDeviceSetReport(private->device, kIOHIDReportTypeFeature, packet->reportId, + result = IOHIDDeviceSetReport(impl->device, kIOHIDReportTypeFeature, packet->reportId, packet->reportBuffer, packet->reportBufferLen); if (result == kIOReturnSuccess) { @@ -274,7 +274,7 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void * .input = -1, .serialnumber = {"0000"}, }; - struct platform_private *private; + struct iohid_device *impl; CFStringRef str = NULL;
desc.vid = CFNumberToDWORD(IOHIDDeviceGetProperty(IOHIDDevice, CFSTR(kIOHIDVendorIDKey))); @@ -343,17 +343,17 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
TRACE("dev %p, desc %s.\n", IOHIDDevice, debugstr_device_desc(&desc));
- if (!(private = unix_device_create(&iohid_device_vtbl, sizeof(struct platform_private)))) return; - list_add_tail(&device_list, &private->unix_device.entry); - private->device = IOHIDDevice; - private->buffer = NULL; + if (!(impl = unix_device_create(&iohid_device_vtbl, sizeof(struct iohid_device)))) return; + list_add_tail(&device_list, &impl->unix_device.entry); + impl->device = IOHIDDevice; + impl->buffer = NULL;
- bus_event_queue_device_created(&event_queue, &private->unix_device, &desc); + bus_event_queue_device_created(&event_queue, &impl->unix_device, &desc); }
static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceRef IOHIDDevice) { - struct platform_private *device; + struct iohid_device *impl;
TRACE("OS/X IOHID Device Removed %p\n", IOHIDDevice); IOHIDDeviceRegisterInputReportCallback(IOHIDDevice, NULL, 0, NULL, NULL); @@ -362,8 +362,8 @@ static void handle_RemovalCallback(void *context, IOReturn result, void *sender, IOHIDDeviceUnscheduleFromRunLoop(IOHIDDevice, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDDeviceClose(IOHIDDevice, 0);
- device = find_device_from_iohid(IOHIDDevice); - if (device) bus_event_queue_device_removed(&event_queue, &device->unix_device); + impl = find_device_from_iohid(IOHIDDevice); + if (impl) bus_event_queue_device_removed(&event_queue, &impl->unix_device); else WARN("failed to find device for iohid device %p\n", IOHIDDevice); }
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=98483
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 Task: Patch failed to apply
For any device which requires building HID reports.
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_iohid.c | 4 +- dlls/winebus.sys/bus_sdl.c | 70 ++++++++------------ dlls/winebus.sys/bus_udev.c | 46 +++++-------- dlls/winebus.sys/hid.c | 113 ++++++++++++++++++++++++-------- dlls/winebus.sys/unix_private.h | 51 ++++++++------ dlls/winebus.sys/unixlib.c | 70 ++++---------------- 6 files changed, 174 insertions(+), 180 deletions(-)
diff --git a/dlls/winebus.sys/bus_iohid.c b/dlls/winebus.sys/bus_iohid.c index 9b32289a1f6..2dadcc793b1 100644 --- a/dlls/winebus.sys/bus_iohid.c +++ b/dlls/winebus.sys/bus_iohid.c @@ -256,7 +256,7 @@ static void iohid_device_set_feature_report(struct unix_device *iface, HID_XFER_ } }
-static const struct unix_device_vtbl iohid_device_vtbl = +static const struct raw_device_vtbl iohid_device_vtbl = { iohid_device_destroy, iohid_device_start, @@ -343,7 +343,7 @@ static void handle_DeviceMatchingCallback(void *context, IOReturn result, void *
TRACE("dev %p, desc %s.\n", IOHIDDevice, debugstr_device_desc(&desc));
- if (!(impl = unix_device_create(&iohid_device_vtbl, sizeof(struct iohid_device)))) return; + if (!(impl = raw_device_create(&iohid_device_vtbl, sizeof(struct iohid_device)))) return; list_add_tail(&device_list, &impl->unix_device.entry); impl->device = IOHIDDevice; impl->buffer = NULL; diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index eaa0ed9329e..908b6614287 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -128,8 +128,6 @@ struct sdl_device int ball_start; int hat_start;
- struct hid_descriptor desc; - int buffer_length; BYTE *report_buffer;
@@ -219,7 +217,7 @@ static BOOL descriptor_add_haptic(struct sdl_device *impl) { pSDL_HapticStopAll(impl->sdl_haptic); pSDL_HapticRumbleInit(impl->sdl_haptic); - if (!hid_descriptor_add_haptics(&impl->desc)) + if (!hid_device_add_haptics(&impl->unix_device)) return FALSE; impl->haptic_effect_id = -1; } @@ -233,7 +231,7 @@ static BOOL descriptor_add_haptic(struct sdl_device *impl) return TRUE; }
-static NTSTATUS build_joystick_report_descriptor(struct sdl_device *impl) +static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) { static const USAGE joystick_usages[] = { @@ -247,7 +245,7 @@ static NTSTATUS build_joystick_report_descriptor(struct sdl_device *impl) HID_USAGE_GENERIC_DIAL, HID_USAGE_GENERIC_WHEEL }; - + struct sdl_device *impl = impl_from_unix_device(iface); int i, report_size = 1; int button_count, axis_count, ball_count, hat_count;
@@ -280,27 +278,27 @@ static NTSTATUS build_joystick_report_descriptor(struct sdl_device *impl)
TRACE("Report will be %i bytes\n", report_size);
- if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) + if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) return STATUS_NO_MEMORY;
- if (axis_count && !hid_descriptor_add_axes(&impl->desc, axis_count, HID_USAGE_PAGE_GENERIC, - joystick_usages, FALSE, -32768, 32767)) + if (axis_count && !hid_device_add_axes(iface, axis_count, HID_USAGE_PAGE_GENERIC, + joystick_usages, FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (ball_count && !hid_descriptor_add_axes(&impl->desc, ball_count * 2, HID_USAGE_PAGE_GENERIC, - &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) + if (ball_count && !hid_device_add_axes(iface, ball_count * 2, HID_USAGE_PAGE_GENERIC, + &joystick_usages[axis_count], TRUE, INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
- if (hat_count && !hid_descriptor_add_hatswitch(&impl->desc, hat_count)) + if (hat_count && !hid_device_add_hatswitch(iface, hat_count)) return STATUS_NO_MEMORY;
- if (button_count && !hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (button_count && !hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(impl)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_end(&impl->desc)) + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
impl->buffer_length = report_size; @@ -316,7 +314,6 @@ static NTSTATUS build_joystick_report_descriptor(struct sdl_device *impl)
failed: free(impl->report_buffer); - hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
@@ -347,11 +344,12 @@ static SHORT compose_dpad_value(SDL_GameController *joystick) return SDL_HAT_CENTERED; }
-static NTSTATUS build_controller_report_descriptor(struct sdl_device *impl) +static NTSTATUS build_controller_report_descriptor(struct unix_device *iface) { static const USAGE left_axis_usages[] = {HID_USAGE_GENERIC_X, HID_USAGE_GENERIC_Y}; static const USAGE right_axis_usages[] = {HID_USAGE_GENERIC_RX, HID_USAGE_GENERIC_RY}; static const USAGE trigger_axis_usages[] = {HID_USAGE_GENERIC_Z, HID_USAGE_GENERIC_RZ}; + struct sdl_device *impl = impl_from_unix_device(iface); ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1; C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
@@ -362,31 +360,31 @@ static NTSTATUS build_controller_report_descriptor(struct sdl_device *impl)
TRACE("Report will be %i bytes\n", impl->buffer_length);
- if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) + if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, - FALSE, -32768, 32767)) + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, left_axis_usages, + FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, - FALSE, -32768, 32767)) + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, right_axis_usages, + FALSE, -32768, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_axes(&impl->desc, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, - FALSE, 0, 32767)) + if (!hid_device_add_axes(iface, 2, HID_USAGE_PAGE_GENERIC, trigger_axis_usages, + FALSE, 0, 32767)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_hatswitch(&impl->desc, 1)) + if (!hid_device_add_hatswitch(iface, 1)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
if (!descriptor_add_haptic(impl)) return STATUS_NO_MEMORY;
- if (!hid_descriptor_end(&impl->desc)) + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
if (!(impl->report_buffer = calloc(1, impl->buffer_length))) goto failed; @@ -400,7 +398,6 @@ static NTSTATUS build_controller_report_descriptor(struct sdl_device *impl)
failed: free(impl->report_buffer); - hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
@@ -411,8 +408,8 @@ static void sdl_device_destroy(struct unix_device *iface) static NTSTATUS sdl_device_start(struct unix_device *iface) { struct sdl_device *impl = impl_from_unix_device(iface); - if (impl->sdl_controller) return build_controller_report_descriptor(impl); - return build_joystick_report_descriptor(impl); + if (impl->sdl_controller) return build_controller_report_descriptor(iface); + return build_joystick_report_descriptor(iface); }
static void sdl_device_stop(struct unix_device *iface) @@ -428,18 +425,6 @@ static void sdl_device_stop(struct unix_device *iface) pthread_mutex_unlock(&sdl_cs); }
-static NTSTATUS sdl_device_get_reportdescriptor(struct unix_device *iface, BYTE *buffer, - DWORD length, DWORD *out_length) -{ - struct sdl_device *impl = impl_from_unix_device(iface); - - *out_length = impl->desc.size; - if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL; - - memcpy(buffer, impl->desc.data, impl->desc.size); - return STATUS_SUCCESS; -} - static void sdl_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { struct sdl_device *impl = impl_from_unix_device(iface); @@ -499,12 +484,11 @@ static void sdl_device_set_feature_report(struct unix_device *iface, HID_XFER_PA io->Status = STATUS_NOT_IMPLEMENTED; }
-static const struct unix_device_vtbl sdl_device_vtbl = +static const struct hid_device_vtbl sdl_device_vtbl = { sdl_device_destroy, sdl_device_start, sdl_device_stop, - sdl_device_get_reportdescriptor, sdl_device_set_output_report, sdl_device_get_feature_report, sdl_device_set_feature_report, @@ -664,7 +648,7 @@ static void sdl_add_device(unsigned int index)
TRACE("%s id %d, desc %s.\n", controller ? "controller" : "joystick", id, debugstr_device_desc(&desc));
- if (!(impl = unix_device_create(&sdl_device_vtbl, sizeof(struct sdl_device)))) return; + if (!(impl = hid_device_create(&sdl_device_vtbl, sizeof(struct sdl_device)))) return; list_add_tail(&device_list, &impl->unix_device.entry); impl->sdl_joystick = joystick; impl->sdl_controller = controller; diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 09b00e177a4..0aa3094d348 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -127,8 +127,6 @@ struct lnxev_device BYTE *current_report_buffer; enum { FIRST, NORMAL, DROPPED } report_state;
- struct hid_descriptor desc; - int button_start; BYTE button_map[KEY_MAX]; BYTE rel_map[HID_REL_MAX]; @@ -451,7 +449,7 @@ static INT count_abs_axis(int device_fd) return abs_count; }
-static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_device *dev) +static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_device *dev) { struct input_absinfo abs_info[HID_ABS_MAX]; BYTE absbits[(ABS_MAX+7)/8]; @@ -461,6 +459,7 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d INT report_size; INT button_count, abs_count, rel_count, hat_count; const BYTE *device_usage = what_am_I(dev); + struct lnxev_device *impl = lnxev_impl_from_unix_device(iface);
if (ioctl(impl->base.device_fd, EVIOCGBIT(EV_REL, sizeof(relbits)), relbits) == -1) { @@ -475,7 +474,7 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d
report_size = 0;
- if (!hid_descriptor_begin(&impl->desc, device_usage[0], device_usage[1])) + if (!hid_device_begin_report_descriptor(iface, device_usage[0], device_usage[1])) return STATUS_NO_MEMORY;
abs_count = 0; @@ -487,8 +486,8 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d if (!(usage.UsagePage = ABS_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = ABS_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&impl->desc, 1, usage.UsagePage, &usage.Usage, FALSE, - LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) + if (!hid_device_add_axes(iface, 1, usage.UsagePage, &usage.Usage, FALSE, + LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) return STATUS_NO_MEMORY;
impl->abs_map[i] = report_size; @@ -503,8 +502,8 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d if (!(usage.UsagePage = REL_TO_HID_MAP[i][0])) continue; if (!(usage.Usage = REL_TO_HID_MAP[i][1])) continue;
- if (!hid_descriptor_add_axes(&impl->desc, 1, usage.UsagePage, &usage.Usage, TRUE, - INT32_MIN, INT32_MAX)) + if (!hid_device_add_axes(iface, 1, usage.UsagePage, &usage.Usage, TRUE, + INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
impl->rel_map[i] = report_size; @@ -525,7 +524,7 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d
if (hat_count) { - if (!hid_descriptor_add_hatswitch(&impl->desc, hat_count)) + if (!hid_device_add_hatswitch(iface, hat_count)) return STATUS_NO_MEMORY; }
@@ -534,13 +533,13 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d button_count = count_buttons(impl->base.device_fd, impl->button_map); if (button_count) { - if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, button_count)) + if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) return STATUS_NO_MEMORY;
report_size += (button_count + 7) / 8; }
- if (!hid_descriptor_end(&impl->desc)) + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
TRACE("Report will be %i bytes\n", report_size); @@ -560,7 +559,6 @@ static NTSTATUS build_report_descriptor(struct lnxev_device *impl, struct udev_d failed: free(impl->current_report_buffer); free(impl->last_report_buffer); - hid_descriptor_free(&impl->desc); return STATUS_NO_MEMORY; }
@@ -785,7 +783,7 @@ static void hidraw_device_set_feature_report(struct unix_device *iface, HID_XFER #endif }
-static const struct unix_device_vtbl hidraw_device_vtbl = +static const struct raw_device_vtbl hidraw_device_vtbl = { hidraw_device_destroy, hidraw_device_start, @@ -804,7 +802,6 @@ static void lnxev_device_destroy(struct unix_device *iface)
free(impl->current_report_buffer); free(impl->last_report_buffer); - hid_descriptor_free(&impl->desc);
udev_device_unref(impl->base.udev_device); } @@ -814,7 +811,7 @@ static NTSTATUS lnxev_device_start(struct unix_device *iface) struct lnxev_device *impl = lnxev_impl_from_unix_device(iface); NTSTATUS status;
- if ((status = build_report_descriptor(impl, impl->base.udev_device))) + if ((status = build_report_descriptor(iface, impl->base.udev_device))) return status;
pthread_mutex_lock(&udev_cs); @@ -833,18 +830,6 @@ static void lnxev_device_stop(struct unix_device *iface) pthread_mutex_unlock(&udev_cs); }
-static NTSTATUS lnxev_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, - DWORD length, DWORD *out_length) -{ - struct lnxev_device *impl = lnxev_impl_from_unix_device(iface); - - *out_length = impl->desc.size; - if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL; - - memcpy(buffer, impl->desc.data, impl->desc.size); - return STATUS_SUCCESS; -} - static void lnxev_device_read_report(struct unix_device *iface) { struct lnxev_device *impl = lnxev_impl_from_unix_device(iface); @@ -881,12 +866,11 @@ static void lnxev_device_set_feature_report(struct unix_device *iface, HID_XFER_ io->Status = STATUS_NOT_IMPLEMENTED; }
-static const struct unix_device_vtbl lnxev_device_vtbl = +static const struct hid_device_vtbl lnxev_device_vtbl = { lnxev_device_destroy, lnxev_device_start, lnxev_device_stop, - lnxev_device_get_report_descriptor, lnxev_device_set_output_report, lnxev_device_get_feature_report, lnxev_device_set_feature_report, @@ -1032,7 +1016,7 @@ static void udev_add_device(struct udev_device *dev)
if (strcmp(subsystem, "hidraw") == 0) { - if (!(impl = unix_device_create(&hidraw_device_vtbl, sizeof(struct hidraw_device)))) return; + if (!(impl = raw_device_create(&hidraw_device_vtbl, sizeof(struct hidraw_device)))) return; list_add_tail(&device_list, &impl->unix_device.entry); impl->read_report = hidraw_device_read_report; impl->udev_device = udev_device_ref(dev); @@ -1043,7 +1027,7 @@ static void udev_add_device(struct udev_device *dev) #ifdef HAS_PROPER_INPUT_HEADER else if (strcmp(subsystem, "input") == 0) { - if (!(impl = unix_device_create(&lnxev_device_vtbl, sizeof(struct lnxev_device)))) return; + if (!(impl = hid_device_create(&lnxev_device_vtbl, sizeof(struct lnxev_device)))) return; list_add_tail(&device_list, &impl->unix_device.entry); impl->read_report = lnxev_device_read_report; impl->udev_device = udev_device_ref(dev); diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index d2dff7e5a24..98eb5341a2e 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -34,7 +34,7 @@
#include "unix_private.h"
-static BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffer, SIZE_T size) +static BOOL hid_report_descriptor_append(struct hid_report_descriptor *desc, const BYTE *buffer, SIZE_T size) { BYTE *tmp = desc->data;
@@ -57,18 +57,19 @@ static BOOL hid_descriptor_append(struct hid_descriptor *desc, const BYTE *buffe
#include "psh_hid_macros.h"
-static BOOL hid_descriptor_append_usage(struct hid_descriptor *desc, USAGE usage) +static BOOL hid_report_descriptor_append_usage(struct hid_report_descriptor *desc, USAGE usage) { const BYTE template[] = { USAGE(2, usage), };
- return hid_descriptor_append(desc, template, sizeof(template)); + return hid_report_descriptor_append(desc, template, sizeof(template)); }
-BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) +BOOL hid_device_begin_report_descriptor(struct unix_device *iface, USAGE usage_page, USAGE usage) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; const BYTE template[] = { USAGE_PAGE(2, usage_page), @@ -78,27 +79,23 @@ BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE u };
memset(desc, 0, sizeof(*desc)); - return hid_descriptor_append(desc, template, sizeof(template)); + return hid_report_descriptor_append(desc, template, sizeof(template)); }
-BOOL hid_descriptor_end(struct hid_descriptor *desc) +BOOL hid_device_end_report_descriptor(struct unix_device *iface) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; static const BYTE template[] = { END_COLLECTION, };
- return hid_descriptor_append(desc, template, sizeof(template)); + return hid_report_descriptor_append(desc, template, sizeof(template)); }
-void hid_descriptor_free(struct hid_descriptor *desc) -{ - free(desc->data); -} - -BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, - USAGE usage_min, USAGE usage_max) +BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, USAGE usage_min, USAGE usage_max) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; const USHORT count = usage_max - usage_min + 1; const BYTE template[] = { @@ -120,17 +117,18 @@ BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, INPUT(1, Cnst|Var|Abs), };
- if (!hid_descriptor_append(desc, template, sizeof(template))) + if (!hid_report_descriptor_append(desc, template, sizeof(template))) return FALSE;
- if ((count % 8) && !hid_descriptor_append(desc, template_pad, sizeof(template_pad))) + if ((count % 8) && !hid_report_descriptor_append(desc, template_pad, sizeof(template_pad))) return FALSE;
return TRUE; }
-BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) +BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; const BYTE template[] = { USAGE_PAGE(1, HID_USAGE_PAGE_GENERIC), @@ -145,12 +143,13 @@ BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) INPUT(1, Data|Var|Abs|Null), };
- return hid_descriptor_append(desc, template, sizeof(template)); + return hid_report_descriptor_append(desc, template, sizeof(template)); }
-BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, - const USAGE *usages, BOOL rel, LONG min, LONG max) +BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page, + const USAGE *usages, BOOL rel, LONG min, LONG max) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; const BYTE template_begin[] = { USAGE_PAGE(1, usage_page), @@ -172,26 +171,27 @@ BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usag }; int i;
- if (!hid_descriptor_append(desc, template_begin, sizeof(template_begin))) + if (!hid_report_descriptor_append(desc, template_begin, sizeof(template_begin))) return FALSE;
for (i = 0; i < count; i++) { - if (!hid_descriptor_append_usage(desc, usages[i])) + if (!hid_report_descriptor_append_usage(desc, usages[i])) return FALSE; }
- if (!hid_descriptor_append(desc, template, sizeof(template))) + if (!hid_report_descriptor_append(desc, template, sizeof(template))) return FALSE;
- if (!hid_descriptor_append(desc, template_end, sizeof(template_end))) + if (!hid_report_descriptor_append(desc, template_end, sizeof(template_end))) return FALSE;
return TRUE; }
-BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) +BOOL hid_device_add_haptics(struct unix_device *iface) { + struct hid_report_descriptor *desc = &iface->hid_report_descriptor; static const BYTE template[] = { USAGE_PAGE(2, HID_USAGE_PAGE_VENDOR_DEFINED_BEGIN), @@ -214,7 +214,68 @@ BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) OUTPUT(1, Data|Var|Abs), };
- return hid_descriptor_append(desc, template, sizeof(template)); + return hid_report_descriptor_append(desc, template, sizeof(template)); }
#include "pop_hid_macros.h" + +static void hid_device_destroy(struct unix_device *iface) +{ + iface->hid_vtbl->destroy(iface); + free(iface->hid_report_descriptor.data); +} + +static NTSTATUS hid_device_start(struct unix_device *iface) +{ + return iface->hid_vtbl->start(iface); +} + +static void hid_device_stop(struct unix_device *iface) +{ + iface->hid_vtbl->stop(iface); +} + +NTSTATUS hid_device_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *out_length) +{ + *out_length = iface->hid_report_descriptor.size; + if (length < iface->hid_report_descriptor.size) return STATUS_BUFFER_TOO_SMALL; + + memcpy(buffer, iface->hid_report_descriptor.data, iface->hid_report_descriptor.size); + return STATUS_SUCCESS; +} + +static void hid_device_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) +{ + return iface->hid_vtbl->set_output_report(iface, packet, io); +} + +static void hid_device_get_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) +{ + return iface->hid_vtbl->get_feature_report(iface, packet, io); +} + +static void hid_device_set_feature_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) +{ + return iface->hid_vtbl->set_feature_report(iface, packet, io); +} + +static const struct raw_device_vtbl raw_device_vtbl = +{ + hid_device_destroy, + hid_device_start, + hid_device_stop, + hid_device_get_report_descriptor, + hid_device_set_output_report, + hid_device_get_feature_report, + hid_device_set_feature_report, +}; + +void *hid_device_create(const struct hid_device_vtbl *vtbl, SIZE_T size) +{ + struct unix_device *impl; + + if (!(impl = raw_device_create(&raw_device_vtbl, size))) return NULL; + impl->hid_vtbl = vtbl; + + return impl; +} diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index cfb56d2d83e..d1d48737e67 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -29,7 +29,7 @@
#include "wine/list.h"
-struct unix_device_vtbl +struct raw_device_vtbl { void (*destroy)(struct unix_device *iface); NTSTATUS (*start)(struct unix_device *iface); @@ -40,14 +40,35 @@ struct unix_device_vtbl void (*set_feature_report)(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); };
+struct hid_device_vtbl +{ + void (*destroy)(struct unix_device *iface); + NTSTATUS (*start)(struct unix_device *iface); + void (*stop)(struct unix_device *iface); + void (*set_output_report)(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); + void (*get_feature_report)(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); + void (*set_feature_report)(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io); +}; + +struct hid_report_descriptor +{ + BYTE *data; + SIZE_T size; + SIZE_T max_size; +}; + struct unix_device { - const struct unix_device_vtbl *vtbl; + const struct raw_device_vtbl *vtbl; struct list entry; LONG ref; + + const struct hid_device_vtbl *hid_vtbl; + struct hid_report_descriptor hid_report_descriptor; };
-extern void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN; +extern void *raw_device_create(const struct raw_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN; +extern void *hid_device_create(const struct hid_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN;
extern NTSTATUS sdl_bus_init(void *) DECLSPEC_HIDDEN; extern NTSTATUS sdl_bus_wait(void *) DECLSPEC_HIDDEN; @@ -69,24 +90,16 @@ extern BOOL bus_event_queue_input_report(struct list *queue, struct unix_device BYTE *report, USHORT length) DECLSPEC_HIDDEN; extern BOOL bus_event_queue_pop(struct list *queue, struct bus_event *event) DECLSPEC_HIDDEN;
-struct hid_descriptor -{ - BYTE *data; - SIZE_T size; - SIZE_T max_size; -}; - -extern BOOL hid_descriptor_begin(struct hid_descriptor *desc, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN; -extern BOOL hid_descriptor_end(struct hid_descriptor *desc) DECLSPEC_HIDDEN; -extern void hid_descriptor_free(struct hid_descriptor *desc) DECLSPEC_HIDDEN; +extern BOOL hid_device_begin_report_descriptor(struct unix_device *iface, USAGE usage_page, USAGE usage) DECLSPEC_HIDDEN; +extern BOOL hid_device_end_report_descriptor(struct unix_device *iface) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_add_buttons(struct hid_descriptor *desc, USAGE usage_page, - USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN; -extern BOOL hid_descriptor_add_hatswitch(struct hid_descriptor *desc, INT count) DECLSPEC_HIDDEN; -extern BOOL hid_descriptor_add_axes(struct hid_descriptor *desc, BYTE count, USAGE usage_page, - const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN; +extern BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, + USAGE usage_min, USAGE usage_max) DECLSPEC_HIDDEN; +extern BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count) DECLSPEC_HIDDEN; +extern BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page, + const USAGE *usages, BOOL rel, LONG min, LONG max) DECLSPEC_HIDDEN;
-extern BOOL hid_descriptor_add_haptics(struct hid_descriptor *desc) DECLSPEC_HIDDEN; +extern BOOL hid_device_add_haptics(struct unix_device *iface) DECLSPEC_HIDDEN;
BOOL is_xbox_gamepad(WORD vid, WORD pid) DECLSPEC_HIDDEN;
diff --git a/dlls/winebus.sys/unixlib.c b/dlls/winebus.sys/unixlib.c index 893296e8ebb..8981dce7a55 100644 --- a/dlls/winebus.sys/unixlib.c +++ b/dlls/winebus.sys/unixlib.c @@ -62,29 +62,19 @@ BOOL is_xbox_gamepad(WORD vid, WORD pid) struct mouse_device { struct unix_device unix_device; - struct hid_descriptor desc; };
-static inline struct mouse_device *mouse_from_unix_device(struct unix_device *iface) -{ - return CONTAINING_RECORD(iface, struct mouse_device, unix_device); -} - static void mouse_destroy(struct unix_device *iface) { - struct mouse_device *impl = mouse_from_unix_device(iface); - hid_descriptor_free(&impl->desc); }
static NTSTATUS mouse_start(struct unix_device *iface) { - struct mouse_device *impl = mouse_from_unix_device(iface); - - if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE)) + if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_MOUSE)) return STATUS_NO_MEMORY; - if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_BUTTON, 1, 3)) + if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, 3)) return STATUS_NO_MEMORY; - if (!hid_descriptor_end(&impl->desc)) + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
return STATUS_SUCCESS; @@ -94,19 +84,6 @@ static void mouse_stop(struct unix_device *iface) { }
-static NTSTATUS mouse_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *ret_length) -{ - struct mouse_device *impl = mouse_from_unix_device(iface); - - TRACE("buffer %p, length %u.\n", buffer, length); - - *ret_length = impl->desc.size; - if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL; - - memcpy(buffer, impl->desc.data, impl->desc.size); - return STATUS_SUCCESS; -} - static void mouse_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { FIXME("id %u, stub!\n", packet->reportId); @@ -128,12 +105,11 @@ static void mouse_set_feature_report(struct unix_device *iface, HID_XFER_PACKET io->Status = STATUS_NOT_IMPLEMENTED; }
-static const struct unix_device_vtbl mouse_vtbl = +static const struct hid_device_vtbl mouse_vtbl = { mouse_destroy, mouse_start, mouse_stop, - mouse_get_report_descriptor, mouse_set_output_report, mouse_get_feature_report, mouse_set_feature_report, @@ -153,36 +129,26 @@ static NTSTATUS mouse_device_create(void *args) { struct device_create_params *params = args; params->desc = mouse_device_desc; - params->device = unix_device_create(&mouse_vtbl, sizeof(struct mouse_device)); + params->device = hid_device_create(&mouse_vtbl, sizeof(struct mouse_device)); return STATUS_SUCCESS; }
struct keyboard_device { struct unix_device unix_device; - struct hid_descriptor desc; };
-static inline struct keyboard_device *keyboard_from_unix_device(struct unix_device *iface) -{ - return CONTAINING_RECORD(iface, struct keyboard_device, unix_device); -} - static void keyboard_destroy(struct unix_device *iface) { - struct keyboard_device *impl = keyboard_from_unix_device(iface); - hid_descriptor_free(&impl->desc); }
static NTSTATUS keyboard_start(struct unix_device *iface) { - struct keyboard_device *impl = keyboard_from_unix_device(iface); - - if (!hid_descriptor_begin(&impl->desc, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD)) + if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_KEYBOARD)) return STATUS_NO_MEMORY; - if (!hid_descriptor_add_buttons(&impl->desc, HID_USAGE_PAGE_KEYBOARD, 0, 101)) + if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_KEYBOARD, 0, 101)) return STATUS_NO_MEMORY; - if (!hid_descriptor_end(&impl->desc)) + if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
return STATUS_SUCCESS; @@ -192,19 +158,6 @@ static void keyboard_stop(struct unix_device *iface) { }
-static NTSTATUS keyboard_get_report_descriptor(struct unix_device *iface, BYTE *buffer, DWORD length, DWORD *ret_length) -{ - struct keyboard_device *impl = keyboard_from_unix_device(iface); - - TRACE("buffer %p, length %u.\n", buffer, length); - - *ret_length = impl->desc.size; - if (length < impl->desc.size) return STATUS_BUFFER_TOO_SMALL; - - memcpy(buffer, impl->desc.data, impl->desc.size); - return STATUS_SUCCESS; -} - static void keyboard_set_output_report(struct unix_device *iface, HID_XFER_PACKET *packet, IO_STATUS_BLOCK *io) { FIXME("id %u, stub!\n", packet->reportId); @@ -226,12 +179,11 @@ static void keyboard_set_feature_report(struct unix_device *iface, HID_XFER_PACK io->Status = STATUS_NOT_IMPLEMENTED; }
-static const struct unix_device_vtbl keyboard_vtbl = +static const struct hid_device_vtbl keyboard_vtbl = { keyboard_destroy, keyboard_start, keyboard_stop, - keyboard_get_report_descriptor, keyboard_set_output_report, keyboard_get_feature_report, keyboard_set_feature_report, @@ -251,11 +203,11 @@ static NTSTATUS keyboard_device_create(void *args) { struct device_create_params *params = args; params->desc = keyboard_device_desc; - params->device = unix_device_create(&keyboard_vtbl, sizeof(struct keyboard_device)); + params->device = hid_device_create(&keyboard_vtbl, sizeof(struct keyboard_device)); return STATUS_SUCCESS; }
-void *unix_device_create(const struct unix_device_vtbl *vtbl, SIZE_T size) +void *raw_device_create(const struct raw_device_vtbl *vtbl, SIZE_T size) { struct unix_device *iface;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=98484
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/hid.c | 83 +++++++++++++++++++++++++++++++++ dlls/winebus.sys/unix_private.h | 14 ++++++ 2 files changed, 97 insertions(+)
diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index 98eb5341a2e..6d3dae5690d 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -32,8 +32,12 @@ #include "hidusage.h" #include "ddk/wdm.h"
+#include "wine/debug.h" + #include "unix_private.h"
+WINE_DEFAULT_DEBUG_CHANNEL(plugplay); + static BOOL hid_report_descriptor_append(struct hid_report_descriptor *desc, const BYTE *buffer, SIZE_T size) { BYTE *tmp = desc->data; @@ -93,6 +97,25 @@ BOOL hid_device_end_report_descriptor(struct unix_device *iface) return hid_report_descriptor_append(desc, template, sizeof(template)); }
+static BOOL hid_device_add_button_count(struct unix_device *iface, BYTE count) +{ + USHORT offset = iface->hid_device_state.bit_size / 8; + + if ((iface->hid_device_state.bit_size % 8) && !iface->hid_device_state.button_count) + ERR("buttons should start byte aligned, missing padding!\n"); + else if (iface->hid_device_state.bit_size + count > 0x80000) + ERR("report size overflow, too many elements!\n"); + else + { + if (!iface->hid_device_state.button_count) iface->hid_device_state.button_start = offset; + iface->hid_device_state.button_count += count; + iface->hid_device_state.bit_size += count; + return TRUE; + } + + return FALSE; +} + BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, USAGE usage_min, USAGE usage_max) { struct hid_report_descriptor *desc = &iface->hid_report_descriptor; @@ -117,6 +140,9 @@ BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, USAGE u INPUT(1, Cnst|Var|Abs), };
+ if (!hid_device_add_button_count(iface, usage_max - usage_min + 1)) + return FALSE; + if (!hid_report_descriptor_append(desc, template, sizeof(template))) return FALSE;
@@ -126,6 +152,27 @@ BOOL hid_device_add_buttons(struct unix_device *iface, USAGE usage_page, USAGE u return TRUE; }
+static BOOL hid_device_add_hatswitch_count(struct unix_device *iface, BYTE count) +{ + USHORT offset = iface->hid_device_state.bit_size / 8; + + if (iface->hid_device_state.button_count) + ERR("hatswitches should be added before buttons!\n"); + else if ((iface->hid_device_state.bit_size % 8)) + ERR("hatswitches should be byte aligned, missing padding!\n"); + else if (iface->hid_device_state.bit_size + 8 * count > 0x80000) + ERR("report size overflow, too many elements!\n"); + else + { + if (!iface->hid_device_state.hatswitch_count) iface->hid_device_state.hatswitch_start = offset; + iface->hid_device_state.hatswitch_count += count; + iface->hid_device_state.bit_size += 8 * count; + return TRUE; + } + + return FALSE; +} + BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count) { struct hid_report_descriptor *desc = &iface->hid_report_descriptor; @@ -143,9 +190,42 @@ BOOL hid_device_add_hatswitch(struct unix_device *iface, INT count) INPUT(1, Data|Var|Abs|Null), };
+ if (!hid_device_add_hatswitch_count(iface, count)) + return FALSE; + return hid_report_descriptor_append(desc, template, sizeof(template)); }
+static BOOL hid_device_add_axis_count(struct unix_device *iface, BOOL rel, BYTE count) +{ + USHORT offset = iface->hid_device_state.bit_size / 8; + + if (!rel && iface->hid_device_state.rel_axis_count) + ERR("absolute axes should be added before relative axes!\n"); + else if (iface->hid_device_state.button_count || iface->hid_device_state.hatswitch_count) + ERR("axes should be added before buttons or hatswitches!\n"); + else if ((iface->hid_device_state.bit_size % 8)) + ERR("axes should be byte aligned, missing padding!\n"); + else if (iface->hid_device_state.bit_size + 32 * count > 0x80000) + ERR("report size overflow, too many elements!\n"); + else if (rel) + { + if (!iface->hid_device_state.rel_axis_count) iface->hid_device_state.rel_axis_start = offset; + iface->hid_device_state.rel_axis_count += count; + iface->hid_device_state.bit_size += 32 * count; + return TRUE; + } + else + { + if (!iface->hid_device_state.abs_axis_count) iface->hid_device_state.abs_axis_start = offset; + iface->hid_device_state.abs_axis_count += count; + iface->hid_device_state.bit_size += 32 * count; + return TRUE; + } + + return FALSE; +} + BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page, const USAGE *usages, BOOL rel, LONG min, LONG max) { @@ -171,6 +251,9 @@ BOOL hid_device_add_axes(struct unix_device *iface, BYTE count, USAGE usage_page }; int i;
+ if (!hid_device_add_axis_count(iface, rel, count)) + return FALSE; + if (!hid_report_descriptor_append(desc, template_begin, sizeof(template_begin))) return FALSE;
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index d1d48737e67..acb2f45aca3 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -57,6 +57,19 @@ struct hid_report_descriptor SIZE_T max_size; };
+struct hid_device_state +{ + ULONG bit_size; + USHORT abs_axis_start; + USHORT abs_axis_count; + USHORT rel_axis_start; + USHORT rel_axis_count; + USHORT hatswitch_start; + USHORT hatswitch_count; + USHORT button_start; + USHORT button_count; +}; + struct unix_device { const struct raw_device_vtbl *vtbl; @@ -65,6 +78,7 @@ struct unix_device
const struct hid_device_vtbl *hid_vtbl; struct hid_report_descriptor hid_report_descriptor; + struct hid_device_state hid_device_state; };
extern void *raw_device_create(const struct raw_device_vtbl *vtbl, SIZE_T size) DECLSPEC_HIDDEN;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=98485
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
Signed-off-by: Rémi Bernon rbernon@codeweavers.com --- dlls/winebus.sys/bus_sdl.c | 70 +++++++++--------------- dlls/winebus.sys/bus_udev.c | 94 ++++++++++++++------------------- dlls/winebus.sys/hid.c | 1 + dlls/winebus.sys/unix_private.h | 1 + 4 files changed, 67 insertions(+), 99 deletions(-)
diff --git a/dlls/winebus.sys/bus_sdl.c b/dlls/winebus.sys/bus_sdl.c index 908b6614287..e6b67fae3c0 100644 --- a/dlls/winebus.sys/bus_sdl.c +++ b/dlls/winebus.sys/bus_sdl.c @@ -123,11 +123,6 @@ struct sdl_device SDL_GameController *sdl_controller; SDL_JoystickID id;
- int button_start; - int axis_start; - int ball_start; - int hat_start; - int buffer_length; BYTE *report_buffer;
@@ -152,40 +147,44 @@ static struct sdl_device *find_device_from_id(SDL_JoystickID id)
static void set_button_value(struct sdl_device *impl, int index, int value) { - int byte_index = impl->button_start + index / 8; + struct hid_device_state *state = &impl->unix_device.hid_device_state; + USHORT offset = state->button_start; + int byte_index = offset + index / 8; int bit_index = index % 8; BYTE mask = 1 << bit_index; - - if (value) - { - impl->report_buffer[byte_index] = impl->report_buffer[byte_index] | mask; - } - else - { - mask = ~mask; - impl->report_buffer[byte_index] = impl->report_buffer[byte_index] & mask; - } + if (index >= state->button_count) return; + if (value) impl->report_buffer[byte_index] |= mask; + else impl->report_buffer[byte_index] &= ~mask; }
static void set_axis_value(struct sdl_device *impl, int index, short value) { - DWORD *report = (DWORD *)(impl->report_buffer + impl->axis_start); - report[index] = LE_DWORD(value); + struct hid_device_state *state = &impl->unix_device.hid_device_state; + USHORT offset = state->abs_axis_start; + if (index >= state->abs_axis_count) return; + offset += index * sizeof(DWORD); + *(DWORD *)&impl->report_buffer[offset] = LE_DWORD(value); }
static void set_ball_value(struct sdl_device *impl, int index, int value1, int value2) { - int offset; - offset = impl->ball_start + (index * sizeof(DWORD)); + struct hid_device_state *state = &impl->unix_device.hid_device_state; + USHORT offset = state->rel_axis_start; + if (index >= state->rel_axis_count) return; + offset += index * sizeof(DWORD); *(DWORD *)&impl->report_buffer[offset] = LE_DWORD(value1); *(DWORD *)&impl->report_buffer[offset + sizeof(DWORD)] = LE_DWORD(value2); }
static void set_hat_value(struct sdl_device *impl, int index, int value) { - int byte = impl->hat_start + index; + struct hid_device_state *state = &impl->unix_device.hid_device_state; + USHORT offset = state->hatswitch_start; unsigned char val;
+ if (index >= state->hatswitch_count) return; + offset += index; + switch (value) { /* 8 1 2 @@ -203,7 +202,7 @@ static void set_hat_value(struct sdl_device *impl, int index, int value) default: return; }
- impl->report_buffer[byte] = val; + impl->report_buffer[offset] = val; }
static BOOL descriptor_add_haptic(struct sdl_device *impl) @@ -246,8 +245,7 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) HID_USAGE_GENERIC_WHEEL }; struct sdl_device *impl = impl_from_unix_device(iface); - int i, report_size = 1; - int button_count, axis_count, ball_count, hat_count; + int i, button_count, axis_count, ball_count, hat_count;
axis_count = pSDL_JoystickNumAxes(impl->sdl_joystick); if (axis_count > 6) @@ -255,8 +253,6 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) FIXME("Clamping joystick to 6 axis\n"); axis_count = 6; } - impl->axis_start = report_size; - report_size += (sizeof(DWORD) * axis_count);
ball_count = pSDL_JoystickNumBalls(impl->sdl_joystick); if (axis_count + ball_count * 2 > ARRAY_SIZE(joystick_usages)) @@ -264,19 +260,9 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) FIXME("Capping ball + axis at 9\n"); ball_count = (ARRAY_SIZE(joystick_usages) - axis_count) / 2; } - impl->ball_start = report_size; - report_size += (sizeof(DWORD) * 2 * ball_count);
hat_count = pSDL_JoystickNumHats(impl->sdl_joystick); - impl->hat_start = report_size; - report_size += hat_count; - - /* For now lump all buttons just into incremental usages, Ignore Keys */ button_count = pSDL_JoystickNumButtons(impl->sdl_joystick); - impl->button_start = report_size; - report_size += (button_count + 7) / 8; - - TRACE("Report will be %i bytes\n", report_size);
if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_JOYSTICK)) return STATUS_NO_MEMORY; @@ -301,8 +287,8 @@ static NTSTATUS build_joystick_report_descriptor(struct unix_device *iface) if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
- impl->buffer_length = report_size; - if (!(impl->report_buffer = calloc(1, report_size))) goto failed; + impl->buffer_length = iface->hid_device_state.report_len; + if (!(impl->report_buffer = calloc(1, impl->buffer_length))) goto failed;
/* Initialize axis in the report */ for (i = 0; i < axis_count; i++) @@ -353,13 +339,6 @@ static NTSTATUS build_controller_report_descriptor(struct unix_device *iface) ULONG i, button_count = SDL_CONTROLLER_BUTTON_MAX - 1; C_ASSERT(SDL_CONTROLLER_AXIS_MAX == 6);
- impl->axis_start = 0; - impl->hat_start = SDL_CONTROLLER_AXIS_MAX * sizeof(DWORD); - impl->button_start = impl->hat_start + 1; - impl->buffer_length = impl->button_start + (button_count + 7) / 8; - - TRACE("Report will be %i bytes\n", impl->buffer_length); - if (!hid_device_begin_report_descriptor(iface, HID_USAGE_PAGE_GENERIC, HID_USAGE_GENERIC_GAMEPAD)) return STATUS_NO_MEMORY;
@@ -387,6 +366,7 @@ static NTSTATUS build_controller_report_descriptor(struct unix_device *iface) if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
+ impl->buffer_length = impl->unix_device.hid_device_state.report_len; if (!(impl->report_buffer = calloc(1, impl->buffer_length))) goto failed;
/* Initialize axis in the report */ diff --git a/dlls/winebus.sys/bus_udev.c b/dlls/winebus.sys/bus_udev.c index 0aa3094d348..9f3b731364d 100644 --- a/dlls/winebus.sys/bus_udev.c +++ b/dlls/winebus.sys/bus_udev.c @@ -127,12 +127,11 @@ struct lnxev_device BYTE *current_report_buffer; enum { FIRST, NORMAL, DROPPED } report_state;
- int button_start; - BYTE button_map[KEY_MAX]; + BYTE abs_map[HID_ABS_MAX]; BYTE rel_map[HID_REL_MAX]; BYTE hat_map[8]; + BYTE button_map[KEY_MAX]; int hat_values[8]; - int abs_map[HID_ABS_MAX]; };
static inline struct base_device *impl_from_unix_device(struct unix_device *iface) @@ -331,25 +330,22 @@ static const BYTE* what_am_I(struct udev_device *dev) return Unknown; }
-static void set_button_value(int index, int value, BYTE* buffer) +static void set_button_value(struct lnxev_device *impl, int index, int value) { - int bindex = index / 8; - int b = index % 8; - BYTE mask; - - mask = 1<<b; - if (value) - buffer[bindex] = buffer[bindex] | mask; - else - { - mask = ~mask; - buffer[bindex] = buffer[bindex] & mask; - } + struct hid_device_state *state = &impl->base.unix_device.hid_device_state; + USHORT offset = state->button_start; + int byte_index = offset + index / 8; + int bit_index = index % 8; + BYTE mask = 1 << bit_index; + if (index >= state->button_count) return; + if (value) impl->current_report_buffer[byte_index] |= mask; + else impl->current_report_buffer[byte_index] &= ~mask; }
static void set_abs_axis_value(struct lnxev_device *impl, int code, int value) { - int index; + struct hid_device_state *state = &impl->base.unix_device.hid_device_state; + USHORT offset, index; /* check for hatswitches */ if (code <= ABS_HAT3Y && code >= ABS_HAT0X) { @@ -387,22 +383,33 @@ static void set_abs_axis_value(struct lnxev_device *impl, int code, int value) else value = 6; } - impl->current_report_buffer[impl->hat_map[index]] = value; + index = impl->hat_map[index]; + offset = state->hatswitch_start; + if (index >= state->hatswitch_count) return; + offset += index; + impl->current_report_buffer[offset] = value; } else if (code < HID_ABS_MAX && ABS_TO_HID_MAP[code][0] != 0) { index = impl->abs_map[code]; - *((DWORD*)&impl->current_report_buffer[index]) = LE_DWORD(value); + offset = state->abs_axis_start; + if (index >= state->abs_axis_count) return; + offset += index * sizeof(DWORD); + *(DWORD *)&impl->current_report_buffer[offset] = LE_DWORD(value); } }
static void set_rel_axis_value(struct lnxev_device *impl, int code, int value) { - int index; + struct hid_device_state *state = &impl->base.unix_device.hid_device_state; + USHORT offset, index; if (code < HID_REL_MAX && REL_TO_HID_MAP[code][0] != 0) { index = impl->rel_map[code]; - *(DWORD *)&impl->current_report_buffer[index] = LE_DWORD(value); + offset = state->rel_axis_start; + if (index >= state->rel_axis_count) return; + offset += index * sizeof(DWORD); + *(DWORD *)&impl->current_report_buffer[offset] = LE_DWORD(value); } }
@@ -455,9 +462,7 @@ static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_d BYTE absbits[(ABS_MAX+7)/8]; BYTE relbits[(REL_MAX+7)/8]; USAGE_AND_PAGE usage; - INT i; - INT report_size; - INT button_count, abs_count, rel_count, hat_count; + INT i, button_count, abs_count, rel_count, hat_count; const BYTE *device_usage = what_am_I(dev); struct lnxev_device *impl = lnxev_impl_from_unix_device(iface);
@@ -472,8 +477,6 @@ static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_d memset(absbits, 0, sizeof(absbits)); }
- report_size = 0; - if (!hid_device_begin_report_descriptor(iface, device_usage[0], device_usage[1])) return STATUS_NO_MEMORY;
@@ -490,9 +493,7 @@ static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_d LE_DWORD(abs_info[i].minimum), LE_DWORD(abs_info[i].maximum))) return STATUS_NO_MEMORY;
- impl->abs_map[i] = report_size; - report_size += 4; - abs_count++; + impl->abs_map[i] = abs_count++; }
rel_count = 0; @@ -506,47 +507,32 @@ static NTSTATUS build_report_descriptor(struct unix_device *iface, struct udev_d INT32_MIN, INT32_MAX)) return STATUS_NO_MEMORY;
- impl->rel_map[i] = report_size; - report_size += 4; - rel_count++; + impl->rel_map[i] = rel_count++; }
hat_count = 0; for (i = ABS_HAT0X; i <=ABS_HAT3X; i+=2) { if (!test_bit(absbits, i)) continue; - impl->hat_map[i - ABS_HAT0X] = report_size; + impl->hat_map[i - ABS_HAT0X] = hat_count++; impl->hat_values[i - ABS_HAT0X] = 0; impl->hat_values[i - ABS_HAT0X + 1] = 0; - report_size++; - hat_count++; }
- if (hat_count) - { - if (!hid_device_add_hatswitch(iface, hat_count)) - return STATUS_NO_MEMORY; - } + if (hat_count && !hid_device_add_hatswitch(iface, hat_count)) + return STATUS_NO_MEMORY;
/* For now lump all buttons just into incremental usages, Ignore Keys */ - impl->button_start = report_size; button_count = count_buttons(impl->base.device_fd, impl->button_map); - if (button_count) - { - if (!hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) - return STATUS_NO_MEMORY; - - report_size += (button_count + 7) / 8; - } + if (button_count && !hid_device_add_buttons(iface, HID_USAGE_PAGE_BUTTON, 1, button_count)) + return STATUS_NO_MEMORY;
if (!hid_device_end_report_descriptor(iface)) return STATUS_NO_MEMORY;
- TRACE("Report will be %i bytes\n", report_size); - - impl->buffer_length = report_size; - if (!(impl->current_report_buffer = calloc(1, report_size))) goto failed; - if (!(impl->last_report_buffer = calloc(1, report_size))) goto failed; + impl->buffer_length = iface->hid_device_state.report_len; + if (!(impl->current_report_buffer = calloc(1, impl->buffer_length))) goto failed; + if (!(impl->last_report_buffer = calloc(1, impl->buffer_length))) goto failed; impl->report_state = FIRST;
/* Initialize axis in the report */ @@ -594,7 +580,7 @@ static BOOL set_report_from_event(struct lnxev_device *impl, struct input_event return FALSE; #endif case EV_KEY: - set_button_value(impl->button_start * 8 + impl->button_map[ie->code], ie->value, impl->current_report_buffer); + set_button_value(impl, impl->button_map[ie->code], ie->value); return FALSE; case EV_ABS: set_abs_axis_value(impl, ie->code, ie->value); diff --git a/dlls/winebus.sys/hid.c b/dlls/winebus.sys/hid.c index 6d3dae5690d..acf0c52cfa8 100644 --- a/dlls/winebus.sys/hid.c +++ b/dlls/winebus.sys/hid.c @@ -94,6 +94,7 @@ BOOL hid_device_end_report_descriptor(struct unix_device *iface) END_COLLECTION, };
+ iface->hid_device_state.report_len = (iface->hid_device_state.bit_size + 7) / 8; return hid_report_descriptor_append(desc, template, sizeof(template)); }
diff --git a/dlls/winebus.sys/unix_private.h b/dlls/winebus.sys/unix_private.h index acb2f45aca3..ec0568faa6f 100644 --- a/dlls/winebus.sys/unix_private.h +++ b/dlls/winebus.sys/unix_private.h @@ -68,6 +68,7 @@ struct hid_device_state USHORT hatswitch_count; USHORT button_start; USHORT button_count; + USHORT report_len; };
struct unix_device
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=98486
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
On 9/22/21 10:26 AM, Marvin wrote:
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=98486
Your paranoid android.
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
=== debiant2 (build log) ===
error: patch failed: dlls/winebus.sys/bus_iohid.c:108 error: patch failed: dlls/winebus.sys/bus_iohid.c:343 Task: Patch failed to apply
Ah, I probably missed some upstream changes, I'll rebase.