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