| 1 |
/* Simple Plugin API |
| 2 |
* |
| 3 |
* Copyright © 2019 Wim Taymans |
| 4 |
* |
| 5 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 6 |
* copy of this software and associated documentation files (the "Software"), |
| 7 |
* to deal in the Software without restriction, including without limitation |
| 8 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 10 |
* Software is furnished to do so, subject to the following conditions: |
| 11 |
* |
| 12 |
* The above copyright notice and this permission notice (including the next |
| 13 |
* paragraph) shall be included in all copies or substantial portions of the |
| 14 |
* Software. |
| 15 |
* |
| 16 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 |
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 22 |
* DEALINGS IN THE SOFTWARE. |
| 23 |
*/ |
| 24 |
|
| 25 |
#ifndef SPA_SYSTEM_H |
| 26 |
#define SPA_SYSTEM_H |
| 27 |
|
| 28 |
#ifdef __cplusplus |
| 29 |
extern "C" { |
| 30 |
#endif |
| 31 |
|
| 32 |
struct itimerspec; |
| 33 |
|
| 34 |
#include <time.h> |
| 35 |
#include <sys/types.h> |
| 36 |
|
| 37 |
#include <spa/utils/defs.h> |
| 38 |
#include <spa/utils/hook.h> |
| 39 |
|
| 40 |
/** |
| 41 |
* a collection of core system functions |
| 42 |
*/ |
| 43 |
#define SPA_TYPE_INTERFACE_System SPA_TYPE_INFO_INTERFACE_BASE "System" |
| 44 |
#define SPA_TYPE_INTERFACE_DataSystem SPA_TYPE_INFO_INTERFACE_BASE "DataSystem" |
| 45 |
|
| 46 |
#define SPA_VERSION_SYSTEM 0 |
| 47 |
struct spa_system { struct spa_interface iface; }; |
| 48 |
|
| 49 |
/* IO events */ |
| 50 |
#define SPA_IO_IN (1 << 0) |
| 51 |
#define SPA_IO_OUT (1 << 2) |
| 52 |
#define SPA_IO_ERR (1 << 3) |
| 53 |
#define SPA_IO_HUP (1 << 4) |
| 54 |
|
| 55 |
/* flags */ |
| 56 |
#define SPA_FD_CLOEXEC (1<<0) |
| 57 |
#define SPA_FD_NONBLOCK (1<<1) |
| 58 |
#define SPA_FD_EVENT_SEMAPHORE (1<<2) |
| 59 |
#define SPA_FD_TIMER_ABSTIME (1<<3) |
| 60 |
#define SPA_FD_TIMER_CANCEL_ON_SET (1<<4) |
| 61 |
|
| 62 |
struct spa_poll_event { |
| 63 |
uint32_t events; |
| 64 |
void *data; |
| 65 |
}; |
| 66 |
|
| 67 |
struct spa_system_methods { |
| 68 |
#define SPA_VERSION_SYSTEM_METHODS 0 |
| 69 |
uint32_t version; |
| 70 |
|
| 71 |
/* read/write/ioctl */ |
| 72 |
ssize_t (*read) (void *object, int fd, void *buf, size_t count); |
| 73 |
ssize_t (*write) (void *object, int fd, const void *buf, size_t count); |
| 74 |
int (*ioctl) (void *object, int fd, unsigned long request, ...); |
| 75 |
int (*close) (void *object, int fd); |
| 76 |
|
| 77 |
/* clock */ |
| 78 |
int (*clock_gettime) (void *object, |
| 79 |
int clockid, struct timespec *value); |
| 80 |
int (*clock_getres) (void *object, |
| 81 |
int clockid, struct timespec *res); |
| 82 |
|
| 83 |
/* poll */ |
| 84 |
int (*pollfd_create) (void *object, int flags); |
| 85 |
int (*pollfd_add) (void *object, int pfd, int fd, uint32_t events, void *data); |
| 86 |
int (*pollfd_mod) (void *object, int pfd, int fd, uint32_t events, void *data); |
| 87 |
int (*pollfd_del) (void *object, int pfd, int fd); |
| 88 |
int (*pollfd_wait) (void *object, int pfd, |
| 89 |
struct spa_poll_event *ev, int n_ev, int timeout); |
| 90 |
|
| 91 |
/* timers */ |
| 92 |
int (*timerfd_create) (void *object, int clockid, int flags); |
| 93 |
int (*timerfd_settime) (void *object, |
| 94 |
int fd, int flags, |
| 95 |
const struct itimerspec *new_value, |
| 96 |
struct itimerspec *old_value); |
| 97 |
int (*timerfd_gettime) (void *object, |
| 98 |
int fd, struct itimerspec *curr_value); |
| 99 |
int (*timerfd_read) (void *object, int fd, uint64_t *expirations); |
| 100 |
|
| 101 |
/* events */ |
| 102 |
int (*eventfd_create) (void *object, int flags); |
| 103 |
int (*eventfd_write) (void *object, int fd, uint64_t count); |
| 104 |
int (*eventfd_read) (void *object, int fd, uint64_t *count); |
| 105 |
|
| 106 |
/* signals */ |
| 107 |
int (*signalfd_create) (void *object, int signal, int flags); |
| 108 |
int (*signalfd_read) (void *object, int fd, int *signal); |
| 109 |
}; |
| 110 |
|
| 111 |
#define spa_system_method_r(o,method,version,...) \ |
| 112 |
({ \ |
| 113 |
int _res = -ENOTSUP; \ |
| 114 |
struct spa_system *_o = o; \ |
| 115 |
spa_interface_call_res(&_o->iface, \ |
| 116 |
struct spa_system_methods, _res, \ |
| 117 |
method, version, ##__VA_ARGS__); \ |
| 118 |
_res; \ |
| 119 |
}) |
| 120 |
|
| 121 |
|
| 122 |
#define spa_system_read(s,...) spa_system_method_r(s,read,0,__VA_ARGS__) |
| 123 |
#define spa_system_write(s,...) spa_system_method_r(s,write,0,__VA_ARGS__) |
| 124 |
#define spa_system_ioctl(s,...) spa_system_method_r(s,ioctl,0,__VA_ARGS__) |
| 125 |
#define spa_system_close(s,...) spa_system_method_r(s,close,0,__VA_ARGS__) |
| 126 |
|
| 127 |
#define spa_system_clock_gettime(s,...) spa_system_method_r(s,clock_gettime,0,__VA_ARGS__) |
| 128 |
#define spa_system_clock_getres(s,...) spa_system_method_r(s,clock_getres,0,__VA_ARGS__) |
| 129 |
|
| 130 |
#define spa_system_pollfd_create(s,...) spa_system_method_r(s,pollfd_create,0,__VA_ARGS__) |
| 131 |
#define spa_system_pollfd_add(s,...) spa_system_method_r(s,pollfd_add,0,__VA_ARGS__) |
| 132 |
#define spa_system_pollfd_mod(s,...) spa_system_method_r(s,pollfd_mod,0,__VA_ARGS__) |
| 133 |
#define spa_system_pollfd_del(s,...) spa_system_method_r(s,pollfd_del,0,__VA_ARGS__) |
| 134 |
#define spa_system_pollfd_wait(s,...) spa_system_method_r(s,pollfd_wait,0,__VA_ARGS__) |
| 135 |
|
| 136 |
#define spa_system_timerfd_create(s,...) spa_system_method_r(s,timerfd_create,0,__VA_ARGS__) |
| 137 |
#define spa_system_timerfd_settime(s,...) spa_system_method_r(s,timerfd_settime,0,__VA_ARGS__) |
| 138 |
#define spa_system_timerfd_gettime(s,...) spa_system_method_r(s,timerfd_gettime,0,__VA_ARGS__) |
| 139 |
#define spa_system_timerfd_read(s,...) spa_system_method_r(s,timerfd_read,0,__VA_ARGS__) |
| 140 |
|
| 141 |
#define spa_system_eventfd_create(s,...) spa_system_method_r(s,eventfd_create,0,__VA_ARGS__) |
| 142 |
#define spa_system_eventfd_write(s,...) spa_system_method_r(s,eventfd_write,0,__VA_ARGS__) |
| 143 |
#define spa_system_eventfd_read(s,...) spa_system_method_r(s,eventfd_read,0,__VA_ARGS__) |
| 144 |
|
| 145 |
#define spa_system_signalfd_create(s,...) spa_system_method_r(s,signalfd_create,0,__VA_ARGS__) |
| 146 |
#define spa_system_signalfd_read(s,...) spa_system_method_r(s,signalfd_read,0,__VA_ARGS__) |
| 147 |
|
| 148 |
#ifdef __cplusplus |
| 149 |
} /* extern "C" */ |
| 150 |
#endif |
| 151 |
|
| 152 |
#endif /* SPA_SYSTEM_H */ |