[3297] | 1 | //roardl.h: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5381] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012 |
---|
[3297] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[3297] | 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 | |
---|
[5317] | 41 | #define ROAR_DL_FLAG_DEFAULTS -1 |
---|
| 42 | #define ROAR_DL_FLAG_NONE 0x0000 |
---|
| 43 | #define ROAR_DL_FLAG_STATIC 0x0001 /* plugins are linked statically -lfoo */ |
---|
[5344] | 44 | #define ROAR_DL_FLAG_LAZY 0x0002 |
---|
[3303] | 45 | |
---|
[3297] | 46 | #define ROAR_DL_HANDLE_DEFAULT ((struct roar_dl_lhandle*)(void*)0) |
---|
| 47 | #define ROAR_DL_HANDLE_NEXT ((struct roar_dl_lhandle*)(void*)1) |
---|
| 48 | |
---|
[3299] | 49 | #define ROAR_DL_FN_DSTR 0 |
---|
| 50 | #define ROAR_DL_FN_CDRIVER 1 |
---|
| 51 | #define ROAR_DL_FN_TRANSCODER 2 |
---|
| 52 | #define ROAR_DL_FN_DRIVER 3 |
---|
| 53 | #define ROAR_DL_FN_SOURCE 4 |
---|
| 54 | #define ROAR_DL_FN_FILTER 5 |
---|
| 55 | #define ROAR_DL_FN_FF 6 /* file format */ |
---|
| 56 | #define ROAR_DL_FN_AUTH 7 |
---|
| 57 | #define ROAR_DL_FN_BRIDGE 8 |
---|
| 58 | #define ROAR_DL_FN_ROARDSCHED 9 |
---|
| 59 | #define ROAR_DL_FN_APPSCHED 10 |
---|
[3360] | 60 | #define ROAR_DL_FN_PROTO 11 |
---|
[5313] | 61 | #define ROAR_DL_FN_NOTIFY 12 |
---|
[5317] | 62 | #define ROAR_DL_FN_INIT 13 /* global plugin instance init. should be avoided */ |
---|
[3299] | 63 | //#define ROAR_DL_FN_ 9 |
---|
[5275] | 64 | #define ROAR_DL_FN_MAX 24 |
---|
[3300] | 65 | |
---|
[5275] | 66 | #define ROAR_DL_LIBPARA_VERSION 1 |
---|
| 67 | #define ROAR_DL_LIBNAME_VERSION 0 |
---|
| 68 | #define ROAR_DL_LIBINST_VERSION 1 |
---|
[5347] | 69 | #define ROAR_DL_LIBDEP_VERSION 0 |
---|
[3300] | 70 | |
---|
| 71 | #define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst * \ |
---|
[3306] | 72 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para); \ |
---|
| 73 | struct roar_dl_libraryinst * \ |
---|
[3300] | 74 | _roaraudio_library_init(struct roar_dl_librarypara * para) { \ |
---|
| 75 | return _##lib##_roaraudio_library_init(para); \ |
---|
| 76 | } \ |
---|
| 77 | struct roar_dl_libraryinst * \ |
---|
| 78 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para) \ |
---|
[3299] | 79 | |
---|
[3308] | 80 | #define ROAR_DL_PLUGIN_START(xlib) ROAR_DL_PLUGIN(xlib) { \ |
---|
| 81 | static int _inited = 0; \ |
---|
| 82 | static struct roar_dl_libraryinst lib; \ |
---|
[5275] | 83 | static struct roar_dl_libraryname libname; \ |
---|
[4681] | 84 | (void)para; \ |
---|
[3308] | 85 | if ( _inited ) \ |
---|
| 86 | return &lib; \ |
---|
| 87 | memset(&lib, 0, sizeof(lib)); \ |
---|
| 88 | lib.version = ROAR_DL_LIBINST_VERSION; \ |
---|
| 89 | lib.len = sizeof(lib); \ |
---|
[5275] | 90 | memset(&libname, 0, sizeof(libname)); \ |
---|
| 91 | libname.version = ROAR_DL_LIBNAME_VERSION; \ |
---|
| 92 | libname.len = sizeof(libname); \ |
---|
| 93 | libname.name = #xlib; \ |
---|
| 94 | lib.libname = &libname; \ |
---|
[3308] | 95 | do |
---|
| 96 | |
---|
| 97 | #define ROAR_DL_PLUGIN_END while(0); \ |
---|
| 98 | _inited = 1; \ |
---|
| 99 | return &lib; \ |
---|
| 100 | } |
---|
| 101 | |
---|
[5335] | 102 | // general stuff: |
---|
[5275] | 103 | #define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL |
---|
[5353] | 104 | #define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) ((lib.host_appname = (app)) != NULL || \ |
---|
| 105 | (lib.host_abiversion = (abi)) != NULL ) |
---|
| 106 | // should we keep this macro at all? Is it helpfull at all? |
---|
| 107 | // if a plugin can handle multiple hosts it needs to call roar_dl_para_check_version() itself anyway. |
---|
| 108 | #define ROAR_DL_PLUGIN_CHECK_VERSIONS_NOW(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL |
---|
[5335] | 109 | |
---|
| 110 | // register stuff: |
---|
[3363] | 111 | #define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr)) |
---|
[3360] | 112 | #define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func)) |
---|
[5317] | 113 | #define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched)) |
---|
[5313] | 114 | #define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \ |
---|
| 115 | lib.global_data_init = &(init); \ |
---|
| 116 | lib.global_data_pointer = (void*)&(ptr) |
---|
[5353] | 117 | #define ROAR_DL_PLUGIN_REG_LIBDEP(deps) (((lib.libdep = (deps)) == NULL) ? \ |
---|
[5347] | 118 | (ssize_t)-1 : \ |
---|
[5353] | 119 | (ssize_t)(lib.libdep_len = sizeof((deps))/sizeof(struct roar_dl_librarydep))) |
---|
[3314] | 120 | |
---|
[5335] | 121 | // meta data stuff: |
---|
| 122 | #define ROAR_DL_PLUGIN_META_PRODUCT(x) (libname.libname = (x)) |
---|
| 123 | #define ROAR_DL_PLUGIN_META_PRODUCT_NV(name,vendor) ROAR_DL_PLUGIN_META_PRODUCT(name " <" vendor ">") |
---|
[5338] | 124 | #define ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor) ROAR_DL_PLUGIN_META_PRODUCT(name " <" #id "/" vendor ">") |
---|
| 125 | #define ROAR_DL_PLUGIN_META_PRODUCT_NIV(name,id,vendor) ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor) |
---|
[5335] | 126 | #define ROAR_DL_PLUGIN_META_VERSION(x) (libname.libversion = (x)) |
---|
| 127 | #define ROAR_DL_PLUGIN_META_ABI(x) (libname.abiversion = (x)) |
---|
| 128 | #define ROAR_DL_PLUGIN_META_DESC(x) (libname.description = (x)) |
---|
| 129 | #define ROAR_DL_PLUGIN_META_CONTACT(x) (libname.contact = (x)) |
---|
| 130 | #define ROAR_DL_PLUGIN_META_CONTACT_FL(first,last) ROAR_DL_PLUGIN_META_CONTACT(first " " last) |
---|
| 131 | #define ROAR_DL_PLUGIN_META_CONTACT_FLE(first,last,email) ROAR_DL_PLUGIN_META_CONTACT(first " " last " <" email ">") |
---|
| 132 | #define ROAR_DL_PLUGIN_META_CONTACT_FLNE(first,last,nick,email) ROAR_DL_PLUGIN_META_CONTACT(first " \"" nick "\" " last " <" email ">") |
---|
| 133 | #define ROAR_DL_PLUGIN_META_AUTHORS(x) (libname.authors = (x)) |
---|
| 134 | #define ROAR_DL_PLUGIN_META_LICENSE(x) (libname.license = (x)) |
---|
| 135 | #define ROAR_DL_PLUGIN_META_LICENSE_TAG(x) ROAR_DL_PLUGIN_META_LICENSE(ROAR_LICENSE_ ## x) |
---|
| 136 | |
---|
[5322] | 137 | enum roar_dl_loadercmd { |
---|
[5327] | 138 | ROAR_DL_LOADER_NOOP = 0, |
---|
| 139 | ROAR_DL_LOADER_PRELOAD, |
---|
| 140 | ROAR_DL_LOADER_LOAD, |
---|
| 141 | ROAR_DL_LOADER_POSTLOAD, |
---|
| 142 | ROAR_DL_LOADER_PREUNLOAD, |
---|
| 143 | ROAR_DL_LOADER_UNLOAD, |
---|
| 144 | ROAR_DL_LOADER_POSTUNLOAD |
---|
[5322] | 145 | }; |
---|
| 146 | |
---|
[5335] | 147 | struct roar_plugincontainer; |
---|
| 148 | |
---|
[3297] | 149 | struct roar_dl_librarypara { |
---|
[5275] | 150 | int version; // version of this struct type (must be ROAR_DL_LIBPARA_VERSION) |
---|
| 151 | size_t len; // Length of this struct type (must be sizeof(struct roar_dl_librarypara) |
---|
| 152 | |
---|
| 153 | size_t refc; // Reference counter. |
---|
| 154 | |
---|
| 155 | size_t argc; // number of elements in argv |
---|
| 156 | struct roar_keyval * argv; // Parameter for the plugin |
---|
| 157 | void * args_store; // Storage area for argv's data. |
---|
| 158 | // If not NULL this and argv will be freed. |
---|
| 159 | // If NULL argv will be left untouched. |
---|
| 160 | |
---|
| 161 | void * binargv; // A pointer with binary data arguments. |
---|
| 162 | // This can be used to pass any non-string data to |
---|
| 163 | // the plugin. Normally this is NULL or the pointer |
---|
| 164 | // to a struct with members of whatever is needed. |
---|
| 165 | |
---|
| 166 | const char * appname; // application name in common format: |
---|
| 167 | // Product/Version <VendorID/VendorName> (comments) |
---|
| 168 | // Version and comment are optional and should be avoided. |
---|
| 169 | // When no vendor ID is registered use <VendorName>. |
---|
| 170 | // The VendorName MUST NOT contain a slash and SHOULD |
---|
| 171 | // be as unique as possible. |
---|
| 172 | // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>, |
---|
| 173 | // AnAPP <Musterman GbR> |
---|
| 174 | const char * abiversion; // The ABI version. For libraries this should be the SONAME. |
---|
| 175 | // For applications this should be the version of the release |
---|
| 176 | // which introduced the current ABI. |
---|
| 177 | // Examples: libroar2, 0.5.1 |
---|
[5317] | 178 | struct roar_notify_core * notifycore; |
---|
[5335] | 179 | struct roar_plugincontainer * container; |
---|
| 180 | int (*loader)(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp); |
---|
| 181 | void * loader_userdata; |
---|
[5275] | 182 | }; |
---|
| 183 | |
---|
| 184 | struct roar_dl_libraryname { |
---|
| 185 | int version; |
---|
| 186 | size_t len; |
---|
| 187 | const char * name; //Format: shortname |
---|
[5317] | 188 | const char * libname; //This is the same as appname in struct roar_dl_librarypara. |
---|
| 189 | //Format: Product <VendorID/VendorName> (comments) |
---|
| 190 | const char * libversion; //This is the pure version number of the library. |
---|
| 191 | const char * abiversion; //This is the same as abiversion in struct roar_dl_librarypara. |
---|
| 192 | //Format: Version |
---|
[5275] | 193 | const char * description; //Free form. |
---|
| 194 | const char * contact; //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room |
---|
| 195 | const char * authors; //Other authors as free form. |
---|
| 196 | const char * license; //Format: LicenseName-Version (options) |
---|
| 197 | //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later). |
---|
[3297] | 198 | }; |
---|
| 199 | |
---|
[5317] | 200 | struct roar_dl_librarydep { |
---|
| 201 | int version; |
---|
| 202 | size_t len; |
---|
[5335] | 203 | uint32_t flags; |
---|
[5317] | 204 | const char * name; |
---|
| 205 | const char * libname; |
---|
| 206 | const char * abiversion; |
---|
| 207 | }; |
---|
| 208 | |
---|
[5347] | 209 | #define ROAR_DL_DEP(__flags,__name,__libname,__abiversion) \ |
---|
| 210 | {.version = ROAR_DL_LIBDEP_VERSION, \ |
---|
| 211 | .len = sizeof(struct roar_dl_librarydep), \ |
---|
| 212 | .flags = __flags, \ |
---|
| 213 | .name = __name, \ |
---|
| 214 | .libname = __libname, \ |
---|
| 215 | .abiversion = __abiversion} |
---|
| 216 | |
---|
[3297] | 217 | struct roar_dl_libraryinst { |
---|
[3299] | 218 | int version; |
---|
| 219 | size_t len; |
---|
[3301] | 220 | int (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
[3299] | 221 | int (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
[5275] | 222 | struct roar_dl_libraryname * libname; |
---|
[5312] | 223 | size_t global_data_len; |
---|
| 224 | void * global_data_init; |
---|
| 225 | void ** global_data_pointer; |
---|
[5317] | 226 | struct roar_dl_librarydep * libdep; |
---|
| 227 | size_t libdep_len; |
---|
| 228 | struct roar_dl_appsched * appsched; |
---|
[5353] | 229 | const char * host_appname; |
---|
| 230 | const char * host_abiversion; |
---|
[3297] | 231 | }; |
---|
| 232 | |
---|
[5313] | 233 | struct roar_dl_appsched { |
---|
[5317] | 234 | int (*init) (struct roar_dl_librarypara * para); |
---|
| 235 | int (*free) (struct roar_dl_librarypara * para); |
---|
| 236 | int (*update)(struct roar_dl_librarypara * para); |
---|
[5335] | 237 | int (*tick) (struct roar_dl_librarypara * para); |
---|
| 238 | int (*wait) (struct roar_dl_librarypara * para); |
---|
[5317] | 239 | }; |
---|
| 240 | |
---|
| 241 | enum roar_dl_appsched_trigger { |
---|
| 242 | ROAR_DL_APPSCHED_INIT = 1, |
---|
| 243 | #define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT |
---|
| 244 | ROAR_DL_APPSCHED_FREE, |
---|
| 245 | #define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE |
---|
[5335] | 246 | ROAR_DL_APPSCHED_UPDATE, |
---|
[5317] | 247 | #define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE |
---|
[5335] | 248 | ROAR_DL_APPSCHED_TICK, |
---|
| 249 | #define ROAR_DL_APPSCHED_TICK ROAR_DL_APPSCHED_TICK |
---|
| 250 | ROAR_DL_APPSCHED_WAIT |
---|
| 251 | #define ROAR_DL_APPSCHED_WAIT ROAR_DL_APPSCHED_WAIT |
---|
[5313] | 252 | }; |
---|
| 253 | |
---|
[5312] | 254 | // parameter functions: |
---|
[5275] | 255 | struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, |
---|
| 256 | const char * appname, const char * abiversion); |
---|
| 257 | int roar_dl_para_ref (struct roar_dl_librarypara * para); |
---|
| 258 | int roar_dl_para_unref (struct roar_dl_librarypara * para); |
---|
| 259 | int roar_dl_para_check_version (struct roar_dl_librarypara * para, |
---|
| 260 | const char * appname, const char * abiversion); |
---|
| 261 | |
---|
[5312] | 262 | // 'core' dynamic loader functions. |
---|
[5275] | 263 | struct roar_dl_lhandle * roar_dl_open (const char * filename, int flags, |
---|
| 264 | int ra_init, struct roar_dl_librarypara * para); |
---|
[5321] | 265 | int roar_dl_ref (struct roar_dl_lhandle * lhandle); |
---|
| 266 | int roar_dl_unref (struct roar_dl_lhandle * lhandle); |
---|
| 267 | #define roar_dl_close(x) roar_dl_unref((x)) |
---|
[3301] | 268 | |
---|
[5275] | 269 | void * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type); |
---|
[3297] | 270 | |
---|
[5275] | 271 | int roar_dl_ra_init(struct roar_dl_lhandle * lhandle, |
---|
| 272 | const char * prefix, |
---|
| 273 | struct roar_dl_librarypara * para); |
---|
[3297] | 274 | |
---|
[5275] | 275 | const char * roar_dl_errstr (struct roar_dl_lhandle * lhandle); |
---|
[3297] | 276 | |
---|
[5312] | 277 | // getting meta data: |
---|
[5275] | 278 | struct roar_dl_librarypara * roar_dl_getpara(struct roar_dl_lhandle * lhandle); |
---|
| 279 | const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle); |
---|
[3364] | 280 | |
---|
[5312] | 281 | // context switching: |
---|
| 282 | // _restore() is to switch from main to library context. _store() is to store library context |
---|
| 283 | // and switch back to main context. |
---|
| 284 | int roar_dl_context_restore(struct roar_dl_lhandle * lhandle); |
---|
| 285 | int roar_dl_context_store(struct roar_dl_lhandle * lhandle); |
---|
| 286 | |
---|
[5317] | 287 | // appsched: |
---|
| 288 | int roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger); |
---|
| 289 | |
---|
[3297] | 290 | #endif |
---|
| 291 | |
---|
| 292 | //ll |
---|