PipeWire: spa/support/system.h Source File

PipeWire 1.6.5

Loading...
Searching...
No Matches
system.h
Go to the documentation of this file.
1/* Simple Plugin API */
2/* SPDX-FileCopyrightText: Copyright © 2019 Wim Taymans */
3/* SPDX-License-Identifier: MIT */
4
5#ifndef SPA_SYSTEM_H
6#define SPA_SYSTEM_H
7
8#include <time.h>
9#include <errno.h>
10#include <sys/types.h>
11
12#include <spa/utils/defs.h>
13#include <spa/utils/hook.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
19struct itimerspec;
20
21#ifndef SPA_API_SYSTEM
22 #ifdef SPA_API_IMPL
23 #define SPA_API_SYSTEM SPA_API_IMPL
24 #else
25 #define SPA_API_SYSTEM static inline
26 #endif
27#endif
28
32
37
41#define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System"
42#define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem"
43
44#define SPA_VERSION_SYSTEM 0
45struct spa_system { struct spa_interface iface; };
46
47/* IO events */
48#define SPA_IO_IN (1 << 0)
49#define SPA_IO_OUT (1 << 2)
50#define SPA_IO_ERR (1 << 3)
51#define SPA_IO_HUP (1 << 4)
52
53/* flags */
54#define SPA_FD_CLOEXEC (1<<0)
55#define SPA_FD_NONBLOCK (1<<1)
56#define SPA_FD_EVENT_SEMAPHORE (1<<2)
57#define SPA_FD_TIMER_ABSTIME (1<<3)
58#define SPA_FD_TIMER_CANCEL_ON_SET (1<<4)
59
60 struct spa_poll_event {
61 uint32_t events;
62 void *data;
63};
64
65struct spa_system_methods {
66#define SPA_VERSION_SYSTEM_METHODS 0
67 uint32_t version;
68
69 /* read/write/ioctl */
70 ssize_t (*read) (void *object, int fd, void *buf, size_t count);
71 ssize_t (*write) (void *object, int fd, const void *buf, size_t count);
72 int (*ioctl) (void *object, int fd, unsigned long request, ...);
73 int (*close) (void *object, int fd);
74
75 /* clock */
76 int (*clock_gettime) (void *object,
77 int clockid, struct timespec *value);
78 int (*clock_getres) (void *object,
79 int clockid, struct timespec *res);
80
81 /* poll */
82 int (*pollfd_create) (void *object, int flags);
83 int (*pollfd_add) (void *object, int pfd, int fd, uint32_t events, void *data);
84 int (*pollfd_mod) (void *object, int pfd, int fd, uint32_t events, void *data);
85 int (*pollfd_del) (void *object, int pfd, int fd);
86 int (*pollfd_wait) (void *object, int pfd,
87 struct spa_poll_event *ev, int n_ev, int timeout);
88
89 /* timers */
90 int (*timerfd_create) (void *object, int clockid, int flags);
91 int (*timerfd_settime) (void *object,
92 int fd, int flags,
93 const struct itimerspec *new_value,
94 struct itimerspec *old_value);
95 int (*timerfd_gettime) (void *object,
96 int fd, struct itimerspec *curr_value);
97 int (*timerfd_read) (void *object, int fd, uint64_t *expirations);
98
99 /* events */
100 int (*eventfd_create) (void *object, int flags);
101 int (*eventfd_write) (void *object, int fd, uint64_t count);
102 int (*eventfd_read) (void *object, int fd, uint64_t *count);
103
104 /* signals */
105 int (*signalfd_create) (void *object, int signal, int flags);
106 int (*signalfd_read) (void *object, int fd, int *signal);
107};
108
109 SPA_API_SYSTEM ssize_t spa_system_read(struct spa_system *object, int fd, void *buf, size_t count)
110{
111 return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, read, 0, fd, buf, count);
112}
113 SPA_API_SYSTEM ssize_t spa_system_write(struct spa_system *object, int fd, const void *buf, size_t count)
114{
115 return spa_api_method_fast_r(ssize_t, -ENOTSUP, spa_system, &object->iface, write, 0, fd, buf, count);
116}
117#define spa_system_ioctl(object,fd,request,...) \
118 spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, ioctl, 0, fd, request, ##__VA_ARGS__)
119
120 SPA_API_SYSTEM int spa_system_close(struct spa_system *object, int fd)
121{
122 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, close, 0, fd);
123}
124 SPA_API_SYSTEM int spa_system_clock_gettime(struct spa_system *object,
125 int clockid, struct timespec *value)
126{
127 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_gettime, 0, clockid, value);
128}
129 SPA_API_SYSTEM int spa_system_clock_getres(struct spa_system *object,
130 int clockid, struct timespec *res)
131{
132 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, clock_getres, 0, clockid, res);
133}
134
135 SPA_API_SYSTEM int spa_system_pollfd_create(struct spa_system *object, int flags)
136{
137 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_create, 0, flags);
138}
139 SPA_API_SYSTEM int spa_system_pollfd_add(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
140{
141 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_add, 0, pfd, fd, events, data);
142}
143 SPA_API_SYSTEM int spa_system_pollfd_mod(struct spa_system *object, int pfd, int fd, uint32_t events, void *data)
144{
145 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_mod, 0, pfd, fd, events, data);
146}
147 SPA_API_SYSTEM int spa_system_pollfd_del(struct spa_system *object, int pfd, int fd)
148{
149 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_del, 0, pfd, fd);
150}
151 SPA_API_SYSTEM int spa_system_pollfd_wait(struct spa_system *object, int pfd,
152 struct spa_poll_event *ev, int n_ev, int timeout)
153{
154 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, pollfd_wait, 0, pfd, ev, n_ev, timeout);
155}
156
157 SPA_API_SYSTEM int spa_system_timerfd_create(struct spa_system *object, int clockid, int flags)
158{
159 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_create, 0, clockid, flags);
160}
161
162 SPA_API_SYSTEM int spa_system_timerfd_settime(struct spa_system *object,
163 int fd, int flags,
164 const struct itimerspec *new_value,
165 struct itimerspec *old_value)
166{
167 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_settime, 0,
168 fd, flags, new_value, old_value);
169}
170
171 SPA_API_SYSTEM int spa_system_timerfd_gettime(struct spa_system *object,
172 int fd, struct itimerspec *curr_value)
173{
174 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_gettime, 0,
175 fd, curr_value);
176}
177 SPA_API_SYSTEM int spa_system_timerfd_read(struct spa_system *object, int fd, uint64_t *expirations)
178{
179 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, timerfd_read, 0,
180 fd, expirations);
181}
182
183 SPA_API_SYSTEM int spa_system_eventfd_create(struct spa_system *object, int flags)
184{
185 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_create, 0, flags);
186}
187 SPA_API_SYSTEM int spa_system_eventfd_write(struct spa_system *object, int fd, uint64_t count)
188{
189 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_write, 0,
190 fd, count);
191}
192 SPA_API_SYSTEM int spa_system_eventfd_read(struct spa_system *object, int fd, uint64_t *count)
193{
194 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, eventfd_read, 0,
195 fd, count);
196}
197
198 SPA_API_SYSTEM int spa_system_signalfd_create(struct spa_system *object, int signal, int flags)
199{
200 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_create, 0,
201 signal, flags);
202}
203
204 SPA_API_SYSTEM int spa_system_signalfd_read(struct spa_system *object, int fd, int *signal)
205{
206 return spa_api_method_fast_r(int, -ENOTSUP, spa_system, &object->iface, signalfd_read, 0,
207 fd, signal);
208}
209
213
214#ifdef __cplusplus
215} /* extern "C" */
216#endif
217
218#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