PipeWire: spa/support/system.h Source File

PipeWire 1.0.3

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#ifdef __cplusplus
9extern "C" {
10#endif
11
12struct itimerspec;
13
14#include <time.h>
15#include <sys/types.h>
16
17#include <spa/utils/defs.h>
18#include <spa/utils/hook.h>
19
32#define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System"
33#define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem"
34
35#define SPA_VERSION_SYSTEM 0
36struct spa_system { struct spa_interface iface; };
37
38/* IO events */
39#define SPA_IO_IN (1 << 0)
40#define SPA_IO_OUT (1 << 2)
41#define SPA_IO_ERR (1 << 3)
42#define SPA_IO_HUP (1 << 4)
43
44/* flags */
45#define SPA_FD_CLOEXEC (1<<0)
46#define SPA_FD_NONBLOCK (1<<1)
47#define SPA_FD_EVENT_SEMAPHORE (1<<2)
48#define SPA_FD_TIMER_ABSTIME (1<<3)
49#define SPA_FD_TIMER_CANCEL_ON_SET (1<<4)
50
51 struct spa_poll_event {
52 uint32_t events;
53 void *data;
54};
55
56struct spa_system_methods {
57#define SPA_VERSION_SYSTEM_METHODS 0
58 uint32_t version;
59
60 /* read/write/ioctl */
61 ssize_t (*read) (void *object, int fd, void *buf, size_t count);
62 ssize_t (*write) (void *object, int fd, const void *buf, size_t count);
63 int (*ioctl) (void *object, int fd, unsigned long request, ...);
64 int (*close) (void *object, int fd);
65
66 /* clock */
67 int (*clock_gettime) (void *object,
68 int clockid, struct timespec *value);
69 int (*clock_getres) (void *object,
70 int clockid, struct timespec *res);
71
72 /* poll */
73 int (*pollfd_create) (void *object, int flags);
74 int (*pollfd_add) (void *object, int pfd, int fd, uint32_t events, void *data);
75 int (*pollfd_mod) (void *object, int pfd, int fd, uint32_t events, void *data);
76 int (*pollfd_del) (void *object, int pfd, int fd);
77 int (*pollfd_wait) (void *object, int pfd,
78 struct spa_poll_event *ev, int n_ev, int timeout);
79
80 /* timers */
81 int (*timerfd_create) (void *object, int clockid, int flags);
82 int (*timerfd_settime) (void *object,
83 int fd, int flags,
84 const struct itimerspec *new_value,
85 struct itimerspec *old_value);
86 int (*timerfd_gettime) (void *object,
87 int fd, struct itimerspec *curr_value);
88 int (*timerfd_read) (void *object, int fd, uint64_t *expirations);
89
90 /* events */
91 int (*eventfd_create) (void *object, int flags);
92 int (*eventfd_write) (void *object, int fd, uint64_t count);
93 int (*eventfd_read) (void *object, int fd, uint64_t *count);
94
95 /* signals */
96 int (*signalfd_create) (void *object, int signal, int flags);
97 int (*signalfd_read) (void *object, int fd, int *signal);
98};
99
100#define spa_system_method_r(o,method,version,...) \
101({ \
102 volatile int _res = -ENOTSUP; \
103 struct spa_system *_o = o; \
104 spa_interface_call_fast_res(&_o->iface, \
105 struct spa_system_methods, _res, \
106 method, version, ##__VA_ARGS__); \
107 _res; \
108})
109
110#define spa_system_read(s,...) spa_system_method_r(s,read,0,__VA_ARGS__)
111#define spa_system_write(s,...) spa_system_method_r(s,write,0,__VA_ARGS__)
112#define spa_system_ioctl(s,...) spa_system_method_r(s,ioctl,0,__VA_ARGS__)
113#define spa_system_close(s,...) spa_system_method_r(s,close,0,__VA_ARGS__)
114
115#define spa_system_clock_gettime(s,...) spa_system_method_r(s,clock_gettime,0,__VA_ARGS__)
116#define spa_system_clock_getres(s,...) spa_system_method_r(s,clock_getres,0,__VA_ARGS__)
117
118#define spa_system_pollfd_create(s,...) spa_system_method_r(s,pollfd_create,0,__VA_ARGS__)
119#define spa_system_pollfd_add(s,...) spa_system_method_r(s,pollfd_add,0,__VA_ARGS__)
120#define spa_system_pollfd_mod(s,...) spa_system_method_r(s,pollfd_mod,0,__VA_ARGS__)
121#define spa_system_pollfd_del(s,...) spa_system_method_r(s,pollfd_del,0,__VA_ARGS__)
122#define spa_system_pollfd_wait(s,...) spa_system_method_r(s,pollfd_wait,0,__VA_ARGS__)
123
124#define spa_system_timerfd_create(s,...) spa_system_method_r(s,timerfd_create,0,__VA_ARGS__)
125#define spa_system_timerfd_settime(s,...) spa_system_method_r(s,timerfd_settime,0,__VA_ARGS__)
126#define spa_system_timerfd_gettime(s,...) spa_system_method_r(s,timerfd_gettime,0,__VA_ARGS__)
127#define spa_system_timerfd_read(s,...) spa_system_method_r(s,timerfd_read,0,__VA_ARGS__)
128
129#define spa_system_eventfd_create(s,...) spa_system_method_r(s,eventfd_create,0,__VA_ARGS__)
130#define spa_system_eventfd_write(s,...) spa_system_method_r(s,eventfd_write,0,__VA_ARGS__)
131#define spa_system_eventfd_read(s,...) spa_system_method_r(s,eventfd_read,0,__VA_ARGS__)
132
133#define spa_system_signalfd_create(s,...) spa_system_method_r(s,signalfd_create,0,__VA_ARGS__)
134#define spa_system_signalfd_read(s,...) spa_system_method_r(s,signalfd_read,0,__VA_ARGS__)
135
140#ifdef __cplusplus
141} /* extern "C" */
142#endif
143
144#endif /* SPA_SYSTEM_H */
defs.h
spa/utils/defs.h
hook.h
spa/utils/hook.h
itimerspec
spa_interface
Definition hook.h:138
spa_poll_event
Definition system.h:69
spa_poll_event::events
uint32_t events
Definition system.h:70
spa_poll_event::data
void * data
Definition system.h:71
spa_system_methods
Definition system.h:74
spa_system_methods::pollfd_del
int(* pollfd_del)(void *object, int pfd, int fd)
Definition system.h:95
spa_system_methods::eventfd_read
int(* eventfd_read)(void *object, int fd, uint64_t *count)
Definition system.h:112
spa_system_methods::signalfd_read
int(* signalfd_read)(void *object, int fd, int *signal)
Definition system.h:116
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:96
spa_system_methods::timerfd_create
int(* timerfd_create)(void *object, int clockid, int flags)
Definition system.h:100
spa_system_methods::eventfd_write
int(* eventfd_write)(void *object, int fd, uint64_t count)
Definition system.h:111
spa_system_methods::eventfd_create
int(* eventfd_create)(void *object, int flags)
Definition system.h:110
spa_system_methods::read
ssize_t(* read)(void *object, int fd, void *buf, size_t count)
Definition system.h:80
spa_system_methods::version
uint32_t version
Definition system.h:77
spa_system_methods::clock_getres
int(* clock_getres)(void *object, int clockid, struct timespec *res)
Definition system.h:88
spa_system_methods::timerfd_read
int(* timerfd_read)(void *object, int fd, uint64_t *expirations)
Definition system.h:107
spa_system_methods::close
int(* close)(void *object, int fd)
Definition system.h:83
spa_system_methods::pollfd_create
int(* pollfd_create)(void *object, int flags)
Definition system.h:92
spa_system_methods::clock_gettime
int(* clock_gettime)(void *object, int clockid, struct timespec *value)
Definition system.h:86
spa_system_methods::write
ssize_t(* write)(void *object, int fd, const void *buf, size_t count)
Definition system.h:81
spa_system_methods::pollfd_add
int(* pollfd_add)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:93
spa_system_methods::timerfd_gettime
int(* timerfd_gettime)(void *object, int fd, struct itimerspec *curr_value)
Definition system.h:105
spa_system_methods::signalfd_create
int(* signalfd_create)(void *object, int signal, int flags)
Definition system.h:115
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:101
spa_system_methods::pollfd_mod
int(* pollfd_mod)(void *object, int pfd, int fd, uint32_t events, void *data)
Definition system.h:94
spa_system_methods::ioctl
int(* ioctl)(void *object, int fd, unsigned long request,...)
Definition system.h:82
spa_system
Definition system.h:45
spa_system::iface
struct spa_interface iface
Definition system.h:45