source: roaraudio/include/libroar/roardl.h @ 5511:e2207bedaf0e

Last change on this file since 5511:e2207bedaf0e was 5511:e2207bedaf0e, checked in by phi, 12 years ago

Added a way to register plugin parts with a universal API (Closes: #245)

File size: 18.3 KB
Line 
1//roardl.h:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2010-2012
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
53#define ROAR_DL_FN_DSTR                 0 /* VIO and DSTR drivers */
54#define ROAR_DL_FN_CDRIVER              1 /* Client drivers, libroareio */
55#define ROAR_DL_FN_TRANSCODER           2 /* Transcoder, libroardsp */
56#define ROAR_DL_FN_DRIVER               3 /* Driver, roard? */
57#define ROAR_DL_FN_SOURCE               4 /* Sources, roard? */
58#define ROAR_DL_FN_FILTER               5 /* Filter, libroardsp */
59#define ROAR_DL_FN_FF                   6 /* file format??? */
60#define ROAR_DL_FN_AUTH                 7 /* Auth */
61#define ROAR_DL_FN_BRIDGE               8 /* Bridges, roard? */
62#define ROAR_DL_FN_ROARDSCHED           9 /* Like appsched, but roard specific, old */
63#define ROAR_DL_FN_APPSCHED            10 /* AppSched, old interface */
64#define ROAR_DL_FN_PROTO               11 /* Protocols, roard? */
65#define ROAR_DL_FN_NOTIFY              12 /* ??? */
66#define ROAR_DL_FN_INIT                13 /* global plugin instance init. should be avoided */
67#define ROAR_DL_FN_REGFN               14 /* FN Registrations */
68#define ROAR_DL_FN_APPLICATION         15 /* Application specific stuff */
69//#define ROAR_DL_FN_               9
70#define ROAR_DL_FN_MAX                 24
71
72#define ROAR_DL_LIBPARA_VERSION         1
73#define ROAR_DL_LIBNAME_VERSION         0
74#define ROAR_DL_LIBINST_VERSION         1
75#define ROAR_DL_LIBDEP_VERSION          0
76
77#define ROAR_DL_PLUGIN(lib) struct roar_dl_libraryinst *                                          \
78                             _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para);  \
79                            struct roar_dl_libraryinst *                                          \
80                             _roaraudio_library_init(struct roar_dl_librarypara * para) {         \
81                              return _##lib##_roaraudio_library_init(para);                       \
82                            }                                                                     \
83                            struct roar_dl_libraryinst *                                          \
84                             _##lib##_roaraudio_library_init(struct roar_dl_librarypara * para)   \
85
86#define ROAR_DL_PLUGIN_START(xlib) ROAR_DL_PLUGIN(xlib) {                                         \
87                                     static int _inited = 0;                                      \
88                                     static struct roar_dl_libraryinst lib;                       \
89                                     static struct roar_dl_libraryname libname;                   \
90                                     (void)para;                                                  \
91                                     if ( _inited )                                               \
92                                      return &lib;                                                \
93                                     if ( para != NULL &&                                         \
94                                          (para->version != ROAR_DL_LIBPARA_VERSION ||            \
95                                           para->len < sizeof(struct roar_dl_librarypara)) ) {    \
96                                      roar_err_set(ROAR_ERROR_NSVERSION);                         \
97                                      return NULL;                                                \
98                                     }                                                            \
99                                     memset(&lib, 0, sizeof(lib));                                \
100                                     lib.version = ROAR_DL_LIBINST_VERSION;                       \
101                                     lib.len     = sizeof(lib);                                   \
102                                     memset(&libname, 0, sizeof(libname));                        \
103                                     libname.version = ROAR_DL_LIBNAME_VERSION;                   \
104                                     libname.len     = sizeof(libname);                           \
105                                     libname.name = #xlib;                                        \
106                                     lib.libname  = &libname;                                     \
107                                     do
108
109#define ROAR_DL_PLUGIN_END          while(0);                                                     \
110                                    _inited = 1;                                                  \
111                                    return &lib;                                                  \
112                                   }
113
114// general stuff:
115#define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL
116#define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) (((lib.host_appname = (app))    != NULL) | \
117                                                ((lib.host_abiversion = (abi)) != NULL) )
118// should we keep this macro at all? Is it helpfull at all?
119// if a plugin can handle multiple hosts it needs to call roar_dl_para_check_version() itself anyway.
120#define ROAR_DL_PLUGIN_CHECK_VERSIONS_NOW(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL
121
122// register stuff:
123#define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr))
124#define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func))
125#define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched))
126#define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \
127                                                 lib.global_data_init = &(init);       \
128                                                 lib.global_data_pointer = (void*)&(ptr)
129#define ROAR_DL_PLUGIN_REG_LIBDEP(deps) (((lib.libdep = (deps)) == NULL) ? \
130                                           (ssize_t)-1 : \
131                                           (ssize_t)(lib.libdep_len = sizeof((deps))/sizeof(struct roar_dl_librarydep)))
132
133// meta data stuff:
134#define ROAR_DL_PLUGIN_META_PRODUCT(x)      (libname.libname     = (x))
135#define ROAR_DL_PLUGIN_META_PRODUCT_NV(name,vendor)      ROAR_DL_PLUGIN_META_PRODUCT(name " <" vendor ">")
136#define ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor)  ROAR_DL_PLUGIN_META_PRODUCT(name " <" #id "/" vendor ">")
137#define ROAR_DL_PLUGIN_META_PRODUCT_NIV(name,id,vendor)  ROAR_DL_PLUGIN_META_PRODUCT_NIV_REAL(name,id,vendor)
138#define ROAR_DL_PLUGIN_META_VERSION(x)      (libname.libversion  = (x))
139#define ROAR_DL_PLUGIN_META_ABI(x)          (libname.abiversion  = (x))
140#define ROAR_DL_PLUGIN_META_DESC(x)         (libname.description = (x))
141#define ROAR_DL_PLUGIN_META_CONTACT(x)      (libname.contact = (x))
142#define ROAR_DL_PLUGIN_META_CONTACT_FL(first,last)        ROAR_DL_PLUGIN_META_CONTACT(first " " last)
143#define ROAR_DL_PLUGIN_META_CONTACT_FLE(first,last,email) ROAR_DL_PLUGIN_META_CONTACT(first " " last " <" email ">")
144#define ROAR_DL_PLUGIN_META_CONTACT_FLNE(first,last,nick,email) ROAR_DL_PLUGIN_META_CONTACT(first " \"" nick "\" " last " <" email ">")
145#define ROAR_DL_PLUGIN_META_AUTHORS(x)      (libname.authors = (x))
146#define ROAR_DL_PLUGIN_META_LICENSE(x)      (libname.license = (x))
147#define ROAR_DL_PLUGIN_META_LICENSE_TAG(x)  ROAR_DL_PLUGIN_META_LICENSE(ROAR_LICENSE_ ## x)
148
149enum roar_dl_loadercmd {
150 ROAR_DL_LOADER_NOOP = 0,
151 ROAR_DL_LOADER_PRELOAD,
152 ROAR_DL_LOADER_LOAD,
153 ROAR_DL_LOADER_POSTLOAD,
154 ROAR_DL_LOADER_PREUNLOAD,
155 ROAR_DL_LOADER_UNLOAD,
156 ROAR_DL_LOADER_POSTUNLOAD
157};
158
159struct roar_plugincontainer;
160
161struct roar_dl_librarypara {
162 int version;               // version of this struct type (must be ROAR_DL_LIBPARA_VERSION)
163 size_t len;                // Length of this struct type (must be sizeof(struct roar_dl_librarypara)
164
165 size_t refc;               // Reference counter.
166
167 size_t argc;               // number of elements in argv
168 struct roar_keyval * argv; // Parameter for the plugin
169 void * args_store;         // Storage area for argv's data.
170                            // If not NULL this and argv will be freed.
171                            // If NULL argv will be left untouched.
172
173 void * binargv;            // A pointer with binary data arguments.
174                            // This can be used to pass any non-string data to
175                            // the plugin. Normally this is NULL or the pointer
176                            // to a struct with members of whatever is needed.
177
178 const char * appname;      // application name in common format:
179                            // Product/Version <VendorID/VendorName> (comments)
180                            // Version and comment are optional and should be avoided.
181                            // When no vendor ID is registered use <VendorName>.
182                            // The VendorName MUST NOT contain a slash and SHOULD
183                            // be as unique as possible.
184                            // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>,
185                            //           AnAPP <Musterman GbR>
186 const char * abiversion;   // The ABI version. For libraries this should be the SONAME.
187                            // For applications this should be the version of the release
188                            // which introduced the current ABI.
189                            // Examples: libroar2, 0.5.1
190 struct roar_notify_core * notifycore;
191 struct roar_plugincontainer * container;
192 int (*loader)(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp);
193 void * loader_userdata;
194};
195
196struct roar_dl_libraryname {
197 int      version;
198 size_t   len;
199 const char * name;        //Format: shortname
200 const char * libname;     //This is the same as appname in struct roar_dl_librarypara.
201                           //Format: Product <VendorID/VendorName> (comments)
202 const char * libversion;  //This is the pure version number of the library.
203 const char * abiversion;  //This is the same as abiversion in struct roar_dl_librarypara.
204                           //Format: Version
205 const char * description; //Free form.
206 const char * contact;     //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room
207 const char * authors;     //Other authors as free form.
208 const char * license;     //Format: LicenseName-Version (options)
209                           //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later).
210};
211
212struct roar_dl_librarydep {
213 int      version;
214 size_t   len;
215 uint32_t flags;
216 const char * name;
217 const char * libname;
218 const char * abiversion;
219};
220
221#define ROAR_DL_DEP(__flags,__name,__libname,__abiversion) \
222                                                   {.version    = ROAR_DL_LIBDEP_VERSION,            \
223                                                    .len        = sizeof(struct roar_dl_librarydep), \
224                                                    .flags      = __flags,                           \
225                                                    .name       = __name,                            \
226                                                    .libname    = __libname,                         \
227                                                    .abiversion = __abiversion}
228
229struct roar_dl_libraryinst {
230 int      version;
231 size_t   len;
232 int    (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
233 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
234 struct roar_dl_libraryname * libname;
235 size_t  global_data_len;
236 void *  global_data_init;
237 void ** global_data_pointer;
238 struct roar_dl_librarydep * libdep;
239 size_t libdep_len;
240 struct roar_dl_appsched * appsched;
241 const char * host_appname;
242 const char * host_abiversion;
243};
244
245struct roar_dl_appsched {
246 int (*init)  (struct roar_dl_librarypara * para);
247 int (*free)  (struct roar_dl_librarypara * para);
248 int (*update)(struct roar_dl_librarypara * para);
249 int (*tick)  (struct roar_dl_librarypara * para);
250 int (*wait)  (struct roar_dl_librarypara * para);
251};
252
253enum roar_dl_appsched_trigger {
254 ROAR_DL_APPSCHED_INIT = 1,
255#define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT
256 ROAR_DL_APPSCHED_FREE,
257#define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE
258 ROAR_DL_APPSCHED_UPDATE,
259#define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE
260 ROAR_DL_APPSCHED_TICK,
261#define ROAR_DL_APPSCHED_TICK ROAR_DL_APPSCHED_TICK
262 ROAR_DL_APPSCHED_WAIT
263#define ROAR_DL_APPSCHED_WAIT ROAR_DL_APPSCHED_WAIT
264};
265
266// parameter functions:
267struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv,
268                                              const char * appname, const char * abiversion);
269int roar_dl_para_ref                    (struct roar_dl_librarypara * para);
270int roar_dl_para_unref                  (struct roar_dl_librarypara * para);
271int roar_dl_para_check_version          (struct roar_dl_librarypara * para,
272                                         const char * appname, const char * abiversion);
273
274// 'core' dynamic loader functions.
275struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags,
276                                         int ra_init, struct roar_dl_librarypara * para);
277int                      roar_dl_ref    (struct roar_dl_lhandle * lhandle);
278int                      roar_dl_unref  (struct roar_dl_lhandle * lhandle);
279#define roar_dl_close(x) roar_dl_unref((x))
280
281void                   * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type);
282
283int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle,
284                                         const char * prefix,
285                                         struct roar_dl_librarypara * para);
286
287const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle);
288
289// getting meta data:
290struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle);
291const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle);
292
293// context switching:
294// _restore() is to switch from main to library context. _store() is to store library context
295// and switch back to main context.
296int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle);
297int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle);
298
299// appsched:
300int                      roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger);
301
302// FN Registration:
303
304// Actions objects can emit:
305enum roar_dl_fnreg_action {
306 ROAR_DL_FNREG   = 1, // The object is been registered
307 ROAR_DL_FNUNREG = 2  // The object is been unregistered
308};
309
310// Callback for registering/unregistering objects:
311struct roar_dl_fnreg {
312 int fn;          // Filter: The FN of the registering object or -1 for any.
313 int subtype;     // Filter: The subtype of the registering object or -1 for any.
314 int version;     // Filter: The version of the registering object or -1 for any.
315 int (*callback)( // Callback to call on register/unregister.
316   enum roar_dl_fnreg_action action, // The action happening
317   int fn,                           // The FN of the object
318   int subtype,                      // The subtype of the object
319   const void * object,              // Pointer to the object
320   size_t objectlen,                 // Length of the object
321   int version,                      // Version of the object
322   int options,                      // Object Options.
323   void * userdata,                  // User data for the callback.
324   struct roar_dl_lhandle * lhandle  // The registering handle.
325                                     // This is valid until the object is unregistered.
326                                     // Only roar_dl_context_restore() and roar_dl_context_store()
327                                     // may be used on this object. Result of all other functions
328                                     // is undefined.
329 );
330 void * userdata; // The user data pointer passed to the callback.
331};
332
333// Parameters for FNREG registration:
334#define ROAR_DL_FNREG_SUBTYPE  0
335#define ROAR_DL_FNREG_VERSION  0
336#define ROAR_DL_FNREG_SIZE     sizeof(struct roar_dl_fnreg)
337
338
339// Reg FN:
340
341// Options:
342#define ROAR_DL_FNREG_OPT_NONE 0   /* no options */
343
344// Register an FN.
345int                      roar_dl_register_fn(struct roar_dl_lhandle * lhandle, int fn, int subtype, const void * object, size_t objectlen, int version, int options);
346
347// Unregister FN for the given plugin.
348// This should not be called directly and is called internally when needed.
349int                      roar_dl_unregister_fn(struct roar_dl_lhandle * lhandle);
350
351#endif
352
353//ll
Note: See TracBrowser for help on using the repository browser.