mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-14 06:59:57 -05:00
support: abstract some system functions
Make a new API to hide some the implementation of eventfd, timerfd and signalfd along with clock and read/write/ioctl/close functions. We would like to have plugins use the abstractions so that we can switch them to something else when needed.
This commit is contained in:
parent
98602f0343
commit
81c7dd4433
12 changed files with 492 additions and 50 deletions
|
|
@ -89,6 +89,7 @@ spa_support_headers = [
|
|||
'support/log-impl.h',
|
||||
'support/loop.h',
|
||||
'support/plugin.h',
|
||||
'support/system.h',
|
||||
]
|
||||
|
||||
install_headers(spa_support_headers,
|
||||
|
|
|
|||
|
|
@ -202,7 +202,6 @@ struct spa_loop_control_methods {
|
|||
#define spa_loop_control_leave(l) spa_loop_control_method_v(l,leave,0)
|
||||
#define spa_loop_control_iterate(l,...) spa_loop_control_method_r(l,iterate,0,__VA_ARGS__)
|
||||
|
||||
|
||||
typedef void (*spa_source_io_func_t) (void *data, int fd, enum spa_io mask);
|
||||
typedef void (*spa_source_idle_func_t) (void *data);
|
||||
typedef void (*spa_source_event_func_t) (void *data, uint64_t count);
|
||||
|
|
|
|||
120
spa/include/spa/support/system.h
Normal file
120
spa/include/spa/support/system.h
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
/* Simple Plugin API
|
||||
*
|
||||
* Copyright © 2019 Wim Taymans
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SPA_SYSTEM_H
|
||||
#define SPA_SYSTEM_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <spa/utils/defs.h>
|
||||
#include <spa/utils/hook.h>
|
||||
#include <spa/utils/result.h>
|
||||
|
||||
/**
|
||||
* a collection of system functions
|
||||
*/
|
||||
#define SPA_VERSION_SYSTEM 0
|
||||
struct spa_system { struct spa_interface iface; };
|
||||
|
||||
|
||||
#define SPA_FD_CLOEXEC (1<<0)
|
||||
#define SPA_FD_NONBLOCK (1<<1)
|
||||
#define SPA_FD_EVENT_SEMAPHORE (1<<2)
|
||||
#define SPA_FD_TIMER_ABSTIME (1<<3)
|
||||
#define SPA_FD_TIMER_CANCEL_ON_SET (1<<4)
|
||||
|
||||
struct spa_system_methods {
|
||||
#define SPA_VERSION_SYSTEM_METHODS 0
|
||||
uint32_t version;
|
||||
|
||||
/* read/write/ioctl */
|
||||
ssize_t (*read) (void *object, int fd, void *buf, size_t count);
|
||||
ssize_t (*write) (void *object, int fd, const void *buf, size_t count);
|
||||
int (*ioctl) (void *object, int fd, unsigned long request, ...);
|
||||
int (*close) (void *object, int fd);
|
||||
|
||||
/* clock */
|
||||
int (*clock_gettime) (void *object,
|
||||
int clockid, struct timespec *value);
|
||||
int (*clock_getres) (void *object,
|
||||
int clockid, struct timespec *res);
|
||||
|
||||
/* timers */
|
||||
int (*timerfd_create) (void *object, int clockid, int flags);
|
||||
int (*timerfd_settime) (void *object,
|
||||
int fd, int flags,
|
||||
const struct itimerspec *new_value,
|
||||
struct itimerspec *old_value);
|
||||
int (*timerfd_gettime) (void *object,
|
||||
int fd, struct itimerspec *curr_value);
|
||||
int (*timerfd_read) (void *object, int fd, uint64_t *expirations);
|
||||
|
||||
/* events */
|
||||
int (*eventfd_create) (void *object, int flags);
|
||||
int (*eventfd_write) (void *object, int fd, uint64_t count);
|
||||
int (*eventfd_read) (void *object, int fd, uint64_t *count);
|
||||
|
||||
/* signals */
|
||||
int (*signalfd_create) (void *object, int signal, int flags);
|
||||
int (*signalfd_read) (void *object, int fd, int *signal);
|
||||
};
|
||||
|
||||
#define spa_system_method_r(o,method,version,...) \
|
||||
({ \
|
||||
int _res = -ENOTSUP; \
|
||||
struct spa_system *_o = o; \
|
||||
spa_interface_call_res(&_o->iface, \
|
||||
struct spa_system_methods, _res, \
|
||||
method, version, ##__VA_ARGS__); \
|
||||
_res; \
|
||||
})
|
||||
|
||||
|
||||
#define spa_system_read(s,...) spa_system_method_r(s,read,0,__VA_ARGS__)
|
||||
#define spa_system_write(s,...) spa_system_method_r(s,write,0,__VA_ARGS__)
|
||||
#define spa_system_ioctl(s,...) spa_system_method_r(s,ioctl,0,__VA_ARGS__)
|
||||
#define spa_system_close(s,...) spa_system_method_r(s,close,0,__VA_ARGS__)
|
||||
|
||||
#define spa_system_clock_gettime(s,...) spa_system_method_r(s,clock_gettime,0,__VA_ARGS__)
|
||||
#define spa_system_clock_getres(s,...) spa_system_method_r(s,clock_getres,0,__VA_ARGS__)
|
||||
|
||||
#define spa_system_timerfd_create(s,...) spa_system_method_r(s,timerfd_create,0,__VA_ARGS__)
|
||||
#define spa_system_timerfd_settime(s,...) spa_system_method_r(s,timerfd_settime,0,__VA_ARGS__)
|
||||
#define spa_system_timerfd_gettime(s,...) spa_system_method_r(s,timerfd_gettime,0,__VA_ARGS__)
|
||||
#define spa_system_timerfd_read(s,...) spa_system_method_r(s,timerfd_read,0,__VA_ARGS__)
|
||||
|
||||
#define spa_system_eventfd_create(s,...) spa_system_method_r(s,eventfd_create,0,__VA_ARGS__)
|
||||
#define spa_system_eventfd_write(s,...) spa_system_method_r(s,eventfd_write,0,__VA_ARGS__)
|
||||
#define spa_system_eventfd_read(s,...) spa_system_method_r(s,eventfd_read,0,__VA_ARGS__)
|
||||
|
||||
#define spa_system_signalfd_create(s,...) spa_system_method_r(s,signalfd_create,0,__VA_ARGS__)
|
||||
#define spa_system_signalfd_read(s,...) spa_system_method_r(s,signalfd_read,0,__VA_ARGS__)
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /* SPA_SYSTEM_H */
|
||||
|
|
@ -103,6 +103,7 @@ static const struct spa_type_info spa_types[] = {
|
|||
{ SPA_TYPE_INTERFACE_Handle, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Handle", NULL },
|
||||
{ SPA_TYPE_INTERFACE_HandleFactory, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "HandleFactory", NULL },
|
||||
{ SPA_TYPE_INTERFACE_Log, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Log", NULL },
|
||||
{ SPA_TYPE_INTERFACE_System, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "System", NULL },
|
||||
{ SPA_TYPE_INTERFACE_Loop, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "Loop", NULL },
|
||||
{ SPA_TYPE_INTERFACE_LoopControl, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "LoopControl", NULL },
|
||||
{ SPA_TYPE_INTERFACE_LoopUtils, SPA_TYPE_Pointer, SPA_TYPE_INFO_INTERFACE_BASE "LoopUtils", NULL },
|
||||
|
|
|
|||
|
|
@ -68,6 +68,7 @@ enum {
|
|||
SPA_TYPE_INTERFACE_Handle, /**< object handle */
|
||||
SPA_TYPE_INTERFACE_HandleFactory, /**< factory for object handles */
|
||||
SPA_TYPE_INTERFACE_Log, /**< log interface */
|
||||
SPA_TYPE_INTERFACE_System, /**< System functions */
|
||||
SPA_TYPE_INTERFACE_Loop, /**< poll loop support */
|
||||
SPA_TYPE_INTERFACE_LoopControl, /**< control of loops */
|
||||
SPA_TYPE_INTERFACE_LoopUtils, /**< loop utilities */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue