src/joystick/dummy/SDL_sysjoystick.c
author David Ludwig
Thu, 31 Dec 2015 01:54:11 -0500
changeset 9993 e05d46c27ce3
parent 9619 b94b6d0bff0f
child 9998 f67cf37e9cd4
permissions -rw-r--r--
WinRT: minor code-comment cleanups
     1 /*
     2   Simple DirectMedia Layer
     3   Copyright (C) 1997-2015 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 device index.
    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 if 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 }
    89 
    90 /* Function to close a joystick after use */
    91 void
    92 SDL_SYS_JoystickClose(SDL_Joystick * joystick)
    93 {
    94 }
    95 
    96 /* Function to perform any system-specific joystick related cleanup */
    97 void
    98 SDL_SYS_JoystickQuit(void)
    99 {
   100 }
   101 
   102 SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID( int device_index )
   103 {
   104     SDL_JoystickGUID guid;
   105     /* the GUID is just the first 16 chars of the name for now */
   106     const char *name = SDL_SYS_JoystickNameForDeviceIndex( device_index );
   107     SDL_zero( guid );
   108     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   109     return guid;
   110 }
   111 
   112 
   113 SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick * joystick)
   114 {
   115     SDL_JoystickGUID guid;
   116     /* the GUID is just the first 16 chars of the name for now */
   117     const char *name = joystick->name;
   118     SDL_zero( guid );
   119     SDL_memcpy( &guid, name, SDL_min( sizeof(guid), SDL_strlen( name ) ) );
   120     return guid;
   121 }
   122 
   123 #endif /* SDL_JOYSTICK_DUMMY || SDL_JOYSTICK_DISABLED */
   124 
   125 /* vi: set ts=4 sw=4 expandtab: */