tools: move the interface into the shared code

No need to duplicate this atm

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2015-06-24 14:52:48 +10:00
parent 6b2afee368
commit 41ad79f8d8
5 changed files with 29 additions and 67 deletions

View file

@ -45,24 +45,6 @@ static const uint32_t screen_height = 100;
struct tools_options options;
static unsigned int stop = 0;
static int
open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
return fd < 0 ? -errno : fd;
}
static void
close_restricted(int fd, void *user_data)
{
close(fd);
}
static const struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
static void
print_event_header(struct libinput_event *ev)
{
@ -403,7 +385,7 @@ main(int argc, char **argv)
if (tools_parse_args(argc, argv, &options))
return 1;
li = tools_open_backend(&options, NULL, &interface);
li = tools_open_backend(&options, NULL);
if (!li)
return 1;

View file

@ -489,24 +489,6 @@ sockets_init(struct libinput *li)
g_io_add_watch(c, G_IO_IN, handle_event_libinput, li);
}
static int
open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
return fd < 0 ? -errno : fd;
}
static void
close_restricted(int fd, void *user_data)
{
close(fd);
}
static const struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
int
main(int argc, char *argv[])
{
@ -525,7 +507,7 @@ main(int argc, char *argv[])
if (!udev)
error("Failed to initialize udev\n");
li = tools_open_backend(&options, &w, &interface);
li = tools_open_backend(&options, &w);
if (!li)
return 1;

View file

@ -23,7 +23,6 @@
#define _GNU_SOURCE
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
@ -36,27 +35,6 @@
#include "shared.h"
static int
open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
if (fd < 0)
fprintf(stderr, "Failed to open %s (%s)\n",
path, strerror(errno));
return fd < 0 ? -errno : fd;
}
static void
close_restricted(int fd, void *user_data)
{
close(fd);
}
static const struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
static inline const char*
bool_to_str(bool b)
{
@ -308,7 +286,7 @@ main(int argc, char **argv)
tools_init_options(&options);
li = tools_open_backend(&options, NULL, &interface);
li = tools_open_backend(&options, NULL);
if (!li)
return 1;

View file

@ -25,6 +25,7 @@
#include <config.h>
#include <errno.h>
#include <fcntl.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
@ -344,17 +345,37 @@ open_device(const struct libinput_interface *interface,
return li;
}
static int
open_restricted(const char *path, int flags, void *user_data)
{
int fd = open(path, flags);
if (fd < 0)
fprintf(stderr, "Failed to open %s (%s)\n",
path, strerror(errno));
return fd < 0 ? -errno : fd;
}
static void
close_restricted(int fd, void *user_data)
{
close(fd);
}
static const struct libinput_interface interface = {
.open_restricted = open_restricted,
.close_restricted = close_restricted,
};
struct libinput *
tools_open_backend(struct tools_options *options,
void *userdata,
const struct libinput_interface *interface)
void *userdata)
{
struct libinput *li = NULL;
if (options->backend == BACKEND_UDEV) {
li = open_udev(interface, userdata, options->seat, options->verbose);
li = open_udev(&interface, userdata, options->seat, options->verbose);
} else if (options->backend == BACKEND_DEVICE) {
li = open_device(interface, userdata, options->device, options->verbose);
li = open_device(&interface, userdata, options->device, options->verbose);
} else
abort();

View file

@ -51,8 +51,7 @@ struct tools_options {
void tools_init_options(struct tools_options *options);
int tools_parse_args(int argc, char **argv, struct tools_options *options);
struct libinput* tools_open_backend(struct tools_options *options,
void *userdata,
const struct libinput_interface *interface);
void *userdata);
void tools_device_apply_config(struct libinput_device *device,
struct tools_options *options);
void tools_usage();