mirror of
https://github.com/libretro/RetroArch
synced 2025-02-19 12:41:00 +00:00
Create udev_common.c/udev_common.h
This commit is contained in:
parent
bf66b43ecd
commit
fd91cf130e
@ -525,6 +525,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
|
||||
|
@ -385,6 +385,7 @@ INPUT
|
||||
|
||||
#ifdef HAVE_UDEV
|
||||
#include "../input/drivers/udev_input.c"
|
||||
#include "../input/common/udev_common.c"
|
||||
#include "../input/drivers_keyboard/keyboard_event_udev.c"
|
||||
#include "../input/drivers_joypad/udev_joypad.c"
|
||||
#endif
|
||||
|
31
input/common/udev_common.c
Normal file
31
input/common/udev_common.c
Normal file
@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include "udev_common.h"
|
||||
|
||||
struct udev_monitor *g_udev_mon;
|
||||
struct udev *g_udev;
|
||||
|
||||
bool udev_mon_new(void)
|
||||
{
|
||||
g_udev = udev_new();
|
||||
if (!g_udev)
|
||||
return false;
|
||||
|
||||
g_udev_mon = udev_monitor_new_from_netlink(g_udev, "udev");
|
||||
if (g_udev_mon)
|
||||
{
|
||||
udev_monitor_filter_add_match_subsystem_devtype(g_udev_mon, "input", NULL);
|
||||
udev_monitor_enable_receiving(g_udev_mon);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void udev_mon_free(void)
|
||||
{
|
||||
if (g_udev_mon)
|
||||
udev_monitor_unref(g_udev_mon);
|
||||
g_udev_mon = NULL;
|
||||
if (g_udev)
|
||||
udev_unref(g_udev);
|
||||
g_udev = NULL;
|
||||
}
|
31
input/common/udev_common.h
Normal file
31
input/common/udev_common.h
Normal file
@ -0,0 +1,31 @@
|
||||
/* RetroArch - A frontend for libretro.
|
||||
* Copyright (C) 2011-2015 - 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 <stdint.h>
|
||||
#include <libudev.h>
|
||||
|
||||
#include <boolean.h>
|
||||
|
||||
extern struct udev_monitor *g_udev_mon;
|
||||
extern struct udev *g_udev;
|
||||
|
||||
bool udev_mon_new(void);
|
||||
|
||||
void udev_mon_free(void);
|
||||
|
||||
#endif
|
@ -23,13 +23,13 @@
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/poll.h>
|
||||
#include <libudev.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/input.h>
|
||||
|
||||
#include <retro_inline.h>
|
||||
|
||||
#include "../input_autodetect.h"
|
||||
#include "../common/udev_common.h"
|
||||
#include "../../general.h"
|
||||
#include "../../verbosity.h"
|
||||
|
||||
@ -77,8 +77,6 @@ struct udev_joypad
|
||||
int32_t pid;
|
||||
};
|
||||
|
||||
static struct udev *g_udev;
|
||||
static struct udev_monitor *g_udev_mon;
|
||||
static struct udev_joypad udev_pads[MAX_USERS];
|
||||
|
||||
static INLINE int16_t udev_compute_axis(const struct input_absinfo *info, int value)
|
||||
@ -405,12 +403,7 @@ static void udev_joypad_destroy(void)
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
udev_free_pad(i);
|
||||
|
||||
if (g_udev_mon)
|
||||
udev_monitor_unref(g_udev_mon);
|
||||
g_udev_mon = NULL;
|
||||
if (g_udev)
|
||||
udev_unref(g_udev);
|
||||
g_udev = NULL;
|
||||
udev_mon_free();
|
||||
}
|
||||
|
||||
static void udev_joypad_handle_hotplug(void)
|
||||
@ -536,16 +529,8 @@ static bool udev_joypad_init(void *data)
|
||||
for (i = 0; i < MAX_USERS; i++)
|
||||
udev_pads[i].fd = -1;
|
||||
|
||||
g_udev = udev_new();
|
||||
if (!g_udev)
|
||||
return false;
|
||||
|
||||
g_udev_mon = udev_monitor_new_from_netlink(g_udev, "udev");
|
||||
if (g_udev_mon)
|
||||
{
|
||||
udev_monitor_filter_add_match_subsystem_devtype(g_udev_mon, "input", NULL);
|
||||
udev_monitor_enable_receiving(g_udev_mon);
|
||||
}
|
||||
if (!udev_mon_new())
|
||||
goto error;
|
||||
|
||||
enumerate = udev_enumerate_new(g_udev);
|
||||
if (!enumerate)
|
||||
|
Loading…
x
Reference in New Issue
Block a user