Create udev_mon_hotplug_available

This commit is contained in:
twinaphex 2015-11-30 16:42:52 +01:00
parent 2db1197942
commit b76481b21e
4 changed files with 22 additions and 31 deletions

View File

@ -1,4 +1,7 @@
#include <stdio.h>
#include <sys/poll.h>
#include "udev_common.h"
static bool udev_mon_inited;
@ -40,3 +43,16 @@ void udev_mon_free(bool is_joypad)
g_udev = NULL;
udev_mon_inited = false;
}
bool udev_mon_hotplug_available(void)
{
struct pollfd fds = {0};
if (!g_udev_mon)
return false;
fds.fd = udev_monitor_get_fd(g_udev_mon);
fds.events = POLLIN;
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}

View File

@ -28,4 +28,6 @@ bool udev_mon_new(void);
void udev_mon_free(bool is_joypad);
bool udev_mon_hotplug_available(void);
#endif

View File

@ -220,19 +220,6 @@ static void udev_handle_mouse(void *data,
}
}
static bool udev_input_hotplug_available(udev_input_t *udev)
{
struct pollfd fds = {0};
if (!udev || !g_udev_mon)
return false;
fds.fd = udev_monitor_get_fd(g_udev_mon);
fds.events = POLLIN;
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}
static bool add_device(udev_input_t *udev,
const char *devnode, device_handle_cb cb)
{
@ -312,7 +299,6 @@ static void udev_input_remove_device(udev_input_t *udev, const char *devnode)
static void udev_input_handle_hotplug(udev_input_t *udev)
{
bool is_keyboard, is_mouse, is_touchpad;
struct udev_device *dev = udev_monitor_receive_device(g_udev_mon);
device_handle_cb cb = NULL;
const char *devtype = NULL;
const char *val_keyboard = NULL;
@ -320,6 +306,7 @@ static void udev_input_handle_hotplug(udev_input_t *udev)
const char *val_touchpad = NULL;
const char *action = NULL;
const char *devnode = NULL;
struct udev_device *dev = udev_monitor_receive_device(g_udev_mon);
if (!dev)
return;
@ -378,7 +365,7 @@ static void udev_input_poll(void *data)
udev->mouse_wu = udev->mouse_wd = 0;
udev->mouse_whu = udev->mouse_whd = 0;
while (udev_input_hotplug_available(udev))
while (udev_mon_hotplug_available())
udev_input_handle_hotplug(udev);
ret = epoll_wait(udev->epfd, events, ARRAY_SIZE(events), 0);

View File

@ -22,7 +22,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <linux/types.h>
#include <linux/input.h>
@ -153,19 +152,6 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
}
}
static bool udev_hotplug_available(void)
{
struct pollfd fds = {0};
if (!g_udev_mon)
return false;
fds.fd = udev_monitor_get_fd(g_udev_mon);
fds.events = POLLIN;
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}
static int udev_find_vacant_pad(void)
{
unsigned i;
@ -408,10 +394,10 @@ static void udev_joypad_destroy(void)
static void udev_joypad_handle_hotplug(void)
{
struct udev_device *dev = udev_monitor_receive_device(g_udev_mon);
const char *val;
const char *action;
const char *devnode;
struct udev_device *dev = udev_monitor_receive_device(g_udev_mon);
if (!dev)
return;
@ -509,7 +495,7 @@ static bool udev_set_rumble(unsigned i, enum retro_rumble_effect effect, uint16_
static void udev_joypad_poll(void)
{
unsigned i;
while (udev_hotplug_available())
while (udev_mon_hotplug_available())
udev_joypad_handle_hotplug();
for (i = 0; i < MAX_USERS; i++)