mirror of
https://gitlab.freedesktop.org/libinput/libei.git
synced 2026-05-05 20:38:04 +02:00
eis: implement an fd backend
Caller opens the socket, passes it to eis, done. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
ad721d342a
commit
ba9b0bb903
4 changed files with 105 additions and 1 deletions
|
|
@ -66,6 +66,7 @@ lib_libeis = shared_library('eis',
|
|||
'src/libeis-client.c',
|
||||
'src/libeis-device.c',
|
||||
'src/libeis-socket.c',
|
||||
'src/libeis-fd.c',
|
||||
proto_headers,
|
||||
dependencies: [dep_libutil, dep_protobuf],
|
||||
install: true
|
||||
|
|
|
|||
91
src/libeis-fd.c
Normal file
91
src/libeis-fd.c
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
/*
|
||||
* 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 <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
|
||||
#include "util-logger.h"
|
||||
#include "util-mem.h"
|
||||
#include "util-macros.h"
|
||||
#include "util-sources.h"
|
||||
#include "util-strings.h"
|
||||
|
||||
#include "libeis.h"
|
||||
#include "libeis-private.h"
|
||||
|
||||
struct eis_fd {
|
||||
struct object object;
|
||||
};
|
||||
|
||||
static inline struct eis_fd *
|
||||
eis_fd(struct eis *eis)
|
||||
{
|
||||
return eis->backend;
|
||||
}
|
||||
|
||||
static inline void
|
||||
eis_fd_destroy(struct eis_fd *eis_fd)
|
||||
{
|
||||
}
|
||||
|
||||
OBJECT_IMPLEMENT_CREATE(eis_fd);
|
||||
static
|
||||
OBJECT_IMPLEMENT_UNREF(eis_fd);
|
||||
|
||||
static void
|
||||
interface_fd_destroy(struct eis *eis, void *backend)
|
||||
{
|
||||
struct eis_fd *fd = backend;
|
||||
eis_fd_unref(fd);
|
||||
}
|
||||
|
||||
static const struct eis_backend_interface interface = {
|
||||
.destroy = interface_fd_destroy,
|
||||
};
|
||||
|
||||
_public_ int
|
||||
eis_setup_backend_fd(struct eis *eis)
|
||||
{
|
||||
assert(eis);
|
||||
assert(!eis->backend);
|
||||
|
||||
eis->backend = eis_fd_create(&eis->object);
|
||||
eis->backend_interface = interface;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
_public_ int
|
||||
eis_backend_fd_add_fd(struct eis *eis, int fd)
|
||||
{
|
||||
assert(eis);
|
||||
assert(eis->backend);
|
||||
|
||||
if (eis_client_new(eis, fd) != NULL)
|
||||
return 0;
|
||||
else
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ interface_socket_destroy(struct eis *eis, void *backend)
|
|||
|
||||
}
|
||||
|
||||
const struct eis_backend_interface interface = {
|
||||
static const struct eis_backend_interface interface = {
|
||||
.destroy = interface_socket_destroy,
|
||||
};
|
||||
|
||||
|
|
|
|||
12
src/libeis.h
12
src/libeis.h
|
|
@ -143,6 +143,18 @@ eis_dbus_init(struct eis *ctx);
|
|||
int
|
||||
eis_setup_backend_socket(struct eis *ctx, const char *path);
|
||||
|
||||
/**
|
||||
* Initialize the context that can take pre-configured sockets.
|
||||
*/
|
||||
int
|
||||
eis_setup_backend_fd(struct eis *ctx);
|
||||
|
||||
/**
|
||||
* Add a new client to a context set up with eis_setup_backend_fd()
|
||||
*/
|
||||
int
|
||||
eis_backend_fd_add_fd(struct eis *ctx, int fd);
|
||||
|
||||
int
|
||||
eis_get_fd(struct eis *eis);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue