(Joypad driver) Init function - return void pointer

This commit is contained in:
twinaphex 2020-09-22 02:30:47 +02:00
parent 2e79940ec5
commit 236622ffa6
27 changed files with 114 additions and 119 deletions

View File

@ -25,7 +25,7 @@ static const char *android_joypad_name(unsigned pad)
return input_config_get_device_name(pad);
}
static bool android_joypad_init(void *data) { return true; }
static void *android_joypad_init(void *data) { return (void*)-1; }
static int16_t android_joypad_button_state(
struct android_app *android_app,

View File

@ -52,10 +52,10 @@ static void ctr_joypad_autodetect_add(unsigned autoconf_pad)
);
}
static bool ctr_joypad_init(void *data)
static void *ctr_joypad_init(void *data)
{
ctr_joypad_autodetect_add(0);
return true;
return (void*)-1;
}
static int16_t ctr_joypad_button(unsigned port_num, uint16_t joykey)

View File

@ -156,12 +156,12 @@ static BOOL CALLBACK enum_joypad_cb(const DIDEVICEINSTANCE *inst, void *p)
return DIENUM_CONTINUE;
}
static bool dinput_joypad_init(void *data)
static void *dinput_joypad_init(void *data)
{
unsigned i;
if (!dinput_init_context())
return false;
return NULL;
for (i = 0; i < MAX_USERS; ++i)
{
@ -171,7 +171,8 @@ static bool dinput_joypad_init(void *data)
IDirectInput8_EnumDevices(g_dinput_ctx, DI8DEVCLASS_GAMECTRL,
enum_joypad_cb, NULL, DIEDFL_ATTACHEDONLY);
return true;
return (void*)-1;
}
#endif

View File

@ -153,13 +153,11 @@ static void dos_joypad_autodetect_add(unsigned autoconf_pad)
);
}
static bool dos_joypad_init(void *data)
static void *dos_joypad_init(void *data)
{
hook_keyb_int();
dos_joypad_autodetect_add(0);
return true;
return (void*)-1;
}
static int16_t dos_joypad_button_state(

View File

@ -617,7 +617,7 @@ static void gx_joypad_poll(void)
BIT64_SET(lifecycle_state, RARCH_MENU_TOGGLE);
}
static bool gx_joypad_init(void *data)
static void *gx_joypad_init(void *data)
{
int i;
SYS_SetResetCallback(reset_cb);
@ -625,8 +625,6 @@ static bool gx_joypad_init(void *data)
SYS_SetPowerCallback(power_callback);
#endif
(void)data;
for (i = 0; i < DEFAULT_MAX_PADS; i++)
pad_type[i] = WPAD_EXP_NOCONTROLLER;
@ -640,7 +638,7 @@ static bool gx_joypad_init(void *data)
gx_joypad_poll();
return true;
return (void*)-1;
}
static void gx_joypad_destroy(void)

View File

@ -20,12 +20,12 @@
/* TODO/FIXME - static global */
static const hid_driver_t *generic_hid = NULL;
static bool hid_joypad_init(void *data)
static void *hid_joypad_init(void *data)
{
generic_hid = input_hid_init_first();
if (!generic_hid)
return false;
return true;
return NULL;
return (void*)-1;
}
static bool hid_joypad_query_pad(unsigned pad)

View File

@ -217,13 +217,13 @@ retry:
}
}
static bool linuxraw_joypad_init(void *data)
static void *linuxraw_joypad_init(void *data)
{
unsigned i;
int fd = epoll_create(32);
if (fd < 0)
return false;
return NULL;
linuxraw_epoll = fd;
@ -273,7 +273,7 @@ static bool linuxraw_joypad_init(void *data)
linuxraw_hotplug = true;
return true;
return (void*)-1;
}
static void linuxraw_joypad_destroy(void)

View File

