Add udev_common.c/.h

This commit is contained in:
twinaphex 2016-12-01 15:02:29 +01:00
parent 8f3039316a
commit 63ae172a23
5 changed files with 63 additions and 13 deletions

View File

@ -638,6 +638,7 @@ ifeq ($(HAVE_UDEV), 1)
DEFINES += $(UDEV_CFLAGS)
LIBS += $(UDEV_LIBS)
OBJ += input/drivers/udev_input.o \
input/common/udev_common.o \
input/drivers_keyboard/keyboard_event_udev.o \
input/drivers_joypad/udev_joypad.o
endif

View File

@ -473,6 +473,7 @@ INPUT
#endif
#ifdef HAVE_UDEV
#include "../input/common/udev_common.c"
#include "../input/drivers/udev_input.c"
#include "../input/drivers_keyboard/keyboard_event_udev.c"
#include "../input/drivers_joypad/udev_joypad.c"

View File

@ -0,0 +1,34 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdlib.h>
#include <libudev.h>
#include <sys/poll.h>
#include "udev_common.h"
bool udev_hotplug_available(void *dev)
{
struct pollfd fds;
fds.fd = udev_monitor_get_fd((struct udev_monitor*)dev);
fds.events = POLLIN;
fds.revents = 0;
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}

View File

@ -0,0 +1,23 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2011-2016 - Daniel De Matteis
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _UDEV_COMMON_H
#define _UDEV_COMMON_H
#include <boolean.h>
bool udev_hotplug_available(void *dev);
#endif

View File

@ -23,7 +23,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/poll.h>
#include <libudev.h>
#include <linux/types.h>
#include <linux/input.h>
@ -34,6 +33,9 @@
#include "../input_autodetect.h"
#include "../input_driver.h"
#include "../common/udev_common.h"
#include "../../configuration.h"
#include "../../runloop.h"
#include "../../verbosity.h"
@ -160,17 +162,6 @@ static void udev_poll_pad(struct udev_joypad *pad, unsigned p)
}
}
static INLINE bool udev_hotplug_available(void)
{
struct pollfd fds;
fds.fd = udev_monitor_get_fd(g_udev_mon);
fds.events = POLLIN;
fds.revents = 0;
return (poll(&fds, 1, 0) == 1) && (fds.revents & POLLIN);
}
static int udev_find_vacant_pad(void)
{
unsigned i;
@ -515,7 +506,7 @@ static void udev_joypad_poll(void)
{
unsigned i;
while (g_udev_mon && udev_hotplug_available())
while (g_udev_mon && udev_hotplug_available(g_udev_mon))
{
struct udev_device *dev = udev_monitor_receive_device(g_udev_mon);
if (dev)