Create hid_driver_get_data

This commit is contained in:
twinaphex 2015-11-29 21:11:57 +01:00
parent e2fde41124
commit d15ad86705
5 changed files with 25 additions and 30 deletions

View File

@ -210,7 +210,6 @@ typedef struct driver
void *font_osd_data;
void *video_shader_data;
void *hid_data;
void *camera_data;
void *location_data;
void *recording_data;

View File

@ -133,10 +133,9 @@ static void iohidmanager_hid_device_report(void *data,
CFIndex reportLength)
{
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data;
driver_t *driver = driver_get_ptr();
iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
if (adapter)
if (hid && adapter)
pad_connection_packet(&hid->slots[adapter->slot], adapter->slot,
adapter->data, reportLength + 1);
}
@ -147,8 +146,7 @@ static void iohidmanager_hid_device_report(void *data,
static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
void* sender, IOHIDValueRef value)
{
driver_t *driver = driver_get_ptr();
iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data;
IOHIDElementRef element = IOHIDValueGetElement(value);
uint32_t type = IOHIDElementGetType(element);
@ -224,11 +222,10 @@ static void iohidmanager_hid_device_input_callback(void *data, IOReturn result,
static void iohidmanager_hid_device_remove(void *data, IOReturn result, void* sender)
{
driver_t *driver = driver_get_ptr();
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)data;
iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
if (adapter && (adapter->slot < MAX_USERS))
if (hid && adapter && (adapter->slot < MAX_USERS))
{
input_config_autoconfigure_disconnect(adapter->slot, adapter->name);
@ -299,8 +296,7 @@ static void iohidmanager_hid_device_add(void *data, IOReturn result,
uint16_t dev_vid, dev_pid;
settings_t *settings = config_get_ptr();
driver_t *driver = driver_get_ptr();
iohidmanager_hid_t *hid = driver ? (iohidmanager_hid_t*)driver->hid_data : NULL;
iohidmanager_hid_t *hid = (iohidmanager_hid_t*)hid_driver_get_data();
struct iohidmanager_hid_adapter *adapter = (struct iohidmanager_hid_adapter*)
calloc(1, sizeof(*adapter));

View File

@ -33,52 +33,44 @@ static bool hid_joypad_init(void *data)
static bool hid_joypad_query_pad(unsigned pad)
{
driver_t *driver = driver_get_ptr();
return generic_hid->query_pad(driver->hid_data, pad);
return generic_hid->query_pad((void*)hid_driver_get_data(), pad);
}
static void hid_joypad_free(void)
{
driver_t *driver = driver_get_ptr();
generic_hid->free(driver->hid_data);
generic_hid->free((void*)hid_driver_get_data());
generic_hid = NULL;
}
static bool hid_joypad_button(unsigned port, uint16_t joykey)
{
driver_t *driver = driver_get_ptr();
return generic_hid->button(driver->hid_data, port, joykey);
return generic_hid->button((void*)hid_driver_get_data(), port, joykey);
}
static uint64_t hid_joypad_get_buttons(unsigned port)
{
driver_t *driver = driver_get_ptr();
return generic_hid->get_buttons(driver->hid_data, port);
return generic_hid->get_buttons((void*)hid_driver_get_data(), port);
}
static int16_t hid_joypad_axis(unsigned port, uint32_t joyaxis)
{
driver_t *driver = driver_get_ptr();
return generic_hid->axis(driver->hid_data, port, joyaxis);
return generic_hid->axis((void*)hid_driver_get_data(), port, joyaxis);
}
static void hid_joypad_poll(void)
{
driver_t *driver = driver_get_ptr();
generic_hid->poll(driver->hid_data);
generic_hid->poll((void*)hid_driver_get_data());
}
static bool hid_joypad_rumble(unsigned pad,
enum retro_rumble_effect effect, uint16_t strength)
{
driver_t *driver = driver_get_ptr();
return generic_hid->set_rumble(driver->hid_data, pad, effect, strength);
return generic_hid->set_rumble((void*)hid_driver_get_data(), pad, effect, strength);
}
static const char *hid_joypad_name(unsigned pad)
{
driver_t *driver = driver_get_ptr();
return generic_hid->name(driver->hid_data, pad);
return generic_hid->name((void*)hid_driver_get_data(), pad);
}
input_device_driver_t hid_joypad = {

View File

@ -40,6 +40,8 @@ static hid_driver_t *hid_drivers[] = {
NULL,
};
static const void *hid_data;
/**
* hid_driver_find_handle:
* @idx : index of driver to get handle to.
@ -55,6 +57,11 @@ const void *hid_driver_find_handle(int idx)
return drv;
}
const void *hid_driver_get_data(void)
{
return hid_data;
}
/**
* hid_driver_find_ident:
* @idx : index of driver to get handle to.
@ -95,10 +102,9 @@ const hid_driver_t *input_hid_init_first(void)
for (i = 0; hid_drivers[i]; i++)
{
driver_t *driver = driver_get_ptr();
driver->hid_data = hid_drivers[i]->init();
hid_data = hid_drivers[i]->init();
if (driver->hid_data)
if (hid_data)
{
RARCH_LOG("Found HID driver: \"%s\".\n",
hid_drivers[i]->ident);

View File

@ -85,6 +85,8 @@ const char* config_get_hid_driver_options(void);
**/
const hid_driver_t *input_hid_init_first(void);
const void *hid_driver_get_data(void);
#ifdef __cplusplus
}
#endif