@ -319,32 +319,32 @@ static void apple_gamecontroller_joypad_disconnect(GCController* controller)
}
}
bool apple_gamecontroller_joypad_init(void *data)
void *apple_gamecontroller_joypad_init(void *data)
{
static bool inited = false;
if (inited)
return true;
if (!apple_gamecontroller_available())
return false;
mfiControllers = [[NSMutableArray alloc] initWithCapacity:MAX_MFI_CONTROLLERS];
static bool inited = false;
if (inited)
return (void*)-1;
if (!apple_gamecontroller_available())
return NULL;
mfiControllers = [[NSMutableArray alloc] initWithCapacity:MAX_MFI_CONTROLLERS];
#ifdef __IPHONE_7_0
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
apple_gamecontroller_joypad_connect([note object]);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
apple_gamecontroller_joypad_disconnect([note object]);
} ];
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidConnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
apple_gamecontroller_joypad_connect([note object]);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:GCControllerDidDisconnectNotification
object:nil
queue:[NSOperationQueue mainQueue]
usingBlock:^(NSNotification *note)
{
apple_gamecontroller_joypad_disconnect([note object]);
} ];
#endif
return true;
return (void*)-1;
}
static void apple_gamecontroller_joypad_destroy(void) { }

View File

@ -229,7 +229,7 @@ static void parport_free_pad(struct parport_joypad *pad)
pad->fd = -1;
}
static bool parport_joypad_init(void *data)
static void *parport_joypad_init(void *data)
{
unsigned i, j;
bool found_enabled_button = false;
@ -237,8 +237,6 @@ static bool parport_joypad_init(void *data)
char buf[PARPORT_NUM_BUTTONS * 3 + 1] = {0};
char pin[3 + 1] = {0};
(void)data;
memset(buf, 0, PARPORT_NUM_BUTTONS * 3 + 1);
for (i = 0; i < MAX_USERS; i++)
@ -290,13 +288,15 @@ static bool parport_joypad_init(void *data)
strlcat(buf, pin, sizeof(buf));
}
}
RARCH_WARN("[Joypad]: Pin(s) %son %s were low on init, assuming not connected\n", \
RARCH_WARN("[Joypad]: Pin(s) %son %s were low"
" on init, assuming not connected\n", \
buf, path);
}
}
else
{
RARCH_WARN("[Joypad]: All pins low on %s, assuming nothing connected\n", path);
RARCH_WARN("[Joypad]: All pins low on %s, assuming"
" nothing connected\n", path);
parport_free_pad(pad);
}
}
@ -311,7 +311,7 @@ static bool parport_joypad_init(void *data)
);
}
return true;
return (void*)-1;
}
static void parport_joypad_destroy(void)

View File

@ -44,11 +44,10 @@ static const char *ps2_joypad_name(unsigned pad)
return "PS2 Controller";
}
static bool ps2_joypad_init(void *data)
static void *ps2_joypad_init(void *data)
{
unsigned ret = 0;
unsigned port = 0;
bool init = true;
for (port = 0; port < DEFAULT_MAX_PADS; port++)
{
@ -61,13 +60,10 @@ static bool ps2_joypad_init(void *data)
/* Port 0 -> Connector 1, Port 1 -> Connector 2 */
if((ret = padPortOpen(port, PS2_PAD_SLOT, padBuf[port])) == 0)
{
init = false;
break;
}
return NULL;
}
return init;
return (void*)-1;
}
static int16_t ps2_joypad_button(unsigned port, uint16_t joykey)

View File

@ -53,13 +53,11 @@ static void ps3_joypad_autodetect_add(unsigned autoconf_pad)
);
}
static bool ps3_joypad_init(void *data)
static void *ps3_joypad_init(void *data)
{
(void)data;
cellPadInit(DEFAULT_MAX_PADS);
return true;
return (void*)-1;
}
static int16_t ps3_joypad_button(unsigned port, uint16_t joykey)

View File

@ -78,7 +78,7 @@ static const char *ps4_joypad_name(unsigned pad)
return "PS4 Controller";
}
static bool ps4_joypad_init(void *data)
static void *ps4_joypad_init(void *data)
{
int result;
SceUserServiceLoginUserIdList userIdList;
@ -130,7 +130,7 @@ static bool ps4_joypad_init(void *data)
}
return true;
return (void*)-1;
}
static int16_t ps4_joypad_button(unsigned port, uint16_t joykey)

View File

@ -83,13 +83,11 @@ static const char *psp_joypad_name(unsigned pad)
#endif
}
static bool psp_joypad_init(void *data)
static void *psp_joypad_init(void *data)
{
unsigned i;
unsigned players_count = DEFAULT_MAX_PADS;
(void)data;
#if defined(VITA)
if (!sceCtrlIsMultiControllerSupported())
psp2_model = SCE_KERNEL_MODEL_VITA;
@ -118,7 +116,7 @@ static bool psp_joypad_init(void *data)
0
);
return true;
return (void*)-1;
}
static int16_t psp_joypad_button(unsigned port, uint16_t joykey)

