Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
/* Simple Plugin API */
/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
/* SPDX-License-Identifier: MIT */
#ifndef SPA_SYSTEM_H
#define SPA_SYSTEM_H
#include <time.h>
#include <errno.h>
#include <sys/types.h>
#include <spa/utils/defs.h>
#include <spa/utils/hook.h>
#ifdef __cplusplus
extern "C" {
#endif
struct itimerspec;
#ifndef SPA_API_SYSTEM
#ifdef SPA_API_IMPL
#define SPA_API_SYSTEM SPA_API_IMPL
#else
#define SPA_API_SYSTEM static inline
#endif
#endif
#define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System"
#define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem"
#define SPA_VERSION_SYSTEM 0
struct spa_system { struct spa_interface iface; };
/* IO events */
#define SPA_IO_IN (1 << 0)
#define SPA_IO_OUT (1 << 2)
#define SPA_IO_ERR (1 << 3)
#define SPA_IO_HUP (1 << 4)
/* flags */
#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_poll_event {
uint32_t events;
void *data;
};
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);
/* poll */
int (*pollfd_create) (void *object, int flags);
int (*pollfd_add) (void *object, int pfd, int fd, uint32_t events, void *data);
int (*pollfd_mod) (void *object, int pfd, int fd, uint32_t events, void *data);
int (*pollfd_del) (void *object, int pfd, int fd);
int (*pollfd_wait) (void *object, int pfd,
struct spa_poll_event *ev, int n_ev, int timeout);
/* 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);
};
SPA_API_SYSTEM ssize_t spa_system_read(struct spa_system *object, int fd, void *buf, size_t count)
{
return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, read, 0, fd, buf, count);
}
SPA_API_SYSTEM ssize_t spa_system_write(struct spa_system *object, int fd, const void *buf, size_t count)
{
return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, write, 0, fd, buf, count);
}
#define spa_system_ioctl(object,fd,request,...) \
spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, ioctl, 0, fd, request, ##__VA_ARGS__)
SPA_API_SYSTEM int spa_system_close(struct spa_system *object, int fd)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, close, 0, fd);
}
SPA_API_SYSTEM int spa_system_clock_gettime(struct spa_system *object,
int clockid, struct timespec *value)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_gettime, 0, clockid, value);
}
SPA_API_SYSTEM int spa_system_clock_getres(struct spa_system *object,
int clockid, struct timespec *res)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_getres, 0, clockid, res);
}
SPA_API_SYSTEM int spa_system_pollfd_create(struct spa_system *object, int flags)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_create, 0, flags);
}
SPA_API_SYSTEM int spa_system_pollfd_add(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_add, 0, pfd, fd, events, data);
}
SPA_API_SYSTEM int spa_system_pollfd_mod(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_mod, 0, pfd, fd, events, data);
}
SPA_API_SYSTEM int spa_system_pollfd_del(struct spa_system *object, int pfd, int fd)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_del, 0, pfd, fd);
}
SPA_API_SYSTEM int spa_system_pollfd_wait(struct spa_system *object, int pfd,
struct spa_poll_event *ev, int n_ev, int timeout)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_wait, 0, pfd, ev, n_ev, timeout);
}
SPA_API_SYSTEM int spa_system_timerfd_create(struct spa_system *object, int clockid, int flags)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_create, 0, clockid, flags);
}
SPA_API_SYSTEM int spa_system_timerfd_settime(struct spa_system *object,
int fd, int flags,
const struct itimerspec *new_value,
struct itimerspec *old_value)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_settime, 0,
fd, flags, new_value, old_value);
}
SPA_API_SYSTEM int spa_system_timerfd_gettime(struct spa_system *object,
int fd, struct itimerspec *curr_value)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_gettime, 0,
fd, curr_value);
}
SPA_API_SYSTEM int spa_system_timerfd_read(struct spa_system *object, int fd, uint64_t *expirations)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_read, 0,
fd, expirations);
}
SPA_API_SYSTEM int spa_system_eventfd_create(struct spa_system *object, int flags)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_create, 0, flags);
}
SPA_API_SYSTEM int spa_system_eventfd_write(struct spa_system *object, int fd, uint64_t count)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_write, 0,
fd, count);
}
SPA_API_SYSTEM int spa_system_eventfd_read(struct spa_system *object, int fd, uint64_t *count)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_read, 0,
fd, count);
}
SPA_API_SYSTEM int spa_system_signalfd_create(struct spa_system *object, int signal, int flags)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_create, 0,
signal, flags);
}
SPA_API_SYSTEM int spa_system_signalfd_read(struct spa_system *object, int fd, int *signal)
{
return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_read, 0,
fd, signal);
}
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* SPA_SYSTEM_H */
defs.h
spa/utils/defs.h
res
uint32_t int int res
Definition core.h:433
spa_api_method_fast_r
#define spa_api_method_fast_r(rtype, def, type, o, method, version,...)
Definition hook.h:325
spa_system_clock_gettime
SPA_API_SYSTEM int spa_system_clock_gettime(struct spa_system *object, int clockid, struct timespec *value)
Definition system.h:145
spa_system_timerfd_gettime
SPA_API_SYSTEM int spa_system_timerfd_gettime(struct spa_system *object, int fd, struct itimerspec *curr_value)
Definition system.h:192
spa_system_pollfd_add
SPA_API_SYSTEM int spa_system_pollfd_add(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:160
spa_system_timerfd_settime
SPA_API_SYSTEM int spa_system_timerfd_settime(struct spa_system *object, int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
Definition system.h:183
spa_system_write
SPA_API_SYSTEM ssize_t spa_system_write(struct spa_system *object, int fd, const void *buf, size_t count)
Definition system.h:134
spa_system_pollfd_create
SPA_API_SYSTEM int spa_system_pollfd_create(struct spa_system *object, int flags)
Definition system.h:156
spa_system_signalfd_create
SPA_API_SYSTEM int spa_system_signalfd_create(struct spa_system *object, int signal, int flags)
Definition system.h:219
spa_system_pollfd_wait
SPA_API_SYSTEM int spa_system_pollfd_wait(struct spa_system *object, int pfd, struct spa_poll_event *ev, int n_ev, int timeout)
Definition system.h:172
spa_system_eventfd_write
SPA_API_SYSTEM int spa_system_eventfd_write(struct spa_system *object, int fd, uint64_t count)
Definition system.h:208
spa_system_eventfd_read
SPA_API_SYSTEM int spa_system_eventfd_read(struct spa_system *object, int fd, uint64_t *count)
Definition system.h:213
spa_system_timerfd_create
SPA_API_SYSTEM int spa_system_timerfd_create(struct spa_system *object, int clockid, int flags)
Definition system.h:178
spa_system_eventfd_create
SPA_API_SYSTEM int spa_system_eventfd_create(struct spa_system *object, int flags)
Definition system.h:204
spa_system_signalfd_read
SPA_API_SYSTEM int spa_system_signalfd_read(struct spa_system *object, int fd, int *signal)
Definition system.h:225
spa_system_close
SPA_API_SYSTEM int spa_system_close(struct spa_system *object, int fd)
Definition system.h:141
spa_system_timerfd_read
SPA_API_SYSTEM int spa_system_timerfd_read(struct spa_system *object, int fd, uint64_t *expirations)
Definition system.h:198
spa_system_clock_getres
SPA_API_SYSTEM int spa_system_clock_getres(struct spa_system *object, int clockid, struct timespec *res)
Definition system.h:150
spa_system_pollfd_del
SPA_API_SYSTEM int spa_system_pollfd_del(struct spa_system *object, int pfd, int fd)
Definition system.h:168
spa_system_read
SPA_API_SYSTEM ssize_t spa_system_read(struct spa_system *object, int fd, void *buf, size_t count)
Definition system.h:130
spa_system_pollfd_mod
SPA_API_SYSTEM int spa_system_pollfd_mod(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:164
hook.h
spa/utils/hook.h
itimerspec
spa_interface
Definition hook.h:148
spa_poll_event
Definition system.h:80
spa_poll_event::events
uint32_t events
Definition system.h:81
spa_poll_event::data
void * data
Definition system.h:82
spa_system_methods
Definition system.h:85
spa_system_methods::pollfd_del
int(* pollfd_del)(void *object, int pfd, int fd)
Definition system.h:106
spa_system_methods::eventfd_read
int(* eventfd_read)(void *object, int fd, uint64_t *count)
Definition system.h:123
spa_system_methods::signalfd_read
int(* signalfd_read)(void *object, int fd, int *signal)
Definition system.h:127
spa_system_methods::pollfd_wait
int(* pollfd_wait)(void *object, int pfd, struct spa_poll_event *ev, int n_ev, int timeout)
Definition system.h:107
spa_system_methods::timerfd_create
int(* timerfd_create)(void *object, int clockid, int flags)
Definition system.h:111
spa_system_methods::eventfd_write
int(* eventfd_write)(void *object, int fd, uint64_t count)
Definition system.h:122
spa_system_methods::eventfd_create
int(* eventfd_create)(void *object, int flags)
Definition system.h:121
spa_system_methods::read
ssize_t(* read)(void *object, int fd, void *buf, size_t count)
Definition system.h:91
spa_system_methods::version
uint32_t version
Definition system.h:88
spa_system_methods::clock_getres
int(* clock_getres)(void *object, int clockid, struct timespec *res)
Definition system.h:99
spa_system_methods::timerfd_read
int(* timerfd_read)(void *object, int fd, uint64_t *expirations)
Definition system.h:118
spa_system_methods::close
int(* close)(void *object, int fd)
Definition system.h:94
spa_system_methods::pollfd_create
int(* pollfd_create)(void *object, int flags)
Definition system.h:103
spa_system_methods::clock_gettime
int(* clock_gettime)(void *object, int clockid, struct timespec *value)
Definition system.h:97
spa_system_methods::write
ssize_t(* write)(void *object, int fd, const void *buf, size_t count)
Definition system.h:92
spa_system_methods::pollfd_add
int(* pollfd_add)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:104
spa_system_methods::timerfd_gettime
int(* timerfd_gettime)(void *object, int fd, struct itimerspec *curr_value)
Definition system.h:116
spa_system_methods::signalfd_create
int(* signalfd_create)(void *object, int signal, int flags)
Definition system.h:126
spa_system_methods::timerfd_settime
int(* timerfd_settime)(void *object, int fd, int flags, const struct itimerspec *new_value, struct itimerspec *old_value)
Definition system.h:112
spa_system_methods::pollfd_mod
int(* pollfd_mod)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:105
spa_system_methods::ioctl
int(* ioctl)(void *object, int fd, unsigned long request,...)
Definition system.h:93
spa_system
Definition system.h:56
spa_system::iface
struct spa_interface iface
Definition system.h:56
SPA_API_SYSTEM
#define SPA_API_SYSTEM
Definition system.h:33