src/joystick/dummy/SDL_sysjoystick.c
author Ryan C. Gordon <icculus@icculus.org>
Wed, 24 Dec 2014 22:22:35 -0500
changeset 9289 5f857c00d25d
parent 8860 c4133d635375
child 9380 07b7c1005a23
permissions -rw-r--r--
Maybe actually patched to compile this time?
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2014 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 SDL_SYS_NumJoysticks()
    41 {
    42     return 0;
    43 }
    44 
    45 void SDL_SYS_JoystickDetect()
    46 {
    47 }
    48 
    49 /* Function to get the device-dependent name of a joystick */
    50 const char *
    51 SDL_SYS_JoystickNameForDeviceIndex(int device_index)
    52 {
    53     SDL_SetError("Logic error: No joysticks available");
    54     return (NULL);
    55 }
    56 
    57 /* Function to perform the mapping from device index to the instance id for this index */
    58 SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
    59 {
    60     return device_index;
    61 }
    62 
    63 /* Function to open a joystick for use.
    64    The joystick to open is specified by the index field of the joystick.
    65    This should fill the nbuttons and naxes fields of the joystick structure.
    66    It returns 0, or -1 if there is an error.
    67  */
    68 int
    69 SDL_SYS_JoystickOpen(SDL_Joystick * joystick, int device_index)
    70 {
    71     return SDL_SetError("Logic error: No joysticks available");
    72 }
    73 
    74 /* Function to determine is this joystick is attached to the system right now */
    75 SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
    76 {
    77     return SDL_TRUE;
    78 }
    79 
    80 /* Function to update the state of a joystick - called as a device poll.
    81  * This function shouldn't update the joystick structure directly,
    82  * but instead should call SDL_PrivateJoystick*() to deliver events
    83  * and update joystick device state.
    84  */
    85 void
    86 SDL_SYS_JoystickUpdate(SDL_Joystick * joystick)
    87 {
    88     return;
    89 }
    90 
    91 /* Function to close a joystick after use */
    92 void
    93 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
    94 {
    95     return;
    96 }
    97 
    98 /* Function to perform any system-specific joystick related cleanup */
    99 void
   100 SDL_SYS_JoystickQuit(void)
   101 {
   102     return;
   103 }
   104 
   105 SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   106 {
   107     SDL_JoystickGUID guid;
   108     /* the GUID is just the first 16 chars of the name for now */
   109     const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   110     SDL_zero( guid );
   111     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   112     return guid;
   113 }
   114 
   115 
   116 SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   117 {
   118     SDL_JoystickGUID guid;
   119     /* the GUID is just the first 16 chars of the name for now */
   120     const char *name = joystick->name;
   121     SDL_zero( guid );
   122     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   123     return guid;
   124 }
   125 
   126 #endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */
   127 
   128 /* vi: set ts=4 sw=4 expandtab: */