View File

@ -25,7 +25,7 @@ static const char *qnx_joypad_name(unsigned pad)
return input_config_get_device_name(pad);
}
static bool qnx_joypad_init(void *data)
static void *qnx_joypad_init(void *data)
{
unsigned autoconf_pad;
@ -39,7 +39,7 @@ static bool qnx_joypad_init(void *data)
0
);
return true;
return (void*)-1;
}
static int16_t qnx_joypad_button(unsigned port, uint16_t joykey)

View File

@ -63,11 +63,11 @@ static EM_BOOL rwebpad_gamepad_cb(int event_type,
return EM_TRUE;
}
static bool rwebpad_joypad_init(void *data)
static void *rwebpad_joypad_init(void *data)
{
EMSCRIPTEN_RESULT r = emscripten_sample_gamepad_data();
if (r == EMSCRIPTEN_RESULT_NOT_SUPPORTED)
return false;
return NULL;
/* callbacks needs to be registered for gamepads to connect */
r = emscripten_set_gamepadconnected_callback(NULL, false,
@ -76,7 +76,7 @@ static bool rwebpad_joypad_init(void *data)
r = emscripten_set_gamepaddisconnected_callback(NULL, false,
rwebpad_gamepad_cb);
return true;
return (void*)-1;
}
static const char *rwebpad_joypad_name(unsigned pad)

View File

@ -248,7 +248,7 @@ static void sdl_joypad_destroy(void)
memset(sdl_pads, 0, sizeof(sdl_pads));
}
static bool sdl_joypad_init(void *data)
static void *sdl_joypad_init(void *data)
{
unsigned i, num_sticks;
#ifdef HAVE_SDL2
@ -260,10 +260,10 @@ static bool sdl_joypad_init(void *data)
if (SDL_WasInit(0) == 0)
{
if (SDL_Init(subsystem) < 0)
return false;
return NULL;
}
else if (SDL_InitSubSystem(subsystem) < 0)
return false;
return NULL;
#if HAVE_SDL2
g_has_haptic = false;
@ -294,12 +294,13 @@ static bool sdl_joypad_init(void *data)
goto error;
#endif
return true;
return (void*)-1;
#ifndef HAVE_SDL2
error:
sdl_joypad_destroy();
return false;
return NULL;
#endif
}

View File

@ -51,7 +51,7 @@ static void switch_joypad_autodetect_add(unsigned autoconf_pad)
0); /* pid */
}
static bool switch_joypad_init(void *data)
static void *switch_joypad_init(void *data)
{
#ifdef HAVE_LIBNX
unsigned i;
@ -83,7 +83,7 @@ static bool switch_joypad_init(void *data)
switch_joypad_autodetect_add(1);
#endif
return true;
return (void*)-1;
}
static int16_t switch_joypad_button(unsigned port_num, uint16_t joykey)

View File

@ -538,7 +538,7 @@ static void udev_joypad_poll(void)
}
}
static bool udev_joypad_init(void *data)
static void *udev_joypad_init(void *data)
{
unsigned i;
unsigned sorted_count = 0;
@ -547,8 +547,6 @@ static bool udev_joypad_init(void *data)
struct udev_enumerate *enumerate = NULL;
struct joypad_udev_entry sorted[MAX_USERS];
(void)data;
for (i = 0; i < MAX_USERS; i++)
udev_pads[i].fd = -1;
@ -584,11 +582,12 @@ static bool udev_joypad_init(void *data)
}
udev_enumerate_unref(enumerate);
return true;
return (void*)-1;
error:
udev_joypad_destroy();
return false;
return NULL;
}
static int16_t udev_joypad_button_state(

View File

@ -30,20 +30,18 @@ static void hidpad_poll(void)
HID_POLL();
}
static bool hidpad_init(void *data)
static void *hidpad_init(void *data)
{
(void)data;
if(!init_hid_driver())
{
RARCH_ERR("Failed to initialize HID driver.\n");
return false;
return NULL;
}
hidpad_poll();
hidpad_ready = true;
return true;
return (void*)-1;
}
static bool hidpad_query_pad(unsigned port)

View File

