From 6451e221f3a67ecbcf7b6dabb45544b4540ee67d Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 15 Mar 2005 19:36:15 +0000 Subject: [PATCH] Build a static list of devices instead of relying on ELF constructors. --- dlls/dinput/dinput_main.c | 53 ++++++++++++------------------- dlls/dinput/dinput_private.h | 10 +++--- dlls/dinput/joystick_linux.c | 22 +++++++++---- dlls/dinput/joystick_linuxinput.c | 29 +++++++++-------- dlls/dinput/keyboard.c | 5 +-- dlls/dinput/mouse.c | 6 ++-- 6 files changed, 59 insertions(+), 66 deletions(-) diff --git a/dlls/dinput/dinput_main.c b/dlls/dinput/dinput_main.c index 4b2df7f2ece..2920e223c81 100644 --- a/dlls/dinput/dinput_main.c +++ b/dlls/dinput/dinput_main.c @@ -51,10 +51,14 @@ static IDirectInput7WVtbl ddi7wvt; static IDirectInput8AVtbl ddi8avt; static IDirectInput8WVtbl ddi8wvt; -/* This array will be filled a dinput.so loading */ -#define MAX_WINE_DINPUT_DEVICES 4 -static dinput_device * dinput_devices[MAX_WINE_DINPUT_DEVICES]; -static int nrof_dinput_devices = 0; +static const struct dinput_device *dinput_devices[] = +{ + &mouse_device, + &keyboard_device, + &joystick_linuxinput_device, + &joystick_linux_device +}; +#define NB_DINPUT_DEVICES (sizeof(dinput_devices)/sizeof(dinput_devices[0])) HINSTANCE DINPUT_instance = NULL; @@ -73,29 +77,6 @@ BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserv) } -/* register a direct draw driver. We better not use malloc for we are in - * the ELF startup initialisation at this point. - */ -void dinput_register_device(dinput_device *device) { - int i; - - /* insert according to priority */ - for (i=0;ipref <= device->pref) { - memcpy(dinput_devices+i+1,dinput_devices+i,sizeof(dinput_devices[0])*(nrof_dinput_devices-i)); - dinput_devices[i] = device; - break; - } - } - if (i==nrof_dinput_devices) /* not found, or too low priority */ - dinput_devices[nrof_dinput_devices] = device; - - nrof_dinput_devices++; - - /* increase MAX_DDRAW_DRIVERS if the line below triggers */ - assert(nrof_dinput_devices <= MAX_WINE_DINPUT_DEVICES); -} - /****************************************************************************** * DirectInputCreateEx (DINPUT.@) */ @@ -247,7 +228,8 @@ static HRESULT WINAPI IDirectInputAImpl_EnumDevices( lpCallback, pvRef, dwFlags); TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n"); - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { + if (!dinput_devices[i]->enum_deviceA) continue; for (j = 0, r = -1; r != 0; j++) { devInstance.dwSize = sizeof(devInstance); TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name); @@ -276,7 +258,8 @@ static HRESULT WINAPI IDirectInputWImpl_EnumDevices( lpCallback, pvRef, dwFlags); TRACE(" flags: "); _dump_EnumDevices_dwFlags(dwFlags); TRACE("\n"); - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { + if (!dinput_devices[i]->enum_deviceW) continue; for (j = 0, r = -1; r != 0; j++) { devInstance.dwSize = sizeof(devInstance); TRACE(" - checking device %d ('%s')\n", i, dinput_devices[i]->name); @@ -349,8 +332,9 @@ static HRESULT WINAPI IDirectInputAImpl_CreateDevice( TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk); /* Loop on all the devices to see if anyone matches the given GUID */ - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { HRESULT ret; + if (!dinput_devices[i]->create_deviceA) continue; if ((ret = dinput_devices[i]->create_deviceA(This, rguid, NULL, pdev)) == DI_OK) return DI_OK; @@ -370,8 +354,9 @@ static HRESULT WINAPI IDirectInputWImpl_CreateDevice(LPDIRECTINPUT7A iface, TRACE("(this=%p,%s,%p,%p)\n",This,debugstr_guid(rguid),pdev,punk); /* Loop on all the devices to see if anyone matches the given GUID */ - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { HRESULT ret; + if (!dinput_devices[i]->create_deviceW) continue; if ((ret = dinput_devices[i]->create_deviceW(This, rguid, NULL, pdev)) == DI_OK) return DI_OK; @@ -430,8 +415,9 @@ static HRESULT WINAPI IDirectInput7AImpl_CreateDeviceEx(LPDIRECTINPUT7A iface, R TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter); /* Loop on all the devices to see if anyone matches the given GUID */ - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { HRESULT ret; + if (!dinput_devices[i]->create_deviceA) continue; if ((ret = dinput_devices[i]->create_deviceA(This, rguid, riid, (LPDIRECTINPUTDEVICEA*) pvOut)) == DI_OK) return DI_OK; @@ -452,8 +438,9 @@ static HRESULT WINAPI IDirectInput7WImpl_CreateDeviceEx(LPDIRECTINPUT7W iface, R TRACE("(%p)->(%s, %s, %p, %p)\n", This, debugstr_guid(rguid), debugstr_guid(riid), pvOut, lpUnknownOuter); /* Loop on all the devices to see if anyone matches the given GUID */ - for (i = 0; i < nrof_dinput_devices; i++) { + for (i = 0; i < NB_DINPUT_DEVICES; i++) { HRESULT ret; + if (!dinput_devices[i]->create_deviceW) continue; if ((ret = dinput_devices[i]->create_deviceW(This, rguid, riid, (LPDIRECTINPUTDEVICEW*) pvOut)) == DI_OK) return DI_OK; diff --git a/dlls/dinput/dinput_private.h b/dlls/dinput/dinput_private.h index 393d1259dbd..98e8add3eab 100644 --- a/dlls/dinput/dinput_private.h +++ b/dlls/dinput/dinput_private.h @@ -39,16 +39,18 @@ struct IDirectInputImpl }; /* Function called by all devices that Wine supports */ -typedef struct dinput_device { - INT pref; +struct dinput_device { const char *name; BOOL (*enum_deviceA)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEA lpddi, int version, int id); BOOL (*enum_deviceW)(DWORD dwDevType, DWORD dwFlags, LPDIDEVICEINSTANCEW lpddi, int version, int id); HRESULT (*create_deviceA)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEA* pdev); HRESULT (*create_deviceW)(IDirectInputImpl *dinput, REFGUID rguid, REFIID riid, LPDIRECTINPUTDEVICEW* pdev); -} dinput_device; +}; -extern void dinput_register_device(dinput_device *device); +extern const struct dinput_device mouse_device; +extern const struct dinput_device keyboard_device; +extern const struct dinput_device joystick_linux_device; +extern const struct dinput_device joystick_linuxinput_device; extern HINSTANCE DINPUT_instance; diff --git a/dlls/dinput/joystick_linux.c b/dlls/dinput/joystick_linux.c index 4562ed5c314..77578c6cbd6 100644 --- a/dlls/dinput/joystick_linux.c +++ b/dlls/dinput/joystick_linux.c @@ -28,8 +28,6 @@ #include "config.h" #include "wine/port.h" -#ifdef HAVE_LINUX_22_JOYSTICK_API - #include #include #include @@ -55,7 +53,6 @@ #ifdef HAVE_LINUX_JOYSTICK_H # include #endif -#define JOYDEV "/dev/js" #include "wine/debug.h" #include "wine/unicode.h" @@ -70,6 +67,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); +#ifdef HAVE_LINUX_22_JOYSTICK_API + +#define JOYDEV "/dev/js" + typedef struct { LONG lMin; LONG lMax; @@ -646,8 +647,7 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE return DIERR_DEVICENOTREG; } -static dinput_device joydev = { - 10, +const struct dinput_device joystick_linux_device = { "Wine Linux joystick driver", joydev_enum_deviceA, joydev_enum_deviceW, @@ -655,8 +655,6 @@ static dinput_device joydev = { joydev_create_deviceW }; -DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); } - /****************************************************************************** * Joystick */ @@ -1695,4 +1693,14 @@ static IDirectInputDevice8WVtbl SysJoystickWvt = }; #undef XCAST +#else /* HAVE_LINUX_22_JOYSTICK_API */ + +const struct dinput_device joystick_linux_device = { + "Wine Linux joystick driver", + NULL, + NULL, + NULL, + NULL +}; + #endif /* HAVE_LINUX_22_JOYSTICK_API */ diff --git a/dlls/dinput/joystick_linuxinput.c b/dlls/dinput/joystick_linuxinput.c index 4200abe6d83..efb5af254ad 100644 --- a/dlls/dinput/joystick_linuxinput.c +++ b/dlls/dinput/joystick_linuxinput.c @@ -22,8 +22,6 @@ #include "config.h" #include "wine/port.h" -#ifdef HAVE_LINUX_INPUT_H - #include #include #include @@ -43,16 +41,10 @@ #ifdef HAVE_SYS_ERRNO_H # include #endif - -#ifdef HAVE_CORRECT_LINUXINPUT_H - #ifdef HAVE_LINUX_INPUT_H # include #endif - -#define EVDEVPREFIX "/dev/input/event" - #include "wine/debug.h" #include "wine/unicode.h" #include "windef.h" @@ -65,6 +57,10 @@ WINE_DEFAULT_DEBUG_CHANNEL(dinput); +#ifdef HAVE_CORRECT_LINUXINPUT_H + +#define EVDEVPREFIX "/dev/input/event" + /* Wine joystick driver object instances */ #define WINE_JOYSTICK_AXIS_BASE 0 #define WINE_JOYSTICK_BUTTON_BASE 8 @@ -322,8 +318,7 @@ static HRESULT joydev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, RE return DIERR_DEVICENOTREG; } -static dinput_device joydev = { - 20, +const struct dinput_device joystick_linuxinput_device = { "Wine Linux-input joystick driver", joydev_enum_deviceA, joydev_enum_deviceW, @@ -331,8 +326,6 @@ static dinput_device joydev = { joydev_create_deviceW }; -DECL_GLOBAL_CONSTRUCTOR(joydev_register) { dinput_register_device(&joydev); } - /****************************************************************************** * Joystick */ @@ -1094,6 +1087,14 @@ static IDirectInputDevice8WVtbl JoystickWvt = }; #undef XCAST -#endif /* HAVE_LINUX_INPUT_H */ +#else /* HAVE_CORRECT_LINUXINPUT_H */ -#endif +struct dinput_device joystick_linuxinput_device = { + "Wine Linux-input joystick driver", + NULL, + NULL, + NULL, + NULL +}; + +#endif /* HAVE_CORRECT_LINUXINPUT_H */ diff --git a/dlls/dinput/keyboard.c b/dlls/dinput/keyboard.c index 36628da0fcc..ceee1f591d4 100644 --- a/dlls/dinput/keyboard.c +++ b/dlls/dinput/keyboard.c @@ -289,8 +289,7 @@ static HRESULT keyboarddev_create_deviceW(IDirectInputImpl *dinput, REFGUID rgui return DIERR_DEVICENOTREG; } -static dinput_device keyboarddev = { - 100, +const struct dinput_device keyboard_device = { "Wine keyboard driver", keyboarddev_enum_deviceA, keyboarddev_enum_deviceW, @@ -298,8 +297,6 @@ static dinput_device keyboarddev = { keyboarddev_create_deviceW }; -DECL_GLOBAL_CONSTRUCTOR(keyboarddev_register) { dinput_register_device(&keyboarddev); } - static ULONG WINAPI SysKeyboardAImpl_Release(LPDIRECTINPUTDEVICE8A iface) { SysKeyboardImpl *This = (SysKeyboardImpl *)iface; diff --git a/dlls/dinput/mouse.c b/dlls/dinput/mouse.c index 9086e1caf07..3394142b3b5 100644 --- a/dlls/dinput/mouse.c +++ b/dlls/dinput/mouse.c @@ -305,8 +305,8 @@ static HRESULT mousedev_create_deviceW(IDirectInputImpl *dinput, REFGUID rguid, return DIERR_DEVICENOTREG; } -static dinput_device mousedev = { - 100, + +const struct dinput_device mouse_device = { "Wine mouse driver", mousedev_enum_deviceA, mousedev_enum_deviceW, @@ -314,8 +314,6 @@ static dinput_device mousedev = { mousedev_create_deviceW }; -DECL_GLOBAL_CONSTRUCTOR(mousedev_register) { dinput_register_device(&mousedev); } - /****************************************************************************** * SysMouseA (DInput Mouse support) */