mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-02-18 10:40:30 +01:00
libei: add a backend to work off a single fd
For the case where someone else opens the sockets for us - like a test suite or eventually the portal. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
48cbc48a38
commit
bc5be06549
3 changed files with 97 additions and 0 deletions
|
|
@ -38,6 +38,7 @@ src_libei = [
|
|||
'src/libei.c',
|
||||
'src/libei-device.c',
|
||||
'src/libei-socket.c',
|
||||
'src/libei-fd.c',
|
||||
proto_headers,
|
||||
]
|
||||
|
||||
|
|
|
|||
90
src/libei-fd.c
Normal file
90
src/libei-fd.c
Normal file
|
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* Copyright © 2020 Red Hat, Inc.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a
|
||||
* copy of this software and associated documentation files (the "Software"),
|
||||
* to deal in the Software without restriction, including without limitation
|
||||
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||||
* and/or sell copies of the Software, and to permit persons to whom the
|
||||
* Software is furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice (including the next
|
||||
* paragraph) shall be included in all copies or substantial portions of the
|
||||
* Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||||
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
* DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "util-logger.h"
|
||||
#include "util-mem.h"
|
||||
#include "util-macros.h"
|
||||
#include "util-sources.h"
|
||||
#include "util-strings.h"
|
||||
#include "util-object.h"
|
||||
|
||||
#include "libei.h"
|
||||
#include "libei-private.h"
|
||||
|
||||
/**
|
||||
* This is the simplest backend: the caller prepares a socket and we just
|
||||
* take that and use it.
|
||||
*/
|
||||
struct ei_fd {
|
||||
struct object object;
|
||||
};
|
||||
|
||||
static inline struct ei_fd *
|
||||
ei_fd(struct ei *ei)
|
||||
{
|
||||
return ei->backend;
|
||||
}
|
||||
|
||||
static inline void
|
||||
ei_fd_destroy(struct ei_fd *backend)
|
||||
{
|
||||
/* nothing to do here */
|
||||
}
|
||||
|
||||
OBJECT_IMPLEMENT_CREATE(ei_fd);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(ei_fd);
|
||||
|
||||
static void
|
||||
interface_fd_destroy(struct ei *ei, void *backend)
|
||||
{
|
||||
struct ei_fd *ei_fd = backend;
|
||||
ei_fd_unref(ei_fd);
|
||||
}
|
||||
|
||||
static const struct ei_backend_interface interface = {
|
||||
.destroy = interface_fd_destroy,
|
||||
};
|
||||
|
||||
_public_ int
|
||||
ei_setup_backend_fd(struct ei *ei, int fd)
|
||||
{
|
||||
assert(ei);
|
||||
assert(!ei->backend);
|
||||
|
||||
struct ei_fd *ei_fd = ei_fd_create(&ei->object);
|
||||
|
||||
ei->backend = ei_fd;
|
||||
ei->backend_interface = interface;
|
||||
|
||||
return ei_set_connection(ei, fd);
|
||||
}
|
||||
|
|
@ -114,6 +114,12 @@ ei_configure_name(struct ei * ei, const char *name);
|
|||
int
|
||||
ei_setup_backend_socket(struct ei *ei, const char *socketpath);
|
||||
|
||||
/**
|
||||
* Initialize the ei context on the given socket
|
||||
*/
|
||||
int
|
||||
ei_setup_backend_fd(struct ei *ei, int fd);
|
||||
|
||||
struct ei *
|
||||
ei_ref(struct ei *ctx);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue