source: roaraudio/include/libroar/roardl.h @ 5505:a39728598a5f

Last change on this file since 5505:a39728598a5f was 5501:fc2e83547f0d, checked in by phi, 12 years ago

ROAR_DL_PLUGIN_START() now checks para structure (Closes: #236)

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