source: roaraudio/include/libroar/roardl.h @ 5770:b3577113c65e

Last change on this file since 5770:b3577113c65e was 5770:b3577113c65e, checked in by phi, 11 years ago

support unregging FN Regs without unregging all FN Regs of current lhandle

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