3dd96a001406c2c53e52f2930ff63cfd4633d6a6
[platform/upstream/SDL.git] / src / joystick / dummy / SDL_sysjoystick.c
1 /*
2   Simple DirectMedia Layer
3   Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
4
5   This software is provided 'as-is', without any express or implied
6   warranty.  In no event will the authors be held liable for any damages
7   arising from the use of this software.
8
9   Permission is granted to anyone to use this software for any purpose,
10   including commercial applications, and to alter it and redistribute it
11   freely, subject to the following restrictions:
12
13   1. The origin of this software must not be misrepresented; you must not
14      claim that you wrote the original software. If you use this software
15      in a product, an acknowledgment in the product documentation would be
16      appreciated but is not required.
17   2. Altered source versions must be plainly marked as such, and must not be
18      misrepresented as being the original software.
19   3. This notice may not be removed or altered from any source distribution.
20 */
21 #include "../../SDL_internal.h"
22
23 #if defined(SDL_JOYSTICK_DUMMY) || defined(SDL_JOYSTICK_DISABLED)
24
25 /* This is the dummy implementation of the SDL joystick API */
26
27 #include "SDL_joystick.h"
28 #include "../SDL_sysjoystick.h"
29 #include "../SDL_joystick_c.h"
30
31 /* Function to scan the system for joysticks.
32  * It should return 0, or -1 on an unrecoverable fatal error.
33  */
34 int
35 SDL_SYS_JoystickInit(void)
36 {
37     return 0;
38 }
39
40 int
41 SDL_SYS_NumJoysticks(void)
42 {
43     return 0;
44 }
45
46 void
47 SDL_SYS_JoystickDetect(void)
48 {
49 }
50
51 /* Function to get the device-dependent name of a joystick */
52 const char *
53 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
54 {
55     SDL_SetError("Logic error: No joysticks available");
56     return (NULL);
57 }
58
59 /* Function to perform the mapping from device index to the instance id for this index */
60 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
61 {
62     return device_index;
63 }
64
65 /* Function to open a joystick for use.
66    The joystick to open is specified by the device index.
67    This should fill the nbuttons and naxes fields of the joystick structure.
68    It returns 0, or -1 if there is an error.
69  */
70 int
71 SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
72 {
73     return SDL_SetError("Logic error: No joysticks available");
74 }
75
76 /* Function to determine if this joystick is attached to the system right now */
77 SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
78 {
79     return SDL_TRUE;
80 }
81
82 /* Function to update the state of a joystick - called as a device poll.
83  * This function shouldn't update the joystick structure directly,
84  * but instead should call SDL_PrivateJoystick*() to deliver events
85  * and update joystick device state.
86  */
87 void
88 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
89 {
90 }
91
92 /* Function to close a joystick after use */
93 void
94 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
95 {
96 }
97
98 /* Function to perform any system-specific joystick related cleanup */
99 void
100 SDL_SYS_JoystickQuit(void)
101 {
102 }
103
104 SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
105 {
106     SDL_JoystickGUID guid;
107     /* the GUID is just the first 16 chars of the name for now */
108     const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
109     SDL_zero( guid );
110     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
111     return guid;
112 }
113
114
115 SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
116 {
117     SDL_JoystickGUID guid;
118     /* the GUID is just the first 16 chars of the name for now */
119     const char *name = joystick->name;
120     SDL_zero( guid );
121     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
122     return guid;
123 }
124
125 #endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */
126
127 /* vi: set ts=4 sw=4 expandtab: */