source: roaraudio/include/libroar/roardl.h @ 5335:dba934a2d1e0

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

cleanup and updates to roardl API

File size: 13.4 KB
RevLine 
[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
[5335]100// general stuff:
[5275]101#define ROAR_DL_PLUGIN_ABORT_LOADING(err) roar_err_set((err)); return NULL
102#define ROAR_DL_PLUGIN_CHECK_VERSIONS(app,abi) if ( roar_dl_para_check_version(para, (app), (abi)) == -1 ) return NULL
[5335]103
104// register stuff:
[3363]105#define ROAR_DL_PLUGIN_REG(fn, funcptr) (lib.func[(fn)] = (funcptr))
[3360]106#define ROAR_DL_PLUGIN_REG_UNLOAD(func) (lib.unload = (func))
[5317]107#define ROAR_DL_PLUGIN_REG_APPSCHED(sched) (lib.appsched = (sched))
[5313]108#define ROAR_DL_PLUGIN_REG_GLOBAL_DATA(ptr,init) lib.global_data_len = sizeof((init)); \
109                                                 lib.global_data_init = &(init);       \
110                                                 lib.global_data_pointer = (void*)&(ptr)
[3314]111
[5335]112// meta data stuff:
113#define ROAR_DL_PLUGIN_META_PRODUCT(x)      (libname.libname     = (x))
114#define ROAR_DL_PLUGIN_META_PRODUCT_NV(name,vendor)      ROAR_DL_PLUGIN_META_PRODUCT(name " <" vendor ">")
115#define ROAR_DL_PLUGIN_META_PRODUCT_NIV(name,id,vendor)  ROAR_DL_PLUGIN_META_PRODUCT(name " <" #id "/" vendor ">")
116#define ROAR_DL_PLUGIN_META_VERSION(x)      (libname.libversion  = (x))
117#define ROAR_DL_PLUGIN_META_ABI(x)          (libname.abiversion  = (x))
118#define ROAR_DL_PLUGIN_META_DESC(x)         (libname.description = (x))
119#define ROAR_DL_PLUGIN_META_CONTACT(x)      (libname.contact = (x))
120#define ROAR_DL_PLUGIN_META_CONTACT_FL(first,last)        ROAR_DL_PLUGIN_META_CONTACT(first " " last)
121#define ROAR_DL_PLUGIN_META_CONTACT_FLE(first,last,email) ROAR_DL_PLUGIN_META_CONTACT(first " " last " <" email ">")
122#define ROAR_DL_PLUGIN_META_CONTACT_FLNE(first,last,nick,email) ROAR_DL_PLUGIN_META_CONTACT(first " \"" nick "\" " last " <" email ">")
123#define ROAR_DL_PLUGIN_META_AUTHORS(x)      (libname.authors = (x))
124#define ROAR_DL_PLUGIN_META_LICENSE(x)      (libname.license = (x))
125#define ROAR_DL_PLUGIN_META_LICENSE_TAG(x)  ROAR_DL_PLUGIN_META_LICENSE(ROAR_LICENSE_ ## x)
126
[5322]127enum roar_dl_loadercmd {
[5327]128 ROAR_DL_LOADER_NOOP = 0,
129 ROAR_DL_LOADER_PRELOAD,
130 ROAR_DL_LOADER_LOAD,
131 ROAR_DL_LOADER_POSTLOAD,
132 ROAR_DL_LOADER_PREUNLOAD,
133 ROAR_DL_LOADER_UNLOAD,
134 ROAR_DL_LOADER_POSTUNLOAD
[5322]135};
136
[5335]137struct roar_plugincontainer;
138
[3297]139struct roar_dl_librarypara {
[5275]140 int version;               // version of this struct type (must be ROAR_DL_LIBPARA_VERSION)
141 size_t len;                // Length of this struct type (must be sizeof(struct roar_dl_librarypara)
142
143 size_t refc;               // Reference counter.
144
145 size_t argc;               // number of elements in argv
146 struct roar_keyval * argv; // Parameter for the plugin
147 void * args_store;         // Storage area for argv's data.
148                            // If not NULL this and argv will be freed.
149                            // If NULL argv will be left untouched.
150
151 void * binargv;            // A pointer with binary data arguments.
152                            // This can be used to pass any non-string data to
153                            // the plugin. Normally this is NULL or the pointer
154                            // to a struct with members of whatever is needed.
155
156 const char * appname;      // application name in common format:
157                            // Product/Version <VendorID/VendorName> (comments)
158                            // Version and comment are optional and should be avoided.
159                            // When no vendor ID is registered use <VendorName>.
160                            // The VendorName MUST NOT contain a slash and SHOULD
161                            // be as unique as possible.
162                            // Examples: roard <0/RoarAudio>, MyAPP <myapp.org>,
163                            //           AnAPP <Musterman GbR>
164 const char * abiversion;   // The ABI version. For libraries this should be the SONAME.
165                            // For applications this should be the version of the release
166                            // which introduced the current ABI.
167                            // Examples: libroar2, 0.5.1
[5317]168 struct roar_notify_core * notifycore;
[5335]169 struct roar_plugincontainer * container;
170 int (*loader)(struct roar_dl_librarypara * lhandle, void * loader_userdata, enum roar_dl_loadercmd cmd, void * argp);
171 void * loader_userdata;
[5275]172};
173
174struct roar_dl_libraryname {
175 int      version;
176 size_t   len;
177 const char * name;        //Format: shortname
[5317]178 const char * libname;     //This is the same as appname in struct roar_dl_librarypara.
179                           //Format: Product <VendorID/VendorName> (comments)
180 const char * libversion;  //This is the pure version number of the library.
181 const char * abiversion;  //This is the same as abiversion in struct roar_dl_librarypara.
182                           //Format: Version
[5275]183 const char * description; //Free form.
184 const char * contact;     //Format: first ["']nick["'] last (comment) <email>/OpenPGPkey/Phone/Room
185 const char * authors;     //Other authors as free form.
186 const char * license;     //Format: LicenseName-Version (options)
187                           //Examples: GPL-3.0, LGPL-2.1, LGPL-3.0 (or later).
[3297]188};
189
[5317]190struct roar_dl_librarydep {
191 int      version;
192 size_t   len;
[5335]193 uint32_t flags;
[5317]194 const char * name;
195 const char * libname;
196 const char * abiversion;
197};
198
[3297]199struct roar_dl_libraryinst {
[3299]200 int      version;
201 size_t   len;
[3301]202 int    (*unload)(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
[3299]203 int    (*func[ROAR_DL_FN_MAX])(struct roar_dl_librarypara * para, struct roar_dl_libraryinst * lib);
[5275]204 struct roar_dl_libraryname * libname;
[5312]205 size_t  global_data_len;
206 void *  global_data_init;
207 void ** global_data_pointer;
[5317]208 struct roar_dl_librarydep * libdep;
209 size_t libdep_len;
210 struct roar_dl_appsched * appsched;
[3297]211};
212
[5313]213struct roar_dl_appsched {
[5317]214 int (*init)  (struct roar_dl_librarypara * para);
215 int (*free)  (struct roar_dl_librarypara * para);
216 int (*update)(struct roar_dl_librarypara * para);
[5335]217 int (*tick)  (struct roar_dl_librarypara * para);
218 int (*wait)  (struct roar_dl_librarypara * para);
[5317]219};
220
221enum roar_dl_appsched_trigger {
222 ROAR_DL_APPSCHED_INIT = 1,
223#define ROAR_DL_APPSCHED_INIT ROAR_DL_APPSCHED_INIT
224 ROAR_DL_APPSCHED_FREE,
225#define ROAR_DL_APPSCHED_FREE ROAR_DL_APPSCHED_FREE
[5335]226 ROAR_DL_APPSCHED_UPDATE,
[5317]227#define ROAR_DL_APPSCHED_UPDATE ROAR_DL_APPSCHED_UPDATE
[5335]228 ROAR_DL_APPSCHED_TICK,
229#define ROAR_DL_APPSCHED_TICK ROAR_DL_APPSCHED_TICK
230 ROAR_DL_APPSCHED_WAIT
231#define ROAR_DL_APPSCHED_WAIT ROAR_DL_APPSCHED_WAIT
[5313]232};
233
[5312]234// parameter functions:
[5275]235struct roar_dl_librarypara * roar_dl_para_new(const char * args, void * binargv,
236                                              const char * appname, const char * abiversion);
237int roar_dl_para_ref                    (struct roar_dl_librarypara * para);
238int roar_dl_para_unref                  (struct roar_dl_librarypara * para);
239int roar_dl_para_check_version          (struct roar_dl_librarypara * para,
240                                         const char * appname, const char * abiversion);
241
[5312]242// 'core' dynamic loader functions.
[5275]243struct roar_dl_lhandle * roar_dl_open   (const char * filename, int flags,
244                                         int ra_init, struct roar_dl_librarypara * para);
[5321]245int                      roar_dl_ref    (struct roar_dl_lhandle * lhandle);
246int                      roar_dl_unref  (struct roar_dl_lhandle * lhandle);
247#define roar_dl_close(x) roar_dl_unref((x))
[3301]248
[5275]249void                   * roar_dl_getsym (struct roar_dl_lhandle * lhandle, const char * sym, int type);
[3297]250
[5275]251int                      roar_dl_ra_init(struct roar_dl_lhandle * lhandle,
252                                         const char * prefix,
253                                         struct roar_dl_librarypara * para);
[3297]254
[5275]255const char *             roar_dl_errstr (struct roar_dl_lhandle * lhandle);
[3297]256
[5312]257// getting meta data:
[5275]258struct roar_dl_librarypara       * roar_dl_getpara(struct roar_dl_lhandle * lhandle);
259const struct roar_dl_libraryname * roar_dl_getlibname(struct roar_dl_lhandle * lhandle);
[3364]260
[5312]261// context switching:
262// _restore() is to switch from main to library context. _store() is to store library context
263// and switch back to main context.
264int                      roar_dl_context_restore(struct roar_dl_lhandle * lhandle);
265int                      roar_dl_context_store(struct roar_dl_lhandle * lhandle);
266
[5317]267// appsched:
268int                      roar_dl_appsched_trigger(struct roar_dl_lhandle * lhandle, enum roar_dl_appsched_trigger trigger);
269
[3297]270#endif
271
272//ll
Note: See TracBrowser for help on using the repository browser.