1 | //roardl.h: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2014 |
---|
5 | * |
---|
6 | * This file is part of libroar a part of RoarAudio, |
---|
7 | * a cross-platform sound system for both, home and professional use. |
---|
8 | * See README for details. |
---|
9 | * |
---|
10 | * This file is free software; you can redistribute it and/or modify |
---|
11 | * it under the terms of the GNU General Public License version 3 |
---|
12 | * as published by the Free Software Foundation. |
---|
13 | * |
---|
14 | * libroar is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this software; see the file COPYING. If not, write to |
---|
21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | * NOTE for everyone want's to change something and send patches: |
---|
25 | * read README and HACKING! There a addition information on |
---|
26 | * the license of this document you need to read before you send |
---|
27 | * any patches. |
---|
28 | * |
---|
29 | * NOTE for uses of non-GPL (LGPL,...) software using libesd, libartsc |
---|
30 | * or libpulse*: |
---|
31 | * The libs libroaresd, libroararts and libroarpulse link this lib |
---|
32 | * and are therefore GPL. Because of this it may be illigal to use |
---|
33 | * them with any software that uses libesd, libartsc or libpulse*. |
---|
34 | */ |
---|
35 | |
---|
36 | #ifndef _LIBROARROARDL_H_ |
---|
37 | #define _LIBROARROARDL_H_ |
---|
38 | |
---|
39 | #include "libroar.h" |
---|
40 | |
---|
41 | #define ROAR_DL_FLAG_DEFAULTS -1 |
---|
42 | #define ROAR_DL_FLAG_PLUGIN -2 |
---|
43 | #define ROAR_DL_FLAG_NONE 0x0000 |
---|
44 | #define ROAR_DL_FLAG_STATIC 0x0001 /* plugins are linked statically -lfoo */ |
---|
45 | #define ROAR_DL_FLAG_LAZY 0x0002 |
---|
46 | #define ROAR_DL_FLAG_PLUGINPATH 0x0004 /* Use plugin search path */ |
---|
47 | |
---|
48 | #define ROAR_DL_HANDLE_DEFAULT ((struct roar_dl_lhandle*)(void*)0) |
---|
49 | #define ROAR_DL_HANDLE_NEXT ((struct roar_dl_lhandle*)(void*)1) |
---|
50 | #define ROAR_DL_HANDLE_LIBROAR ((struct roar_dl_lhandle*)(void*)2) |
---|
51 | #define ROAR_DL_HANDLE_APPLICATION ((struct roar_dl_lhandle*)(void*)3) |
---|
52 | #define ROAR_DL_HANDLE_LIB ((struct roar_dl_lhandle*)(void*)4) |
---|
53 | |
---|
54 | #define LIBROAR_DL_APPNAME "libroar " ROAR_VSTR_ROARAUDIO |
---|
55 | #define LIBROAR_DL_ABIVERSION "1.0beta9" |
---|
56 | |
---|
57 | #define ROAR_DL_FN_DSTR 0 /* VIO and DSTR drivers */ |
---|
58 | #define ROAR_DL_FN_CDRIVER 1 /* Client drivers, libroareio */ |
---|
59 | #define ROAR_DL_FN_TRANSCODER 2 /* Transcoder, libroardsp */ |
---|
60 | #define ROAR_DL_FN_DRIVER 3 /* Driver, roard? */ |
---|
61 | #define ROAR_DL_FN_SOURCE 4 /* Sources, roard? */ |
---|
62 | #define ROAR_DL_FN_FILTER 5 /* Filter, libroardsp, libroarlight */ |
---|
63 | #define ROAR_DL_FN_FF 6 /* file format??? */ |
---|
64 | #define ROAR_DL_FN_AUTH 7 /* Auth */ |
---|
65 | #define ROAR_DL_FN_BRIDGE 8 /* Bridges, roard? */ |
---|
66 | #define ROAR_DL_FN_ROARDSCHED 9 /* legacy, roard: Like appsched, but roard specific, old */ |
---|
67 | #define ROAR_DL_FN_APPSCHED 10 /* legacy: AppSched, old interface */ |
---|
68 | #define ROAR_DL_FN_PROTO 11 /* CPI, roard: Protocols */ |
---|
69 | #define ROAR_DL_FN_NOTIFY 12 /* ??? */ |
---|
70 | #define ROAR_DL_FN_INIT 13 /* global plugin instance init. should be avoided */ |
---|
71 | #define ROAR_DL_FN_REGFN 14 /* FN Registrations */ |
---|
72 | #define ROAR_DL_FN_APPLICATION 15 /* Application specific stuff */ |
---|
73 | #define ROAR_DL_FN_SERVICE 16 /* CSI: Services */ |
---|
74 | //#define ROAR_DL_FN_ 9 |
---|
75 | #define ROAR_DL_FN_MAX 24 |
---|
76 | |
---|
77 | #define ROAR_DL_LIBPARA_VERSION 1 |
---|
78 | #define ROAR_DL_LIBNAME_VERSION 0 |
---|
79 | #define ROAR_DL_LIBINST_VERSION 1 |
---|
80 | #define ROAR_DL_LIBDEP_VERSION 0 |
---|
81 | |
---|
82 | #define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst * \ |
---|
83 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para); \ |
---|
84 | struct roar_dl_libraryinst * \ |
---|
85 | _roaraudio_library_init(struct roar_dl_librarypara * para) { \ |
---|
86 | return _##lib##_roaraudio_library_init(para); \ |
---|
87 | } \ |
---|
88 | struct roar_dl_libraryinst * \ |
---|
89 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para) \ |
---|
90 | |
---|
91 | #define ROAR_DL_PLUGIN_START(xlib) ROAR_DL_PLUGIN(xlib) { \ |
---|
92 | static int _inited = 0; \ |
---|
93 | static struct roar_dl_libraryinst lib; \ |
---|
94 | static struct roar_dl_libraryname libname; \ |
---|
95 | (void)para; \ |
---|
96 | if ( _inited ) \ |
---|
97 | return &lib; \ |
---|
98 | if ( para != NULL && \ |
---|
99 | (para->version != ROAR_DL_LIBPARA_VERSION || \ |
---|
100 | para->len < sizeof(struct roar_dl_librarypara)) ) { \ |
---|
101 | /* we should set ROAR_ERROR_NSVERSION here but can not */ \ |
---|
102 | /* because that would require the plugin to be linked */ \ |
---|
103 | /* aginst libroar */ \ |
---|
104 | return NULL; \ |
---|
105 | } \ |
---|
106 | memset(&lib, 0, sizeof(lib)); \ |
---|
107 | lib.version = ROAR_DL_LIBINST_VERSION; \ |
---|
108 | lib.len = sizeof(lib); \ |
---|
109 | memset(&libname, 0, sizeof(libname)); \ |
---|
110 | libname.version = ROAR_DL_LIBNAME_VERSION; \ |
---|
111 | libname.len = sizeof(libname); \ |
---|
112 | libname.name = #xlib; \ |
---|
113 | lib.libname = &libname; \ |
---|
114 | do |
---|
115 | |
---|
116 | #define ROAR_DL_PLUGIN_END while(0); \ |
---|
117 | _inited = 1; \ |
---|
118 | return &lib; \ |
---|
119 | } |
---|
120 | |
---|
121 | // general stuff: |
---|
122 | #define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL |
---|
123 | #define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) (((lib.host_appname = (app)) != NULL) | \ |
---|
124 | ((lib.host_abiversion = (abi)) != NULL) ) |
---|
125 | // should we keep this macro at all? Is it helpfull at all? |
---|
126 | // if a plugin can handle multiple hosts it needs to call roar_dl_para_check_version() itself anyway. |
---|
127 | #define ROAR_DL_PLUGIN_CHECK_VERSIONS_NOW(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL |
---|
128 | |
---|
129 | // register stuff: |
---|
130 | #define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr)) |
---|
131 | #define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func)) |
---|
132 | #define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched)) |
---|
133 | #define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \ |
---|
134 | lib.global_data_init = &(init); \ |
---|
135 | lib.global_data_pointer = (void*)&(ptr) |
---|
136 | #define ROAR_DL_PLUGIN_REG_LIBDEP(deps) (((lib.libdep = (deps)) == NULL) ? \ |
---|
137 | (ssize_t)-1 : \ |
---|
138 | (ssize_t)(lib.libdep_len = sizeof((deps))/sizeof(struct roar_dl_librarydep))) |
---|
139 | |
---|
140 | // register objects using FN: |
---|
141 | #define ROAR_DL_PLUGIN_REG_FN(subtype,obj,version) roar_dl_register_fn(NULL, -1, (subtype), &(obj), sizeof((obj)), (version), ROAR_DL_FNREG_OPT_NONE) |
---|
142 | #define ROAR_DL_PLUGIN_REG_FNFUNC(fn) ROAR_DL_PLUGIN_REG((fn), _roaraudio_library_ ## fn) |
---|
143 | |
---|
144 | // Do a FN reg callback registration: |
---|
145 | #define ROAR_DL_RFNREG(lhandle,obj) roar_dl_register_fn((lhandle), ROAR_DL_FN_REGFN, ROAR_DL_FNREG_SUBTYPE, &(obj), sizeof((obj)), ROAR_DL_FNREG_VERSION, ROAR_DL_FNREG_OPT_NONE) |
---|
146 | |
---|
147 | // meta data stuff: |
---|
148 | #define ROAR_DL_PLUGIN_META_PRODUCT(x) (libname.libname = (x)) |
---|
149 | #define ROAR_DL_PLUGIN_META_PRODUCT_NV(name,vendor) ROAR_DL_PLUGIN_META_PRODUCT(name " <" vendor ">") |
---|
150 | #define ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor) ROAR_DL_PLUGIN_META_PRODUCT(name " <" #id "/" vendor ">") |
---|
151 | #define ROAR_DL_PLUGIN_META_PRODUCT_NIV(name,id,vendor) ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor) |
---|
152 | #define ROAR_DL_PLUGIN_META_VERSION(x) (libname.libversion = (x)) |
---|
153 | #define ROAR_DL_PLUGIN_META_ABI(x) (libname.abiversion = (x)) |
---|
154 | #define ROAR_DL_PLUGIN_META_DESC(x) (libname.description = (x)) |
---|
155 | #define ROAR_DL_PLUGIN_META_CONTACT(x) (libname.contact = (x)) |
---|
156 | #define ROAR_DL_PLUGIN_META_CONTACT_FL(first,last) ROAR_DL_PLUGIN_META_CONTACT(first " " last) |
---|
157 | #define ROAR_DL_PLUGIN_META_CONTACT_FLE(first,last,email) ROAR_DL_PLUGIN_META_CONTACT(first " " last " <" email ">") |
---|
158 | #define ROAR_DL_PLUGIN_META_CONTACT_FLNE(first,last,nick,email) ROAR_DL_PLUGIN_META_CONTACT(first " \"" nick "\" " last " <" email ">") |
---|
159 | #define ROAR_DL_PLUGIN_META_AUTHORS(x) (libname.authors = (x)) |
---|
160 | #define ROAR_DL_PLUGIN_META_LICENSE(x) (libname.license = (x)) |
---|
161 | #define ROAR_DL_PLUGIN_META_LICENSE_TAG(x) ROAR_DL_PLUGIN_META_LICENSE(ROAR_LICENSE_ ## x) |
---|
162 | |
---|
163 | enum roar_dl_loadercmd { |
---|
164 | ROAR_DL_LOADER_NOOP = 0, |
---|
165 | ROAR_DL_LOADER_PRELOAD, |
---|
166 | ROAR_DL_LOADER_LOAD, |
---|
167 | ROAR_DL_LOADER_POSTLOAD, |
---|
168 | ROAR_DL_LOADER_PREUNLOAD, |
---|
169 | ROAR_DL_LOADER_UNLOAD, |
---|
170 | ROAR_DL_LOADER_POSTUNLOAD |
---|
171 | }; |
---|
172 | |
---|
173 | struct roar_plugincontainer; |
---|
174 | |
---|
175 | struct roar_dl_librarypara { |
---|
176 | int version; // version of this struct type (must be ROAR_DL_LIBPARA_VERSION) |
---|
177 | size_t len; // Length of this struct type (must be sizeof(struct roar_dl_librarypara) |
---|
178 | |
---|
179 | size_t refc; // Reference counter. |
---|
180 | |
---|
181 | size_t argc; // number of elements in argv |
---|
182 | struct roar_keyval * argv; // Parameter for the plugin |
---|
183 | void * args_store; // Storage area for argv's data. |
---|
184 | // If not NULL this and argv will be freed. |
---|
185 | // If NULL argv will be left untouched. |
---|
186 | |
---|
187 | void * binargv; // A pointer with binary data arguments. |
---|
188 | // This can be used to pass any non-string data to |
---|
189 | // the plugin. Normally this is NULL or the pointer |
---|
190 | // to a struct with members of whatever is needed. |
---|
191 | |
---|
192 | const char * appname; // application name in common format: |
---|
193 | // Product/Version <VendorID/VendorName> (comments) |
---|
194 | // Version and comment are optional and should be avoided. |
---|
195 | // When no vendor ID is registered use <VendorName>. |
---|
196 | // The VendorName MUST NOT contain a slash and SHOULD |
---|
197 | // be as unique as possible. |
---|
198 | // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>, |
---|
199 | // AnAPP <Musterman GbR> |
---|
200 | const char * abiversion; // The ABI version. For libraries this should be the SONAME. |
---|
201 | // For applications this should be the version of the release |
---|
202 | // which introduced the current ABI. |
---|
203 | // Examples: libroar2, 0.5.1 |
---|
204 | struct roar_notify_core * notifycore; |
---|
205 | struct roar_plugincontainer * container; |
---|
206 | int (*loader)(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp); |
---|
207 | void * loader_userdata; |
---|
208 | }; |
---|
209 | |
---|
210 | struct roar_dl_libraryname { |
---|
211 | int version; |
---|
212 | size_t len; |
---|
213 | const char * name; //Format: shortname |
---|
214 | const char * libname; //This is the same as appname in struct roar_dl_librarypara. |
---|
215 | //Format: Product <VendorID/VendorName> (comments) |
---|
216 | const char * libversion; //This is the pure version number of the library. |
---|
217 | const char * abiversion; //This is the same as abiversion in struct roar_dl_librarypara. |
---|
218 | //Format: Version |
---|
219 | const char * description; //Free form. |
---|
220 | const char * contact; //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room |
---|
221 | const char * authors; //Other authors as free form. |
---|
222 | const char * license; //Format: LicenseName-Version (options) |
---|
223 | //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later). |
---|
224 | }; |
---|
225 | |
---|
226 | struct roar_dl_librarydep { |
---|
227 | int version; |
---|
228 | size_t len; |
---|
229 | uint32_t flags; |
---|
230 | const char * name; |
---|
231 | const char * libname; |
---|
232 | const char * abiversion; |
---|
233 | }; |
---|
234 | |
---|
235 | #define ROAR_DL_DEP(__flags,__name,__libname,__abiversion) \ |
---|
236 | {.version = ROAR_DL_LIBDEP_VERSION, \ |
---|
237 | .len = sizeof(struct roar_dl_librarydep), \ |
---|
238 | .flags = __flags, \ |
---|
239 | .name = __name, \ |
---|
240 | .libname = __libname, \ |
---|
241 | .abiversion = __abiversion} |
---|
242 | |
---|
243 | struct roar_dl_libraryinst { |
---|
244 | int version; |
---|
245 | size_t len; |
---|
246 | int (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
247 | int (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
248 | struct roar_dl_libraryname * libname; |
---|
249 | size_t global_data_len; |
---|
250 | void * global_data_init; |
---|
251 | void ** global_data_pointer; |
---|
252 | struct roar_dl_librarydep * libdep; |
---|
253 | size_t libdep_len; |
---|
254 | struct roar_dl_appsched * appsched; |
---|
255 | const char * host_appname; |
---|
256 | const char * host_abiversion; |
---|
257 | }; |
---|
258 | |
---|
259 | struct roar_dl_appsched { |
---|
260 | int (*init) (struct roar_dl_librarypara * para); |
---|
261 | int (*free) (struct roar_dl_librarypara * para); |
---|
262 | int (*update)(struct roar_dl_librarypara * para); |
---|
263 | int (*tick) (struct roar_dl_librarypara * para); |
---|
264 | int (*wait) (struct roar_dl_librarypara * para); |
---|
265 | }; |
---|
266 | |
---|
267 | enum roar_dl_appsched_trigger { |
---|
268 | ROAR_DL_APPSCHED_INIT = 1, |
---|
269 | #define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT |
---|
270 | ROAR_DL_APPSCHED_FREE, |
---|
271 | #define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE |
---|
272 | ROAR_DL_APPSCHED_UPDATE, |
---|
273 | #define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE |
---|
274 | ROAR_DL_APPSCHED_TICK, |
---|
275 | #define ROAR_DL_APPSCHED_TICK ROAR_DL_APPSCHED_TICK |
---|
276 | ROAR_DL_APPSCHED_WAIT, |
---|
277 | #define ROAR_DL_APPSCHED_WAIT ROAR_DL_APPSCHED_WAIT |
---|
278 | ROAR_DL_APPSCHED_ABOUT, |
---|
279 | #define ROAR_DL_APPSCHED_ABOUT ROAR_DL_APPSCHED_ABOUT |
---|
280 | ROAR_DL_APPSCHED_HELP, |
---|
281 | #define ROAR_DL_APPSCHED_HELP ROAR_DL_APPSCHED_HELP |
---|
282 | ROAR_DL_APPSCHED_PREFERENCES |
---|
283 | #define ROAR_DL_APPSCHED_PREFERENCES ROAR_DL_APPSCHED_PREFERENCES |
---|
284 | }; |
---|
285 | |
---|
286 | // parameter functions: |
---|
287 | struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, |
---|
288 | const char * appname, const char * abiversion); |
---|
289 | int roar_dl_para_ref (struct roar_dl_librarypara * para); |
---|
290 | int roar_dl_para_unref (struct roar_dl_librarypara * para); |
---|
291 | int roar_dl_para_check_version (struct roar_dl_librarypara * para, |
---|
292 | const char * appname, const char * abiversion); |
---|
293 | |
---|
294 | // 'core' dynamic loader functions. |
---|
295 | struct roar_dl_lhandle * roar_dl_open (const char * filename, int flags, |
---|
296 | int ra_init, struct roar_dl_librarypara * para); |
---|
297 | int roar_dl_ref (struct roar_dl_lhandle * lhandle); |
---|
298 | int roar_dl_unref (struct roar_dl_lhandle * lhandle); |
---|
299 | #define roar_dl_close(x) roar_dl_unref((x)) |
---|
300 | |
---|
301 | void * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type); |
---|
302 | |
---|
303 | int roar_dl_ra_init(struct roar_dl_lhandle * lhandle, |
---|
304 | const char * prefix, |
---|
305 | struct roar_dl_librarypara * para); |
---|
306 | |
---|
307 | const char * roar_dl_errstr (struct roar_dl_lhandle * lhandle); |
---|
308 | |
---|
309 | // getting meta data: |
---|
310 | struct roar_dl_librarypara * roar_dl_getpara(struct roar_dl_lhandle * lhandle); |
---|
311 | const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle); |
---|
312 | |
---|
313 | // context switching: |
---|
314 | // _restore() is to switch from main to library context. _store() is to store library context |
---|
315 | // and switch back to main context. |
---|
316 | int roar_dl_context_restore(struct roar_dl_lhandle * lhandle); |
---|
317 | int roar_dl_context_store(struct roar_dl_lhandle * lhandle); |
---|
318 | |
---|
319 | // appsched: |
---|
320 | int roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger); |
---|
321 | |
---|
322 | // FN Registration: |
---|
323 | |
---|
324 | // Actions objects can emit: |
---|
325 | enum roar_dl_fnreg_action { |
---|
326 | ROAR_DL_FNREG = 1, // The object is being registered |
---|
327 | ROAR_DL_FNUNREG = 2 // The object is being unregistered |
---|
328 | }; |
---|
329 | |
---|
330 | // Callback for registering/unregistering objects: |
---|
331 | struct roar_dl_fnreg { |
---|
332 | int fn; // Filter: The FN of the registering object or -1 for any. |
---|
333 | int subtype; // Filter: The subtype of the registering object or -1 for any. |
---|
334 | int version; // Filter: The version of the registering object or -1 for any. |
---|
335 | int (*callback)( // Callback to call on register/unregister. |
---|
336 | enum roar_dl_fnreg_action action, // The action happening |
---|
337 | int fn, // The FN of the object |
---|
338 | int subtype, // The subtype of the object |
---|
339 | const void * object, // Pointer to the object |
---|
340 | size_t objectlen, // Length of the object |
---|
341 | int version, // Version of the object |
---|
342 | int options, // Object Options. |
---|
343 | void * userdata, // User data for the callback. |
---|
344 | struct roar_dl_lhandle * lhandle // The registering handle. |
---|
345 | // This is valid until the object is unregistered. |
---|
346 | // Only roar_dl_context_restore(), roar_dl_context_store() |
---|
347 | // and roar_dl_getpara() may be used on this object. |
---|
348 | // Result of all other functions is undefined. |
---|
349 | ); |
---|
350 | void * userdata; // The user data pointer passed to the callback. |
---|
351 | }; |
---|
352 | |
---|
353 | // Parameters for FNREG registration: |
---|
354 | #define ROAR_DL_FNREG_SUBTYPE 0 |
---|
355 | #define ROAR_DL_FNREG_VERSION 0 |
---|
356 | #define ROAR_DL_FNREG_SIZE sizeof(struct roar_dl_fnreg) |
---|
357 | |
---|
358 | |
---|
359 | // Filter Infrastructure (FN_FILTER): |
---|
360 | // Parameters for FNREG registration: |
---|
361 | #define ROAR_DL_FILTER_SUBTYPE_DSP 0 /* libroardsp */ |
---|
362 | #define ROAR_DL_FILTER_SUBTYPE_SLFI 1 /* libroarlight */ |
---|
363 | // ROAR_DL_FILTER_{VERSION,SIZE}_* are defined in corresponding headers. |
---|
364 | |
---|
365 | |
---|
366 | // Common protocol interface (CPI): |
---|
367 | struct roar_dl_proto { |
---|
368 | const int proto; |
---|
369 | const char * description; |
---|
370 | const int flags; |
---|
371 | int (*set_proto)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
372 | int (*unset_proto)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
373 | int (*handle)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
374 | int (*flush)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
375 | int (*flushed)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
376 | int (*status)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara); |
---|
377 | }; |
---|
378 | |
---|
379 | #define ROAR_DL_PROTO_FLAGS_NONE 0 |
---|
380 | |
---|
381 | #define ROAR_DL_PROTO_STATUS_RX_READY 0x0001 |
---|
382 | #define ROAR_DL_PROTO_STATUS_TX_READY 0x0002 |
---|
383 | #define ROAR_DL_PROTO_STATUS_WAIT_NOTIFY 0x0004 |
---|
384 | |
---|
385 | // Parameters for FNREG registration: |
---|
386 | #define ROAR_DL_PROTO_SUBTYPE 1 /* 0 = roard */ |
---|
387 | #define ROAR_DL_PROTO_VERSION 0 |
---|
388 | #define ROAR_DL_PROTO_SIZE sizeof(struct roar_dl_proto) |
---|
389 | |
---|
390 | |
---|
391 | // Common Service Interface (CSI): |
---|
392 | struct roar_dl_service { |
---|
393 | // Name and ABI version of the application: |
---|
394 | // if appname is NULL this is a /universal/ service. |
---|
395 | // Such services MUST use APIs defined by the RoarAudio Project. |
---|
396 | // If a random Vendor needs a API universal to own applications |
---|
397 | // it should define a virtual application name for this. |
---|
398 | const char * appname; |
---|
399 | const char * appabi; |
---|
400 | // Name and ABI/API version of service: |
---|
401 | const char * servicename; |
---|
402 | const char * serviceabi; |
---|
403 | // Description: |
---|
404 | const char * description; |
---|
405 | // Flags (see below for defined flags): |
---|
406 | const int flags; |
---|
407 | // Userdata: |
---|
408 | // This is some kind of constant data. |
---|
409 | // It can bed used by the functions below for internal stuff. |
---|
410 | const void * userdata; |
---|
411 | // Functions: |
---|
412 | // get_api returns a pointer to a struct with the API. |
---|
413 | // The api is specific to [appname, appabi, servicename, serviceabi]. |
---|
414 | const void * (*get_api)(const struct roar_dl_service * service, struct roar_dl_librarypara * para); |
---|
415 | }; |
---|
416 | |
---|
417 | #define ROAR_DL_SERVICE_FLAGS_NONE 0x0000 |
---|
418 | |
---|
419 | #define ROAR_DL_SERVICE_SUBTYPE 0 |
---|
420 | #define ROAR_DL_SERVICE_VERSION 0 |
---|
421 | #define ROAR_DL_SERVICE_SIZE sizeof(struct roar_dl_service) |
---|
422 | |
---|
423 | #define ROAR_DL_PLUGIN_REG_SERVICES(obj) \ |
---|
424 | static int _roaraudio_library_ROAR_DL_FN_SERVICE(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib) { \ |
---|
425 | size_t i; \ |
---|
426 | (void)para, (void)lib; \ |
---|
427 | for (i = 0; i < (sizeof((obj))/sizeof(*(obj))); i++) { \ |
---|
428 | ROAR_DL_PLUGIN_REG_FN(ROAR_DL_SERVICE_SUBTYPE, (obj)[i], ROAR_DL_SERVICE_VERSION); \ |
---|
429 | } \ |
---|
430 | return 0; \ |
---|
431 | } |
---|
432 | #define ROAR_DL_PLUGIN_REG_SERVICES_GET_API(name,obj) \ |
---|
433 | static const void * name(const struct roar_dl_service * service, struct roar_dl_librarypara * para) { \ |
---|
434 | (void)service, (void)para; \ |
---|
435 | return &(obj); \ |
---|
436 | } |
---|
437 | |
---|
438 | struct roar_dl_service_api { |
---|
439 | const void * api; |
---|
440 | struct roar_dl_lhandle * lhandle; |
---|
441 | const struct roar_dl_service * service; |
---|
442 | }; |
---|
443 | |
---|
444 | #define libroar_dl_service_apitype(type) \ |
---|
445 | union { \ |
---|
446 | struct roar_dl_service_api apiinterface; \ |
---|
447 | const struct type * api; \ |
---|
448 | } |
---|
449 | |
---|
450 | int libroar_dl_service_get_api_real(struct roar_dl_librarypara * para, const char * appname, const char * appabi, const char * servicename, const char * serviceabi, int universal, struct roar_dl_service_api * api, int retry); |
---|
451 | #define libroar_dl_service_get_api(para,appname,appabi,servicename,serviceabi,universal,api) libroar_dl_service_get_api_real((para),(appname),(appabi),(servicename),(serviceabi),(universal),(struct roar_dl_service_api *)(api), 1) |
---|
452 | #define roar_dl_service_get_api(para,servicename,serviceabi,api) libroar_dl_service_get_api((para), (para) == NULL ? NULL : ((struct roar_dl_librarypara *)(para))->appname, (para) == NULL ? NULL : ((struct roar_dl_librarypara *)(para))->abiversion, (servicename), (serviceabi), 1, (api)) |
---|
453 | |
---|
454 | int libroar_dl_service_free_api_real(struct roar_dl_service_api * api); |
---|
455 | #define libroar_dl_service_free_api(api) libroar_dl_service_free_api_real((struct roar_dl_service_api *)&(api)) |
---|
456 | |
---|
457 | #define libroar_dl_service_run_func(obj,name,type,...) ((type[3]){(type)roar_dl_context_restore((obj).apiinterface.lhandle), ((obj).api->name(__VA_ARGS__)), (type)roar_dl_context_store((obj).apiinterface.lhandle)})[1] |
---|
458 | #define libroar_dl_service_run_func_void(obj,name,...) do { roar_dl_context_restore((obj).apiinterface.lhandle); (obj).api->name(__VA_ARGS__); roar_dl_context_store((obj).apiinterface.lhandle); } while (0) |
---|
459 | #define libroar_dl_service_check_func(obj,name) ((obj).api->name != NULL) |
---|
460 | |
---|
461 | // Reg FN: |
---|
462 | |
---|
463 | // Options: |
---|
464 | #define ROAR_DL_FNREG_OPT_NONE 0 /* no options */ |
---|
465 | |
---|
466 | // Register an FN. |
---|
467 | int roar_dl_register_fn(struct roar_dl_lhandle * lhandle, int fn, int subtype, const void * object, size_t objectlen, int version, int options); |
---|
468 | |
---|
469 | // Unregister an FN. |
---|
470 | int roar_dl_unregister_fn2(struct roar_dl_lhandle * lhandle, int fn, int subtype, const void * object, size_t objectlen, int version, int options); |
---|
471 | |
---|
472 | // Unregister FN for the given plugin. |
---|
473 | // This should not be called directly and is called internally when needed. |
---|
474 | int roar_dl_unregister_fn(struct roar_dl_lhandle * lhandle); |
---|
475 | |
---|
476 | // asking for a object: |
---|
477 | int roar_dl_query_fn(struct roar_dl_lhandle ** lhandle, int fn, int subtype, const void ** object, size_t * objectlen, int version, int * options, ssize_t index); |
---|
478 | |
---|
479 | #endif |
---|
480 | |
---|
481 | //ll |
---|