From 8c534f856f5a4dd02e04ce97d44070a2a2b73df2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vincas=20Mili=C5=ABnas?= Date: Sun, 26 Jun 2011 23:39:33 +0300 Subject: [PATCH 16/20] server+user32: Added GetRegisteredRawInputDevices implementation (try 16) --- dlls/user32/input.c | 34 ++++++++++++++++++++++++- dlls/user32/tests/input.c | 34 +++++++++++++------------- server/process.c | 3 ++ server/process.h | 1 + server/protocol.def | 8 ++++++ server/raw_input.c | 58 +++++++++++++++++++++++++++++++++++++++++++++ server/raw_input.h | 28 +++++++++++++++++++++ 7 files changed, 147 insertions(+), 19 deletions(-) create mode 100644 server/raw_input.h diff --git a/dlls/user32/input.c b/dlls/user32/input.c index fcbe84a..5923fac 100644 --- a/dlls/user32/input.c +++ b/dlls/user32/input.c @@ -644,9 +644,39 @@ UINT WINAPI GetRawInputDeviceInfoW(HANDLE hDevice, UINT uiCommand, LPVOID pData, */ UINT WINAPI GetRegisteredRawInputDevices(PRAWINPUTDEVICE pRawInputDevices, PUINT puiNumDevices, UINT cbSize) { - FIXME("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d) stub!\n", pRawInputDevices, puiNumDevices, cbSize); + BOOL ret = FALSE; + UINT result; - return 0; + TRACE("(pRawInputDevices=%p, puiNumDevices=%p, cbSize=%d)\n", pRawInputDevices, puiNumDevices, cbSize); + + if (cbSize != sizeof( RAWINPUTDEVICE )) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return (UINT)-1; + } + if (puiNumDevices == NULL) + { + SetLastError( ERROR_NOACCESS ); + return (UINT)-1; + } + + SERVER_START_REQ( get_registered_raw_input_devices ) + { + req->report_size_only = pRawInputDevices == NULL; + if (pRawInputDevices != NULL) + wine_server_set_reply( req, pRawInputDevices, *puiNumDevices * sizeof( RAWINPUTDEVICE ) ); + ret = !wine_server_call_err( req ); + if (!ret || pRawInputDevices == NULL) + { + *puiNumDevices = reply->num_devices; + result = 0; + } + else + result = reply->num_devices; + } + SERVER_END_REQ; + + return ret ? result : (UINT)-1; } diff --git a/dlls/user32/tests/input.c b/dlls/user32/tests/input.c index adbc23b..543912a 100644 --- a/dlls/user32/tests/input.c +++ b/dlls/user32/tests/input.c @@ -1907,32 +1907,32 @@ static void test_basic_get_registered_raw_input_devices(void) SetLastError(0xdeadbeef); ret2 = pGetRegisteredRawInputDevices(NULL, NULL, 0); error = GetLastError(); - todo_wine ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " + ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " "expected (UINT)-1, got %u\n", ret2); - todo_wine ok(error == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices returned " + ok(error == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices returned " "wrong error code: %u\n", error); SetLastError(0xdeadbeef); ret2 = pGetRegisteredRawInputDevices(NULL, NULL, sizeof(RAWINPUTDEVICE)); error = GetLastError(); - todo_wine ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " + ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " "expected (UINT)-1, got %u\n", ret2); - todo_wine ok(error == ERROR_NOACCESS, "GetRegisteredRawInputDevices returned " + ok(error == ERROR_NOACCESS, "GetRegisteredRawInputDevices returned " "wrong error code: %u\n", error); SetLastError(0xdeadbeef); ret2 = pGetRegisteredRawInputDevices(NULL, &count, 1); error = GetLastError(); - todo_wine ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " + ok(ret2 == (UINT)-1, "GetRegisteredRawInputDevices returned wrong value: " "expected (UINT)-1, got %u\n", ret2); - todo_wine ok(error == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices returned " + ok(error == ERROR_INVALID_PARAMETER, "GetRegisteredRawInputDevices returned " "wrong error code: %u\n", error); count = 0xdeadbeef; ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); device.usUsagePage = HID_USAGE_PAGE_GENERIC; @@ -1975,7 +1975,7 @@ static void test_basic_get_registered_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); } @@ -2052,7 +2052,7 @@ static void test_basic_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); } @@ -2187,7 +2187,7 @@ static void test_raw_input_device_flag_preconditions(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); } @@ -2220,7 +2220,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); /* Should allow to exclude a device */ @@ -2267,7 +2267,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); /* Should register a usage page and a device from that usage page, @@ -2304,7 +2304,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); /* Should include a usage page and exclude a device */ @@ -2336,7 +2336,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); /* Should allow to subscribe and unsubscribe in the same call */ @@ -2356,7 +2356,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); /* Test that RegisterRawInputDevices is atomic, @@ -2377,7 +2377,7 @@ static void test_extended_register_raw_input_devices(void) ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); } @@ -2662,7 +2662,7 @@ static void test_get_raw_input_data_simulation_teardown(HWND hWnd, RAWINPUTDEVIC ret2 = pGetRegisteredRawInputDevices(NULL, &count, sizeof(RAWINPUTDEVICE)); ok(ret2 == 0, "GetRegisteredRawInputDevices returned wrong value: " "expected 0, got %u\n", ret2); - todo_wine ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " + ok(count == 0, "GetRegisteredRawInputDevices returned incorrect registration count: " "expected 0, got %u\n", count); DestroyWindow(hWnd); diff --git a/server/process.c b/server/process.c index c88c89b..96709e8 100644 --- a/server/process.c +++ b/server/process.c @@ -48,6 +48,7 @@ #include "request.h" #include "user.h" #include "security.h" +#include "raw_input.h" /* process structure */ @@ -337,6 +338,7 @@ struct thread *create_process( int fd, struct thread *parent_thread, int inherit list_init( &process->locks ); list_init( &process->classes ); list_init( &process->dlls ); + list_init( &process->raw_registered ); process->start_time = current_time; process->end_time = 0; @@ -419,6 +421,7 @@ static void process_destroy( struct object *obj ) close_process_handles( process ); set_process_startup_state( process, STARTUP_ABORTED ); + release_raw_input( &process->raw_registered ); if (process->console) release_object( process->console ); if (process->parent) release_object( process->parent ); if (process->msg_fd) release_object( process->msg_fd ); diff --git a/server/process.h b/server/process.h index da51a0e..b1ceded 100644 --- a/server/process.h +++ b/server/process.h @@ -81,6 +81,7 @@ struct process client_ptr_t peb; /* PEB address in client address space */ client_ptr_t ldt_copy; /* pointer to LDT copy in client addr space */ unsigned int trace_data; /* opaque data used by the process tracing mechanism */ + struct list raw_registered; /* registered raw input devices */ }; struct process_snapshot diff --git a/server/protocol.def b/server/protocol.def index 85efb12..0bdc018 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -3384,3 +3384,11 @@ enum coords_relative data_size_t size; /* size of the data about the device */ VARARG(info,bytes); /* string or data structure about the device */ @END + +/* Get the registered raw input devices */ +@REQ(get_registered_raw_input_devices) + unsigned int report_size_only; /* reply only with the device count */ +@REPLY + unsigned int num_devices; /* number of raw input device registrations */ + VARARG(devices,bytes); /* RAWINPUTDEVICE structures */ +@END diff --git a/server/raw_input.c b/server/raw_input.c index b57181e..2869315 100644 --- a/server/raw_input.c +++ b/server/raw_input.c @@ -44,6 +44,15 @@ #define HID_USAGE_GENERIC_MOUSE ((unsigned short)0x02) #define HID_USAGE_GENERIC_KEYBOARD ((unsigned short)0x06) +struct raw_registration +{ + struct list entry; + unsigned short usage_page; + unsigned short usage; + unsigned int flags; + user_handle_t target_window; +}; + struct raw_device { user_handle_t handle; @@ -68,6 +77,19 @@ static const struct raw_device raw_devices[] = }; #define NUM_RAW_DEVICES (sizeof( raw_devices ) / sizeof( raw_devices[0] )) +/* Release allocated raw input data */ +void release_raw_input( struct list *registrations ) +{ + struct raw_registration *registration, *registration2; + + LIST_FOR_EACH_ENTRY_SAFE( registration, registration2, registrations, + struct raw_registration, entry ) + { + list_remove( ®istration->entry ); + free( registration ); + } +} + /* Get the raw input device list */ DECL_HANDLER(get_raw_input_device_list) { @@ -159,3 +181,39 @@ DECL_HANDLER(get_raw_input_device_info) if (!valid) set_error( STATUS_INVALID_HANDLE ); } + +/* Get the registered raw input devices */ +DECL_HANDLER(get_registered_raw_input_devices) +{ + unsigned int index = 0, size_in_bytes; + struct raw_registration *registration; + RAWINPUTDEVICE *result; + + reply->num_devices = list_count(¤t->process->raw_registered); + if (!reply->num_devices || req->report_size_only) + return; + + size_in_bytes = reply->num_devices * sizeof( RAWINPUTDEVICE ); + if (size_in_bytes > get_reply_max_size()) + { + set_error( STATUS_BUFFER_TOO_SMALL ); + return; + } + + result = set_reply_data_size( size_in_bytes ); + if (!result) + { + set_error( STATUS_NO_MEMORY ); + return; + } + + LIST_FOR_EACH_ENTRY( registration, ¤t->process->raw_registered, + struct raw_registration, entry ) + { + result[index].usUsagePage = registration->usage_page; + result[index].usUsage = registration->usage; + result[index].dwFlags = registration->flags; + result[index].hwndTarget = (HWND)registration->target_window; + index += 1; + } +} diff --git a/server/raw_input.h b/server/raw_input.h new file mode 100644 index 0000000..3c79800 --- /dev/null +++ b/server/raw_input.h @@ -0,0 +1,28 @@ +/* + * Server-side Raw Input Handling + * + * Copyright (C) 2011 Vincas MiliĆ«nas + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#ifndef __WINE_SERVER_RAW_INPUT_H +#define __WINE_SERVER_RAW_INPUT_H + +#include "wine/list.h" + +extern void release_raw_input( struct list *registrations ); + +#endif /* __WINE_SERVER_RAW_INPUT_H */ -- 1.7.3.4