[3297] | 1 | //roardl.h: |
---|
| 2 | |
---|
| 3 | /* |
---|
[4708] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2011 |
---|
[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 */ |
---|
[3303] | 44 | |
---|
[3297] | 45 | #define ROAR_DL_HANDLE_DEFAULT ((struct roar_dl_lhandle*)(void*)0) |
---|
| 46 | #define ROAR_DL_HANDLE_NEXT ((struct roar_dl_lhandle*)(void*)1) |
---|
| 47 | |
---|
[3299] | 48 | #define ROAR_DL_FN_DSTR 0 |
---|
| 49 | #define ROAR_DL_FN_CDRIVER 1 |
---|
| 50 | #define ROAR_DL_FN_TRANSCODER 2 |
---|
| 51 | #define ROAR_DL_FN_DRIVER 3 |
---|
| 52 | #define ROAR_DL_FN_SOURCE 4 |
---|
| 53 | #define ROAR_DL_FN_FILTER 5 |
---|
| 54 | #define ROAR_DL_FN_FF 6 /* file format */ |
---|
| 55 | #define ROAR_DL_FN_AUTH 7 |
---|
| 56 | #define ROAR_DL_FN_BRIDGE 8 |
---|
| 57 | #define ROAR_DL_FN_ROARDSCHED 9 |
---|
| 58 | #define ROAR_DL_FN_APPSCHED 10 |
---|
[3360] | 59 | #define ROAR_DL_FN_PROTO 11 |
---|
[5313] | 60 | #define ROAR_DL_FN_NOTIFY 12 |
---|
[5317] | 61 | #define ROAR_DL_FN_INIT 13 /* global plugin instance init. should be avoided */ |
---|
[3299] | 62 | //#define ROAR_DL_FN_ 9 |
---|
[5275] | 63 | #define ROAR_DL_FN_MAX 24 |
---|
[3300] | 64 | |
---|
[5275] | 65 | #define ROAR_DL_LIBPARA_VERSION 1 |
---|
| 66 | #define ROAR_DL_LIBNAME_VERSION 0 |
---|
| 67 | #define ROAR_DL_LIBINST_VERSION 1 |
---|
[3300] | 68 | |
---|
| 69 | #define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst * \ |
---|
[3306] | 70 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para); \ |
---|
| 71 | struct roar_dl_libraryinst * \ |
---|
[3300] | 72 | _roaraudio_library_init(struct roar_dl_librarypara * para) { \ |
---|
| 73 | return _##lib##_roaraudio_library_init(para); \ |
---|
| 74 | } \ |
---|
| 75 | struct roar_dl_libraryinst * \ |
---|
| 76 | _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para) \ |
---|
[3299] | 77 | |
---|
[3308] | 78 | #define ROAR_DL_PLUGIN_START(xlib) ROAR_DL_PLUGIN(xlib) { \ |
---|
| 79 | static int _inited = 0; \ |
---|
| 80 | static struct roar_dl_libraryinst lib; \ |
---|
[5275] | 81 | static struct roar_dl_libraryname libname; \ |
---|
[4681] | 82 | (void)para; \ |
---|
[3308] | 83 | if ( _inited ) \ |
---|
| 84 | return &lib; \ |
---|
| 85 | memset(&lib, 0, sizeof(lib)); \ |
---|
| 86 | lib.version = ROAR_DL_LIBINST_VERSION; \ |
---|
| 87 | lib.len = sizeof(lib); \ |
---|
[5275] | 88 | memset(&libname, 0, sizeof(libname)); \ |
---|
| 89 | libname.version = ROAR_DL_LIBNAME_VERSION; \ |
---|
| 90 | libname.len = sizeof(libname); \ |
---|
| 91 | libname.name = #xlib; \ |
---|
| 92 | lib.libname = &libname; \ |
---|
[3308] | 93 | do |
---|
| 94 | |
---|
| 95 | #define ROAR_DL_PLUGIN_END while(0); \ |
---|
| 96 | _inited = 1; \ |
---|
| 97 | return &lib; \ |
---|
| 98 | } |
---|
| 99 | |
---|
[5275] | 100 | #define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL |
---|
| 101 | #define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL |
---|
[3363] | 102 | #define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr)) |
---|
[3360] | 103 | #define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func)) |
---|
[5317] | 104 | #define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched)) |
---|
[5313] | 105 | #define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \ |
---|
| 106 | lib.global_data_init = &(init); \ |
---|
| 107 | lib.global_data_pointer = (void*)&(ptr) |
---|
[3314] | 108 | |
---|
[5322] | 109 | enum roar_dl_loadercmd { |
---|
| 110 | ROAR_DL_LOADER_NOOP = 0 |
---|
| 111 | }; |
---|
| 112 | |
---|
[3297] | 113 | struct roar_dl_librarypara { |
---|
[5275] | 114 | int version; // version of this struct type (must be ROAR_DL_LIBPARA_VERSION) |
---|
| 115 | size_t len; // Length of this struct type (must be sizeof(struct roar_dl_librarypara) |
---|
| 116 | |
---|
| 117 | size_t refc; // Reference counter. |
---|
| 118 | |
---|
| 119 | size_t argc; // number of elements in argv |
---|
| 120 | struct roar_keyval * argv; // Parameter for the plugin |
---|
| 121 | void * args_store; // Storage area for argv's data. |
---|
| 122 | // If not NULL this and argv will be freed. |
---|
| 123 | // If NULL argv will be left untouched. |
---|
| 124 | |
---|
| 125 | void * binargv; // A pointer with binary data arguments. |
---|
| 126 | // This can be used to pass any non-string data to |
---|
| 127 | // the plugin. Normally this is NULL or the pointer |
---|
| 128 | // to a struct with members of whatever is needed. |
---|
| 129 | |
---|
| 130 | const char * appname; // application name in common format: |
---|
| 131 | // Product/Version <VendorID/VendorName> (comments) |
---|
| 132 | // Version and comment are optional and should be avoided. |
---|
| 133 | // When no vendor ID is registered use <VendorName>. |
---|
| 134 | // The VendorName MUST NOT contain a slash and SHOULD |
---|
| 135 | // be as unique as possible. |
---|
| 136 | // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>, |
---|
| 137 | // AnAPP <Musterman GbR> |
---|
| 138 | const char * abiversion; // The ABI version. For libraries this should be the SONAME. |
---|
| 139 | // For applications this should be the version of the release |
---|
| 140 | // which introduced the current ABI. |
---|
| 141 | // Examples: libroar2, 0.5.1 |
---|
[5317] | 142 | struct roar_notify_core * notifycore; |
---|
[5322] | 143 | int (*loader)(struct roar_dl_librarypara * lhandle, enum roar_dl_loadercmd cmd, void * argp); |
---|
[5275] | 144 | }; |
---|
| 145 | |
---|
| 146 | struct roar_dl_libraryname { |
---|
| 147 | int version; |
---|
| 148 | size_t len; |
---|
| 149 | const char * name; //Format: shortname |
---|
[5317] | 150 | const char * libname; //This is the same as appname in struct roar_dl_librarypara. |
---|
| 151 | //Format: Product <VendorID/VendorName> (comments) |
---|
| 152 | const char * libversion; //This is the pure version number of the library. |
---|
| 153 | const char * abiversion; //This is the same as abiversion in struct roar_dl_librarypara. |
---|
| 154 | //Format: Version |
---|
[5275] | 155 | const char * description; //Free form. |
---|
| 156 | const char * contact; //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room |
---|
| 157 | const char * authors; //Other authors as free form. |
---|
| 158 | const char * license; //Format: LicenseName-Version (options) |
---|
| 159 | //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later). |
---|
[3297] | 160 | }; |
---|
| 161 | |
---|
[5317] | 162 | struct roar_dl_librarydep { |
---|
| 163 | int version; |
---|
| 164 | size_t len; |
---|
| 165 | const char * name; |
---|
| 166 | const char * libname; |
---|
| 167 | const char * abiversion; |
---|
| 168 | }; |
---|
| 169 | |
---|
[3297] | 170 | struct roar_dl_libraryinst { |
---|
[3299] | 171 | int version; |
---|
| 172 | size_t len; |
---|
[3301] | 173 | int (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
[3299] | 174 | int (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib); |
---|
[5275] | 175 | struct roar_dl_libraryname * libname; |
---|
[5312] | 176 | size_t global_data_len; |
---|
| 177 | void * global_data_init; |
---|
| 178 | void ** global_data_pointer; |
---|
[5317] | 179 | struct roar_dl_librarydep * libdep; |
---|
| 180 | size_t libdep_len; |
---|
| 181 | struct roar_dl_appsched * appsched; |
---|
[3297] | 182 | }; |
---|
| 183 | |
---|
[5313] | 184 | struct roar_dl_appsched { |
---|
[5317] | 185 | int (*init) (struct roar_dl_librarypara * para); |
---|
| 186 | int (*free) (struct roar_dl_librarypara * para); |
---|
| 187 | int (*update)(struct roar_dl_librarypara * para); |
---|
| 188 | }; |
---|
| 189 | |
---|
| 190 | enum roar_dl_appsched_trigger { |
---|
| 191 | ROAR_DL_APPSCHED_INIT = 1, |
---|
| 192 | #define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT |
---|
| 193 | ROAR_DL_APPSCHED_FREE, |
---|
| 194 | #define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE |
---|
| 195 | ROAR_DL_APPSCHED_UPDATE |
---|
| 196 | #define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE |
---|
[5313] | 197 | }; |
---|
| 198 | |
---|
[5312] | 199 | // parameter functions: |
---|
[5275] | 200 | struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv, |
---|
| 201 | const char * appname, const char * abiversion); |
---|
| 202 | int roar_dl_para_ref (struct roar_dl_librarypara * para); |
---|
| 203 | int roar_dl_para_unref (struct roar_dl_librarypara * para); |
---|
| 204 | int roar_dl_para_check_version (struct roar_dl_librarypara * para, |
---|
| 205 | const char * appname, const char * abiversion); |
---|
| 206 | |
---|
[5312] | 207 | // 'core' dynamic loader functions. |
---|
[5275] | 208 | struct roar_dl_lhandle * roar_dl_open (const char * filename, int flags, |
---|
| 209 | int ra_init, struct roar_dl_librarypara * para); |
---|
[5321] | 210 | int roar_dl_ref (struct roar_dl_lhandle * lhandle); |
---|
| 211 | int roar_dl_unref (struct roar_dl_lhandle * lhandle); |
---|
| 212 | #define roar_dl_close(x) roar_dl_unref((x)) |
---|
[3301] | 213 | |
---|
[5275] | 214 | void * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type); |
---|
[3297] | 215 | |
---|
[5275] | 216 | int roar_dl_ra_init(struct roar_dl_lhandle * lhandle, |
---|
| 217 | const char * prefix, |
---|
| 218 | struct roar_dl_librarypara * para); |
---|
[3297] | 219 | |
---|
[5275] | 220 | const char * roar_dl_errstr (struct roar_dl_lhandle * lhandle); |
---|
[3297] | 221 | |
---|
[5312] | 222 | // getting meta data: |
---|
[5275] | 223 | struct roar_dl_librarypara * roar_dl_getpara(struct roar_dl_lhandle * lhandle); |
---|
| 224 | const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle); |
---|
[3364] | 225 | |
---|
[5312] | 226 | // context switching: |
---|
| 227 | // _restore() is to switch from main to library context. _store() is to store library context |
---|
| 228 | // and switch back to main context. |
---|
| 229 | int roar_dl_context_restore(struct roar_dl_lhandle * lhandle); |
---|
| 230 | int roar_dl_context_store(struct roar_dl_lhandle * lhandle); |
---|
| 231 | |
---|
[5317] | 232 | // appsched: |
---|
| 233 | int roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger); |
---|
| 234 | |
---|
[3297] | 235 | #endif |
---|
| 236 | |
---|
| 237 | //ll |
---|