@ -74,12 +74,12 @@ static int get_slot_for_channel(unsigned channel)
return slot;
}
static bool kpad_init(void *data)
static void *kpad_init(void *data)
{
kpad_poll();
kpad_ready = true;
return true;
return (void*)-1;
}
static bool kpad_query_pad(unsigned pad)

View File

@ -263,11 +263,10 @@ static void wpad_poll(void)
}
}
static bool wpad_init(void *data)
static void *wpad_init(void *data)
{
wpad_poll();
return true;
return (void*)-1;
}
static bool wpad_query_pad(unsigned port)

View File

@ -24,7 +24,7 @@ extern pad_connection_listener_t wiiu_pad_connection_listener;
static input_device_driver_t *wiiu_pad_drivers[MAX_USERS];
static bool wiiu_joypad_ready = false;
static bool wiiu_joypad_init(void* data)
static void *wiiu_joypad_init(void *data)
{
set_connection_listener(&wiiu_pad_connection_listener);
hid_instance.pad_list = pad_connection_init(MAX_USERS);
@ -37,9 +37,8 @@ static bool wiiu_joypad_init(void* data)
#endif
wiiu_joypad_ready = true;
(void)data;
return true;
return (void*)-1;
}
static bool wiiu_joypad_query_pad(unsigned pad)

View File

@ -54,10 +54,10 @@ static void xdk_joypad_autodetect_add(unsigned autoconf_pad)
0);
}
static bool xdk_joypad_init(void *data)
static void *xdk_joypad_init(void *data)
{
XInitDevices(0, NULL);
return true;
return (void*)-1;
}
static int16_t xdk_joypad_button_state(

View File

@ -341,7 +341,7 @@ static const char *xinput_joypad_name(unsigned pad)
return dinput_joypad_name(pad);
}
static bool xinput_joypad_init(void *data)
static void *xinput_joypad_init(void *data)
{
unsigned i, j;
XINPUT_STATE dummy_state;
@ -469,12 +469,14 @@ succeeded:
#endif
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return true;
return (void*)-1;
error:
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return false;
return NULL;
}
static bool xinput_joypad_query_pad(unsigned pad)

View File

@ -116,7 +116,7 @@ static const char *xinput_joypad_name(unsigned pad)
return XBOX_CONTROLLER_NAME;
}
static bool xinput_joypad_init(void *data)
static void *xinput_joypad_init(void *data)
{
unsigned i, j;
XINPUT_STATE dummy_state;
@ -228,12 +228,14 @@ succeeded:
#endif
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return true;
return (void*)-1;
error:
/* non-hat button. */
g_xinput_num_buttons = g_xinput_guide_button_supported ? 11 : 10;
return false;
return NULL;
}
static bool xinput_joypad_query_pad(unsigned pad)

View File

@ -185,7 +185,7 @@ struct input_driver
struct rarch_joypad_driver
{
bool (*init)(void *data);
void *(*init)(void *data);
bool (*query_pad)(unsigned);
void (*destroy)(void);
int16_t (*button)(unsigned, uint16_t);

View File

@ -27150,12 +27150,15 @@ static const input_device_driver_t *input_joypad_init_first(void *data)
for (i = 0; joypad_drivers[i]; i++)
{
if ( joypad_drivers[i]
&& joypad_drivers[i]->init
&& joypad_drivers[i]->init(data))
&& joypad_drivers[i]->init)
{
RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
void *ptr = joypad_drivers[i]->init(data);
if (ptr)
{
RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
}
}
}
@ -27177,18 +27180,21 @@ const input_device_driver_t *input_joypad_init_driver(
const char *ident, void *data)
{
unsigned i;
if (!ident || !*ident)
return input_joypad_init_first(data);
for (i = 0; joypad_drivers[i]; i++)
if (ident && *ident)
{
if (string_is_equal(ident, joypad_drivers[i]->ident)
&& joypad_drivers[i]->init
&& joypad_drivers[i]->init(data))
for (i = 0; joypad_drivers[i]; i++)
{
RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
if (string_is_equal(ident, joypad_drivers[i]->ident)
&& joypad_drivers[i]->init)
{
void *ptr = joypad_drivers[i]->init(data);
if (ptr)
{
RARCH_LOG("[Joypad]: Found joypad driver: \"%s\".\n",
joypad_drivers[i]->ident);
return joypad_drivers[i];
}
}
}
}