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